Commit fece9f79 authored by Emmanuel Papillon's avatar Emmanuel Papillon
Browse files

first implementation of BeamLine Check on Scans

It checks for USM mode, FE opened, shutter/valves opened
and move ID motors to last set position.
parent c6ebfc3e
import gevent
import tabulate
import math
from bliss.config.settings import HashObjSetting
from bliss.scanning.chain import ChainPreset
from bliss.scanning.scan import ScanPreset
from bliss.common.scans import DEFAULT_CHAIN
from bliss.common.logtools import user_warning
from bliss.controllers.tango_shutter import TangoShutterState
class NotInUSMMode(Exception):
def __str__(self):
return "Machine not in USM Mode"
class BLCheckError(Exception):
class BLCheckTask:
def __init__(self, name, config): = name
self.title = config.get("title")
def __info__(self):
return f"BLCHECK [{}] : {self.title}"
def init(self, config):
def check(self):
class BLCheckFE(BLCheckTask):
def init(self, config):
self.machinfo = config.get("machinfo")
self.frontend = config.get("frontend")
def check(self):
all_machinfo = self.machinfo.all_information
# check USM mode
srmode = all_machinfo["SR_Mode"]
if srmode != "USM":
raise NotInUSMMode()
# check FE auto mode
feauto = all_machinfo["Automatic_Mode"]
if feauto is False:
self.machinfo.automatic_mode = True
fetime = all_machinfo["Auto_Mode_Time"]
if fetime < 24 * 60 * 60:
self.machinfo.automatic_mode = True
# check FE really open
if self.frontend.is_closed:
raise BLCheckError("Cannot open FrontEnd !!")
class BLCheckBSH(BLCheckTask):
def init(self, config):
self.shutter = config.get("shutter")
self.valves = config.get("valves")
def check(self):
# check shutter is opened
state = self.shutter.state
if state == TangoShutterState.DISABLE:
raise BLCheckError(f"shutter [{}] is {state}")
if self.shutter.is_closed:
if self.shutter.is_closed:
raise BLCheckError(f"Cannot open shutter [{}]")
# check valves are opened
for valve in self.valves:
if valve.is_closed:
if valve.is_closed:
raise BLCheckError(f"Cannot open valve [{}]")
class BLCheckIDPos(BLCheckTask):
def init(self, config):
self.motors = config.get("undulators")
def check(self):
for motor in self.motors:
if not "READY" in motor.state:
user_warning(f"{} not READY, cannot check position.")
elif not math.isnan(motor._set_position) and \
abs(motor.position - motor._set_position) < 0.01:
class BLCheckChainPreset(ChainPreset):
def __init__(self, blcheck_master):
self.__blcheck = blcheck_master
def prepare(self, acq_chain):
class BLCheckScanPreset(ScanPreset):
def __init__(self, blcheck_master):
self.__blcheck = blcheck_master
def prepare(self, scan):
class BLCheckMaster:
def __init__(self, name, config):
self.__name = name
self.__checklist = config.get("checklist")
self.__checknames = [ for check in self.__checklist ]
self.__settings = HashObjSetting(f"blcheck:{name}")
self.__state = self.__settings.get("state", False)
self.__chain_preset = BLCheckChainPreset(self)
self.__scan_preset = BLCheckScanPreset(self)
if self.__state:
def name(self):
return self.__name
def chain_preset(self):
return self.__chain_preset
def scan_preset(self):
return self.__scan_preset
def status(self):
status = self.__state is True and "ON" or "OFF"
return status
def get_states(self):
states = dict()
for name in self.__checknames:
states[name] = self.__settings.get(name, True)
return states
def auto_check(self):
if self.__state:
def on(self):
self.__state = True
self.__settings["state"] = True
def off(self):
self.__state = False
self.__settings["state"] = False
def enable(self, name):
if name not in self.__checknames:
raise ValueError("Unknown check name")
self.__settings[name] = True
def disable(self, name):
if name not in self.__checknames:
raise ValueError("Unknown check name")
self.__settings[name] = False
def get(self, name):
for check in self.__checklist:
if == name:
return check
raise ValueError("Unknown check name")
def __info__(self):
states = self.get_states()
heads = ["Name", "Description", "State"]
infos = list()
for check in self.__checklist:
state = states[] is True and "ENABLED" or "DISABLED"
infos.append([, check.title, state])
txt = tabulate.tabulate(infos, headers=heads)
txt += f"\n\nBeamLine check on scans is {self.status}\n"
return txt
def check(self):
states = self.get_states()
for blcheck in self.__checklist:
if not states[]:
print(f"Checking {blcheck.title} ...")
except NotInUSMMode:
print("Not in USM mode ==> no further checks performed.")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment