From 387ee226fb24d68d277bcefbc8c01a72c57468ba Mon Sep 17 00:00:00 2001 From: James Souter Date: Tue, 11 Jun 2024 15:11:47 +0100 Subject: [PATCH] rework option_config_items --- .../eiger_detector/control/eiger_detector.py | 20 ++++++++----------- .../eiger_detector/control/eiger_options.py | 17 +++++----------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/python/src/eiger_detector/control/eiger_detector.py b/python/src/eiger_detector/control/eiger_detector.py index 9e049a6..815fec3 100644 --- a/python/src/eiger_detector/control/eiger_detector.py +++ b/python/src/eiger_detector/control/eiger_detector.py @@ -14,7 +14,7 @@ import zmq from odin.adapters.parameter_tree import ParameterAccessor, ParameterTree -from .eiger_options import option_config_items, option_config_options +from .eiger_options import option_config_options class EigerDetector(object): @@ -440,7 +440,7 @@ def set(self, path, value): return self.hv_reset_detector() else: # mbbi record will send integers; change to string - if any(option == path.split("/")[-1] for option in option_config_items): + if any(option == path.split("/")[-1] for option in option_config_options): value = str(value) return self._params.set(path, value) @@ -454,8 +454,7 @@ def set_mode(self, mode_type, value): logging.info("Setting {} mode to {}".format(mode_type, value)) # Intercept integer values and convert to string values where # option not index is expected - if any(option == "mode" for option in option_config_items): - value = option_config_options["mode"].get_option(value) + value = option_config_options["mode"].get_option(value) if mode_type == self.STR_STREAM: response = self.write_stream_config('mode', value) param = self.read_stream_config('mode') @@ -474,7 +473,7 @@ def set_value(self, item, value): logging.info("Setting {} to {}".format(item, value)) # Intercept integer values and convert to string values where # option not index is expected - if any(option == item for option in option_config_items): + if any(option == item for option in option_config_options): value = option_config_options[item].get_option(value) # First write the value to the hardware if item in self.DETECTOR_CONFIG: @@ -520,12 +519,9 @@ def parse_response(self, response, item): def get_meta(self, item): # Populate any meta data items and return the dict meta = {} - if 'min' in item: - meta['min'] = item['min'] - if 'max' in item: - meta['max'] = item['max'] - if 'allowed_values' in item: - meta['allowed_values'] = item['allowed_values'] + for field in ['min', 'max', 'allowed_values']: + if field in item: + meta[field] = item[field] if 'unit' in item: meta['units'] = item['unit'] return meta @@ -673,7 +669,7 @@ def read_detector_live_image(self): def intercept_reply(self, item, reply): # Intercept detector config for options where we convert to index for # unamabiguous definition and update config to allow these - if any(option == item for option in option_config_items): + if any(option == item for option in option_config_options): # Inconsitency over mapping of index to string # communication via integer, uniquely converted to mapping as defined in eiger_options value = reply[u'value'] diff --git a/python/src/eiger_detector/control/eiger_options.py b/python/src/eiger_detector/control/eiger_options.py index 1a8517e..d1dd59c 100644 --- a/python/src/eiger_detector/control/eiger_options.py +++ b/python/src/eiger_detector/control/eiger_options.py @@ -1,26 +1,19 @@ class EigerOption(object): def __init__(self, options): - self.options = options def get_allowed_values(self): - - return list(map(str, range(0, len(self.options)))) + return list(map(str, range(len(self.options)))) def get_option(self, idx): - return self.options[int(idx)] def get_index(self, val): - return str(self.options.index(val)) -trigger_options = EigerOption(['ints', 'inte', 'exts', 'exte']) -compression_options = EigerOption(['lz4', 'bslz4']) -header_options = EigerOption(['all', 'basic', 'none']) -mode_options = EigerOption(['disabled', 'enabled']) - -option_config_items = ['compression', 'trigger_mode', 'header_detail', 'mode'] -option_config_options = {'compression': compression_options, 'trigger_mode': trigger_options, 'header_detail': header_options, 'mode': mode_options} +option_config_options = {'compression': EigerOption(['lz4', 'bslz4']), + 'trigger_mode': EigerOption(['ints', 'inte', 'exts', 'exte']), + 'header_detail': EigerOption(['all', 'basic', 'none']), + 'mode': EigerOption(['disabled', 'enabled'])}