diff --git a/csaxs_bec/devices/epics/eiger9m_csaxs.py b/csaxs_bec/devices/epics/eiger9m_csaxs.py index f5b98f4..3e818a3 100644 --- a/csaxs_bec/devices/epics/eiger9m_csaxs.py +++ b/csaxs_bec/devices/epics/eiger9m_csaxs.py @@ -292,7 +292,7 @@ class Eiger9MSetup(CustomDetectorMixin): ] if not self.wait_for_signals( signal_conditions=signal_conditions, - timeout=self.parent.timeout, + timeout=timeout, check_stopped=True, all_signals=True, ): diff --git a/csaxs_bec/devices/epics/falcon_csaxs.py b/csaxs_bec/devices/epics/falcon_csaxs.py index 9a861e0..83ddb6c 100644 --- a/csaxs_bec/devices/epics/falcon_csaxs.py +++ b/csaxs_bec/devices/epics/falcon_csaxs.py @@ -2,7 +2,6 @@ import enum import os import threading -from bec_lib import threadlocked from bec_lib.logger import bec_logger from ophyd import Component as Cpt from ophyd import Device, EpicsSignal, EpicsSignalRO, EpicsSignalWithRBV @@ -215,7 +214,7 @@ class FalconSetup(CustomDetectorMixin): def on_unstage(self) -> None: """Unstage detector and backend""" - self.finished() + self.finished(timeout=self.parent.TIMEOUT_FOR_SIGNALS) self.publish_file_location(done=True, successful=True) def on_stop(self) -> None: @@ -247,29 +246,29 @@ class FalconSetup(CustomDetectorMixin): """Stop the detector backend""" self.parent.hdf5.capture.put(0) - @threadlocked - def finished(self) -> None: + def finished(self, timeout: int = 5) -> None: """Check if scan finished succesfully""" - total_frames = int( - self.parent.scaninfo.num_points * self.parent.scaninfo.frames_per_trigger - ) - signal_conditions = [ - (self.parent.dxp.current_pixel.get, total_frames), - (self.parent.hdf5.array_counter.get, total_frames), - ] - if not self.wait_for_signals( - signal_conditions=signal_conditions, - timeout=self.parent.TIMEOUT_FOR_SIGNALS, - check_stopped=True, - all_signals=True, - ): - logger.debug( - f"Falcon missed a trigger: received trigger {self.parent.dxp.current_pixel.get()}," - f" send data {self.parent.hdf5.array_counter.get()} from total_frames" - f" {total_frames}" + with self._lock: + total_frames = int( + self.parent.scaninfo.num_points * self.parent.scaninfo.frames_per_trigger ) - self.stop_detector() - self.stop_detector_backend() + signal_conditions = [ + (self.parent.dxp.current_pixel.get, total_frames), + (self.parent.hdf5.array_counter.get, total_frames), + ] + if not self.wait_for_signals( + signal_conditions=signal_conditions, + timeout=timeout, + check_stopped=True, + all_signals=True, + ): + logger.debug( + f"Falcon missed a trigger: received trigger {self.parent.dxp.current_pixel.get()}," + f" send data {self.parent.hdf5.array_counter.get()} from total_frames" + f" {total_frames}" + ) + self.stop_detector() + self.stop_detector_backend() def set_trigger( self, mapping_mode: MappingSource, trigger_source: TriggerSource, ignore_gate: int = 0 diff --git a/csaxs_bec/devices/epics/mcs_csaxs.py b/csaxs_bec/devices/epics/mcs_csaxs.py index a0742e5..fa355a2 100644 --- a/csaxs_bec/devices/epics/mcs_csaxs.py +++ b/csaxs_bec/devices/epics/mcs_csaxs.py @@ -187,9 +187,9 @@ class MCSSetup(CustomDetectorMixin): def on_unstage(self) -> None: """Unstage detector""" - self.finished() + self.finished(timeout=self.parent.TIMEOUT_FOR_SIGNALS) - def finished(self) -> None: + def finished(self, timeout: int = 5) -> None: """Check if acquisition is finished, if not successful, rais MCSTimeoutError""" signal_conditions = [ (lambda: self.acquisition_done, True), @@ -197,7 +197,7 @@ class MCSSetup(CustomDetectorMixin): ] if not self.wait_for_signals( signal_conditions=signal_conditions, - timeout=self.parent.TIMEOUT_FOR_SIGNALS, + timeout=timeout, check_stopped=True, all_signals=True, ): diff --git a/csaxs_bec/devices/epics/pilatus_csaxs.py b/csaxs_bec/devices/epics/pilatus_csaxs.py index 46c8987..6330a98 100644 --- a/csaxs_bec/devices/epics/pilatus_csaxs.py +++ b/csaxs_bec/devices/epics/pilatus_csaxs.py @@ -320,13 +320,12 @@ class PilatusSetup(CustomDetectorMixin): def on_unstage(self) -> None: """Unstage the detector""" - self.finished() + self.finished(timeout=self.parent.TIMEOUT_FOR_SIGNALS) self.publish_file_location( done=True, successful=True, metadata={"input_path": self.parent.filepath_raw} ) - @threadlocked - def finished(self) -> None: + def finished(self, timeout: int = 5) -> None: """Check if acquisition is finished.""" # pylint: disable=protected-access # TODO: at the moment this relies on device.mcs.obj._staged attribute @@ -335,7 +334,7 @@ class PilatusSetup(CustomDetectorMixin): ] if not self.wait_for_signals( signal_conditions=signal_conditions, - timeout=self.parent.TIMEOUT_FOR_SIGNALS, + timeout=timeout, check_stopped=True, all_signals=True, ): diff --git a/tests/tests_devices/test_eiger9m_csaxs.py b/tests/tests_devices/test_eiger9m_csaxs.py index 805f36a..a8c8a89 100644 --- a/tests/tests_devices/test_eiger9m_csaxs.py +++ b/tests/tests_devices/test_eiger9m_csaxs.py @@ -9,7 +9,7 @@ from bec_lib.endpoints import MessageEndpoints from bec_server.device_server.tests.utils import DMMock from ophyd_devices.tests.utils import MockPV -from csaxs_bec.devices.epics.devices.eiger9m_csaxs import Eiger9McSAXS +from csaxs_bec.devices.epics.eiger9m_csaxs import Eiger9McSAXS from csaxs_bec.devices.tests_utils.utils import patch_dual_pvs diff --git a/tests/tests_devices/test_falcon_csaxs.py b/tests/tests_devices/test_falcon_csaxs.py index 4d6d621..18abab0 100644 --- a/tests/tests_devices/test_falcon_csaxs.py +++ b/tests/tests_devices/test_falcon_csaxs.py @@ -10,7 +10,7 @@ from bec_lib.endpoints import MessageEndpoints from bec_server.device_server.tests.utils import DMMock from ophyd_devices.tests.utils import MockPV -from csaxs_bec.devices.epics.devices.falcon_csaxs import FalconcSAXS, FalconTimeoutError +from csaxs_bec.devices.epics.falcon_csaxs import FalconcSAXS, FalconTimeoutError from csaxs_bec.devices.tests_utils.utils import patch_dual_pvs diff --git a/tests/tests_devices/test_pilatus_csaxs.py b/tests/tests_devices/test_pilatus_csaxs.py index 1b4d7a8..b403391 100644 --- a/tests/tests_devices/test_pilatus_csaxs.py +++ b/tests/tests_devices/test_pilatus_csaxs.py @@ -10,7 +10,7 @@ from bec_lib.endpoints import MessageEndpoints from bec_server.device_server.tests.utils import DMMock from ophyd_devices.tests.utils import MockPV -from csaxs_bec.devices.epics.devices.pilatus_csaxs import PilatuscSAXS +from csaxs_bec.devices.epics.pilatus_csaxs import PilatuscSAXS from csaxs_bec.devices.tests_utils.utils import patch_dual_pvs