This commit is contained in:
gobbo_a
2025-01-14 16:18:27 +01:00
parent 8beeb7dbc7
commit 7a0da7c48c
80 changed files with 1697 additions and 589 deletions
+5 -3
View File
@@ -1,7 +1,9 @@
# shift BLM ROI by desired offset in us and reinitialise ioc
blm = "SATUN22-DBLM005"
ioc = "SARCL02-DBLM469"
offset = 0.040 # us
blm = "SARUN05-DBLM030"
#ioc = "SARUN04-DBLM516"
ioc = caget(blm + ":PLL-LOCKED-OP-CALC.INPA").split()[0]
ioc = ioc.split(':')[0]
offset = 0.000 # us
PIX = 2.33426704 # 1 / (124.8 MHz * 3) = 2.33426704 ns
evr = caget(blm + ":GPAC-DELAY-OP.INPA").split()[0]
delay = caget(evr)
+1 -1
View File
@@ -14,7 +14,7 @@ SETTLING_TIME = 0.1
NUM_IMAGES = 50 #number of images for every step
print cam_server.cameras
cam_server.start(CAMERA + "_sp1", True)
cam_server.start(CAMERA + "_sp", True)
wait_cam_server_message()
print cam_server.value.identifiers
m=cam_server.getDataMatrix()
+31 -12
View File
@@ -9,22 +9,27 @@ run("Devices/Elements")
run("Diagnostics/sig_process_wrapper")
BPM_SENSORS = [("x","X1"), ("y","Y1"), ("q","Q1")] #(logic name sufix, channel sufix)
TRAVEL_SPEED = 0.001
TRAVEL_SPEED = 0.05
ADD_CHANNELS = []
ADD_CHANNELS = ["SARFE10-PBPG050:HAMP-INTENSITY-CAL", "SARFE10-PBIG050-EVR0:CALCI"]
#Paramter parsing
prefix = args[0] if is_panel else "SINDI02-DLAC055"
scan_type = args[1] if is_panel else "Shrom3"
scan_range = args[2] if is_panel else [-0.12, 0.12]
cycles = args[3] if is_panel else 1
velocity = args[4] if is_panel else 0.00001
scan_range = args[2] if is_panel else [-0.0, 1.7]
cycles = args[3] if is_panel else 2
velocity = args[4] if is_panel else 0.005
bpms = args[5] if is_panel else ["SINDI02-DBPM040", "SINDI02-DBPM080"]
blms = args[6] if is_panel else ["SINDI02-DBLM085", "S10DI01-DBLM045"]
bkgrd = args[7] if is_panel else 5 #Number of beam synchronous messages
plt = args[8] if is_panel else plot(None, title = "DLAC Scan")[0]
bunch = args[9] if is_panel else 1
do_elog = True if is_panel else False
print "DLAC scan parameters: ", prefix, scan_type, scan_range, cycles, velocity, bpms, blms, bkgrd
center_pos = 199.484
center_pos = 154.50
beam_filter = get_beam_ok_channel(bunch) + " == 1"
scan_type_index = DLAC_POSITIONS.index(scan_type)
if scan_type_index<0:
raise Exception("Bad sample position name")
@@ -60,7 +65,7 @@ park_pos = caget (prefix + ":P0_U0_SP")
#List of stream channels
channels = [] #[("m_pos", scanner.motor_bs_readback.get_channel_name()), ]
for i in range (len(blms)):
channels.append (("blm" + str(i+1), blms[i] + ":B1_LOSS"))
channels.append (("blm" + str(i+1), blms[i] + ":B1_LOSS_RAW"))
series = LinePlotSeries(blms[i], None, min(i+1, 2))
plt.addSeries(series)
series.setLinesVisible(False)
@@ -68,6 +73,9 @@ for i in range (len(blms)):
for i in range (len(bpms)):
for sensor in BPM_SENSORS:
channels.append (("bpm" + str(i+1) + "_" + sensor[0], bpms[i] + ":" + sensor[1]))
channels.append(("beam_ok", get_beam_ok_channel(bunch)))
for ch in ADD_CHANNELS:
channels.append((ch, ch))
#Metadata
set_attribute("/", "DLAC Scanner", prefix)
@@ -93,12 +101,17 @@ if st.take() is None:
raise Exception("Error initializing data stream")
start = st.take().timestamp
st.setFilter(beam_filter)
#Scan callback
scan_complete, cur_cycle = False, 0
scan, res = None, None
destination = None
def check_end_scan(record, scan):
def check_end_scan(record, _scan):
global scan_complete, start, destination
global scan
scan=_scan
if motor.ready:
#if motor.isInPosition(destination):
print "Data aquisition completed"
@@ -106,7 +119,8 @@ def check_end_scan(record, scan):
scan.abort()
record.cancel() #So it won't be saved
else:
position = float( record[1].timestamp - start )
position = float( record[1].timestamp - start ) #TIME
#position = motor.readback.take() #POSITION
for i in range (len(blms)):
plt.getSeries(i).appendData(position, record[2 + i])
@@ -133,7 +147,7 @@ msg = ""
print "Starting scan..."
try:
do_background()
#do_background()
#plt.getAxis(plt.AxisId.X).setRange(scan_range[0], scan_range[1])
for s in plt.getAllSeries():
@@ -157,7 +171,7 @@ try:
#else:
# motor.moveAsync(center_pos + scan_range[0])
start = st.take().timestamp
mscan ( st, [motor.readback,] + st.getReadables(), -1, -1, take_initial = True, after_read = check_end_scan)
res = mscan ( st, [motor.readback,] + st.getReadables(), -1, -1, take_initial = True, after_read = check_end_scan)
except:
print "Quit scan"
if not scan_complete:
@@ -174,9 +188,14 @@ try:
"""
finally:
print "Closing stream"
st.close()
print "Closing stream"
motor.setSpeed(TRAVEL_SPEED)
motor.stop()
st.close()
if res:
plot(res["blm1"], xdata= res[motor.readback], title="BLM 1 x Motor")
plot(res["blm2"], xdata= res[motor.readback], title="BLM 2 x Motor")
print msg
Executable → Regular
+44 -20
View File
@@ -10,7 +10,14 @@ run("Devices/Elements")
run("Devices/WireScanner")
run("Diagnostics/sig_process_wrapper")
#set_exec_pars(layout="default")
#LayoutSF
DATA_GROUP_PREFIX = "data/"
DATASET_SUFIX = "/value"
set_exec_pars(layout="default")
#LayoutDefault
DATA_GROUP_PREFIX = ""
DATASET_SUFIX = ""
#Paramter parsing
prefix = args[0] if has_args else "SARCL01-DWSC160" # "SINDI01-DWSC090" # "S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090"
@@ -42,6 +49,9 @@ SET_BLM_WS_MODE = True
SET_BLM_WS_SETTLING_TIME = 2.0
SET_BLM_WS_BS_READBACK_TIMEOUT = 10000 #ms
ADD_CHANNELS = []
#ADD_CHANNELS = ["SARFE10-PBPG050:HAMP-INTENSITY-CAL", "SARFE10-PBIG050-EVR0:CALCI"]
#TODO: configure biggerCAJ buffer size and set back to 10000
SAMPLE_CHANNEL_SIZE = 2049 #10000
SAMPLE_CHANNEL_EMPTY_VALUE = 0.0
@@ -75,7 +85,6 @@ rr = get_repetition_rate(bunch)
velocity_x = abs(scan_range[1]-scan_range[0])*rr/n_shot
velocity_y = abs(scan_range[3]-scan_range[2])*rr/n_shot
#Creating WireScanner object
print "Creating scanner..."
if prefix not in get_wire_scanners():
@@ -85,10 +94,12 @@ scanner = WireScanner(prefix, scan_range, cycles, None, True)
#List of stream channels
channels = [("m_pos", scanner.motor_bs_readback.get_channel_name()),
("cur_cycle", scanner.curr_cycl.get_channel_name()),
("scanning", scanner.status_channels[0].get_channel_name())]
("scanning", scanner.status_channels[0].get_channel_name())]
for i in range (len(blms)):
channels.append (("blm" + str(i+1), blms[i] + ":B" + str(bunch) + "_LOSS"))
channels.append (("blm" + str(i+1), blms[i] + ":B" + str(bunch) + "_LOSS_RAW"))
#channels.append (("blm" + str(i+1), blms[i] + ":B" + str(bunch) + "_LOSS"))
if plt is not None:
series = LinePlotSeries(blms[i], None, min(i+1, 2))
plt.addSeries(series)
@@ -103,7 +114,9 @@ for i in range (len(bpms)):
if SET_BLM_WS_MODE and (len(blms)>0):
channels.append(("blm1_ws_mode", blms[0] + ":WS_RUNNING"))
channels.append(("beam_ok", get_beam_ok_channel(bunch)))
for ch in ADD_CHANNELS:
channels.append((ch, ch))
#Metadata
set_attribute("/", "Wire Scanner", prefix)
@@ -136,15 +149,19 @@ for retry in range(STREAM_CREATION_RETRIES):
st.addScalar(c[0], c[1], int(100.0 / rr), 0)
st.initialize()
st.start()
add_device(st, True)
st.waitCacheChange(10000) #Wait stream be running before starting scan
break
except:
print "Error starting stream"
print sys.exc_info()[1]
if retry >= (STREAM_CREATION_RETRIES-1):
channels_names = [dev.name for dev in st1.children]
msg = "Error creating stream with channels:\n" + "\n".join(channels_names)
show_message(msg)
print(msg)
raise
else:
print "Retrying"
print "Error creating stream, retrying..."
class Timestamp(Readable):
def read(self):
@@ -168,20 +185,27 @@ def check_end_scan(record, scan):
if (rec is None) and (record is not None):
print "Started receiving from stream"
rec = record
if record[4]<1:
if record["scanning"]<1:
print "Data aquisition completed"
scan_complete=True
scan.abort()
record.cancel() #So it won't be saved
else:
position = record[0]
if record[3] != cur_cycle:
cur_cycle = record[3]
position = record["w_pos"]
if record["cur_cycle"] != cur_cycle:
cur_cycle = record["cur_cycle"]
get_context().dataManager.splitScanData(scan)
#if plt is not None: for s in plt.getAllSeries(): s.clear()
if plt is not None:
for i in range (len(blms)):
plt.getSeries(i).appendData(position, record[5 + i])
try:
val = record["blm" + str(i+1)]
if val is None:
val = float("NaN")
print "Null value for blm ", ("blm" + str(i+1))
plt.getSeries(i).appendData(position, val)
except:
print "Error plotting position " , position, record["blm" + str(i+1)]
if scanner.take() != "At start":
print "Not at start: parking scanner"
@@ -196,7 +220,7 @@ def do_background():
for i in range(len(r.getReadables())):
d = r.getReadable(i)
try:
path = get_exec_pars().group + "/data/"+ r.getReadables()[i].name
path = get_exec_pars().group + "/" + DATA_GROUP_PREFIX + r.getReadables()[i].name
set_attribute(path, "Mean", mean(d))
set_attribute(path, "Sigma", stdev(d) )
except:
@@ -296,19 +320,19 @@ def calculate():
for i in range(len(blms)):
msg += "Wire " + wire + " - BLM " + str(i+1) + ":\n"
try:
blm_back_path = "background/data/blm" + str(i+1)
blm_back_path = "background/" + DATA_GROUP_PREFIX + "blm" + str(i+1)
print "BLM path: ", blm_back_path
blm_back_attrs = get_attributes(blm_back_path)
print "BLM attrs: ", blm_back_attrs
bg = blm_back_attrs["Mean"] if bkgrd>0 else 0.0
samples = [[], [], [], [], [], []]
for cycle in range (cycles):
pos_path = wire+"_" + ("%04d" % (cycle+1)) + "/data/w_pos"
pos_path = wire+"_" + ("%04d" % (cycle+1)) + "/" + DATA_GROUP_PREFIX+ "w_pos"
print "Loading: ", pos_path
pos = load_data(pos_path+"/value")
path = wire+"_" + ("%04d" % (cycle+1)) + "/data/blm" + str(i+1)
pos = load_data(pos_path + DATASET_SUFIX)
path = wire+"_" + ("%04d" % (cycle+1)) + "/" + DATA_GROUP_PREFIX + "blm" + str(i+1)
print "Loading ", path
data = load_data(path+"/value")
data = load_data(path + DATASET_SUFIX)
print "OK"
sp = data #blm_remove_spikes(data)
sig = sp if bg is None else [v-bg for v in sp]
@@ -336,7 +360,7 @@ def calculate():
#g = Gaussian(amp, com, sigma)
#gauss = [g.value(v)+off for v in pos]
#plot([data, sp, sig, gauss], ["data", "sp", "signal", "gauss", ], xdata = pos, title="Fit blm" + str(i+1) + " - " + str(cycle+1))
ret.extend([rms_com, rms_sigma, com, sigma, filename + "|"+ pos_path +"/value", filename + "|"+ path +"/value"])
ret.extend([rms_com, rms_sigma, com, sigma, filename + "|"+ pos_path + DATASET_SUFIX, filename + "|"+ path + DATASET_SUFIX])
stats.append([])
for sample in samples:
@@ -486,7 +510,7 @@ finally:
stop_blm_ws(blms[i])
print "Closing scanner"
scanner.close()
print "Closing stream"
print "Closing stream"
st.close()
print msg