diff --git a/pyaml/common/constants.py b/pyaml/common/constants.py index e63fa3c2..4f8703a2 100644 --- a/pyaml/common/constants.py +++ b/pyaml/common/constants.py @@ -33,3 +33,5 @@ class Action(Enum): "Triggered immediately after restoring the actuator to its initial value." MEASURE = 2 "Triggered immediately after taking a measurement." + INIT = 3 + "Triggered once before the measurement starts" diff --git a/pyaml/tuning_tools/measurement_tool.py b/pyaml/tuning_tools/measurement_tool.py index 7411c4a2..646d38ed 100644 --- a/pyaml/tuning_tools/measurement_tool.py +++ b/pyaml/tuning_tools/measurement_tool.py @@ -61,6 +61,20 @@ def __init__(self, name): self._peer: "ElementHolder" = None # Peer: ControlSystem or Simulator self._callback: Callable = None + @staticmethod + def get_peer_from_cb(cbdata: dict) -> "ElementHolder": + """ + Return the ElementHolder that contains this measaurement tool + """ + return MeasurementTool.get_from_cb(cbdata).peer + + @staticmethod + def get_from_cb(cbdata: dict) -> "MeasurementTool": + """ + Return the Measurement tool that triggered the callback + """ + return cbdata["source"] + def _fill_device(self, holder: "ElementHolder") -> None: holder._fill_tool(self) @@ -79,6 +93,7 @@ def _init_measure(self, measurement_type: str | None = None): self._latest_measurement = {} if measurement_type is not None: self._latest_measurement["type"] = measurement_type + self.send_callback(Action.INIT, {}) @abstractmethod def measure(self) -> bool: