|
| 1 | +import time as ttime |
| 2 | + |
| 3 | +from ophyd import Component as Cpt |
| 4 | +from ophyd import EpicsSignal, EpicsSignalRO, Staged |
| 5 | +from ophyd.areadetector import ADTriggerStatus, TriggerBase |
| 6 | +from ophyd.areadetector.cam import AreaDetectorCam |
| 7 | +from ophyd.areadetector.filestore_mixins import FileStoreHDF5, FileStoreIterativeWrite |
| 8 | +from ophyd.areadetector.plugins import HDF5Plugin |
| 9 | + |
| 10 | + |
| 11 | +class SingleTriggerV33(TriggerBase): |
| 12 | + _status_type = ADTriggerStatus |
| 13 | + |
| 14 | + def __init__(self, *args, image_name=None, **kwargs): |
| 15 | + super().__init__(*args, **kwargs) |
| 16 | + if image_name is None: |
| 17 | + image_name = "_".join([self.name, "image"]) |
| 18 | + self._image_name = image_name |
| 19 | + |
| 20 | + def trigger(self): |
| 21 | + "Trigger one acquisition." |
| 22 | + if self._staged != Staged.yes: |
| 23 | + raise RuntimeError( |
| 24 | + "This detector is not ready to trigger." |
| 25 | + "Call the stage() method before triggering." |
| 26 | + ) |
| 27 | + |
| 28 | + self._status = self._status_type(self) |
| 29 | + |
| 30 | + def _acq_done(*args, **kwargs): |
| 31 | + # TODO sort out if anything useful in here |
| 32 | + self._status._finished() |
| 33 | + |
| 34 | + self._acquisition_signal.put(1, use_complete=True, callback=_acq_done) |
| 35 | + self.dispatch(self._image_name, ttime.time()) |
| 36 | + return self._status |
| 37 | + |
| 38 | + |
| 39 | +class SynchronisedAdDriverBase(AreaDetectorCam): |
| 40 | + """ |
| 41 | + Base Ophyd device to control an AreaDetector driver and |
| 42 | + syncrhonise it on other AreaDetector plugins, even non-blocking ones. |
| 43 | + """ |
| 44 | + |
| 45 | + adcore_version = Cpt(EpicsSignalRO, "ADCoreVersion_RBV", string=True, kind="config") |
| 46 | + driver_version = Cpt(EpicsSignalRO, "DriverVersion_RBV", string=True, kind="config") |
| 47 | + wait_for_plugins = Cpt(EpicsSignal, "WaitForPlugins", string=True, kind="config") |
| 48 | + |
| 49 | + def stage(self, *args, **kwargs): |
| 50 | + # Makes the detector allow non-blocking AD plugins but makes Ophyd use |
| 51 | + # the AcquireBusy PV to determine when an acquisition is complete |
| 52 | + self.ensure_nonblocking() |
| 53 | + return super().stage(*args, **kwargs) |
| 54 | + |
| 55 | + def ensure_nonblocking(self): |
| 56 | + self.stage_sigs["wait_for_plugins"] = "Yes" |
| 57 | + for c in self.parent.component_names: |
| 58 | + cpt = getattr(self.parent, c) |
| 59 | + if cpt is self: |
| 60 | + continue |
| 61 | + if hasattr(cpt, "ensure_nonblocking"): |
| 62 | + cpt.ensure_nonblocking() |
| 63 | + |
| 64 | + |
| 65 | +class Hdf5Writer(HDF5Plugin, FileStoreHDF5, FileStoreIterativeWrite): |
| 66 | + """ """ |
| 67 | + |
| 68 | + pool_max_buffers = None |
| 69 | + file_number_sync = None |
| 70 | + file_number_write = None |
| 71 | + |
| 72 | + def get_frames_per_point(self): |
| 73 | + return self.parent.cam.num_images.get() |
0 commit comments