Skip to content

Commit

Permalink
Rename option_config_items and do not cast their values to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouter committed Sep 11, 2024
1 parent b0a569b commit 33fb5a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
22 changes: 9 additions & 13 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_options
from .eiger_options import eiger_config_options


class EigerDetector(object):
Expand Down Expand Up @@ -484,11 +484,7 @@ def set(self, path, value):
return self.initialize_detector()
elif path == 'command/hv_reset':
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_options):
value = str(value)
return self._params.set(path, value)
return self._params.set(path, value)

def get_value(self, item):
# Check if the item has a value field. If it does then return it
Expand All @@ -500,7 +496,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
value = option_config_options["mode"].get_option(value)
value = eiger_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 @@ -519,8 +515,8 @@ 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_options):
value = option_config_options[item].get_option(value)
if any(option == item for option in eiger_config_options):
value = eiger_config_options[item].get_option(value)
# First write the value to the hardware
if item in self.DETECTOR_CONFIG:
response = self.write_detector_config(item, value)
Expand Down Expand Up @@ -730,12 +726,12 @@ 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_options):
if any(option == item for option in eiger_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']
reply[u'value'] = option_config_options[item].get_index(value)
reply[u'allowed_values'] = option_config_options[item].get_allowed_values()
reply[u'value'] = eiger_config_options[item].get_index(value)
reply[u'allowed_values'] = eiger_config_options[item].get_allowed_values()
return reply

def arm_detector(self):
Expand Down Expand Up @@ -803,7 +799,7 @@ def has_stale_parameters(self):

def get_trigger_mode(self):
trigger_idx = self.get_value(self.trigger_mode)
return option_config_options['trigger_mode'].get_option(trigger_idx)
return eiger_config_options['trigger_mode'].get_option(trigger_idx)

def start_acquisition(self):
# Perform the start sequence
Expand Down
6 changes: 3 additions & 3 deletions python/src/eiger_detector/control/eiger_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ def __init__(self, options):
self.options = options

def get_allowed_values(self):
return list(map(str, range(len(self.options))))
return list(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))
return self.options.index(val)


option_config_options = {'compression': EigerOption(['lz4', 'bslz4']),
eiger_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 33fb5a0

Please sign in to comment.