234 lines
8.8 KiB
Python
234 lines
8.8 KiB
Python
###################################################################################################
|
|
# Deployment specific global definitions - executed after startup.py
|
|
###################################################################################################
|
|
import ntpath
|
|
import traceback
|
|
|
|
"""
|
|
OTF_START = "X11MA-OTF:GO"
|
|
OTF_E1 = "X11MA-OTF:E1"
|
|
OTF_E2 = "X11MA-OTF:E2"
|
|
OTF_TIME = "X11MA-OTF:TIME"
|
|
OTF_FID = "X11MA-OTF:FID"
|
|
OTF_FTS = "X11MA-OTF:FTSTAMP"
|
|
OTF_FILE = "X11MA-OTF:FNAME"
|
|
ID1_MODE = "X11MA-ID1:MODE"
|
|
ID2_MODE = "X11MA-ID2:MODE"
|
|
ID1_ALPHA = "X11MA-ID1:ALPHA"
|
|
ID2_ALPHA = "X11MA-ID2:ALPHA"
|
|
ID1_OFF = "X11MA-ID1:ENERGY-OFFS"
|
|
ID2_OFF = "X11MA-ID2:ENERGY-OFFS"
|
|
ENERGY_SP = "X11MA-PHS:E_SP"
|
|
"""
|
|
ALL_DONE = "X11PHS:alldone"
|
|
VG10_SET = "X11MA-EPS-VG10:SET"
|
|
VG10_GET = "X11MA-OP-VG10:OPEN"
|
|
VG11_SET = "X11MA-EPS-VG11:SET"
|
|
VG11_GET = "X11MA-OP-VG11:OPEN"
|
|
VG12_SET = "X11MA-EPS-VG12:SET"
|
|
VG12_GET = "X11MA-OP-VG12:OPEN"
|
|
VG13_SET = "X11MA-EPS-VG13:SET"
|
|
VG13_GET = "X11MA-OP-VG13:OPEN"
|
|
|
|
"""
|
|
|
|
LPP_DELAY = "X11MA-ES2-4CHT:SET2-DELAY"
|
|
LPP_FINE_DELAY = "X11MA-ES2-4CHT:SET2-FINE"
|
|
TIME_DELAY_SET = "X11MA-ES2:Theta-New.A"
|
|
TIME_DELAY_VAL = "X11MA-ES2:Theta-Cur.VAL"
|
|
TIME_DELAY_START = "X11MA-ES2:SCAN-START"
|
|
TIME_DELAY_COMPLETE = "X11MA-ES2-scan1.SMSG"
|
|
TBT_MAG = "X11MA-LSCI632:MFIELD"
|
|
"
|
|
"""
|
|
def get_next_fid(folder, prefix):
|
|
try:
|
|
import glob
|
|
files = glob.glob(folder + prefix + '*_*.dat')
|
|
last = max(files)
|
|
index = int (last[last.rfind('_')+1 : last.rfind('.')]) + 1
|
|
return index
|
|
except:
|
|
return 0
|
|
|
|
def wait_channel(name, value, timeout =None, type='s'):
|
|
print "Waiting " + str(name) + " = " + str(value)
|
|
cawait(name, value, timeout = timeout, type=type)
|
|
print "Done"
|
|
|
|
def wait_device(dev, value, timeout=-1):
|
|
timeout = int(timeout *1000) if timeout>0 else timeout
|
|
dev.waitValue(value,timeout)
|
|
|
|
def open_vg10():
|
|
if caget (VG10_GET,'i') != 1:
|
|
caput(VG10_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG10_SET, 1)
|
|
|
|
def close_vg10():
|
|
if caget (VG10_GET,'i') == 1:
|
|
caput(VG10_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG10_SET, 1)
|
|
|
|
def open_vg11():
|
|
if caget (VG11_GET,'i') != 1:
|
|
caput(VG11_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG11_SET, 1)
|
|
|
|
def close_vg11():
|
|
if caget (VG11_GET,'i') == 1:
|
|
caput(VG11_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG11_SET, 1)
|
|
|
|
def open_vg12():
|
|
if caget (VG12_GET,'i') != 1:
|
|
caput(VG12_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG12_SET, 1)
|
|
|
|
def close_vg12():
|
|
if caget (VG12_GET,'i') == 1:
|
|
caput(VG12_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG12_SET, 1)
|
|
|
|
def open_vg13():
|
|
if caget (VG13_GET,'i') != 1:
|
|
caput(VG13_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG13_SET, 1)
|
|
|
|
def close_vg13():
|
|
if caget (VG13_GET,'i') == 1:
|
|
caput(VG13_SET, 0)
|
|
time.sleep(0.1)
|
|
caput(VG13_SET, 1)
|
|
|
|
def plot_file(file_name, ctxt = None):
|
|
"""
|
|
"""
|
|
sep = "\t"
|
|
with open(file_name) as f:
|
|
header = f.readline()[1:].split(sep)
|
|
table = Table.loadRaw(file_name, sep, '#',header)
|
|
plots = plot(table, title = ctxt)
|
|
|
|
def has_beam():
|
|
"""
|
|
"""
|
|
return beam_status.readback.read() == "Light Available"
|
|
|
|
def is_id_error():
|
|
return (id_error.read()==0)
|
|
|
|
def check_id_error():
|
|
if is_id_error():
|
|
raise Exception ("ID error: check ID status")
|
|
|
|
###################################################################################################
|
|
#Default scan callbacks
|
|
###################################################################################################
|
|
|
|
def before_sample():
|
|
pass
|
|
|
|
def after_sample():
|
|
check_id_error()
|
|
|
|
##################### Convert_File function #############################
|
|
"""
|
|
def convert_file(input_file_name, output_file_name):
|
|
sep = "\t"
|
|
line_sep = "\r\n"
|
|
field = caget('X11MA-XMCD:Ireadout')
|
|
with open(input_file_name) as inp:
|
|
lines = inp.readlines()
|
|
with open(output_file_name, "wb") as out:
|
|
out.write("Energy" + sep + "Io" + sep + "CADC2" + sep + "CADC3" + sep + "Mag" + line_sep)
|
|
s = sep + " " #File format has a space before numeric values
|
|
for line in lines[1:]:
|
|
line = line.strip()
|
|
if line=="": break
|
|
try:
|
|
(Ecrbk,CADC1, CADC2, NORM, CADC3, CADC4, MCurr, cffrbk, ID1Erbk, ID2Erbk, vTime) = line.split(" ")
|
|
out.write(Ecrbk + s + CADC1 + s + CADC2 + s + CADC3 + s + str(field) +line_sep)
|
|
except:
|
|
traceback.print_exc()
|
|
"""
|
|
def convert_file(input_file_name, output_file_name, pol = None):
|
|
print "Converting data file: " + input_file_name + " to " + output_file_name
|
|
#print "File converted to: ",output_file_name
|
|
sep = "\t"
|
|
line_sep = "\n"
|
|
MODE = pol_mode.read()
|
|
if pol is None:
|
|
pol = pol_angle.read() if (MODE == "LINEAR") else pol_mode.readback.read()
|
|
with open(input_file_name) as inp:
|
|
lines = inp.readlines()
|
|
with open(output_file_name, "wb") as out:
|
|
(db, st) = ("java.lang.Double", "java.lang.String")
|
|
out.write("#Energy" + sep + "CADC1" + sep + "CADC2" + sep + "CADC3" + sep + "NORMtey" + sep + "NORMdiode" + line_sep)
|
|
out.write("#"+ db + sep + db + sep + db + sep + db + sep + db + sep + db + line_sep)
|
|
s = sep
|
|
for line in lines[1:]:
|
|
line = line.strip()
|
|
if line=="": break
|
|
try:
|
|
(Ecrbk, CADC1, CADC2, CADC3, CADC4, MCurr, cffrbk, IDErbk, time) = line.split(" ")
|
|
normtey=repr( float(CADC2)/float(CADC1))
|
|
normdiode=repr(float(CADC3)/float(CADC1))
|
|
#field=caget(MAG)
|
|
out.write(Ecrbk + s + CADC1 + s + CADC2 + s + CADC3 + s + normtey + s + normdiode + line_sep)
|
|
except:
|
|
traceback.print_exc()
|
|
#os.rename(input_file_name, get_context().setup.expandPath("{data}/OTF/" + ntpath.basename(input_file_name)))
|
|
|
|
def convert_file_full(input_file_name, output_file_name, pol = None):
|
|
print "Converting data file: " + input_file_name + " to " + output_file_name
|
|
#print "File converted to: ",output_file_name
|
|
sep = "\t"
|
|
line_sep = "\n"
|
|
MODE = pol_mode.read()
|
|
if pol is None:
|
|
pol = pol_angle.read() if (MODE == "LINEAR") else pol_mode.readback.read()
|
|
with open(input_file_name) as inp:
|
|
lines = inp.readlines()
|
|
with open(output_file_name, "wb") as out:
|
|
(db, st) = ("java.lang.Double", "java.lang.String")
|
|
out.write("#Energy" + sep + "CADC1" + sep + "CADC2" + sep + "CADC3" + sep + "CADC4" + sep + "CADC5" + sep + "MCurr" + sep + "Time" + sep + "FieldX" + sep + "FieldZ" + sep + "Pol" + sep + "Temperature" + sep + "NORMtey" + sep + "NORMdiode" + line_sep)
|
|
out.write("#"+ db + sep + db + sep + db + sep + db + sep + db + sep + db + sep + db + sep + db + sep + db + sep + db + sep + st + sep + db + sep + db + sep + db + line_sep)
|
|
s = sep
|
|
for line in lines[1:]:
|
|
line = line.strip()
|
|
if line=="": break
|
|
try:
|
|
(Ecrbk, CADC1, CADC2, CADC3, CADC4, MCurr, cffrbk, IDErbk, time) = line.split(" ")
|
|
normtey=repr( float(CADC2)/float(CADC1))
|
|
normdiode=repr(float(CADC3)/float(CADC1))
|
|
CADC5=repr(0.0)
|
|
mcurr=repr(machine_cur.read())
|
|
fieldx=repr(field.read())
|
|
fieldz=repr(0.0)
|
|
temp=repr(Temp.read())
|
|
out.write(Ecrbk + s + CADC1 + s + CADC2 + s + CADC3 + s + CADC4 + s + CADC5 + s + mcurr + s + time + s + fieldx + s + fieldz + s + str(pol) + s + temp + s + normtey + s + normdiode + line_sep)
|
|
except:
|
|
traceback.print_exc()
|
|
#os.rename(input_file_name, get_context().setup.expandPath("{data}/OTF/" + ntpath.basename(input_file_name)))
|
|
|
|
###################################################################################################
|
|
#OTF function
|
|
###################################################################################################
|
|
def otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST'):
|
|
"""
|
|
"""
|
|
if name is None:
|
|
name = get_exec_pars().name
|
|
#folder = get_context().setup.expandPath("{year}_{month}/{date}");
|
|
run("templates/EnergyScan", {"E1":start, "E2":end, "TIME":time, "DELAY":float(delay), "MODE":mode, "OFFSET":(offset), "FOLDER":folder, "FILE":name, "ALPHA":float(alpha) if alpha is not None else None})
|
|
|
|
|