mirror of
https://github.com/paulscherrerinstitute/sf_daq_broker.git
synced 2026-08-31 10:50:45 +02:00
split file
This commit is contained in:
@@ -5,7 +5,7 @@ from datetime import datetime
|
||||
from shutil import copyfile
|
||||
|
||||
from sf_daq_broker import config
|
||||
from sf_daq_broker.detector.detector_config import configured_detectors_for_beamline, detector_human_names, get_streamvis_address
|
||||
from sf_daq_broker.detector.utils import configured_detectors_for_beamline, detector_human_names, get_streamvis_address
|
||||
from sf_daq_broker.rabbitmq import broker_config
|
||||
from sf_daq_broker.utils import get_writer_request, get_beamline, json_save, json_load
|
||||
from . import validate
|
||||
|
||||
@@ -9,7 +9,7 @@ import epics
|
||||
from slsdet import Jungfrau, gainMode
|
||||
from slsdet.enums import detectorSettings
|
||||
|
||||
from sf_daq_broker.detector.detector_config import configured_detectors_for_beamline
|
||||
from sf_daq_broker.detector.utils import configured_detectors_for_beamline
|
||||
from sf_daq_broker.detector.power_on_detector import beamline_event_code
|
||||
from sf_daq_broker.utils import get_beamline, json_save, json_load
|
||||
from . import validate
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import logging
|
||||
|
||||
from .detector_config import _detector_daq, DetectorConfig
|
||||
|
||||
|
||||
_logger = logging.getLogger("broker_writer")
|
||||
|
||||
|
||||
|
||||
def compare_buffer_config_file_all(overwrite_config=False):
|
||||
for detector_name in _detector_daq:
|
||||
compare_buffer_config_file(detector_name, overwrite_config)
|
||||
|
||||
|
||||
def compare_buffer_config_file(detector_name=None, overwrite_config=False):
|
||||
import os
|
||||
from sf_daq_broker.utils import json_save, json_load
|
||||
|
||||
detector_configuration = DetectorConfig(detector_name)
|
||||
if not detector_configuration.is_configuration_present():
|
||||
_logger.error(f"{detector_name}: No detector configuration present")
|
||||
return
|
||||
|
||||
config_file = f"/gpfs/photonics/swissfel/buffer/config/{detector_name}.json"
|
||||
|
||||
if not os.path.exists(config_file):
|
||||
_logger.error(f"{config_file} for {detector_name} does not exist")
|
||||
return
|
||||
|
||||
parameters_file = json_load(config_file)
|
||||
|
||||
parameters_current = {
|
||||
"detector_name": detector_configuration.get_detector_name(),
|
||||
"n_modules": detector_configuration.get_number_modules(),
|
||||
"streamvis_stream": f"tcp://{detector_configuration.get_detector_daq_public_ip()}:{detector_configuration.get_detector_daq_public_port()}",
|
||||
"live_stream": f"tcp://{detector_configuration.get_detector_daq_data_ip()}:{detector_configuration.get_detector_daq_data_port()}",
|
||||
"start_udp_port": detector_configuration.get_detector_port_first_module(),
|
||||
"buffer_folder": f"/gpfs/photonics/swissfel/buffer/{detector_name}"
|
||||
}
|
||||
|
||||
need_change = False
|
||||
for p in parameters_current:
|
||||
if p not in parameters_file:
|
||||
_logger.error(f"{detector_name}: parameter {p} is not present in buffer configuration file")
|
||||
need_change = True
|
||||
continue
|
||||
if parameters_current[p] != parameters_file[p]:
|
||||
_logger.error(f"{detector_name}: parameter {p} different in current configuration {parameters_current[p]} compared to config file {parameters_file[p]}")
|
||||
need_change = True
|
||||
|
||||
if need_change:
|
||||
_logger.warning(f"{detector_name}: buffer config file need a change")
|
||||
if overwrite_config:
|
||||
_logger.warning(f"{detector_name}: config file will be overwritten")
|
||||
parameters_file.update(parameters_current)
|
||||
json_save(parameters_file, config_file)
|
||||
|
||||
|
||||
|
||||
@@ -225,84 +225,6 @@ _detector_temp_threshold = {
|
||||
|
||||
|
||||
|
||||
def detector_human_names():
|
||||
return _detector_names
|
||||
|
||||
|
||||
def get_streamvis_address():
|
||||
address = {}
|
||||
for d in _detector_daq:
|
||||
detector_number = int(d[2:4])
|
||||
daq = _detector_daq[d]["daq"]
|
||||
address[d] = f"sf-daq-{daq}:{5000 + detector_number}"
|
||||
return address
|
||||
|
||||
|
||||
def configured_detectors_for_beamline(beamline=None):
|
||||
detectors = []
|
||||
if beamline is None:
|
||||
return detectors
|
||||
|
||||
for detector_name in _detector_daq:
|
||||
daq = _detector_daq[detector_name]["daq"]
|
||||
port = _detector_daq[detector_name]["port"]
|
||||
if daq in _daq_beamline and port in _daq_beamline[daq]:
|
||||
if _daq_beamline[daq][port] == beamline:
|
||||
detectors.append(detector_name)
|
||||
|
||||
return detectors
|
||||
|
||||
|
||||
def compare_buffer_config_file_all(overwrite_config=False):
|
||||
for detector_name in _detector_daq:
|
||||
compare_buffer_config_file(detector_name, overwrite_config)
|
||||
|
||||
|
||||
def compare_buffer_config_file(detector_name=None, overwrite_config=False):
|
||||
import os
|
||||
from sf_daq_broker.utils import json_save, json_load
|
||||
|
||||
detector_configuration = DetectorConfig(detector_name)
|
||||
if not detector_configuration.is_configuration_present():
|
||||
_logger.error(f"{detector_name}: No detector configuration present")
|
||||
return
|
||||
|
||||
config_file = f"/gpfs/photonics/swissfel/buffer/config/{detector_name}.json"
|
||||
|
||||
if not os.path.exists(config_file):
|
||||
_logger.error(f"{config_file} for {detector_name} does not exist")
|
||||
return
|
||||
|
||||
parameters_file = json_load(config_file)
|
||||
|
||||
parameters_current = {
|
||||
"detector_name": detector_configuration.get_detector_name(),
|
||||
"n_modules": detector_configuration.get_number_modules(),
|
||||
"streamvis_stream": f"tcp://{detector_configuration.get_detector_daq_public_ip()}:{detector_configuration.get_detector_daq_public_port()}",
|
||||
"live_stream": f"tcp://{detector_configuration.get_detector_daq_data_ip()}:{detector_configuration.get_detector_daq_data_port()}",
|
||||
"start_udp_port": detector_configuration.get_detector_port_first_module(),
|
||||
"buffer_folder": f"/gpfs/photonics/swissfel/buffer/{detector_name}"
|
||||
}
|
||||
|
||||
need_change = False
|
||||
for p in parameters_current:
|
||||
if p not in parameters_file:
|
||||
_logger.error(f"{detector_name}: parameter {p} is not present in buffer configuration file")
|
||||
need_change = True
|
||||
continue
|
||||
if parameters_current[p] != parameters_file[p]:
|
||||
_logger.error(f"{detector_name}: parameter {p} different in current configuration {parameters_current[p]} compared to config file {parameters_file[p]}")
|
||||
need_change = True
|
||||
|
||||
if need_change:
|
||||
_logger.warning(f"{detector_name}: buffer config file need a change")
|
||||
if overwrite_config:
|
||||
_logger.warning(f"{detector_name}: config file will be overwritten")
|
||||
parameters_file.update(parameters_current)
|
||||
json_save(parameters_file, config_file)
|
||||
|
||||
|
||||
|
||||
class DetectorConfig():
|
||||
|
||||
def __init__(self, detector_name=None):
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from .detector_config import _daq_beamline, _detector_daq, _detector_names
|
||||
|
||||
|
||||
def detector_human_names():
|
||||
return _detector_names
|
||||
|
||||
|
||||
def get_streamvis_address():
|
||||
address = {}
|
||||
for d in _detector_daq:
|
||||
detector_number = int(d[2:4])
|
||||
daq = _detector_daq[d]["daq"]
|
||||
address[d] = f"sf-daq-{daq}:{5000 + detector_number}"
|
||||
return address
|
||||
|
||||
|
||||
def configured_detectors_for_beamline(beamline=None):
|
||||
detectors = []
|
||||
if beamline is None:
|
||||
return detectors
|
||||
|
||||
for detector_name in _detector_daq:
|
||||
daq = _detector_daq[detector_name]["daq"]
|
||||
port = _detector_daq[detector_name]["port"]
|
||||
if daq in _daq_beamline and port in _daq_beamline[daq]:
|
||||
if _daq_beamline[daq][port] == beamline:
|
||||
detectors.append(detector_name)
|
||||
|
||||
return detectors
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user