diff --git a/csaxs_bec/bec_ipython_client/plugins/cSAXS/cSAXS.py b/csaxs_bec/bec_ipython_client/plugins/cSAXS/cSAXS.py index 991e395..859f43f 100644 --- a/csaxs_bec/bec_ipython_client/plugins/cSAXS/cSAXS.py +++ b/csaxs_bec/bec_ipython_client/plugins/cSAXS/cSAXS.py @@ -16,9 +16,11 @@ from csaxs_bec.bec_ipython_client.plugins.cSAXS.smaract import cSAXSInitSmaractS from csaxs_bec.bec_ipython_client.plugins.cSAXS.smaract import cSAXSSmaract from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import OMNYTools from csaxs_bec.bec_ipython_client.plugins.cSAXS.filter_transmission import cSAXSFilterTransmission +from csaxs_bec.bec_ipython_client.plugins.cSAXS.diagnostics import cSAXSDiagnostics class cSAXSError(Exception): pass + class cSAXS( cSAXSInitSmaractStages, cSAXSSmaract, @@ -28,9 +30,12 @@ class cSAXS( self.client = client self.device_manager = client.device_manager self.OMNYTools = OMNYTools(self.client) + + self.diagnostics = cSAXSDiagnostics() super().__init__(client=client) + # this is the csaxs master file that imports all routines from csaxs # can be imported in the bec client by # run in bec from folder /sls/x12sa/config/bec/production/csaxs_bec diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py index f59a2f1..e418373 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py @@ -1829,20 +1829,20 @@ class Flomni( or (self.tomo_type == 3 and projection_number == None) ): - # pylint: disable=undefined-variable - # if bec.active_account != "": - # self.tomo_id = self.add_sample_database( - # self.sample_name, - # str(datetime.date.today()), - # bec.active_account, - # bec.queue.next_scan_number, - # "flomni", - # "test additional info", - # "BEC", - # ) - # self.write_pdf_report() - # else: - self.tomo_id = 0 + #pylint: disable=undefined-variable + if bec.active_account != "": + self.tomo_id = self.add_sample_database( + self.sample_name, + str(datetime.date.today()), + bec.active_account, + bec.queue.next_scan_number, + "flomni", + "test additional info", + "BEC", + ) + self.write_pdf_report() + else: + self.tomo_id = 0 self.write_pdf_report() self.progress["tomo_start_time"] = datetime.datetime.now().isoformat() diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py index 0364576..26919cb 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py @@ -403,8 +403,11 @@ class LocalHttpServer: class _QuietHandler(http.server.SimpleHTTPRequestHandler): def log_message(self, *args): pass + # handle_error here does nothing — wrong class + + class _QuietHTTPServer(http.server.HTTPServer): def handle_error(self, request, client_address): - pass # suppress BrokenPipeError and other per-connection noise + pass # suppress BrokenPipeError and all other per-connection noise def start(self) -> None: Handler = functools.partial( @@ -412,11 +415,11 @@ class LocalHttpServer: directory=str(self._directory), ) try: - self._server = http.server.HTTPServer(("", self._port), Handler) + self._server = self._QuietHTTPServer(("", self._port), Handler) except OSError as exc: raise RuntimeError( f"LocalHttpServer: cannot bind port {self._port}: {exc}" - ) from exc + ) from excs self._thread = threading.Thread( target=self._server.serve_forever, name="LocalHttpServer", diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py index 7d374a6..8ee5c28 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py @@ -234,9 +234,10 @@ class TomoIDManager: ) """ - OMNY_URL = "https://omny.web.psi.ch/samples/newmeasurement.php" - OMNY_USER = "omny" - OMNY_PASSWORD = "samples" + #OMNY_URL = "https://omny.web.psi.ch/samples/newmeasurement.php" + OMNY_URL = "https://v1p0zyg2w9n2k9c1.myfritz.net/samples/newmeasurement.php" + OMNY_USER = "" + OMNY_PASSWORD = "" TMP_FILE = "/tmp/currsamplesnr.txt" def register( @@ -273,9 +274,14 @@ class TomoIDManager: f"&additional={additional_info}" f"&user={user}" ) + # subprocess.run( + # f"wget --user={self.OMNY_USER} --password={self.OMNY_PASSWORD}" + # f" -q -O {self.TMP_FILE} '{url}'", + # shell=True, + # ) + #print(url) subprocess.run( - f"wget --user={self.OMNY_USER} --password={self.OMNY_PASSWORD}" - f" -q -O {self.TMP_FILE} '{url}'", + f"wget -q -O {self.TMP_FILE} '{url}'", shell=True, ) with open(self.TMP_FILE) as f: diff --git a/csaxs_bec/device_configs/bl_endstation.yaml b/csaxs_bec/device_configs/bl_endstation.yaml index c798454..b8fba6b 100644 --- a/csaxs_bec/device_configs/bl_endstation.yaml +++ b/csaxs_bec/device_configs/bl_endstation.yaml @@ -885,11 +885,99 @@ dettrx: softwareTrigger: false + + + #################### -### Beamstop control for flight tube +### BPM XBox2 (first Xbox in ES) and Xbox3 BIM +### This requires galilrioesxbox device. On top of that the gain control devices and slow readback devices are built. #################### -beamstop_control: +galilrioesxbox: + description: Galil RIO for remote gain switching and slow reading XBox ES + deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO + deviceConfig: + host: galilrioesxbox.psi.ch + enabled: true + onFailure: retry + readOnly: false + readoutPriority: baseline + connectionTimeout: 20 + +gain_bpm_xbox2: + description: Gain control for BPM XBox2 + deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl + deviceConfig: + gain_lsb: galilrioesxbox.digital_out.ch0 # Pin 10 -> Galil ch0 + gain_mid: galilrioesxbox.digital_out.ch1 # Pin 11 -> Galil ch1 + gain_msb: galilrioesxbox.digital_out.ch2 # Pin 12 -> Galil ch2 + coupling: galilrioesxbox.digital_out.ch3 # Pin 13 -> Galil ch3 + speed_mode: galilrioesxbox.digital_out.ch4 # Pin 14 -> Galil ch4 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioesxbox + +bpm_xbox2_slowrb: + description: BPM Xbox 2 (First Xbox in ES hutch) readback + deviceClass: csaxs_bec.devices.pseudo_devices.bpm.BPM + deviceConfig: + left_top: galilrioesxbox.analog_in.ch0 + right_top: galilrioesxbox.analog_in.ch1 + right_bot: galilrioesxbox.analog_in.ch2 + left_bot: galilrioesxbox.analog_in.ch3 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioesxbox + +gain_bim_xbox3: + description: Gain control for beam intensity monitor ES Xbox3 + deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl + deviceConfig: + gain_lsb: galilrioesxbox.digital_out.ch6 # Pin 10 -> Galil ch0 + gain_mid: galilrioesxbox.digital_out.ch7 # Pin 11 -> Galil ch1 + gain_msb: galilrioesxbox.digital_out.ch8 # Pin 12 -> Galil ch2 + coupling: galilrioesxbox.digital_out.ch9 # Pin 13 -> Galil ch3 + speed_mode: galilrioesxbox.digital_out.ch10 # Pin 14 -> Galil ch4 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioesxbox + +bim_xbox3_slowrb: + description: Beam intensity slow readback ES XBox3 + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder + deviceConfig: + signal: galilrioesxbox.analog_in.ch6 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioesxbox + + + +#################### +### Beamstop diode control for flight tube +### This requires galilrioft device. On top of that the gain control device is built as well as a slow voltage readback. +#################### + +galilrioesft: + description: Galil RIO for remote gain switching and slow reading FlightTube + deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO + deviceConfig: + host: galilrioesft.psi.ch + enabled: true + onFailure: retry + readOnly: false + readoutPriority: baseline + connectionTimeout: 20 + +gain_beamstop_diode: description: Gain control for beamstop flightube deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl deviceConfig: @@ -904,15 +992,17 @@ beamstop_control: needs: - galilrioesft -galilrioesft: - description: Galil RIO for remote gain switching and slow reading FlightTube - deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO +beamstop_intensity: + description: Beamstop intensity from Galil analog input ch6 + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder deviceConfig: - host: galilrioesft.psi.ch + signal: galilrioesft.analog_in.ch0 enabled: true - onFailure: retry - readOnly: false readoutPriority: baseline - connectionTimeout: 20 + onFailure: retry + needs: + - galilrioesft + + diff --git a/csaxs_bec/device_configs/bl_general.yaml b/csaxs_bec/device_configs/bl_general.yaml index ec607c7..3266e38 100644 --- a/csaxs_bec/device_configs/bl_general.yaml +++ b/csaxs_bec/device_configs/bl_general.yaml @@ -9,17 +9,3 @@ x12saEPS: onFailure: buffer readOnly: false readoutPriority: baseline -############################################################ -##################### GalilRIO ############################# -############################################################ - -galilrioesxbox: - description: Galil RIO for remote gain switching and slow reading ES XBox - deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO - deviceConfig: - host: galilrioesxbox.psi.ch - enabled: true - onFailure: raise - readOnly: false - readoutPriority: baseline - connectionTimeout: 20 \ No newline at end of file diff --git a/csaxs_bec/device_configs/bl_optics_hutch.yaml b/csaxs_bec/device_configs/bl_optics_hutch.yaml index abb3a4a..3486eaf 100644 --- a/csaxs_bec/device_configs/bl_optics_hutch.yaml +++ b/csaxs_bec/device_configs/bl_optics_hutch.yaml @@ -193,4 +193,93 @@ ccm_energy: # enabled: true # readoutPriority: baseline # readOnly: false -# softwareTrigger: false \ No newline at end of file +# softwareTrigger: false + + + +#################### +### BPM and polarization diag XBox1 (optics hutch) +### This requires galilrioop device. On top of that the gain control devices and slow readback devices are built. +### dev.galilrioop.read() shows the analog inputs +### another example ...analog_in.ch0.get() +### dev.galilrioop.read_configuration() shows the digital channels +### example for direct access dev.galilrioesxbox.digital_out.ch1.put(0) +#################### + +galilrioop: + description: Galil RIO for remote gain switching and slow reading XBox OP + deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO + deviceConfig: + host: galilrioop.psi.ch + enabled: true + onFailure: retry + readOnly: false + readoutPriority: baseline + connectionTimeout: 20 + +gain_bpm_xbox1: + description: Gain control for BPM XBox1 (OP hutch) + deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl + deviceConfig: + gain_lsb: galilrioop.digital_out.ch0 # Pin 10 -> Galil ch0 + gain_mid: galilrioop.digital_out.ch1 # Pin 11 -> Galil ch1 + gain_msb: galilrioop.digital_out.ch2 # Pin 12 -> Galil ch2 + coupling: galilrioop.digital_out.ch3 # Pin 13 -> Galil ch3 + speed_mode: galilrioop.digital_out.ch4 # Pin 14 -> Galil ch4 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioop + +bpm_xbox1_slowrb: + description: BPM Xbox 1 (OP hutch) readback + deviceClass: csaxs_bec.devices.pseudo_devices.bpm.BPM + deviceConfig: + left_top: galilrioop.analog_in.ch0 + right_top: galilrioop.analog_in.ch1 + right_bot: galilrioop.analog_in.ch2 + left_bot: galilrioop.analog_in.ch3 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioop + +gain_diodes_xbox1: + description: Gain control for diodes (horizontal and vertical) XBox1 + deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl + deviceConfig: + gain_lsb: galilrioop.digital_out.ch6 # Pin 10 -> Galil ch0 + gain_mid: galilrioop.digital_out.ch7 # Pin 11 -> Galil ch1 + gain_msb: galilrioop.digital_out.ch8 # Pin 12 -> Galil ch2 + coupling: galilrioop.digital_out.ch9 # Pin 13 -> Galil ch3 + speed_mode: galilrioop.digital_out.ch10 # Pin 14 -> Galil ch4 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioop + +diode_horizontal_xbox1_slowrb: + description: Slow readback diode horizontal XBox OP (polarization diagnostics) + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder + deviceConfig: + signal: galilrioop.analog_in.ch6 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioop + +diode_vertical_xbox1_slowrb: + description: Slow readback diode vertical XBox OP (polarization diagnostics) + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder + deviceConfig: + signal: galilrioop.analog_in.ch7 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioop + diff --git a/csaxs_bec/devices/pseudo_devices/signal_forwarder.py b/csaxs_bec/devices/pseudo_devices/signal_forwarder.py new file mode 100644 index 0000000..17e21fb --- /dev/null +++ b/csaxs_bec/devices/pseudo_devices/signal_forwarder.py @@ -0,0 +1,41 @@ +""" +Pseudo device that forwards a single BEC signal 1:1. +""" + +from ophyd import Component as Cpt +from ophyd import Kind, Signal +from ophyd_devices.interfaces.base_classes.psi_pseudo_device_base import PSIPseudoDeviceBase +from ophyd_devices.utils.bec_processed_signal import BECProcessedSignal + + +class SignalForwarder(PSIPseudoDeviceBase): + """Forward one signal unchanged.""" + + signal = Cpt( + BECProcessedSignal, + name="signal", + model_config=None, + kind=Kind.config, + doc="Forwarded signal", + ) + + def __init__( + self, + name, + signal: str, + device_manager=None, + scan_info=None, + **kwargs, + ): + super().__init__(name=name, device_manager=device_manager, scan_info=scan_info, **kwargs) + + src = self.signal.get_device_object_from_bec( + object_name=signal, + signal_name=self.name, + device_manager=device_manager, + ) + + self.signal.set_compute_method(self._compute_signal, signal=src) + + def _compute_signal(self, signal: Signal) -> float: + return signal.get() \ No newline at end of file