From 48991275e419c7c722ec2e9f2854e15f3e88ab1b Mon Sep 17 00:00:00 2001 From: PONS Date: Tue, 15 Sep 2026 14:56:17 +0200 Subject: [PATCH 1/2] Added convenience function for meas tool --- pyaml/common/constants.py | 2 ++ pyaml/tuning_tools/measurement_tool.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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..63b26996 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 cbdata["mode"] + + @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: From 8c42b0d5f981af79de0936ed6b6102cab3b659bc Mon Sep 17 00:00:00 2001 From: PONS Date: Tue, 15 Sep 2026 15:03:04 +0200 Subject: [PATCH 2/2] Little fix --- pyaml/tuning_tools/measurement_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyaml/tuning_tools/measurement_tool.py b/pyaml/tuning_tools/measurement_tool.py index 63b26996..646d38ed 100644 --- a/pyaml/tuning_tools/measurement_tool.py +++ b/pyaml/tuning_tools/measurement_tool.py @@ -66,7 +66,7 @@ def get_peer_from_cb(cbdata: dict) -> "ElementHolder": """ Return the ElementHolder that contains this measaurement tool """ - return cbdata["mode"] + return MeasurementTool.get_from_cb(cbdata).peer @staticmethod def get_from_cb(cbdata: dict) -> "MeasurementTool":