fix: make filepath a signal

This commit is contained in:
appel_c 2024-06-04 08:32:13 +02:00
parent 57b323e647
commit e9aaa0383e
3 changed files with 21 additions and 8 deletions

View File

@ -10,9 +10,10 @@ import time
from bec_lib import messages
from bec_lib.endpoints import MessageEndpoints
from bec_lib.file_utils import FileWriter
from ophyd import Device, DeviceStatus
from ophyd import Component, Device, DeviceStatus, Kind
from ophyd.device import Staged
from ophyd_devices.sim.sim_signals import SetableSignal
from ophyd_devices.utils import bec_utils
from ophyd_devices.utils.bec_scaninfo_mixin import BecScaninfoMixin
@ -111,10 +112,15 @@ class CustomDetectorMixin:
"""
pipe = self.parent.connector.pipeline()
if successful is None:
msg = messages.FileMessage(file_path=self.parent.filepath, done=done, metadata=metadata)
msg = messages.FileMessage(
file_path=self.parent.filepath.get(), done=done, metadata=metadata
)
else:
msg = messages.FileMessage(
file_path=self.parent.filepath, done=done, successful=successful, metadata=metadata
file_path=self.parent.filepath.get(),
done=done,
successful=successful,
metadata=metadata,
)
self.parent.connector.set_and_publish(
MessageEndpoints.public_file(self.parent.scaninfo.scan_id, self.parent.name),
@ -186,6 +192,8 @@ class PSIDetectorBase(Device):
**kwargs: keyword arguments
"""
filepath = Component(SetableSignal, value="", kind=Kind.config)
custom_prepare_cls = CustomDetectorMixin
def __init__(self, prefix="", *, name, kind=None, parent=None, device_manager=None, **kwargs):

View File

@ -128,9 +128,10 @@ class SimCameraSetup(CustomDetectorMixin):
FYI: No data is written to disk in the simulation, but upon each trigger it
is published to the device_monitor endpoint in REDIS.
"""
self.parent.filepath = self.parent.filewriter.compile_full_filename(f"{self.parent.name}")
self.parent.filepath.set(
self.parent.filewriter.compile_full_filename(f"{self.parent.name}")
).wait()
self.parent.file_path.set(self.parent.filepath)
self.parent.frames.set(
self.parent.scaninfo.num_points * self.parent.scaninfo.frames_per_trigger
)
@ -138,7 +139,7 @@ class SimCameraSetup(CustomDetectorMixin):
self.parent.burst.set(self.parent.scaninfo.frames_per_trigger)
if self.parent.write_to_disk.get():
self.parent.h5_writer.prepare(
file_path=self.parent.filepath, h5_entry="/entry/data/data"
file_path=self.parent.filepath.get(), h5_entry="/entry/data/data"
)
self.publish_file_location(done=False)
self.parent.stopped = False
@ -182,7 +183,6 @@ class SimCamera(PSIDetectorBase):
_default_sub = SUB_MONITOR
exp_time = Cpt(SetableSignal, name="exp_time", value=1, kind=Kind.config)
file_path = Cpt(SetableSignal, name="file_path", value="", kind=Kind.config)
file_pattern = Cpt(SetableSignal, name="file_pattern", value="", kind=Kind.config)
frames = Cpt(SetableSignal, name="frames", value=1, kind=Kind.config)
burst = Cpt(SetableSignal, name="burst", value=1, kind=Kind.config)
@ -204,7 +204,6 @@ class SimCamera(PSIDetectorBase):
self._registered_proxies = {}
self.sim = self.sim_cls(parent=self, **kwargs)
self.h5_writer = H5Writer()
self.filepath = None
super().__init__(
name=name, parent=parent, kind=kind, device_manager=device_manager, **kwargs
)

View File

@ -73,6 +73,12 @@ def test_unstage(detector_base):
mock_on_unstage.assert_called_once()
def test_complete(detector_base):
with mock.patch.object(detector_base.custom_prepare, "on_complete") as mock_on_complete:
detector_base.complete()
mock_on_complete.assert_called_once()
def test_stop(detector_base):
with mock.patch.object(detector_base.custom_prepare, "on_stop") as mock_on_stop:
detector_base.stop()