Files
x07db/script/local.py
gac-iss c54f0f9e35
2020-02-27 10:29:42 +01:00

84 lines
2.6 KiB
Python

###################################################################################################
# Deployment specific global definitions - executed after startup.py
###################################################################################################
import ch.psi.pshell.epics.ChannelString as ChannelString
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
scienta.getDataArray().setMonitored(True)
# Handlig diagnostics
diag_channels = []
diag_channels.append(scienta.channelBegin)
diag_channels.append(scienta.channelEnd)
diag_channels.append(scienta.sliceBegin)
diag_channels.append(scienta.sliceEnd)
diag_channels.append(scienta.numSlices)
diag_channels.append(scienta.numChannels)
diag_channels.append(scienta.lowEnergy)
diag_channels.append(scienta.centerEnergy)
diag_channels.append(scienta.highEnergy)
diag_channels.append(scienta.stepTime)
diag_channels.append(scienta.frames)
diag_channels.append(AcquisitionMode)
diag_channels.append(EnergyMode)
diag_channels.append(LensMode)
diag_channels.append(DetectorMode)
diag_channels.append(PassEnergy)
diag_channels.append(ElementSet)
diag_channels.append(StepSize)
diag_channels.append(NumIterations)
diag_channels.append(EntranceSlit)
diag_channels.append(ExitSlit)
diag_channels = sorted(diag_channels, key=lambda channel: channel.name)
def get_diag_name(diag):
return ch.psi.utils.Str.toTitleCase(diag.getName()).replace(" ", "").replace("Readback", "")
def print_diag():
for f in diag_channels:
print "%-25s %s" % (get_diag_name(f) , str(f.read()))
def create_diag_datasets(parent = None):
if parent is None:
parent = get_exec_pars().group
group = parent + "attrs/"
for f in diag_channels:
create_dataset(group+get_diag_name(f) , 's' if (type(f) is ch.psi.pshell.epics.ChannelString) else 'd')
def append_diag_datasets(parent = None):
if parent is None:
parent = get_exec_pars().group
group = parent + "attrs/"
for f in diag_channels:
try:
x = f.read()
if x is None:
x = '' if (type(f) is ch.psi.pshell.epics.ChannelString) else float('nan')
append_dataset(group+get_diag_name(f), x)
except:
log("Error sampling " + str(get_diag_name(f)) + ": " + str(sys.exc_info()[1]))
def after_readout(rec):
#if beam_ok:
if get_exec_pars().save:
#Saving only once the diag data
if rec.index == 0:
create_diag_datasets()
append_diag_datasets()
#else:
# rec.invalidate()