Skip to content

Commit

Permalink
Merge pull request #329 from odin-detector/optional-fr-adapter
Browse files Browse the repository at this point in the history
Make fr adapter optional in fp adapter
  • Loading branch information
GDYendell authored Jan 15, 2024
2 parents d9dabb8 + 5b2ccef commit 1ee7ff1
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions python/src/odin_data/control/frame_processor_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from odin_data.control.odin_data_adapter import OdinDataAdapter

FP_ADAPTER_KEY = 'fr_adapter_name'
FP_DEFAULT_ADAPTER_KEY = 'fr'
PCT_BUFFER_FREE_KEY = 'buffer_threshold'

def bool_from_string(value):
Expand Down Expand Up @@ -45,10 +44,7 @@ def __init__(self, **kwargs):
logging.debug("FPA init called")
super(FrameProcessorAdapter, self).__init__(**kwargs)

self._fr_adapter_name = FP_DEFAULT_ADAPTER_KEY
if FP_ADAPTER_KEY in kwargs:
self._fr_adapter_name = kwargs[FP_ADAPTER_KEY]

self._fr_adapter_name = kwargs.get(FP_ADAPTER_KEY, None)
self._fr_adapter = None

# Set the bufer threshold check, default to 0.0 (no check) if the option
Expand All @@ -73,11 +69,18 @@ def initialize(self, adapters):
"""Initialize the adapter after it has been loaded.
Find and record the FR adapter for later error checks
"""
if self._fr_adapter_name in adapters:
self._fr_adapter = adapters[self._fr_adapter_name]
logging.info("FP adapter initiated connection to FR adapter: {}".format(self._fr_adapter_name))
else:
logging.error("FP adapter could not connect to the FR adapter: {}".format(self._fr_adapter_name))
if self._fr_adapter_name is None:
return

if self._fr_adapter_name not in adapters:
raise ValueError(
"Given FR adapter name '{}', but it is not in the loaded adapters {}".format(
self._fr_adapter_name, adapters
)
)

self._fr_adapter = adapters[self._fr_adapter_name]
logging.info("FP adapter initiated connection to FR adapter: {}".format(self._fr_adapter_name))

@request_types('application/json', 'application/vnd.odin-native')
@response_types('application/json', default='application/json')
Expand Down Expand Up @@ -151,10 +154,11 @@ def put(self, path, request): # pylint: disable=W0613
if write:
# Before attempting to write files, make some simple error checks

# Check if we have a valid buffer status from the FR adapter
valid, reason = self.check_fr_status()
if not valid:
raise RuntimeError(reason)
if self._fr_adapter is not None:
# Check if we have a valid buffer status from the FR adapter
valid, reason = self.check_fr_status()
if not valid:
raise RuntimeError(reason)

# Check the file path is valid
if not os.path.isdir(str(self._param['config/hdf/file/path'])):
Expand Down

0 comments on commit 1ee7ff1

Please sign in to comment.