From 5fdab3e2d69c8aa880cb8ee7dcd15d798afb8456 Mon Sep 17 00:00:00 2001 From: NichtJens Date: Fri, 10 Oct 2025 17:15:00 +0200 Subject: [PATCH] use parse_det_name --- sf_daq_broker/broker_manager.py | 4 ++-- sf_daq_broker/broker_manager_slow.py | 4 ++-- sf_daq_broker/detector/debugger.py | 9 +++------ sf_daq_broker/detector/detector.py | 4 ++-- sf_daq_broker/detector/detector_config.py | 8 ++++---- sf_daq_broker/detector/utils.py | 3 ++- sf_daq_broker/writer/detector_writer.py | 4 ++-- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/sf_daq_broker/broker_manager.py b/sf_daq_broker/broker_manager.py index 6350485..ff9c385 100644 --- a/sf_daq_broker/broker_manager.py +++ b/sf_daq_broker/broker_manager.py @@ -7,7 +7,7 @@ from sf_daq_broker import config from sf_daq_broker.detector.utils import get_configured_detectors, get_streamvis_address from sf_daq_broker.detector.detector_config import DETECTOR_DESC from sf_daq_broker.rabbitmq import broker_config -from sf_daq_broker.utils import get_writer_request, get_beamline, json_save, json_load, dueto +from sf_daq_broker.utils import get_writer_request, get_beamline, json_save, json_load, dueto, parse_det_name from . import validate @@ -172,7 +172,7 @@ class BrokerManager: limping_detectors = {} for detector in allowed_detectors_beamline: - n_modules = int(detector[5:7]) + n_modules = parse_det_name(detector).T running_modules = [] missing_modules = [] diff --git a/sf_daq_broker/broker_manager_slow.py b/sf_daq_broker/broker_manager_slow.py index fb9b3e1..6d6c79f 100644 --- a/sf_daq_broker/broker_manager_slow.py +++ b/sf_daq_broker/broker_manager_slow.py @@ -8,7 +8,7 @@ from sf_daq_broker.detector.jfctrl import JFCtrl from sf_daq_broker.detector.detector import Detector from sf_daq_broker.detector.trigger import Trigger from sf_daq_broker.detector.utils import get_configured_detectors -from sf_daq_broker.utils import get_beamline, json_save, json_load, dueto +from sf_daq_broker.utils import get_beamline, json_save, json_load, dueto, parse_det_name from . import validate @@ -29,7 +29,7 @@ class DetectorManager: def get_jfctrl_monitor(self, request, remote_ip): detector_name = get_validated_detector_name(request, remote_ip) - detector_number = int(detector_name[2:4]) + detector_number = parse_det_name(detector_name).N jfctrl = JFCtrl(detector_number) parameters = jfctrl.get_monitor() diff --git a/sf_daq_broker/detector/debugger.py b/sf_daq_broker/detector/debugger.py index 4b249a3..5649e45 100644 --- a/sf_daq_broker/detector/debugger.py +++ b/sf_daq_broker/detector/debugger.py @@ -1,6 +1,6 @@ from collections import defaultdict -from sf_daq_broker.utils import typename +from sf_daq_broker.utils import typename, parse_det_name from .detector_config import DETECTOR_NAMES, DetectorConfig from .detector import Detector @@ -52,7 +52,7 @@ def parse_name(name): if name not in DETECTOR_NAMES: printable_detector_names = mk_printable(DETECTOR_NAMES) raise ValueError(f"detector name {name} unknown -- choose from: {printable_detector_names}") - ID = name_to_ID(name) + ID = parse_det_name(name).N return ID, name def parse_ID(ID): @@ -70,14 +70,11 @@ def parse_ID(ID): def mk_mapping(): detector_ID_to_name = defaultdict(list) for n in DETECTOR_NAMES: - ID = name_to_ID(n) + ID = parse_det_name(n).N detector_ID_to_name[ID].append(n) detector_ID_to_name = dict(detector_ID_to_name) return detector_ID_to_name -def name_to_ID(n): - return int(n[2:4]) - def mk_printable(seq): return ", ".join(repr(i) for i in sorted(seq)) diff --git a/sf_daq_broker/detector/detector.py b/sf_daq_broker/detector/detector.py index b5000e9..cc835dc 100644 --- a/sf_daq_broker/detector/detector.py +++ b/sf_daq_broker/detector/detector.py @@ -4,7 +4,7 @@ from .slsdetcompat import Jungfrau, detectorSettings, gainMode, pedestalParamete from sf_daq_broker.detector.detector_config import DETECTOR_NAMES, DetectorConfig from sf_daq_broker.errors import DetectorError, ValidationError -from sf_daq_broker.utils import ping_many +from sf_daq_broker.utils import ping_many, parse_det_name def invert_dict(d): @@ -35,7 +35,7 @@ class Detector: def __init__(self, name): validate_detector_name(name) self.name = name - self.ID = int(name[2:4]) + self.ID = parse_det_name(name).N self.load_config() self.connect() diff --git a/sf_daq_broker/detector/detector_config.py b/sf_daq_broker/detector/detector_config.py index 7c036b9..b14b40b 100644 --- a/sf_daq_broker/detector/detector_config.py +++ b/sf_daq_broker/detector/detector_config.py @@ -1,4 +1,4 @@ -from sf_daq_broker.utils import json_load +from sf_daq_broker.utils import json_load, parse_det_name from .detector_consts import BEAMLINE_DELAY, BEAMLINE_VLAN, DAQ_BEAMLINE, DAQ_MAC, DETECTOR_DAQ, DETECTOR_HOSTNAME, DETECTOR_TEMP_THRESHOLD, DETECTOR_TEMP_THRESHOLD_DEFAULT, DETECTOR_TXDELAY_FRAME @@ -8,7 +8,7 @@ def make_udp_srcip(detectors, start=0): res = {} for det in detectors: res[det] = index - nmods = int(det[5:7]) + nmods = parse_det_name(det).T index += nmods if index > 256: raise ValueError(f"index {index} needed for {det} is outside the allowed range (<256)") @@ -101,10 +101,10 @@ class DetectorConfig(): # return self.name def get_number(self): - return int(self.name[2:4]) + return parse_det_name(self.name).N def get_number_modules(self): - return int(self.name[5:7]) + return parse_det_name(self.name).T def get_detsize(self): return [1024, self.get_number_modules()*512] diff --git a/sf_daq_broker/detector/utils.py b/sf_daq_broker/detector/utils.py index fe32fcf..23e8021 100644 --- a/sf_daq_broker/detector/utils.py +++ b/sf_daq_broker/detector/utils.py @@ -1,10 +1,11 @@ +from sf_daq_broker.utils import parse_det_name from .detector_config import DAQ_BEAMLINE, DETECTOR_DAQ def get_streamvis_address(): address = {} for d in DETECTOR_DAQ: - detector_number = int(d[2:4]) + detector_number = parse_det_name(d).N daq = DETECTOR_DAQ[d]["daq"] address[d] = f"sf-daq-{daq}:{5000 + detector_number}" return address diff --git a/sf_daq_broker/writer/detector_writer.py b/sf_daq_broker/writer/detector_writer.py index 3d786d0..934a4f5 100644 --- a/sf_daq_broker/writer/detector_writer.py +++ b/sf_daq_broker/writer/detector_writer.py @@ -12,7 +12,7 @@ import numpy as np from sf_daq_broker.detector.make_crystfel_list import make_crystfel_list from sf_daq_broker.detector.store_dap_info import store_dap_info from sf_daq_broker.writer.convert_file import convert_file -from sf_daq_broker.utils import json_save, json_load +from sf_daq_broker.utils import json_save, json_load, parse_det_name _logger = logging.getLogger("broker_writer") @@ -94,7 +94,7 @@ def detector_retrieve(request, output_file_detector): else: raw_file_name = output_file_detector - number_modules = int(detector_name[5:7]) + number_modules = parse_det_name(detector_name).T command_retrieve_from_buffer = ( "/home/dbe/bin/sf_writer",