mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-02-05 14:48:41 +01:00
refactor: prep detector and filewriter for falcon; stage refactored
This commit is contained in:
@@ -226,17 +226,38 @@ class FalconCsaxs(Device):
|
|||||||
self.pixels_per_buffer.put(self._value_pixel_per_buffer) #
|
self.pixels_per_buffer.put(self._value_pixel_per_buffer) #
|
||||||
self.nd_array_mode.put(1) # Segmentation happens in EPICS
|
self.nd_array_mode.put(1) # Segmentation happens in EPICS
|
||||||
|
|
||||||
|
def stage(self) -> List[object]:
|
||||||
|
"""Stage command, called from BEC in preparation of a scan.
|
||||||
|
The device needs to return with a state once it is ready to start the scan!
|
||||||
|
"""
|
||||||
|
# Set parameters for scan interuption and if acquisition is done
|
||||||
|
self._stopped = False
|
||||||
|
# Get parameters for scan
|
||||||
|
self.scaninfo.load_scan_metadata()
|
||||||
|
self.mokev = self.device_manager.devices.mokev.obj.read()[
|
||||||
|
self.device_manager.devices.mokev.name
|
||||||
|
]["value"]
|
||||||
|
|
||||||
|
# Prepare file writer and detector
|
||||||
|
#TODO refactor logger.info to DEBUG mode?
|
||||||
|
#logger.info("Waiting for falcon filewriter to be ready")
|
||||||
|
self._prep_file_writer()
|
||||||
|
#logger.info("falcon file writer ready")
|
||||||
|
self._prep_det()
|
||||||
|
#logger.info("falcon is ready")
|
||||||
|
self._publish_file_location()
|
||||||
|
self.arm_acquisition()
|
||||||
|
return super().stage()
|
||||||
|
|
||||||
def _prep_det(self) -> None:
|
def _prep_det(self) -> None:
|
||||||
"""Prepare detector for acquisition"""
|
"""Prepare detector for acquisition"""
|
||||||
self.collect_mode.put(1)
|
self.collect_mode.put(1)
|
||||||
self.preset_real.put(self.scaninfo.exp_time)
|
self.preset_real.put(self.scaninfo.exp_time)
|
||||||
self.pixels_per_run.put(int(self.scaninfo.num_points * self.scaninfo.frames_per_trigger))
|
self.pixels_per_run.put(int(self.scaninfo.num_points * self.scaninfo.frames_per_trigger))
|
||||||
# self.auto_pixels_per_buffer.put(0)
|
|
||||||
# self.pixels_per_buffer.put(self._value_pixel_per_buffer)
|
|
||||||
|
|
||||||
def _prep_file_writer(self) -> None:
|
def _prep_file_writer(self) -> None:
|
||||||
"""Prep HDF5 weriting"""
|
"""Prepare filewriting from HDF5 plugin
|
||||||
# TODO creta filename and destination path from filepath
|
#TODO check file_write_mode value in EPICs for details"""
|
||||||
self.destination_path = self.filewriter.compile_full_filename(
|
self.destination_path = self.filewriter.compile_full_filename(
|
||||||
self.scaninfo.scan_number, f"{self.name}.h5", 1000, 5, True
|
self.scaninfo.scan_number, f"{self.name}.h5", 1000, 5, True
|
||||||
)
|
)
|
||||||
@@ -250,29 +271,18 @@ class FalconCsaxs(Device):
|
|||||||
self.hdf5.array_counter.put(0)
|
self.hdf5.array_counter.put(0)
|
||||||
self.hdf5.capture.put(1)
|
self.hdf5.capture.put(1)
|
||||||
|
|
||||||
def stage(self) -> List[object]:
|
def _publish_file_location(self) -> None:
|
||||||
"""stage the detector and file writer"""
|
"""Publish the filepath to REDIS for file writer"""
|
||||||
# TODO clean up needed?
|
msg = BECMessage.FileMessage(file_path=self.filepath, done=False)
|
||||||
self._stopped = False
|
|
||||||
self.scaninfo.load_scan_metadata()
|
|
||||||
self.mokev = self.device_manager.devices.mokev.obj.read()[
|
|
||||||
self.device_manager.devices.mokev.name
|
|
||||||
]["value"]
|
|
||||||
|
|
||||||
logger.info("Waiting for pilatus2 to be armed")
|
|
||||||
self._prep_det()
|
|
||||||
logger.info("Pilatus2 armed")
|
|
||||||
logger.info("Waiting for pilatus2 zmq stream to be ready")
|
|
||||||
self._prep_file_writer()
|
|
||||||
logger.info("Pilatus2 zmq ready")
|
|
||||||
|
|
||||||
msg = BECMessage.FileMessage(file_path=self.destination_path, done=False)
|
|
||||||
self._producer.set_and_publish(
|
self._producer.set_and_publish(
|
||||||
MessageEndpoints.public_file(self.scaninfo.scanID, self.name),
|
MessageEndpoints.public_file(self.scaninfo.scanID, self.name),
|
||||||
msg.dumps(),
|
msg.dumps(),
|
||||||
)
|
)
|
||||||
self.arm_acquisition()
|
|
||||||
|
def arm_acquisition(self) -> None:
|
||||||
|
self.start_all.put(1)
|
||||||
logger.info("Waiting for Falcon to be armed")
|
logger.info("Waiting for Falcon to be armed")
|
||||||
|
#TODO add here timeout?
|
||||||
while True:
|
while True:
|
||||||
det_ctrl = self.state.read()[self.state.name]["value"]
|
det_ctrl = self.state.read()[self.state.name]["value"]
|
||||||
if det_ctrl == int(DetectorState.ACQUIRING):
|
if det_ctrl == int(DetectorState.ACQUIRING):
|
||||||
@@ -281,10 +291,6 @@ class FalconCsaxs(Device):
|
|||||||
break
|
break
|
||||||
time.sleep(0.005)
|
time.sleep(0.005)
|
||||||
logger.info("Falcon is armed")
|
logger.info("Falcon is armed")
|
||||||
return super().stage()
|
|
||||||
|
|
||||||
def arm_acquisition(self) -> None:
|
|
||||||
self.start_all.put(1)
|
|
||||||
|
|
||||||
def unstage(self) -> List[object]:
|
def unstage(self) -> List[object]:
|
||||||
logger.info("Waiting for Falcon to return from acquisition")
|
logger.info("Waiting for Falcon to return from acquisition")
|
||||||
|
|||||||
@@ -167,10 +167,6 @@ class PilatusCsaxs(DetectorBase):
|
|||||||
#TODO in case the data backend is rewritten, add check if it is ready!
|
#TODO in case the data backend is rewritten, add check if it is ready!
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_current_scan_msg(self) -> BECMessage.ScanStatusMessage:
|
|
||||||
msg = self.device_manager.producer.get(MessageEndpoints.scan_status())
|
|
||||||
return BECMessage.ScanStatusMessage.loads(msg)
|
|
||||||
|
|
||||||
def _prep_det(self) -> None:
|
def _prep_det(self) -> None:
|
||||||
# TODO slow reaction, seemed to have timeout.
|
# TODO slow reaction, seemed to have timeout.
|
||||||
self._set_det_threshold()
|
self._set_det_threshold()
|
||||||
|
|||||||
Reference in New Issue
Block a user