def setBPMs(self,bpm_wrappers): self.batchGetRequest = BatchGetValueRequest() self.bpm_wrappers = bpm_wrappers #-------------------------------------------- self.bpm_ch_amp_phase_dict = {} self.bpm_old_phases_dict = {} ch_arr = [] for bpm_wrapper in self.bpm_wrappers: if(not bpm_wrapper.isGood): continue bpm = bpm_wrapper.getBPM() ch_ampl = ChannelFactory.defaultFactory().getChannel(bpm.getId()+":amplitudeAvg") ch_phase = ChannelFactory.defaultFactory().getChannel(bpm.getId()+":phaseAvg") if(ch_ampl.connectAndWait(0.5) and ch_phase.connectAndWait(0.5)): self.bpm_ch_amp_phase_dict[bpm_wrapper] = (ch_ampl,ch_phase) #print "debug bpm=",bpm_wrapper.alias," added!" ch_arr.append(ch_ampl) ch_arr.append(ch_phase) else: bpm_wrapper.isGood = false #print "debug bad BPM =",bpm_wrapper.alias for ch in ch_arr: self.batchGetRequest.addChannel(ch)
class BPM_Batch_Reader: """ Collects PV channel data for all BPMs """ def __init__(self, top_level_cotroller=null): self.top_level_cotroller = top_level_cotroller self.bpms = [] self.batchGetRequest = null self.beam_trigger = null #-------------------------------------------- self.bpm_ch_amp_phase_dict = {} self.bpm_old_phases_dict = {} self.bpm_wrappers = [] def setBPMs(self, bpm_wrappers): self.batchGetRequest = BatchGetValueRequest() self.bpm_wrappers = bpm_wrappers #-------------------------------------------- self.bpm_ch_amp_phase_dict = {} self.bpm_old_phases_dict = {} ch_arr = [] for bpm_wrapper in self.bpm_wrappers: if (not bpm_wrapper.isGood): continue bpm = bpm_wrapper.getBPM() ch_ampl = ChannelFactory.defaultFactory().getChannel( bpm.getId() + ":amplitudeAvg") ch_phase = ChannelFactory.defaultFactory().getChannel(bpm.getId() + ":phaseAvg") if (ch_ampl.connectAndWait(0.5) and ch_phase.connectAndWait(0.5)): self.bpm_ch_amp_phase_dict[bpm_wrapper] = (ch_ampl, ch_phase) #print "debug bpm=",bpm_wrapper.alias," added!" ch_arr.append(ch_ampl) ch_arr.append(ch_phase) else: bpm_wrapper.isGood = false #print "debug bad BPM =",bpm_wrapper.alias for ch in ch_arr: self.batchGetRequest.addChannel(ch) def getBPM_Wrappers(self): return self.bpm_wrappers def setBeamTrigger(self, beam_trigger): self.beam_trigger = beam_trigger def getBatchGetRequest(self): """ returns the batch request object. """ return self.batchGetRequest def makeMeasurement(self): """ It will get a new set of BPM data into the self.batchGetRequest """ count = 0 bad_count = 0 result_info = false #print "debug make shot!" tm_start = time.time() trigger_res = self.beam_trigger.makeShot() #print "debug shot is done = dT=",time.time() -tm_start if (not trigger_res): return false while (result_info == false): count += 1 if (count > 20): return false result_info = true res_info = self.batchGetRequest.submitAndWait(3.) #print "debug shot batch request is done res=",res_info," dT=",time.time() -tm_start if (res_info == false): if (self.top_level_cotroller != null): messageTextField = self.top_level_cotroller.getMessageTextField( ) messageTextField.setText( "Cannot read BPM data! Stop and repare the BPM list!") return false #check if the results are different from the previous measurements bad_bpm_name = null for bpm_wrapper in self.bpm_wrappers: if (self.bpm_old_phases_dict.has_key(bpm_wrapper) and self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (ch_ampl, ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] bpm_phase_new = self.batchGetRequest.getRecord( ch_phase).doubleValue() bpm_phase_old = self.bpm_old_phases_dict[bpm_wrapper] if (bpm_phase_new == bpm_phase_old): #print "debug bad point for bpm=",bpm_wrapper.alias," old phase=",bpm_phase_old," new=",bpm_phase_new result_info = false bad_bpm_name = bpm_wrapper.alias bad_count += 1 break #print "debug measure is done res=",result_info," dT=",time.time() -tm_start," top=",self.top_level_cotroller if (not result_info): if (self.top_level_cotroller != null): messageTextField = self.top_level_cotroller.getMessageTextField( ) txt = "" if (bad_bpm_name != null): txt = " Bad BPM=" + bad_bpm_name + "!" messageTextField.setText( "BPM data did not update after the beam trigger! Do something!" + txt) if (bad_count > 5): time.sleep(1.) trigger_res = self.beam_trigger.makeShot() if (not trigger_res): return false time.sleep(0.01) continue for bpm_wrapper in self.bpm_wrappers: if (self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (ch_ampl, ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] bpm_phase = self.batchGetRequest.getRecord( ch_phase).doubleValue() self.bpm_old_phases_dict[bpm_wrapper] = bpm_phase #print "debug measure is done return dT=",time.time() -tm_start return true def makePhaseScanStep(self, cav_phase, cav_wrapper, bpm_amp_min_limit=0.1): """ It will add one point (cav_phase,bpm_amp) or (cav_phase,bpm_phase) to the plots in the dictonary. bpm_amp_phase_dict[bpm_wrapper] = (graphDataAmp,graphDataPhase) """ scan_is_good = false count = 0 bad_count_limit = 3 while (not scan_is_good): scan_is_good = true count += 1 if (count > bad_count_limit): return false if (not self.makeMeasurement()): return false bpm_amp_phase_dict = cav_wrapper.bpm_amp_phase_dict #--------get bpm amp and phase ------------- if (bpm_amp_phase_dict.has_key(cav_wrapper.bpm_wrapper0)): (ch_ampl, ch_phase ) = self.bpm_ch_amp_phase_dict[cav_wrapper.bpm_wrapper0] bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord( ch_phase).doubleValue() if (bpm_amp < bpm_amp_min_limit): scan_is_good = false if (bpm_amp_phase_dict.has_key(cav_wrapper.bpm_wrapper1)): (ch_ampl, ch_phase ) = self.bpm_ch_amp_phase_dict[cav_wrapper.bpm_wrapper1] bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord( ch_phase).doubleValue() if (bpm_amp < bpm_amp_min_limit): scan_is_good = false if (cav_wrapper.bpm_wrapper0 == null): #that is for "All Off" cavity wrapper bpm_wrapper_first_good = null for bpm_wrapper in self.bpm_wrappers: if (bpm_wrapper.isGood and bpm_amp_phase_dict.has_key(bpm_wrapper)): bpm_wrapper_first_good = bpm_wrapper break if (bpm_wrapper_first_good != null): (ch_ampl, ch_phase ) = self.bpm_ch_amp_phase_dict[bpm_wrapper_first_good] bpm_amp = self.batchGetRequest.getRecord( ch_ampl).doubleValue() if (bpm_amp < bpm_amp_min_limit): scan_is_good = false else: scan_is_good = false if (scan_is_good == false): continue for bpm_wrapper in self.bpm_wrappers: if (bpm_amp_phase_dict.has_key(bpm_wrapper) and self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (graphDataAmp, graphDataPhase) = bpm_amp_phase_dict[bpm_wrapper] (ch_ampl, ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] #print "debug ch amp=",ch_ampl.channelName()," phase=",ch_phase.channelName() bpm_amp = self.batchGetRequest.getRecord( ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord( ch_phase).doubleValue() graphDataAmp.addPoint(cav_phase, bpm_amp) old_bpm_phase = 0. if (graphDataPhase.getNumbOfPoints() > 0): old_bpm_phase = graphDataPhase.getY( graphDataPhase.getNumbOfPoints() - 1) graphDataPhase.addPoint( cav_phase, makePhaseNear(bpm_phase, old_bpm_phase)) return true def collectStatistics(self, bpm_amp_phase_data_dict): """ It will add one point BPMs' amp and phase to the arrays in the dictonary. bpm_amp_phase_data_dict[bpm_wrapper] = ([amp0,amp1,...],[phase0,phase1,...]) """ if (not self.makeMeasurement()): return false #--------get bpm amp and phase ------------- for bpm_wrapper in self.bpm_wrappers: if (bpm_amp_phase_data_dict.has_key(bpm_wrapper) and self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (amp_arr, phase_arr) = bpm_amp_phase_data_dict[bpm_wrapper] (ch_ampl, ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] #print "debug ch amp=",ch_ampl.channelName()," phase=",ch_phase.channelName() bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord( ch_phase).doubleValue() amp_arr.append(bpm_amp) phase_arr.append(bpm_phase) return true
class BPM_Batch_Reader: """ Collects PV channel data for all BPMs """ def __init__(self,top_level_cotroller = null): self.top_level_cotroller = top_level_cotroller self.bpms = [] self.batchGetRequest = null self.beam_trigger = null #-------------------------------------------- self.bpm_ch_amp_phase_dict = {} self.bpm_old_phases_dict = {} self.bpm_wrappers = [] def setBPMs(self,bpm_wrappers): self.batchGetRequest = BatchGetValueRequest() self.bpm_wrappers = bpm_wrappers #-------------------------------------------- self.bpm_ch_amp_phase_dict = {} self.bpm_old_phases_dict = {} ch_arr = [] for bpm_wrapper in self.bpm_wrappers: if(not bpm_wrapper.isGood): continue bpm = bpm_wrapper.getBPM() ch_ampl = ChannelFactory.defaultFactory().getChannel(bpm.getId()+":amplitudeAvg") ch_phase = ChannelFactory.defaultFactory().getChannel(bpm.getId()+":phaseAvg") if(ch_ampl.connectAndWait(0.5) and ch_phase.connectAndWait(0.5)): self.bpm_ch_amp_phase_dict[bpm_wrapper] = (ch_ampl,ch_phase) #print "debug bpm=",bpm_wrapper.alias," added!" ch_arr.append(ch_ampl) ch_arr.append(ch_phase) else: bpm_wrapper.isGood = false #print "debug bad BPM =",bpm_wrapper.alias for ch in ch_arr: self.batchGetRequest.addChannel(ch) def getBPM_Wrappers(self): return self.bpm_wrappers def setBeamTrigger(self,beam_trigger): self.beam_trigger = beam_trigger def getBatchGetRequest(self): """ returns the batch request object. """ return self.batchGetRequest def makeMeasurement(self): """ It will get a new set of BPM data into the self.batchGetRequest """ count = 0 bad_count = 0 result_info = false #print "debug make shot!" tm_start = time.time() trigger_res = self.beam_trigger.makeShot() #print "debug shot is done = dT=",time.time() -tm_start if(not trigger_res): return false while(result_info == false): count += 1 if(count > 20): return false result_info = true res_info = self.batchGetRequest.submitAndWait(3.) #print "debug shot batch request is done res=",res_info," dT=",time.time() -tm_start if(res_info == false): if(self.top_level_cotroller != null): messageTextField = self.top_level_cotroller.getMessageTextField() messageTextField.setText("Cannot read BPM data! Stop and repare the BPM list!") return false #check if the results are different from the previous measurements bad_bpm_name = null for bpm_wrapper in self.bpm_wrappers: if(self.bpm_old_phases_dict.has_key(bpm_wrapper) and self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] bpm_phase_new = self.batchGetRequest.getRecord(ch_phase).doubleValue() bpm_phase_old = self.bpm_old_phases_dict[bpm_wrapper] if(bpm_phase_new == bpm_phase_old): #print "debug bad point for bpm=",bpm_wrapper.alias," old phase=",bpm_phase_old," new=",bpm_phase_new result_info = false bad_bpm_name = bpm_wrapper.alias bad_count += 1 break #print "debug measure is done res=",result_info," dT=",time.time() -tm_start," top=",self.top_level_cotroller if(not result_info): if(self.top_level_cotroller != null): messageTextField = self.top_level_cotroller.getMessageTextField() txt = "" if(bad_bpm_name != null): txt = " Bad BPM="+bad_bpm_name+"!" messageTextField.setText("BPM data did not update after the beam trigger! Do something!"+txt) if(bad_count > 5): time.sleep(1.) trigger_res = self.beam_trigger.makeShot() if(not trigger_res): return false time.sleep(0.01) continue for bpm_wrapper in self.bpm_wrappers: if(self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] bpm_phase = self.batchGetRequest.getRecord(ch_phase).doubleValue() self.bpm_old_phases_dict[bpm_wrapper] = bpm_phase #print "debug measure is done return dT=",time.time() -tm_start return true def makePhaseScanStep(self, cav_phase, cav_wrapper, bpm_amp_min_limit = 0.1): """ It will add one point (cav_phase,bpm_amp) or (cav_phase,bpm_phase) to the plots in the dictonary. bpm_amp_phase_dict[bpm_wrapper] = (graphDataAmp,graphDataPhase) """ scan_is_good = false count = 0 bad_count_limit = 3 while(not scan_is_good): scan_is_good = true count += 1 if(count >bad_count_limit): return false if(not self.makeMeasurement()): return false bpm_amp_phase_dict = cav_wrapper.bpm_amp_phase_dict #--------get bpm amp and phase ------------- if(bpm_amp_phase_dict.has_key(cav_wrapper.bpm_wrapper0)): (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[cav_wrapper.bpm_wrapper0] bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord(ch_phase).doubleValue() if(bpm_amp < bpm_amp_min_limit): scan_is_good = false if(bpm_amp_phase_dict.has_key(cav_wrapper.bpm_wrapper1)): (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[cav_wrapper.bpm_wrapper1] bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord(ch_phase).doubleValue() if(bpm_amp < bpm_amp_min_limit): scan_is_good = false if(cav_wrapper.bpm_wrapper0 == null): #that is for "All Off" cavity wrapper bpm_wrapper_first_good = null for bpm_wrapper in self.bpm_wrappers: if(bpm_wrapper.isGood and bpm_amp_phase_dict.has_key(bpm_wrapper)): bpm_wrapper_first_good = bpm_wrapper break if(bpm_wrapper_first_good != null): (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper_first_good] bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() if(bpm_amp < bpm_amp_min_limit): scan_is_good = false else: scan_is_good = false if(scan_is_good == false): continue for bpm_wrapper in self.bpm_wrappers: if(bpm_amp_phase_dict.has_key(bpm_wrapper) and self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (graphDataAmp,graphDataPhase) = bpm_amp_phase_dict[bpm_wrapper] (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] #print "debug ch amp=",ch_ampl.channelName()," phase=",ch_phase.channelName() bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord(ch_phase).doubleValue() graphDataAmp.addPoint(cav_phase,bpm_amp) old_bpm_phase = 0. if(graphDataPhase.getNumbOfPoints() > 0): old_bpm_phase = graphDataPhase.getY(graphDataPhase.getNumbOfPoints() - 1) graphDataPhase.addPoint(cav_phase,makePhaseNear(bpm_phase,old_bpm_phase)) return true def collectStatistics(self,bpm_amp_phase_data_dict): """ It will add one point BPMs' amp and phase to the arrays in the dictonary. bpm_amp_phase_data_dict[bpm_wrapper] = ([amp0,amp1,...],[phase0,phase1,...]) """ if(not self.makeMeasurement()): return false #--------get bpm amp and phase ------------- for bpm_wrapper in self.bpm_wrappers: if(bpm_amp_phase_data_dict.has_key(bpm_wrapper) and self.bpm_ch_amp_phase_dict.has_key(bpm_wrapper)): (amp_arr,phase_arr) = bpm_amp_phase_data_dict[bpm_wrapper] (ch_ampl,ch_phase) = self.bpm_ch_amp_phase_dict[bpm_wrapper] #print "debug ch amp=",ch_ampl.channelName()," phase=",ch_phase.channelName() bpm_amp = self.batchGetRequest.getRecord(ch_ampl).doubleValue() bpm_phase = self.batchGetRequest.getRecord(ch_phase).doubleValue() amp_arr.append(bpm_amp) phase_arr.append(bpm_phase) return true