def updateConfig(PV, pmgr, objID, cfgID, objDict, cfgDict, allNames, verbose): """ Routine to update the configuration of an obj """ # # PMGR cfg values for comparisons objOld = pmgr.objs[objID] cfgOld = pmgr.cfgs[cfgID] # # Print live values for troubleshooting if verbose: print "\nLive cfg values for {0}".format(pv.get(PV+".DESC")) pprint(objDict) pprint(cfgDict) print "\nPMGR cfg valu es for {0} before update".format(pv.get(PV+".DESC")) pprint(objOld) pprint(cfgOld) print print cfgDict["name"], objDict["name"] cfgDict["FLD_TYPE"] = pmgr.cfgs[cfgID]["FLD_TYPE"] cfgDict["name"] = objDict["name"] if cfgOld["name"] in allNames: allNames.remove(cfgOld["name"]) cfgDict["name"] = incrementMatching(cfgDict["name"], allNames, maxLength=maxLenName) print "Saving configuration..." # # Actually do the update didWork = cfgChange(pmgr, cfgID, cfgDict) return didWork, objOld, cfgOld
def get_motor_PVs(partialPV): motorPVs = [] i = 1 while i != 40: basePV = "%s:%02d"%(partialPV, i) print basePV try: SN = pv.get(basePV + ".SN") if len(SN) >= 8: motor_PVs[sn] = basepv print "PV: {0} is active".format(basePV) motorPVs += basePV except: pass return motorPVs
def motorPrelimChecks(PV, hutches, objType, verbose=False): """ Runs prelimenary checks on the paramter manager inputs, and returns a valid hutch name, and serial number. Returns false for any of the variables if there are any issues when obtaining them. """ SN = False # Check for valid hutch entry if not hutches: hutches.append(PV[0][:3].lower()) for hutch in hutches: if hutch not in supportedHutches: print "Invalid hutch: {0}. Only supports sxr and amo.".format(hutch.upper()) print "Removing hutch: {0}".format(hutch.upper()) hutches.remove(hutch) # Replace sxd with amo and sxr if present if 'sxd' in hutches: if 'amo' not in hutches: hutches.append('amo') if 'sxr' not in hutches: hutches.append('sxr') hutches.remove('sxd') if not hutches: return hutches, objType, SN if verbose: print "Hutches: {0}".format(hutches) # Check for valid obj entry. Pmgr only supports ims motors as of 1/1/2016 if str(objType) in supportedObjTypes: pass elif ":MMS:" in PV[0]: objType = "ims_motor" else: print "Unknown device type for {0}".format(PV[0]) objType = False return hutches, objType, SN # Get the motor serial number via caget i = 0 SN = {} for motorPV in PV: while i < nTries: try: SN[motorPV] = pv.get(motorPV + ".SN") break except: i+=1 if not SN: print "Failed to get motor serial number for motor {0}".format(motorPV) continue return hutches, objType, SN
def dumbMotorCheck(PV): """ Takes in a PV attempts caget on the PN nTries times and then checks the PN to see if it is MFI. Returns True if MFI is in the PN string, false if not. """ PN = "" i = 0 while i < nTries: try: PN = pv.get(PV + ".PN") break except: i += 1 if "MFI" in PN: return True else: return False
def getCfgVals(pmgr, PV): """ Returns a dictionary of the live cfg fields associated with a PV """ PV = PV.upper() configFields = listCfgFields(pmgr) cfgDict = getFieldDict(pmgr, PV, configFields) name = None try: name = pv.get(PV +".DESC") except: name = "Unknown" cfgDict["name"] = name cfgDict["FLD_TYPE"] = "{0}_{1}".format(name, PV[:4]) return cfgDict
def getFieldDict(pmgr, PV, fields): fldDict = {} for field in fields: if field != "FLD_TYPE": pvExt = pmgr.fldmap[field]["pv"] val = pv.get(PV + pvExt) if val is None: return None fieldDict = pmgr.fldmap[field] if "enum" in fieldDict: choices = fieldDict["enum"] if val >= len(choices): print "WARNING: index mismatch in field {0}.".format(field) print "An ioc has been updated without updating the Parameter Manager!" val = len(choices) - 1 val = fieldDict["enum"][val] fldDict[field] = val return fldDict
def pvConfig(pmgr, PV): """ Returns live config dict associated with PV, or None """ configFields = listCfgFields(pmgr) cfgDict = {} for field in configFields: if field != "FLD_TYPE": pvExt = pmgr.fldmap[field]["pv"] val = pv.get(PV + pvExt) if val is None: return None fieldDict = pmgr.fldmap[field] if "enum" in fieldDict: choices = fieldDict["enum"] if val >= len(choices): print "WARNING: index mismatch in field {0}.".format(field) print "An ioc has been updated without updating the Parameter Manager!" val = len(choices) - 1 val = fieldDict["enum"][val] cfgDict[field] = val return cfgDict
def run(self): """Auto run elog poster elog.submit(self, text='TEXT TO DELETE', tag=None, tag2=None, tag3=None, file=None, file_descr='description not known', file2=None, file_descr2='description not known', file3=None, file_descr3='description not known', runnum=None) """ while True: try: time.sleep(1) if self.POST: message = self.TITLE runnum = self.RUN exp = self.EXP if self.RUN > 0: runnum = self.RUN else: runnum = None msg = 'posting {:} to {:} experiment'.format(message, exp) post_kwargs = {} for kw in self._kws: kwval = getattr(self, kw) if kwval: post_kwargs[kw] = kwval print(msg, post_kwargs) pypsElog.submit(message, runnum=runnum, **post_kwargs) #self.elog.submit(message, runnum=runnum) for pv, item in self._pvs.items(): print(pv, getattr(self, pv), Pv.get(item['pv'] + '.DESC')) setattr(self, pv, item['default']) Pv.put(item['pv'] + '.DESC', item['desc']) except KeyboardInterrupt: print('Exiting autopost...') break
def KeV_to_GeV(self, Exray_in_keV): und_period = 3 # in cm und_K = Pv.get("USEG:UND1:150:KACT") return sqrt((1 + und_K**2 / 2) * und_period * Exray_in_keV / 0.95)
def __getDelay(self): return Pv.get(self.__delayPV)
def applyConfig(PV, hutches, objType, SN, verbose, zenity, dumb=False, dumb_cfg=None, dumb_confirm=True): """ Searches the pmgr for the correct SN and then applies the configuration currently associated with that motor. If it fails to find either a SN or a configuration it will exit. """ # Find the most recently updated obj in the pmgrs of each hutch inputted if verbose: print "Getting most recently updated obj\n" objID, pmgr = utlp.getMostRecentObj(hutches, SN, objType, verbose) if not objID or not pmgr: return # # Work-around for applyConfig # # applyObject uses the rec_base field of the obj to apply the PV values # # so for it to work properly we have to set rec_base to the correct # # PV value associated with that motor at the moment # Change rec_base field to the base PV and the port field to the live port obj = pmgr.objs[objID] port = pv.get(PV + ".PORT") if obj["rec_base"] != PV or obj["FLD_PORT"] != port: obj["rec_base"] = PV obj["FLD_PORT"] = port utlp.transaction(pmgr, "objectChange", objID, obj) if dumb: # Get all the cfg names allNames = {} for hutch in hutches: pmgr = utlp.getPmgr(objType, hutch, verbose) names = utlp.allCfgNames(pmgr) for name in names: allNames[name] = hutch # Make sure the user inputs a correct configuration cfgName = dumb_cfg if dumb_confirm: confirm = "no" while(confirm[0].lower() != "y"): if cfgName is not None: print "Closest matches to your input:" closest_cfgs = get_close_matches(cfgName, allNames.keys(), 15, 0.1) pprint(closest_cfgs) cfgName = raw_input("Please input a configuration to apply or search:\n") if cfgName not in allNames: print "Invalid configuration inputted." continue confirm = raw_input("\nAre you sure you want to apply {0} to {1}?\n".format(cfgName, PV)) elif cfgName not in allNames: print "Invalid configuration {} chosen.".format(cfgName) return # Get the selected configuration's ID pmgr = utlp.getPmgr(objType, allNames[cfgName], verbose) cfgID = utlp.cfgFromName(pmgr, cfgName) if not cfgID: print "Error when getting config ID from name: {0}".format(cfgName) if zenity: system("zenity --error --text='Error: Failed to get cfgID'") return # Set configuration of dumb motor pmgr object if obj["config"] != cfgID: status = False status = utlp.setObjCfg(pmgr, objID, cfgID) if not status: print "Failed set cfg to object" if zenity: system("zenity --error --text='Error: Failed to set cfgID to object'") return # Set the obj name and desc to use the cfg name (only for dumb motors) obj["name"] = utlp.nextObjName(pmgr, pmgr.cfgs[cfgID]["name"]) obj["FLD_DESC"] = pmgr.cfgs[cfgID]["name"] utlp.transaction(pmgr, "objectChange", objID, obj) # For future diff comparison cfgOld = utlp.getCfgVals(pmgr, PV) objOld = utlp.getObjVals(pmgr, PV) # Apply the pmgr configuration to the motor print "Applying configuration, please wait..." status = False status = utlp.objApply(pmgr, objID) if not status: print "Failed to apply: pmgr transaction failure" if zenity: system("zenity --error --text='Error: pmgr transaction failure'") return print "Successfully completed apply" # Try to print the diffs cfgNew = utlp.getCfgVals(pmgr, PV) objNew = utlp.getObjVals(pmgr, PV) try: utlp.printDiff(pmgr, objOld, cfgOld, objNew, cfgNew, verbose) except: pass if zenity: system('zenity --info --text="Configuration successfully applied"')
def get_test_nburst(self): return Pv.get("PATT:SYS0:1:TESTBURSTCNT")
def setT(self, transmission, wait=False, E=None, printit=False, use3rd=False, checkSide=False): """ Determines which filters have to be moved in othe beam to achieve a transmission as close as possible to the requested one. Note : the function moves the filters Note2: use the `setE` command before to choose which energy to use for calculation""" # Check the status of the attenuator stat = self.get_par('Status') if stat != 'OK': warn_str = 'The attenuator is not ready - status is ' + str(stat) printnow(warn_str) return if E is not None: self.setE(E, use3rd=use3rd) elif self.get_par('Eget') == 'Passive' and (abs(self.get_par('E1st') - Pv.get('SIOC:SYS0:ML00:AO627') ) > 0.010): printnow('The current set energy for the fundamental (%.5f) is not the beam energy (%.5f).' %(self.get_par('E1st'), Pv.get('SIOC:SYS0:ML00:AO627') )) if raw_input('Is that intended? (y/n)\n') is 'n': self.setE() if use3rd: self.put_par('Td3rd', transmission, wait=True) time.sleep(0.1) self.wait_par('CalcPend', 'No') # wait for T_CALC record to process floor = self.get_par('T3rd_f') ceiling = self.get_par('T3rd_c') else: self.put_par('Td1st', transmission, wait=True) time.sleep(0.1) self.wait_par('CalcPend', 'No') # wait for T_CALC record to process floor = self.get_par('T1st_f') ceiling = self.get_par('T1st_c') if printit or checkSide: printnow('Possible transmissions are: %.5f (floor) and %.5f (ceiling).' %(floor, ceiling)) if checkSide: if raw_input('Use ceiling or floor? (c/f)\n') is 'c': self.put_par('Go', 3) tval = ceiling else: self.put_par('Go', 2) tval = floor else: if abs(floor - transmission) >= abs(ceiling - transmission): self.put_par('Go', 3) tval = ceiling else: self.put_par('Go', 2) tval = floor # wait for put to happen time.sleep(0.1) if wait: self.wait() if use3rd: self.wait_par('E3rd') # wait for T_CALC record to process tval = self.getT3value() else: self.wait_par('E1st') # wait for T_CALC record to process tval = self.getT1value() if printit or (transmission != 0 and abs((tval-transmission)/transmission)>0.1): printnow('Closest possible transmission of %.3f has been applied\n'%(tval)) return tval
def getFEEAttT(self): return Pv.get(self.__BeTpv)
def isburstenabled(self): if (Pv.get(self.__isburstmodeenabled_pv) == 1) or (Pv.get( self.__isburstpcmodeenabled_pv) == 1): return True else: return False
def get(self, what): pvname = self.__pvname(what) return Pv.get(pvname)
else: hutches = [] hutches, objType, SNs = utlp.motorPrelimChecks(motorPVs, hutches, objType, verbose) if not hutches or not objType or not SNs: if zenity: system( "zenity --error --text='Failed preliminary checks on hutch, PV and/or objType'" ) exit("\nFailed preliminary checks on hutch, PV and/or objType\n") # Loop through each of the motorPVs for PV in motorPVs: # Print some motor info print "Motor PV: {0}".format(PV) m_DESC = pv.get(PV + ".DESC") print "Motor description: {0}".format(m_DESC) if not SNs[PV]: print "Could not get SN for motor: {0}.".format(m_DESC) print "Skipping motor.\n" continue SN = SNs[PV] if verbose: print "Motor SN: {0}\n".format(SN) # If inputted apply, run apply routine and sure it is a smart motor if arguments["apply"]: if not utlp.dumbMotorCheck(PV): applyConfig(PV, hutches, objType, SN, verbose, zenity) else: print "Motor connected to PV:{0} is a dumb motor, must use \
def openok(self): """ check wether valve is allowed to be open """ return Pv.get(self._opn_ok)
def isclosed(self): """ returns True if valve is not commanded open """ return Pv.get(self._opn_di) == 0
def pressure(self): """ Returns the pressure """ return Pv.get(self.__pmon)
def main(): # Parse docopt variables arguments = docopt(__doc__) # print arguments PVArguments = arguments["<PV>"] oldSN = arguments["<old SN>"] newSN = arguments["<new SN>"] if arguments["--path"]: path = arguments["--path"] else: path = [] if arguments["--verbose"] or arguments["-v"]: verbose = True else: verbose = False if arguments["--zenity"] or arguments["-z"]: zenity = True else: zenity = False if arguments["--update"] or arguments["-u"]: update = True else: update = False if arguments["--hutch"]: hutches = [hutch.lower() for hutch in arguments["--hutch"].split(',')] else: hutches = [] if arguments["--objtype"]: objType = arguments["--objtype"] else: objType = None if arguments["--norename"]: rename = False else: rename = True # There seems to be a bug in docopt. It can't recognize that what is inputted # is <hutch> rather than <PV> # if arguments["<hutch>"]: # hutchPaths = [hutch.lower() for hutch in arguments["<hutch>"].split(',')] hutchPaths = [] if PVArguments: for arg in PVArguments: if arg.lower() in allHutches: hutchPaths.append(arg.lower()) elif len(path) > 0: hutchPaths = ['sxd'] else: hutchPaths = [] # Try import first if arguments["import"]: # A hack to get the appropriate hutch list and hutch path without # rewriting any new functions. The logic is pretty ugly so it would be # nice to redo at some point. hutches, objType, _ = utlp.motorPrelimChecks(hutchPaths, hutches, objType, verbose) hutchPaths, objType, _ = utlp.motorPrelimChecks( hutchPaths, hutchPaths, objType, verbose) # objType = "ims_motor" for hutchPath in hutchPaths: for hutch in hutches: pmgr = utlp.getPmgr(objType, hutch, verbose) if not pmgr: continue print("Importing configs from {0}opr into {1} pmgr".format( hutchPath, hutch)) importConfigs(hutchPath, pmgr, path, update, verbose) if path: break exit() # Do not continue # Try changesn next if arguments["changesn"]: if not oldSN or not newSN: print( "For changesn routine old and new serial numbers must be inputted. You may also need to add --hutch {HUTCH}. Try --help" ) exit() if not objType: objType = "ims_motor" if not hutches: hutches = allHutches # Loop through all hutches to find and change serial no if verbose: print( "Checking hutch(es) for all {0} objects with old SN\n".format( objType)) for hutch in hutches: pmgr = utlp.getPmgr(objType, hutch, verbose) if not pmgr: continue # Look for obj (default is ims_motor type) with previous serial no objID = utlp.getObjWithSN(pmgr, oldSN, verbose) if not objID: continue print("Motor found: ObjID = {0}, hutch = {1}".format( objID, hutch.upper())) # Create simple dict to change SN, then do it objDict = {'FLD_SN': newSN} if verbose: print("Now saving object with new SN...") output = utlp.objUpdate(pmgr, objID, objDict) pmgr.updateTables() # Now printupdated SN for verification, and in case it was padded if output != "error": print("Motor SN successfully updated to {0}.\n".format( pmgr.objs[objID]['FLD_SN'])) exit() # Do not continue # Parse the PV input into full PV names, exit if none inputted if len(PVArguments) > 0: motorPVs = parsePVArguments(PVArguments) else: if zenity: system("zenity --error --text='No PV inputted. Try --help'") exit("No PV inputted. Try --help") # Run some preliminary checks if verbose: print("\nPerforming preliminary checks for pmgr paramters\n") if arguments["--hutch"]: hutches = [hutch.lower() for hutch in arguments["--hutch"].split(',')] else: hutches = [] hutches, objType, SNs = utlp.motorPrelimChecks(motorPVs, hutches, objType, verbose) if not hutches or not objType or not SNs: if zenity: system( "zenity --error --text='Failed preliminary checks on hutch, PV and/or objType'" ) exit("\nFailed preliminary checks on hutch, PV and/or objType\n") # Loop through each of the motorPVs for PV in motorPVs: # Print some motor info print("Motor PV: {0}".format(PV)) m_DESC = pv.get(PV + ".DESC") print("Motor description: {0}".format(m_DESC)) if not SNs[PV]: print("Could not get SN for motor: {0}.".format(m_DESC)) print("Skipping motor.\n") continue SN = SNs[PV] if verbose: print("Motor SN: {0}\n".format(SN)) # If inputted apply, run apply routine and sure it is a smart motor if arguments["apply"]: if not utlp.dumbMotorCheck(PV): applyConfig(PV, hutches, objType, SN, verbose, zenity) else: print("Motor connected to PV:{0} is a dumb motor, must use \ dmapply\n".format(PV)) if zenity: system( "zenity --error --text='Error: Dumb motor detected'") # Else if inputted dumb apply try apply routine for dumb motors elif arguments["dmapply"]: if utlp.dumbMotorCheck(PV): dumbMotorApply(PV, hutches, objType, SN, verbose, zenity) else: print("Motor connected to PV:{0} is a smart motor, must use \ apply\n".format(PV)) if zenity: system( "zenity --error --text='Error: Smart motor detected'") # Else loop through the hutches and check for diff and save else: for hutch in hutches: pmgr = utlp.getPmgr(objType, hutch, verbose) if not pmgr: continue if arguments["diff"]: Diff(PV, hutch, pmgr, SN, verbose) continue if arguments["save"]: saveConfig(PV, hutch, pmgr, SN, verbose, zenity, rename=rename) continue
def isin(self): state = Pv.get(self._pv) if state == 1: return False elif state == 0: return True
def getBeL(self): return Pv.get(self.__BeMilspv) / 1e3 * 25.4e-3
def applyConfig(PV, hutches, objType, SN, verbose, zenity, dumb=False, dumb_cfg=None, dumb_confirm=True, name=None): """ Searches the pmgr for the correct SN and then applies the configuration currently associated with that motor. If it fails to find either a SN or a configuration it will exit. """ # Find the most recently updated obj in the pmgrs of each hutch inputted if verbose: print "Getting most recently updated obj\n" objID, pmgr = utlp.getMostRecentObj(hutches, SN, objType, verbose) if not objID or not pmgr: return # # Work-around for applyConfig # # applyObject uses the rec_base field of the obj to apply the PV values # # so for it to work properly we have to set rec_base to the correct # # PV value associated with that motor at the moment # Change rec_base field to the base PV and the port field to the live port obj = pmgr.objs[objID] port = pv.get(PV + ".PORT") if obj["rec_base"] != PV or obj["FLD_PORT"] != port: obj["rec_base"] = PV obj["FLD_PORT"] = port utlp.transaction(pmgr, "objectChange", objID, obj) pmgr.updateTables() obj = pmgr.objs[objID] if name is not None: obj["name"] = name obj["FLD_DESC"] = name utlp.transaction(pmgr, "objectChange", objID, obj) pmgr.updateTables() obj = pmgr.objs[objID] if dumb: # Get all the cfg names allNames = {} for hutch in hutches: pmgr = utlp.getPmgr(objType, hutch, verbose) names = utlp.allCfgNames(pmgr) for name in names: allNames[name] = hutch # Make sure the user inputs a correct configuration cfgName = dumb_cfg if dumb_confirm: confirm = "no" while (confirm[0].lower() != "y"): if cfgName is not None: print "Closest matches to your input:" closest_cfgs = get_close_matches(cfgName, allNames.keys(), 10, 0.1) pprint(closest_cfgs) cfgName = raw_input( "Please input a configuration to apply or search: (or 'quit' to quit)\n" ) if cfgName == 'quit': return if cfgName not in allNames: print "Invalid configuration inputted." continue confirm = raw_input( "\nAre you sure you want to apply {0} to {1}?\n".format( cfgName, PV)) elif cfgName not in allNames: print "Invalid configuration {} chosen.".format(cfgName) return # Get the selected configuration's ID pmgr = utlp.getPmgr(objType, allNames[cfgName], verbose) cfgID = utlp.cfgFromName(pmgr, cfgName) if not cfgID: print "Error when getting config ID from name: {0}".format(cfgName) if zenity: system("zenity --error --text='Error: Failed to get cfgID'") return # Set configuration of dumb motor pmgr object if obj["config"] != cfgID: status = False status = utlp.setObjCfg(pmgr, objID, cfgID) pmgr.updateTables() obj = pmgr.objs[objID] if not status: print "Failed set cfg to object" if zenity: system( "zenity --error --text='Error: Failed to set cfgID to object'" ) return # Set the obj name and desc to use the cfg name (only for dumb motors) if name is None: obj["name"] = utlp.nextObjName(pmgr, pmgr.cfgs[cfgID]["name"]) obj["FLD_DESC"] = pmgr.cfgs[cfgID]["name"] utlp.transaction(pmgr, "objectChange", objID, obj) pmgr.updateTables() obj = pmgr.objs[objID] # For future diff comparison cfgOld = utlp.getCfgVals(pmgr, PV) objOld = utlp.getObjVals(pmgr, PV) # Apply the pmgr configuration to the motor print "Applying configuration, please wait..." status = False status = utlp.objApply(pmgr, objID) if not status: print "Failed to apply: pmgr transaction failure" if zenity: system("zenity --error --text='Error: pmgr transaction failure'") return print "Successfully completed apply" # Try to print the diffs cfgNew = utlp.getCfgVals(pmgr, PV) objNew = utlp.getObjVals(pmgr, PV) try: utlp.printDiff(pmgr, objOld, cfgOld, objNew, cfgNew, verbose, kind='changes') except: pass if zenity: system('zenity --info --text="Configuration successfully applied"')
def getBeT(self): return Pv.get(self.__BeTpv)
def configure_sequencer(self,test=False,readOnMotor=True, addDrop=False): """ Configure the sequencer based on the current set of USER PVS Epics pv inputs that define event sequence: - nstart=CXI:USR:ACC: the number of sync pulses to send before starting xray pulses. - ncells=CXI:USR:CELLS: the number of cells to shoot in a row of the sample holder. - freq=CXI:USR:FREQ: the frequency used for both motor sync triggers and the xray pulses (default: 120 Hz). - ngap=CXI:USR:GAP: gap between windows - nwindows=CXI:USR:WINDOWS number of windows """ nstart=self.ACC ncells=self.CELLS nwindows=self.WINDOWS ngap=self.GAP freq=self.FREQ sample_name=self.CHIP runstr = None # Sequencer set to use burst delay off of next shot self._pp._burstdelay = 0.0008 self._pp._flipflopdelay = 0.0008 if test: picker_ec = 201 else: picker_ec = self._pp._codes['pp'] self.STOP = 0 motor_ec = self.motor_ec readout_ec = self._pp._codes['daq'] drop_ec = self._pp._codes['drop'] latch = False # istep is the daq run 'calibration' step istep = 0 env.event.modeOnce() seqstep = 0 motsync_com = 'MotorSync' readout_com = 'Readout' pp_com = 'PulsePicker' drop_com = 'DroppedShot' if self._base_freq % freq != 0: printnow("Warning: %.1f is not an allowed frequency - choosing closest avaiable!"%freq) pulse_step = int(math.ceil(self._base_freq/freq)) printnow("Configuring sequencer for rows with %d cells at pulse frequency of %.1f Hz ..."%(ncells, self._base_freq/pulse_step)) printnow('***********************************\n') printnow(self.sample_info()) if pulse_step == 1: ## set pulse picker to burst mode #if Pv.get(self._pp._PVname('SE')) != 3: print 'Setting PulsePicker to Burst mode' #Pv.put(self._pp._PVname('RUN_BURSTMODE'),1) self._pp.burst() # adding starting pulses before pulse pickers starts to open for index in range(nstart): env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if addDrop: env.event.setstep(seqstep, drop_ec, 0,fiducial=0,comment=drop_com);seqstep+=1 # Repeat for nwindows: for iwindow in range(nwindows): # open pulse picker env.event.setstep(seqstep, picker_ec, 0,fiducial=0,comment=pp_com);seqstep+=1 # add all but the last xray shot for index in range(ncells): # close pulsepicker and read last shot in window if index == ncells-1: env.event.setstep(seqstep, picker_ec, 0,fiducial=0,comment=pp_com);seqstep+=1 env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if not readOnMotor: env.event.setstep(seqstep, readout_ec, 0,fiducial=0,comment=readout_com);seqstep+=1 # Skip ngap pulses for each window for igap in range(ngap): env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if addDrop: env.event.setstep(seqstep, drop_ec, 0,fiducial=0,comment=drop_com);seqstep+=1 # Provide Motor Sync pulses for deacceleration for index in range(nstart-ngap): env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if addDrop: env.event.setstep(seqstep, drop_ec, 0,fiducial=0,comment=drop_com);seqstep+=1 elif pulse_step >= 4: # set pulse picker to flip flop mode if Pv.get(self._pp._PVname('SE')) != 2: print 'Setting PulsePicker to FlipFlop mode' #Pv.put(self._pp._PVname('RUN_FLIPFLOP'),1) self._pp.flipflop() # adding starting MotorSync pulses before pulse pickers starts to open for index in range(nstart): env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if addDrop: env.event.setstep(seqstep, drop_ec, 0,fiducial=0,comment=drop_com);seqstep+=1 # start ncell number of flip-flops of the pulse picker pp_open_delay = 1 pp_ff_delay = pulse_step - pp_open_delay for iwindow in range(nwindows): for index in range(ncells): env.event.setstep(seqstep, picker_ec, pp_ff_delay,fiducial=0,comment=pp_com);seqstep+=1 if not readOnMotor: env.event.setstep(seqstep, readout_ec, pp_open_delay,fiducial=0,comment=readout_com);seqstep+=1 else: env.event.setstep(seqstep, drop_ec, pp_open_delay,fiducial=0,comment=drop_com);seqstep+=1 env.event.setstep(seqstep, motor_ec, 0,fiducial=0,comment=motsync_com);seqstep+=1 # Skip ngap pulses for each window for igap in range(ngap): env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if addDrop: env.event.setstep(seqstep, drop_ec, 0,fiducial=0,comment=drop_com);seqstep+=1 # Add additional deceleration pulses for MotorSync for index in range(nstart): env.event.setstep(seqstep, motor_ec, pulse_step,fiducial=0,comment=motsync_com);seqstep+=1 if addDrop: env.event.setstep(seqstep, drop_ec, 0,fiducial=0,comment=drop_com);seqstep+=1 else: printnow("\nA frequency choice of %.2f Hz is not allowed in this mode! - Aborting...\n"%freq) return # finalize sequence env.event.setnsteps(seqstep) env.event.update() printnow("Done with sequence\n")
def getXrayeV(self): return Pv.get(self.__evpv)
def __wm(self): return Pv.get(self.__pvbase+":SENS_POS")/1.0e6
def get_nburst(self): return Pv.get("PATT:SYS0:1:MPSBURSTCNT")
def defaultName(pmgr, PV): """ Returns a default name for the config associated with PV """ name = pv.get(PV + ".DESC") return nextName(pmgr, name)
def isopen(self): if Pv.get(self._pv) == 0: return True else: return False
def get_ebeamrate(self): return Pv.get(self.__ebeamratepv)
def __getBias(self): return Pv.get(self.__biasPV)
def GeV_to_keV(self, Eelectron_in_GeV): und_period = 3 # in cm und_K = Pv.get("USEG:UND1:150:KACT") return 0.95 * Eelectron_in_GeV**2 / (1 + und_K**2 / 2) / und_period
def saveConfig(PV, hutch, pmgr, SN, verbose, zenity, dumb=False, dumb_cfg=None, dumb_confirm=True, rename=True): """ Searches for the SN of the PV and then saves the live configuration values to the pmgr. It will update the fields if the motor and configuration is already in the pmgr. It will create new motor and config objects if either is not found and make the correct links between them. If a hutch is specified, the function will save the motor obj and cfg to the pmgr of that hutch. Otherwise it will save to the hutch listed on the PV. """ print "Saving motor info to {0} pmgr".format(hutch.upper()) # Grab motor information and configuration cfgDict = utlp.getCfgVals(pmgr, PV, rename) objDict = utlp.getObjVals(pmgr, PV, rename) allNames = utlp.allCfgNames(pmgr) if rename: name = objDict["name"] else: name = pv.get(PV + ".DESC") # Look through pmgr objs for a motor with that id if verbose: print "Checking {0} pmgr SNs for this motor".format(hutch.upper()) objID = utlp.getObjWithSN(pmgr, objDict["FLD_SN"], verbose) if verbose: print "ObjID obtained from {0} pmgr: {1}".format(hutch.upper(), objID) # If an objID was found, update the obj if objID: print "Saving motor information..." utlp.objUpdate(pmgr, objID, objDict) if verbose: print "\nMotor SN found in {0} pmgr, motor information \ updated".format(hutch.upper()) # Else try to create a new obj else: print "\nSN {0} not found in pmgr, adding new motor obj...".format(SN) # Name availability check try: objDict["name"] = utlp.nextObjName(pmgr, objDict["name"]) except KeyError: objDict["name"] = utlp.nextObjName(pmgr, pv.get(PV + ".DESC")) # Create new obj objID = utlp.newObject(pmgr, objDict) if not objID: print "Failed to create obj for {0}".format(objDict["name"]) if zenity: system("zenity --error --text='Error: Failed to create new \ object for {0} pmgr'".format(hutch.upper())) return # Try to get the cfg id the obj uses try: cfgID = pmgr.objs[objID]["config"] except Exception as e: cfgID = None # If there was a valid cfgID and it isnt the default one, try to update the cfg if cfgID and pmgr.cfgs[cfgID]["name"].upper() != hutch.upper(): didWork, objOld, cfgOld = utlp.updateConfig(PV, pmgr, objID, cfgID, objDict, cfgDict, allNames, verbose, rename) if not didWork: print "Failed to update the cfg with new values" if zenity: system( "zenity --error --text='Error: Failed to update config'") return # Else create a new configuration and try to set it to the objID else: print "\nInvalid config associated with motor {0}. Adding new \ config.".format(SN) status = utlp.getAndSetConfig(PV, pmgr, objID, objDict, cfgDict) if not status: print "Motor '{0}' failed to be added to pmgr".format(name) return print "Motor '{0}' successfully added to pmgr".format(name) pmgr.updateTables() # Change the config and object names to be the motor description if rename: obj = pmgr.objs[objID] cfg = pmgr.cfgs[obj["config"]] obj["name"] = utlp.nextObjName(pmgr, obj["FLD_DESC"]) cfg["name"] = utlp.nextCfgName(pmgr, obj["FLD_DESC"]) utlp.transaction(pmgr, "objectChange", objID, obj) utlp.transaction(pmgr, "configChange", cfgID, cfg) print "\nSuccessfully saved motor info and configuration into {0} \ pmgr".format(hutch) # Try to print the diffs if cfgID and objID: cfgPmgr = pmgr.cfgs[cfgID] objPmgr = pmgr.objs[objID] try: utlp.printDiff(pmgr, objOld, cfgOld, objPmgr, cfgPmgr, verbose) except: pass if zenity: system('zenity --info --text="Motor configuration \ successfully saved into {0} pmgr"'.format(hutch.upper()))
# Run some prelimenary checks if verbose: print "\nPerforming preliminary checks for pmgr paramters\n" if arguments["--hutch"]: hutches = [hutch.lower() for hutch in arguments["--hutch"].split(',')] else: hutches = [] hutches, objType, SNs = utlp.motorPrelimChecks(motorPVs, hutches, None, verbose) if not hutches or not objType or not SNs: if zenity: system("zenity --error --text='Failed prelimenary checks'") exit("\nFailed prelimenary checks\n") # Loop through each of the motorPVs for PV in motorPVs: # Print some motor info print "Motor PV: {0}".format(PV) m_DESC = pv.get(PV + ".DESC") print "Motor description: {0}".format(m_DESC) if not SNs[PV]: print "Could not get SN for motor: {0}.".format(m_DESC) print "Skipping motor.\n" continue SN = SNs[PV] if verbose: print "Motor SN: {0}\n".format(SN) # If inputted apply, run apply routine and sure it is a smart motor if arguments["apply"]: if not utlp.dumbMotorCheck(PV): applyConfig(PV, hutches, objType, SN, verbose, zenity) else: print "Motor connected to PV:{0} is a dumb motor, must use \
def __getstepsize(self): return Pv.get(self.__pvbase+":STEP_INC")
def get_offset(self): '''returns the value of the offset''' return Pv.get(self._offset_pv_name)
def wm(self): mposstr=Pv.get(self.pvrd) mpos=double(mposstr) return mpos