Skip to content

Commit

Permalink
rework option_config_items
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouter committed Jun 12, 2024
1 parent c594177 commit 387ee22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
20 changes: 8 additions & 12 deletions python/src/eiger_detector/control/eiger_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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')
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
17 changes: 5 additions & 12 deletions python/src/eiger_detector/control/eiger_options.py
Original file line number Diff line number Diff line change
@@ -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'])}

0 comments on commit 387ee22

Please sign in to comment.