diff --git a/src/cal_tools/calcat_interface.py b/src/cal_tools/calcat_interface.py index 11c35042dbb9a2d1600bf169bc7a5f3f15cad43c..ab369a8b85d985137e0102e6e6a60f41e087d49a 100644 --- a/src/cal_tools/calcat_interface.py +++ b/src/cal_tools/calcat_interface.py @@ -1,9 +1,6 @@ """Interfaces to calibration constant data.""" -import re -import socket from datetime import date, datetime, time, timezone from functools import lru_cache -from os import getenv from pathlib import Path from weakref import WeakKeyDictionary @@ -367,6 +364,7 @@ class CalibrationData: calibrations = set() default_client = None + _default_caldb_root = ... def __init__( self, @@ -375,6 +373,7 @@ class CalibrationData: client=None, event_at=None, module_naming="da", + caldb_root=None, ): """Initialize a new CalibrationData object. @@ -397,6 +396,8 @@ class CalibrationData: integers in karabo_da. `qm`: QxMx naming convention is used. Virtual names for AGIPD, DSSC, and LPD. + caldb_root (str or None): Path to the root directory for caldb + files, finds folder for production caldb by default. **condition_params: Operating condition parameters defined on an instance level. """ @@ -406,6 +407,10 @@ class CalibrationData: self.event_at = event_at self.pdu_snapshot_at = event_at self.module_naming = module_naming + if caldb_root is None: + self.caldb_root = self._get_default_caldb_root() + else: + self.caldb_root = Path(caldb_root) if client is None: @@ -486,29 +491,19 @@ class CalibrationData: ) return CalibrationData.default_client - @property - def caldb_root(self): - """Root directory for calibration constant data. - - Returns: - (Path or None) Location of caldb store or - None if not available. - """ - - if not hasattr(CalibrationData, "_caldb_root"): - if getenv("SASE"): - # ONC - CalibrationData._caldb_root = Path("/common/cal/caldb_store") - elif re.match(r"^max-(.+)\.desy\.de$", socket.getfqdn()): - # Maxwell - CalibrationData._caldb_root = Path( - "/gpfs/exfel/d/cal/caldb_store" - ) + @staticmethod + def _get_default_caldb_root(): + if CalibrationData._default_caldb_root is ...: + onc_path = Path("/common/cal/caldb_store") + maxwell_path = Path("/gpfs/exfel/d/cal/caldb_store") + if onc_path.is_dir(): + CalibrationData._default_caldb_root = onc_path + elif maxwell_path.is_dir(): + CalibrationData._default_caldb_root = maxwell_path else: - # Probably unavailable - CalibrationData._caldb_root = None + CalibrationData._default_caldb_root = None - return CalibrationData._caldb_root + return CalibrationData._default_caldb_root @property def client(self): @@ -947,6 +942,7 @@ class AGIPD_CalibrationData(SplitConditionCalibrationData): gain_setting=None, gain_mode=None, module_naming="da", + caldb_root=None, integration_time=12, source_energy=9.2, pixels_x=512, @@ -958,6 +954,7 @@ class AGIPD_CalibrationData(SplitConditionCalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage @@ -1021,6 +1018,7 @@ class LPD_CalibrationData(SplitConditionCalibrationData): client=None, event_at=None, module_naming="da", + caldb_root=None, ): super().__init__( detector_name, @@ -1028,6 +1026,7 @@ class LPD_CalibrationData(SplitConditionCalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage @@ -1072,6 +1071,7 @@ class DSSC_CalibrationData(CalibrationData): client=None, event_at=None, module_naming="da", + caldb_root=None, ): super().__init__( detector_name, @@ -1079,6 +1079,7 @@ class DSSC_CalibrationData(CalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage @@ -1126,6 +1127,7 @@ class JUNGFRAU_CalibrationData(CalibrationData): client=None, event_at=None, module_naming="da", + caldb_root=None, ): super().__init__( detector_name, @@ -1133,6 +1135,7 @@ class JUNGFRAU_CalibrationData(CalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage @@ -1193,6 +1196,7 @@ class PNCCD_CalibrationData(SplitConditionCalibrationData): client=None, event_at=None, module_naming="da", + caldb_root=None, ): # Ignore modules for this detector. super().__init__( @@ -1201,6 +1205,7 @@ class PNCCD_CalibrationData(SplitConditionCalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage @@ -1249,6 +1254,7 @@ class EPIX100_CalibrationData(SplitConditionCalibrationData): client=None, event_at=None, module_naming="da", + caldb_root=None, ): # Ignore modules for this detector. super().__init__( @@ -1257,6 +1263,7 @@ class EPIX100_CalibrationData(SplitConditionCalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage @@ -1299,6 +1306,7 @@ class GOTTHARD2_CalibrationData(CalibrationData): client=None, event_at=None, module_naming="da", + caldb_root=None, ): # Ignore modules for this detector. super().__init__( @@ -1307,6 +1315,7 @@ class GOTTHARD2_CalibrationData(CalibrationData): client, event_at, module_naming, + caldb_root, ) self.sensor_bias_voltage = sensor_bias_voltage