Skip to content
Snippets Groups Projects
Commit b1b330fd authored by David Hammer's avatar David Hammer
Browse files

Much more chatty about constant loading

parent 5ef4b9f9
No related branches found
No related tags found
2 merge requests!12Snapshot: field test deployed version as of end of run 202201,!3Base correction device, CalCat interaction, DSSC and AGIPD devices
...@@ -394,6 +394,7 @@ class AgipdCorrection(BaseCorrection): ...@@ -394,6 +394,7 @@ class AgipdCorrection(BaseCorrection):
self.set(f"corrections.{field_name}.available", True) self.set(f"corrections.{field_name}.available", True)
self._update_correction_flags() self._update_correction_flags()
self.log_status_info(f"Done loading {constant.name} to GPU")
def _update_pulse_filter(self, filter_string): def _update_pulse_filter(self, filter_string):
"""Called whenever the pulse filter changes, typically followed by """Called whenever the pulse filter changes, typically followed by
......
...@@ -177,3 +177,4 @@ class DsscCorrection(BaseCorrection): ...@@ -177,3 +177,4 @@ class DsscCorrection(BaseCorrection):
self.set("corrections.offset.available", True) self.set("corrections.offset.available", True)
self._update_correction_flags() self._update_correction_flags()
self.log_status_info(f"Done loading {constant.name} to GPU")
...@@ -49,20 +49,6 @@ class CalibrationClientConfigError(Exception): ...@@ -49,20 +49,6 @@ class CalibrationClientConfigError(Exception):
pass pass
def _check_resp(resp, exception=Exception):
# TODO: probably verify using "info" that exception is the right one
if not resp["success"]:
# TODO: probably more types of app_info errors?
if resp["app_info"]:
if "not found" in resp["info"]:
# this was likely the exception exception
raise exception(resp["info"])
else:
# but could also be authorization or similar issue
raise CalibrationClientConfigError(resp["app_info"])
raise exception(resp["info"])
def _add_status_schema_from_enum(schema, prefix, enum_class): def _add_status_schema_from_enum(schema, prefix, enum_class):
for constant in enum_class: for constant in enum_class:
constant_node = f"{prefix}.{constant.name}" constant_node = f"{prefix}.{constant.name}"
...@@ -323,16 +309,20 @@ class BaseCalcatFriend: ...@@ -323,16 +309,20 @@ class BaseCalcatFriend:
@functools.cached_property @functools.cached_property
def detector_id(self): def detector_id(self):
resp = Detector.get_by_identifier(self.client, self._get_param("detectorName")) detector_name = self._get_param("detectorName")
_check_resp(resp, DetectorNotFound) resp = Detector.get_by_identifier(self.client, detector_name)
self._check_resp(resp, DetectorNotFound, f"Detector {detector_name} not found")
res = resp["data"]["id"] res = resp["data"]["id"]
self._set_param("detectorId", str(res)) self._set_param("detectorId", str(res))
return res return res
@functools.cached_property @functools.cached_property
def detector_type_id(self): def detector_type_id(self):
resp = DetectorType.get_by_name(self.client, self._get_param("detectorType")) detector_type = self._get_param("detectorType")
_check_resp(resp, DetectorNotFound) resp = DetectorType.get_by_name(self.client, detector_type)
self._check_resp(
resp, DetectorNotFound, f"Detector type {detector_type} not found"
)
res = resp["data"]["id"] res = resp["data"]["id"]
self._set_param("detectorTypeId", str(res)) self._set_param("detectorTypeId", str(res))
return res return res
...@@ -342,7 +332,7 @@ class BaseCalcatFriend: ...@@ -342,7 +332,7 @@ class BaseCalcatFriend:
resp = PhysicalDetectorUnit.get_all_by_detector( resp = PhysicalDetectorUnit.get_all_by_detector(
self.client, self.detector_id, self._get_param("deviceMappingSnapshotAt") self.client, self.detector_id, self._get_param("deviceMappingSnapshotAt")
) )
_check_resp(resp) self._check_resp(resp, warning="Failed to retrieve module mapping")
for irrelevant_key in ("detector", "detector_type", "flg_available"): for irrelevant_key in ("detector", "detector_type", "flg_available"):
for pdu in resp["data"]: for pdu in resp["data"]:
del pdu[irrelevant_key] del pdu[irrelevant_key]
...@@ -365,7 +355,9 @@ class BaseCalcatFriend: ...@@ -365,7 +355,9 @@ class BaseCalcatFriend:
@utils.threadsafe_cache @utils.threadsafe_cache
def calibration_id(self, calibration_name: str): def calibration_id(self, calibration_name: str):
resp = Calibration.get_by_name(self.client, calibration_name) resp = Calibration.get_by_name(self.client, calibration_name)
_check_resp(resp, CalibrationNotFound) self._check_resp(
resp, CalibrationNotFound, f"Calibration type {calibration_name} not found!"
)
return resp["data"]["id"] return resp["data"]["id"]
@utils.threadsafe_cache @utils.threadsafe_cache
...@@ -377,7 +369,11 @@ class BaseCalcatFriend: ...@@ -377,7 +369,11 @@ class BaseCalcatFriend:
resp = self.client.search_possible_conditions_from_dict( resp = self.client.search_possible_conditions_from_dict(
"", condition_with_detector.encode() "", condition_with_detector.encode()
) )
_check_resp(resp, ConditionNotFound) self._check_resp(
resp,
ConditionNotFound,
f"Failed to find condition {condition} for pdu {pdu}",
)
return resp["data"][0]["id"] return resp["data"][0]["id"]
@utils.threadsafe_cache @utils.threadsafe_cache
...@@ -388,7 +384,7 @@ class BaseCalcatFriend: ...@@ -388,7 +384,7 @@ class BaseCalcatFriend:
detector_type_id=self.detector_type_id, detector_type_id=self.detector_type_id,
condition_id=condition_id, condition_id=condition_id,
) )
_check_resp(resp) self._check_resp(resp, warning="Failed to retrieve constant ID")
return resp["data"]["id"] return resp["data"]["id"]
def get_constant_version(self, constant): def get_constant_version(self, constant):
...@@ -397,6 +393,9 @@ class BaseCalcatFriend: ...@@ -397,6 +393,9 @@ class BaseCalcatFriend:
self.device.log_status_info(f"Attempting to find {constant} for {karabo_da}") self.device.log_status_info(f"Attempting to find {constant} for {karabo_da}")
if karabo_da not in self._karabo_da_to_float_uuid: if karabo_da not in self._karabo_da_to_float_uuid:
self.device.log_status_warn(
f"Module {karabo_da} not found in mapping, check configuration!"
)
raise ModuleNotFound(f"Module map did not include {karabo_da}") raise ModuleNotFound(f"Module map did not include {karabo_da}")
self._set_param("moduleId", str(self._karabo_da_to_id[karabo_da])) self._set_param("moduleId", str(self._karabo_da_to_id[karabo_da]))
...@@ -424,7 +423,7 @@ class BaseCalcatFriend: ...@@ -424,7 +423,7 @@ class BaseCalcatFriend:
event_at=self._get_param("constantVersionEventAt"), event_at=self._get_param("constantVersionEventAt"),
snapshot_at=None, snapshot_at=None,
) )
_check_resp(resp) self._check_resp(resp, warning="Failed to find calibration constant version")
# TODO: replace with start date and end date # TODO: replace with start date and end date
timestamp = resp["data"]["begin_validity_at"] timestamp = resp["data"]["begin_validity_at"]
self._set_status(constant, "validFrom", timestamp) self._set_status(constant, "validFrom", timestamp)
...@@ -438,6 +437,7 @@ class BaseCalcatFriend: ...@@ -438,6 +437,7 @@ class BaseCalcatFriend:
constant_data = np.array(fd[resp["data"]["data_set_name"]]["data"]) constant_data = np.array(fd[resp["data"]["data_set_name"]]["data"])
self.cached_constants[constant] = constant_data self.cached_constants[constant] = constant_data
self._set_status(constant, "found", True) self._set_status(constant, "found", True)
self.device.log_status_info(f"Done finding {constant} for {karabo_da}")
return constant_data return constant_data
...@@ -449,7 +449,7 @@ class BaseCalcatFriend: ...@@ -449,7 +449,7 @@ class BaseCalcatFriend:
) )
resp = CalibrationConstantVersion.get_by_id(self.client, constant_version_id) resp = CalibrationConstantVersion.get_by_id(self.client, constant_version_id)
_check_resp(resp) self._check_resp(resp, warning="Failed to find calibration constant version")
file_path = ( file_path = (
self.caldb_store / resp["data"]["path_to_file"] / resp["data"]["file_name"] self.caldb_store / resp["data"]["path_to_file"] / resp["data"]["file_name"]
) )
...@@ -494,6 +494,24 @@ class BaseCalcatFriend: ...@@ -494,6 +494,24 @@ class BaseCalcatFriend:
self._set_status(constant, "validFrom", "") self._set_status(constant, "validFrom", "")
self._set_status(constant, "found", False) self._set_status(constant, "found", False)
def _check_resp(self, resp, exception=Exception, warning=None):
# TODO: probably verify using "info" that exception is the right one
to_raise = None
if not resp["success"]:
# TODO: probably more types of app_info errors?
if resp["app_info"]:
if "not found" in resp["info"]:
# this was likely the exception exception
to_raise = exception(resp["info"])
else:
# but could also be authorization or similar issue
to_raise = CalibrationClientConfigError(resp["app_info"])
to_raise = exception(resp["info"])
if to_raise is not None:
if warning is not None:
self.device.log_status_warn(warning)
raise to_raise
class AgipdConstants(enum.Enum): class AgipdConstants(enum.Enum):
SlopesFF = enum.auto() SlopesFF = enum.auto()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment