From f2db469c9bcff2277282bd38818b068fcceec705 Mon Sep 17 00:00:00 2001 From: menzel Date: Sun, 30 Aug 2026 12:42:51 +0200 Subject: [PATCH] refactor(filters): share the attenuation interlock between fil_trans and fil_comb The DMM-through / CCM-active check now lives in _attenuation_allowed and fil_trans calls it, so there is one copy rather than two drifting ones. A guard that is duplicated is a guard that gets fixed in one place only. Behaviour is unchanged: the same three PVs are read with the same fallbacks, the same warning is printed, the same default-NO prompt is raised through OMNYTools.yesno, the same "Safe fallback" of refusing when no prompt is available applies, and fil_trans(1) still bypasses the check entirely. Split from the previous commit so that this half can be reverted on its own if it misbehaves at the beamline, without taking fil_comb with it. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_017kLGTqTyXzTT4swt3CfTkV --- .../plugins/cSAXS/filter_transmission.py | 42 ++----------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py b/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py index b7a4015b..3ca0f475 100644 --- a/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py +++ b/csaxs_bec/bec_ipython_client/plugins/cSAXS/filter_transmission.py @@ -203,45 +203,9 @@ class cSAXSFilterTransmission: # Only allow fil_trans < 1 when DMM is in THROUGH (both) # and CCM energy > 1 keV. fil_trans(1) is always allowed. # ------------------------------------------------------- - if transmission < 1.0: - try: - dmm_trans = float(epics_get("X12SA-OP-DMM-EMLS-3010:THRU")) - except Exception: - dmm_trans = -1 - try: - dmm_rot = float(epics_get("X12SA-OP-DMM-EMLS-3030:THRU")) - except Exception: - dmm_rot = -1 - try: - ccm_energy = float(epics_get("X12SA-OP-CCM1:ENERGY-GET")) - except Exception: - ccm_energy = -1 - - allowed = (dmm_trans == 1) and (dmm_rot == 1) and (ccm_energy > 1) - - if not allowed: - print("\n⚠️ SAFETY WARNING: Reducing transmission (< 1) typically requires:") - print(" - DMM translation in THROUGH (THRU == 1)") - print(" - DMM rotation in THROUGH (THRU == 1)") - print(" - CCM energy > 1 keV") - print("\nCurrent state:") - print(f" DMM translation THRU : {dmm_trans}") - print(f" DMM rotation THRU : {dmm_rot}") - print(f" CCM energy (keV) : {ccm_energy}") - - # Ask user (default = NO) - if hasattr(self, "OMNYTools") and hasattr(self.OMNYTools, "yesno"): - proceed = self.OMNYTools.yesno( - "Conditions not satisfied. Proceed anyway?", - default="n", - ) - else: - # Safe fallback - proceed = False - - if not proceed: - print("Aborted. Transmission unchanged.") - return None + if transmission < 1.0 and not self._attenuation_allowed(): + print("Aborted. Transmission unchanged.") + return None # --- Energy handling (EPICS only) --- if energy_kev is None: