fixed stacklevel of warnings; added retry for reference undulator

This commit is contained in:
2025-01-28 18:14:11 +01:00
parent 7a49b276fd
commit def9f58252

View File

@ -37,13 +37,13 @@ class Undulators(Adjustable):
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})")
log.warning(f"the chosen reference undulator ({n_und_ref}) is not the reference undulator currently used by the machine ({machine_n_und_ref})", stacklevel=3)
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")
log.warning(f"the CHIC ({N_UND_CHIC}) is in the list of active undulators: {n_unds}, and will be ignored/removed", stacklevel=3)
n_unds.remove(N_UND_CHIC)
if n_und_ref not in n_unds:
@ -480,7 +480,15 @@ class Phases:
def get_machine_n_und_ref():
res = PVEnumAdjustable("SATUN:REF-UND").get()
n_tries = 3
for i in range(n_tries):
res = PVEnumAdjustable("SATUN:REF-UND", internal=True).get()
if res is not None:
break
print(f"try {i+1}/{n_tries}: got None instead of reference undulator number")
sleep(0.1)
if res is None:
raise ValueError(f"got None instead of reference undulator number {n_tries} times")
if not res.startswith("SATUN"):
return None
n = len("SATUN")