fix: online changes eiger9m
This commit is contained in:
parent
c261fbb55a
commit
e299c71ec0
@ -1,13 +1,14 @@
|
|||||||
import enum
|
import enum
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import os
|
||||||
from ophyd import EpicsSignal, EpicsSignalRO, EpicsSignalWithRBV
|
from ophyd import EpicsSignal, EpicsSignalRO, EpicsSignalWithRBV
|
||||||
from ophyd import DetectorBase, Device
|
from ophyd import DetectorBase, Device
|
||||||
from ophyd import ADComponent as ADCpt
|
from ophyd import ADComponent as ADCpt
|
||||||
|
|
||||||
from bec_lib.core import BECMessage, MessageEndpoints
|
from bec_lib.core import BECMessage, MessageEndpoints, threadlocked
|
||||||
from bec_lib.core.file_utils import FileWriterMixin
|
from bec_lib.core.file_utils import FileWriterMixin
|
||||||
from bec_lib.core import bec_logger
|
from bec_lib.core import bec_logger
|
||||||
from ophyd_devices.utils import bec_utils as bec_utils
|
from ophyd_devices.utils import bec_utils as bec_utils
|
||||||
@ -103,6 +104,9 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
prefix (str): PV prefix (X12SA-ES-EIGER9M:)
|
prefix (str): PV prefix (X12SA-ES-EIGER9M:)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
USER_ACCESS = [
|
||||||
|
"describe",
|
||||||
|
]
|
||||||
|
|
||||||
cam = ADCpt(SlsDetectorCam, "cam1:")
|
cam = ADCpt(SlsDetectorCam, "cam1:")
|
||||||
|
|
||||||
@ -129,6 +133,7 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
self._stopped = False
|
self._stopped = False
|
||||||
|
self._lock = threading.RLock()
|
||||||
if device_manager is None and not sim_mode:
|
if device_manager is None and not sim_mode:
|
||||||
raise EigerError("Add DeviceManager to initialization or init with sim_mode=True")
|
raise EigerError("Add DeviceManager to initialization or init with sim_mode=True")
|
||||||
|
|
||||||
@ -169,6 +174,7 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
def _update_std_cfg(self, cfg_key: str, value: Any) -> None:
|
def _update_std_cfg(self, cfg_key: str, value: Any) -> None:
|
||||||
cfg = self.std_client.get_config()
|
cfg = self.std_client.get_config()
|
||||||
old_value = cfg.get(cfg_key)
|
old_value = cfg.get(cfg_key)
|
||||||
|
logger.info(old_value)
|
||||||
if old_value is None:
|
if old_value is None:
|
||||||
raise EigerError(
|
raise EigerError(
|
||||||
f"Tried to change entry for key {cfg_key} in std_config that does not exist"
|
f"Tried to change entry for key {cfg_key} in std_config that does not exist"
|
||||||
@ -178,20 +184,23 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
f"Type of new value {type(value)}:{value} does not match old value {type(old_value)}:{old_value}"
|
f"Type of new value {type(value)}:{value} does not match old value {type(old_value)}:{old_value}"
|
||||||
)
|
)
|
||||||
cfg.update({cfg_key: value})
|
cfg.update({cfg_key: value})
|
||||||
|
logger.info(cfg)
|
||||||
logger.info(f"Updated std_daq config for key {cfg_key} from {old_value} to {value}")
|
logger.info(f"Updated std_daq config for key {cfg_key} from {old_value} to {value}")
|
||||||
|
self.std_client.set_config(cfg)
|
||||||
|
|
||||||
def _init_standard_daq(self) -> None:
|
def _init_standard_daq(self) -> None:
|
||||||
self.std_rest_server_url = "http://xbl-daq-29:5000"
|
self.std_rest_server_url = "http://xbl-daq-29:5000"
|
||||||
self.std_client = StdDaqClient(url_base=self.std_rest_server_url)
|
self.std_client = StdDaqClient(url_base=self.std_rest_server_url)
|
||||||
self.std_client.stop_writer()
|
self.std_client.stop_writer()
|
||||||
timeout = 0
|
timeout = 0
|
||||||
self._update_std_cfg("writer_user_id", int(self.scaninfo.username.strip(" e")))
|
#TODO put back change of e-account!
|
||||||
time.sleep(1)
|
#self._update_std_cfg("writer_user_id", int(self.scaninfo.username.strip(" e")))
|
||||||
|
#time.sleep(5)
|
||||||
while not self.std_client.get_status()["state"] == "READY":
|
while not self.std_client.get_status()["state"] == "READY":
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
timeout = timeout + 0.1
|
timeout = timeout + 0.1
|
||||||
logger.info("Waiting for std_daq init.")
|
logger.info("Waiting for std_daq init.")
|
||||||
if timeout > 2:
|
if timeout > 5:
|
||||||
if not self.std_client.get_status()["state"]:
|
if not self.std_client.get_status()["state"]:
|
||||||
raise EigerError(
|
raise EigerError(
|
||||||
f"Std client not in READY state, returns: {self.std_client.get_status()}"
|
f"Std client not in READY state, returns: {self.std_client.get_status()}"
|
||||||
@ -240,7 +249,9 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
self.filepath = self.filewriter.compile_full_filename(
|
self.filepath = 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
|
||||||
)
|
)
|
||||||
# self._close_file_writer()
|
while not os.path.exists(os.path.dirname(self.filepath)):
|
||||||
|
time.sleep(0.1)
|
||||||
|
self._close_file_writer()
|
||||||
logger.info(f" std_daq output filepath {self.filepath}")
|
logger.info(f" std_daq output filepath {self.filepath}")
|
||||||
try:
|
try:
|
||||||
self.std_client.start_writer_async(
|
self.std_client.start_writer_async(
|
||||||
@ -273,9 +284,9 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
self.device_manager.devices.mokev.name
|
self.device_manager.devices.mokev.name
|
||||||
]["value"]
|
]["value"]
|
||||||
|
|
||||||
|
self._prep_file_writer()
|
||||||
self._prep_det()
|
self._prep_det()
|
||||||
logger.info("Waiting for std daq to be armed")
|
logger.info("Waiting for std daq to be armed")
|
||||||
self._prep_file_writer()
|
|
||||||
logger.info("std_daq is ready")
|
logger.info("std_daq is ready")
|
||||||
|
|
||||||
msg = BECMessage.FileMessage(file_path=self.filepath, done=False)
|
msg = BECMessage.FileMessage(file_path=self.filepath, done=False)
|
||||||
@ -301,9 +312,12 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
self._stopped = False
|
self._stopped = False
|
||||||
return super().stage()
|
return super().stage()
|
||||||
|
|
||||||
|
@threadlocked
|
||||||
def unstage(self) -> List[object]:
|
def unstage(self) -> List[object]:
|
||||||
"""unstage the detector and file writer"""
|
"""unstage the detector and file writer"""
|
||||||
logger.info("Waiting for Eiger9M to finish")
|
logger.info("Waiting for Eiger9M to finish")
|
||||||
|
if self._stopped ==True:
|
||||||
|
return super().unstage()
|
||||||
self._eiger9M_finished()
|
self._eiger9M_finished()
|
||||||
# Message to BEC
|
# Message to BEC
|
||||||
state = True
|
state = True
|
||||||
@ -317,6 +331,7 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
logger.info("Eiger9M finished")
|
logger.info("Eiger9M finished")
|
||||||
return super().unstage()
|
return super().unstage()
|
||||||
|
|
||||||
|
@threadlocked
|
||||||
def _eiger9M_finished(self):
|
def _eiger9M_finished(self):
|
||||||
"""Function with 10s timeout"""
|
"""Function with 10s timeout"""
|
||||||
timer = 0
|
timer = 0
|
||||||
@ -330,13 +345,17 @@ class Eiger9mCsaxs(DetectorBase):
|
|||||||
if det_ctrl == 0 and std_ctrl == "FINISHED" and total_frames == received_frames:
|
if det_ctrl == 0 and std_ctrl == "FINISHED" and total_frames == received_frames:
|
||||||
break
|
break
|
||||||
if self._stopped == True:
|
if self._stopped == True:
|
||||||
|
self._close_file_writer()
|
||||||
break
|
break
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
timer += 0.1
|
timer += 0.1
|
||||||
if timer > 5:
|
if timer > 5:
|
||||||
|
self._stopped == True
|
||||||
|
self._close_file_writer()
|
||||||
raise EigerTimeoutError(
|
raise EigerTimeoutError(
|
||||||
f"Reached timeout with detector state {det_ctrl}, std_daq state {std_ctrl} and received frames of {received_frames} for the file writer"
|
f"Reached timeout with detector state {det_ctrl}, std_daq state {std_ctrl} and received frames of {received_frames} for the file writer"
|
||||||
)
|
)
|
||||||
|
self._close_file_writer()
|
||||||
|
|
||||||
def arm_acquisition(self) -> None:
|
def arm_acquisition(self) -> None:
|
||||||
"""Start acquisition in software trigger mode,
|
"""Start acquisition in software trigger mode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user