Files
sf-op/script/Diagnostics/WireScan.py
2017-04-13 11:05:05 +02:00

101 lines
3.0 KiB
Python

is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
run("Devices/Elements")
run("Devices/WireScanner")
BPM_SENSORS = {} #{"x":"X1", "y":"Y1", "q":"Q1"}
#Paramter parsing
if is_panel:
prefix = args[0]
sel = args[1]
start = args[2]
end = args[3]
cycles = args[4]
velocity = args[5]
bpm3 = args[6]
else:
prefix = "S30CB09-DWSC440" #"SARCL02-DWSC270" # "SINDI01-DWSC090" #"SARCL02-DWSC270"
sel = WireScanner.W1X
start = -200
end = 200
cycles = 5
velocity = 200
bpm3 = None
print "WireScan parameters: ", prefix, sel, start, end, cycles, cycles, bpm3
#Creating WireScanner object
print "Creating scanner..."
if prefix not in get_wire_scans():
raise Exception("Invalid wire scan: " + prefix)
scanner = WireScanner(prefix, sel, start, end, cycles, velocity, True)
scanner.init()
scanner.waitValue("At start", 60000)
#List of stream channels
channels = [("w_pos", scanner.motor_bs_readback.get_name()),
("cur_cycle", scanner.curr_cycl.get_name()),
("scanning", scanner.status_channels[0].get_name())]
bpms = get_wire_scans_bpms(prefix)
if bpms is None:
raise Exception("Cannot determine wire scan bpms: " + prefix)
if bpm3 is not None:
bpms.append(bpm3)
bpms = ["SINDI01-DBPM060", "SINDI02-DBPM010"] #For testing
for i in range (len(bpms)):
for sensor in BPM_SENSORS.keys():
channels.append (("bpm" + str(i+1) + "_" + sensor, bpms[i] + ":" + BPM_SENSORS[sensor]))
#Stream creation
print "Starting stream..."
st = Stream("pulse_id", dispatcher)
scanner.curr_cycl.write(0)
st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the reansition to know when the finished
for c in channels:
st.addScalar(c[0], c[1], 10, 0)
st.initialize()
st.start()
st.waitCacheChange(10000) #Wait stream be running before starting scan
#End of scan checking
scan_complete=False
cur_cycle = 1
def check_end_scan(record, scan):
global scan_complete,cur_cycle
if record[3]<1:
print "Data aquisition completed"
scan_complete=True
scan.abort()
elif record[2] != cur_cycle:
cur_cycle = record[2]
get_context().dataManager.splitScanData(scan)
#Metadata
set_attribute("/", "Wire Scan", prefix)
set_attribute("/", "Selection", sel)
set_attribute("/", "Range", scanner.scan_range)
set_attribute("/", "Cycles", scanner.cycles )
set_attribute("/", "Velocity", scanner.velocity )
#Scan
try:
print "Starting scan..."
scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait
mscan (st, st.getReadables(), -1, -1, after_read = check_end_scan)
except:
if not scanner.isReady():
print "Aborting Wire Scan"
scanner.abort()
if not scan_complete:
raise
finally:
print "Closing scanner"
scanner.close()
print "Closing stream"
st.close()