CALCULATE = True class CalculateBLM(Readable): def __init__(self, index): self.index = index def getName(self): return "blm" + str(self.index + 1) def read(self): raw = st.take()[blms[self.index] + ":LOSS_SIGNAL_RAW"] #min_wf=np.min(BLM_NAME:LOSS_SIGNAL_RAW[:1500]) #summa=sum(raw[(min_wf-20):(min_wf+20)]) #min_wf=min(raw[:1500]) min_wf=raw.index(min(raw[:1500])) summa=sum(raw[(min_wf-20):(min_wf+20)]) print self.index , (min_wf-20) , (min_wf+20) return summa import traceback is_embedded = (get_exec_pars().getCommand(False).parent != None) has_args = is_embedded or (get_exec_pars().source != CommandSource.ui) STREAM_CREATION_RETRIES = 3 MAX_RANGE_STEP = 3 run("Devices/Elements") run("Devices/WireScanner") run("Diagnostics/sig_process_wrapper") #set_exec_pars(layout="default") #Paramter parsing prefix = args[0] if has_args else "SARCL01-DWSC160" # "SINDI01-DWSC090" # "S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" scan_type = args[1] if has_args else WireScanner.WireX1 scan_range = args[2] if has_args else [] cycles = args[3] if has_args else 2 #velocity = args[4] if has_args else 200 n_shot = args[4] if has_args else 200 bpms = args[5] if has_args else [] #get_wire_scanners_bpms(prefix) blms = args[6] if has_args else get_wire_scanners_blms(prefix) bkgrd = args[7] if has_args else 10 plt = args[8] if has_args else plot(None, title = "Wire Scan")[0] save_raw = args[9] if has_args else False bunch = args[10] if has_args else 1 adaptive = args[11] if has_args else 1 #0=Off, 1=Gain, 2=Gain+range filter_beam_ok = (args[12] if (has_args and len(args)>12) else True) do_elog = True if (has_args and (not is_embedded) and (plt is not None)) else False print has_args, is_embedded, do_elog print "WireScan parameters: ", prefix, scan_type, scan_range, cycles, n_shot, bpms, blms, bkgrd, bunch, adaptive #Adaptive mode parameters MIN_GAIN, MAX_GAIN = 0.5, 1.1 INCREMENT_FACTOR = 0.5 SCAN_RANGE_FACTOR = 6 MAX_RANGE_STEP = 300 SET_BLM_WS_MODE = True SET_BLM_WS_SETTLING_TIME = 2.0 SET_BLM_WS_BS_READBACK_TIMEOUT = 10000 #ms #TODO: configure biggerCAJ buffer size and set back to 10000 SAMPLE_CHANNEL_SIZE = 2049 #10000 SAMPLE_CHANNEL_EMPTY_VALUE = 0.0 BPM_SENSORS = [("x","X"+str(bunch)), ("y","Y"+str(bunch)), ("q","Q"+str(bunch))] #(logic name suffix, channel suffix) #Plot setup if plt is not None: plt.clear() plt.removeMarker(None) plt.getAxis(plt.AxisId.X).setLabel("Position"); plt.getAxis(plt.AxisId.Y).setLabel(""); plt.getAxis(plt.AxisId.Y2).setLabel(""); plt.setLegendVisible(True); snapshots = [] rr = get_repetition_rate(bunch) channels=[] for i in range (len(blms)): index_blm = len(channels) #channels.append (("blm" + str(i+1), blms[i] + ":B" + str(bunch) + "_LOSS_RAW")) channels.append ((("blm_loss" + str(i+1)) if CALCULATE else ("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) series.setLinesVisible(False) series.setPointSize(2) if save_raw or CALCULATE: channels.append (("blm" + str(i+1) + "_raw" , blms[i] + ":LOSS_SIGNAL_RAW")) for i in range (len(bpms)): for sensor in BPM_SENSORS: channels.append (("bpm" + str(i+1) + "_" + sensor[0], bpms[i] + ":" + sensor[1])) 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))) filename = get_exec_pars().path #Stream creation for retry in range(STREAM_CREATION_RETRIES): try: print "Starting stream..." st = Stream("pulse_id", dispatcher) for c in channels: if c[1].endswith("LOSS_SIGNAL_RAW"): st.addWaveform(c[0], c[1], int(100.0 / rr), 0) else: 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): raise else: print "Retrying" class Timestamp(Readable): def read(self): return st.getTimestamp() start_time=time.time() #Pseudo-device returning the wire position class w_pos(Readable): def read(self): return time.time() - start_time rec =None scan_complete=False cur_cycle = 1.0 if plt is not None: for s in plt.getAllSeries(): s.clear() plt.removeMarker(None) l=[w_pos()] ; l.extend(st.getReadables()); l.append(Timestamp()); if CALCULATE: for i in range (len(blms)): l.append (CalculateBLM(i)) print "Start scan" mscan (st, l, 10) print "End scan"