read, use or compare reference undulator currently used by the machine
This commit is contained in:
@ -4,30 +4,51 @@ from epics import PV
|
||||
|
||||
from logzero import logger as log
|
||||
|
||||
from slic.core.adjustable import Adjustable
|
||||
from slic.core.adjustable import PVAdjustable
|
||||
from slic.core.adjustable import Adjustable, PVAdjustable, PVEnumAdjustable
|
||||
from slic.core.scanner.scanbackend import wait_for_all #, stop_all
|
||||
|
||||
|
||||
UND_NAME_FMT = "SATUN{:02}-UIND030"
|
||||
N_UND_CHIC = 14
|
||||
|
||||
N_UNDS = list(range(6, 22+1))
|
||||
N_UNDS.remove(N_UND_CHIC)
|
||||
|
||||
|
||||
|
||||
class Undulators(Adjustable):
|
||||
"""
|
||||
for n_und_ref=None (default), the reference undulator currently used by the machine will be used
|
||||
"""
|
||||
|
||||
def __init__(self, n_unds, n_und_ref, chic_fudge_offset=0, adjust_chic=True, scaled=True, ID="ATHOS_UNDULATORS", name="Athos Undulators", units="eV"):
|
||||
def __init__(self, n_unds=N_UNDS, n_und_ref=None, chic_fudge_offset=0, adjust_chic=True, scaled=True, ID="ATHOS_UNDULATORS", name="Athos Undulators", units="eV"):
|
||||
super().__init__(ID, name=name, units=units)
|
||||
|
||||
self.n_unds = n_unds = list(n_unds)
|
||||
self.n_und_ref = n_und_ref
|
||||
|
||||
if n_und_ref not in n_unds:
|
||||
raise ValueError(f"the reference undulator ({n_und_ref}) is not in the list of active undulators: {n_unds}")
|
||||
machine_n_und_ref = get_machine_n_und_ref()
|
||||
|
||||
if n_und_ref is None:
|
||||
if machine_n_und_ref is None:
|
||||
raise ValueError(f"could not read reference undulator currently used by the machine, please specify n_und_ref")
|
||||
n_und_ref = machine_n_und_ref
|
||||
|
||||
if n_und_ref != machine_n_und_ref:
|
||||
log.warning(f"the chosen reference undulator ({n_und_ref}) is not the reference undulator currently used by the machine ({machine_n_und_ref})")
|
||||
|
||||
|
||||
n_unds = list(n_unds)
|
||||
|
||||
if N_UND_CHIC in n_unds:
|
||||
log.warning(f"the CHIC ({N_UND_CHIC}) is in the list of active undulators: {n_unds}, and will be ignored/removed")
|
||||
n_unds.remove(N_UND_CHIC)
|
||||
|
||||
if n_und_ref not in n_unds:
|
||||
raise ValueError(f"the reference undulator ({n_und_ref}) is not in the list of active undulators: {n_unds}")
|
||||
|
||||
|
||||
self.n_unds = n_unds
|
||||
self.n_und_ref = n_und_ref
|
||||
|
||||
self.und_names = und_names = [UND_NAME_FMT.format(n) for n in n_unds]
|
||||
self.und_name_cal = und_name_cal = UND_NAME_FMT.format(n_und_ref)
|
||||
|
||||
@ -43,6 +64,7 @@ class Undulators(Adjustable):
|
||||
self.scale = ScalerEK(a)
|
||||
|
||||
|
||||
|
||||
def set_target_value(self, value, hold=False):
|
||||
k = self.convert.K(value)
|
||||
if np.isnan(k):
|
||||
@ -200,3 +222,21 @@ class CHIC(PVAdjustable):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def get_machine_n_und_ref():
|
||||
res = PVEnumAdjustable("SATUN:REF-UND").get()
|
||||
if not res.startswith("SATUN"):
|
||||
return None
|
||||
n = len("SATUN")
|
||||
res = res[n:]
|
||||
try:
|
||||
res = int(res)
|
||||
except ValueError:
|
||||
return None
|
||||
return res
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user