bec_worker: further work to modifiy bec_worker.py

This commit is contained in:
appleb_m committed 2026-02-19 16:42:14 +01:00
1 parent bed83f63ef
commit a0530d5261
1 file changed
+91 -83
+91 -83
View File
@@ -2,6 +2,10 @@ from bec_lib.client import BECClient
from bec_ipython_client import BECIPythonClient
from bec_lib.service_config import ServiceConfig
from bec_lib.procedures.helper import FrontendProcedureHelper, BackendProcedureHelper
from aare.common.beamline import MXBeamline, mx_beamline
#from pxii_bec.macros.pxii_guards import GuardViolation
@@ -19,87 +23,6 @@ from bec_lib.procedures.helper import FrontendProcedureHelper, BackendProcedureH
def bec_exception_handler(exception: Exception):
print(f"Exception: {exception}")
class OurBECDevices:
def __init__(self, BECDevices):
print("initialising devices")
init_positioned_devices()
dev = BECDevices
print("devices initialised")
self.coll_y = MultiPositionDevice(device = PD.coll_y,
states = dev.coll_y.user_parameter)
self.scintillator_diode_y = MultiPositionDevice(device = PD.diag_y,
states = dev.diag_y.user_parameter)
self.backlight_pos = PositionedDevice(device = PD.bl_pos)
#self.beamstop_pos = PositionedDevice(device = PD.bs_pos)
self.beamstop_z = GuardedPositionedDevice(device = PD.bs_z)
self.goniometer_x = GuardedPositionedDevice(device = PD.gon_x) # may get deprecated with the IOC
class BECClientWorker:
def __init__(self, service_config:ServiceConfig, name:str = "default"):
self.client = BECIPythonClient(config=service_config)
self.client.start()
#self.client.config.update_session_with_file("/sls/x10sa/config/bec/production/bec/bec_lib/bec_lib/config_helper.py")
self.dev = self.client.device_manager.devices
self.scans = self.client.scans
self.macros = self.client.macros
self.load_user_macros()
self.helper = FrontendProcedureHelper(self.client.connector)
self.ProtectedDevices = OurBECDevices(BECDevices=self.dev)
def run_macro(self, macro_name:str, *args, queue:str = "default", **kwargs):
return self.client.proc.run_macro(macro_name, *args, queue=queue)
def run_macro_blocked(self, macro_name:str, *args, queue:str = "default", **kwargs):
try:
status = self.run_macro(macro_name, *args, queue=queue)
print(status)
status.wait()
print(status)
return status
except Exception as e:
print(f"Error: {e}")
return None
def show_all_devices(self):
return self.dev.show_all
def list_all_macros(self):
return self.macros.list_user_macros()
def load_user_macros(self):
self.macros.load_all_user_macros()
def shutdown_client(self):
self.client.shutdown()
def common2rse(self):
status = self.scans.umv(self.dev.blight_pos, 0, relative=False)
try:
SE.blpos.checkpos()
except NotImplemented as e:
print(f"Backlight position not checked: {e}")
print(f"Moved backlight to position {self.dev.blight_pos.read()} with status {status.status}")
self.scans.umv(self.dev.bs_z, 72.0, self.dev.coll_y, 20.0, self.dev.scin_y, 20.0, self.dev.cryo_pos, 1, relative=False)
self.scans.umv(self.dev.bs_pos, 0, relative=False)
print(f"Moved everything else to park position with status {status.status}")
if self.dev.bs_z.read().value != 72.0:# or self.dev.coll_y.read() != 20.0 or self.dev.scin_y.read() != 20.0:
print(f"is bs_z correct: {self.dev.bs_z.read().value != 72.0}")# is coll_y correct {self.dev.coll_y.read() != 20.0}, is scin_y correct {self.dev.scin_y.read() != 20.0}")
raise Exception("Error: something went wrong")
def rse2sa(self):
self.scans.umv(self.dev.blight_pos, 1, relative=False)
self.scans.umv(self.dev.bs_pos, 1, relative = False)
def mono_pitch_scan_runner(self):
print('this is a print statement from inside DAQ not BEC')
try:
self.macros.mono_pitch_scan(False)
except Exception as e:
print(f"Error: {e}")
class MultiPositionDevice:
"""inherits from the MultiPositionDevice BEC class
@@ -176,7 +99,91 @@ class GuardedPositionedDevice:
class OurBECDevices:
def __init__(self, BECDevices):
print("initialising devices")
init_positioned_devices()
dev = BECDevices
print("devices initialised")
self.coll_y = MultiPositionDevice(device = PD.coll_y,
states = dev.coll_y.user_parameter)
self.scintillator_diode_y = MultiPositionDevice(device = PD.diag_y,
states = dev.diag_y.user_parameter)
self.backlight_pos = PositionedDevice(device = PD.bl_pos)
#self.beamstop_pos = PositionedDevice(device = PD.bs_pos)
self.beamstop_z = GuardedPositionedDevice(device = PD.bs_z)
self.goniometer_x = GuardedPositionedDevice(device = PD.gon_x) # may get deprecated with the IOC
class BECClientWorker:
def __init__(self, beamline:MXBeamline, name:str = "default"):
BEAMLINE = beamline.value.lower()
service_config = ServiceConfig(redis={"host": f"{BEAMLINE}-bec-001.psi.ch", "port": 6379})
print(service_config.config)
service_config.config["log_writer"]["base_path"]='./logs'
print(service_config.config)
self.client = BECIPythonClient(config=service_config)
#self.client.config.update_session_with_file("/sls/x10sa/config/bec/production/bec/bec_lib/bec_lib/config_helper.py")
self.client.start()
self.dev = self.client.device_manager.devices
self.scans = self.client.scans
self.macros = self.client.macros
self.load_user_macros()
self.helper = FrontendProcedureHelper(self.client.connector)
self.ProtectedDevices = OurBECDevices(BECDevices=self.dev)
def run_macro(self, macro_name:str, *args, queue:str = "default", **kwargs):
return self.client.proc.run_macro(macro_name, *args, queue=queue)
def run_macro_blocked(self, macro_name:str, *args, queue:str = "default", **kwargs):
try:
status = self.run_macro(macro_name, *args, queue=queue)
print(status)
status.wait()
print(status)
return status
except Exception as e:
print(f"Error: {e}")
return None
def show_all_devices(self):
return self.dev.show_all
def list_all_macros(self):
return self.macros.list_user_macros()
def load_user_macros(self):
self.macros.load_all_user_macros()
def shutdown_client(self):
self.client.shutdown()
def common2rse(self):
status = self.scans.umv(self.dev.blight_pos, 0, relative=False)
try:
SE.blpos.checkpos()
except NotImplemented as e:
print(f"Backlight position not checked: {e}")
print(f"Moved backlight to position {self.dev.blight_pos.read()} with status {status.status}")
self.scans.umv(self.dev.bs_z, 72.0, self.dev.coll_y, 20.0, self.dev.scin_y, 20.0, self.dev.cryo_pos, 1, relative=False)
self.scans.umv(self.dev.bs_pos, 0, relative=False)
print(f"Moved everything else to park position with status {status.status}")
if self.dev.bs_z.read().value != 72.0:# or self.dev.coll_y.read() != 20.0 or self.dev.scin_y.read() != 20.0:
print(f"is bs_z correct: {self.dev.bs_z.read().value != 72.0}")# is coll_y correct {self.dev.coll_y.read() != 20.0}, is scin_y correct {self.dev.scin_y.read() != 20.0}")
raise Exception("Error: something went wrong")
def rse2sa(self):
self.scans.umv(self.dev.blight_pos, 1, relative=False)
self.scans.umv(self.dev.bs_pos, 1, relative = False)
def mono_pitch_scan_runner(self):
print('this is a print statement from inside DAQ not BEC')
try:
self.macros.mono_pitch_scan(False)
except Exception as e:
print(f"Error: {e}")
# not implemented yet
# self.cryo_pos = PD.cryo_pos
@@ -185,9 +192,10 @@ class GuardedPositionedDevice:
if __name__ == "__main__":
import time
print('starting BEC Client')
beamline = mx_beamline()
try:
service_config = ServiceConfig(redis={"host": "x10sa-bec-001.psi.ch", "port": 6379})
client = BECClientWorker(service_config)
client = BECClientWorker(beamline)
except Exception as e:
print(f"Error: {e}")
import sys