def main(): global topName parser = argparse.ArgumentParser() parser.add_argument("top", help="Top node (eg B_SYS_HV)") parser.add_argument( "topname", help= "Top node name - a layer name in quotes (eg \"High voltage\") or\"\" to skip it" ) parser.add_argument( "confname", help="Name of Alarm configuration - almost certainly HallB") parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) args = parser.parse_args() topName = args.topname configName = args.confname global verbose verbose = args.verbosity now = datetime.datetime.now() print "<!--" print " Alarm config generated by makeAlarmConfig.py on " + now.strftime( "%Y-%m-%d %H:%M") print "-->" print "<config name=\"" + configName + "\">" #This is the function that works recursively through the tree and calls do_unto_element start_node end_node doNode.doNode(args.top, do_node=my_node, v=verbose) print "</config>"
def main(): parser = argparse.ArgumentParser( ) # parser for the inputs - must keep the 2 lines below. parser.add_argument( "top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity 1,2 ..", nargs='?', const=0, default=0) parser.add_argument("-t", "--type", help="summary type: Mean, OR, AND", nargs='?', const="Mean", default="Mean") #add extra args and opts here parser.add_argument("pv", help="pvname") args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity global type type = args.type global pvname pvname = args.pv #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here doNode.doNode(args.top, do_node=my_node, v=verbose)
def main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("-f", "--setupfile", help="setup file (default = monitor.dat)",nargs='?', const=0, default="monitor.dat") parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity setup_file = args.setupfile global pvdata global mon_line global pvf global pvfull #read the setup file, which has the form #index TOP PVname Period(s) for line in file(setup_file): #read the lines in the setup file to pvdata monitor list if not (line.startswith("#") or len(line.split())<3): #skip comments and require 3 fields s=line.split() #split input into fields wf=PV(s[pvf.TOP]+":"+s[pvf.NAME]+"_wf") #wf, en are PVs for waveform and enable en=PV(s[pvf.TOP]+":"+s[pvf.NAME]+"_en") pvdata.append([s[0],s[pvf.TOP],s[pvf.NAME],s[pvf.PERIOD],wf,en,[]]) #add to list, with list for IDS #Call doNode() which works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here) #In this case, it calls my_node() for every element - see below. doNode.doNode(pvdata[mon_line][pvf.TOP],do_node=my_node, v=verbose) #now the pvf.ID array has been filled, try to connect to all the elements for n,chid in enumerate(pvdata[mon_line][pvf.ID]): if not ca.connect_channel(chid,timeout=0.001): if verbose: print pvfull[n], "... Not connected, chid = 0" pvdata[mon_line][pvf.ID][n]=0 else: if verbose: print pvfull[n], "... Connected, chid = ",chid pvdata[mon_line].append(numpy.zeros(len(pvdata[mon_line][pvf.ID]))) #create a zero numpy array for the data pvfull = [] #reset the list of names mon_line+=1 #increment the current line number #start a monitor thread for each for l in range(mon_line): t = Thread(target=monitor, args=(l,)) t.start() #do the poll loop here, to cover all monitor threads while mon_line > 0: ca.poll() time.sleep(1.0) print "poll"
def main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity 1,2 ..", nargs='?', const=0, default=0) #add extra args and opts here args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here doNode.doNode(args.top,do_node=my_node, v=verbose)
def main(): parser = argparse.ArgumentParser( ) # parser for the inputs - must keep the 2 lines below. parser.add_argument( "top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) #add extra args and opts here parser.add_argument("pv", help="pvname") parser.add_argument('value', help="value") parser.add_argument('sigma', help="sigma") args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity global pvname global val global sigma pvname = args.pv val = args.value sigma = args.sigma #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here doNode.doNode(args.top, do_node=my_node, v=verbose) #get random all nodes with elements #This has now filled elemNodes[] with all the names of the nodes which contain detector elements. #go into a loop selecting nodes randomly, and fill pvname with random values n = 0 while n < 1000000: time.sleep(0.001) rand_node = random.choice(elemNodes) randel = random.choice(ElementNames[NodeIndex[rand_node]].split(",")) randval = random.gauss(float(val), float(sigma)) fullpv = rand_node + "_" + randel + ":" + str(pvname) caput(fullpv, randval) if verbose: print n, "caput", fullpv, randval n += 1
def main(): global topName parser = argparse.ArgumentParser() parser.add_argument("top", help="Top node (eg B_SYS_HV)") parser.add_argument("topname", help='Top node name - a nice name in quotes (eg "High voltage")') parser.add_argument("confname", help="Name of Alarm configuration - almost certainly HallB") parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs="?", const=0, default=0) args = parser.parse_args() topName = args.topname configName = args.confname global verbose verbose = args.verbosity now = datetime.datetime.now() print "<!--" print " Alarm config generated by makeAlarmConfig.py on " + now.strftime("%Y-%m-%d %H:%M") print "-->" print '<config name="' + configName + '">' # This is the function that works recursively through the tree and calls do_unto_element start_node end_node doNode.doNode(args.top, do_node=my_node, v=verbose) print "</config>"
def main(): parser = argparse.ArgumentParser( ) # parser for the inputs - must keep the 2 lines below. parser.add_argument("-f", "--setupfile", help="setup file (default = monitor.dat)", nargs='?', const=0, default="monitor.dat") parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity setup_file = args.setupfile global pvdata global mon_line global pvf global pvfull #read the setup file, which has the form #index TOP PVname Period(s) for line in file( setup_file ): #read the lines in the setup file to pvdata monitor list if not (line.startswith("#") or len(line.split()) < 3): #skip comments and require 3 fields s = line.split() #split input into fields wf = PV(s[pvf.TOP] + ":" + s[pvf.NAME] + "_wf") #wf, en are PVs for waveform and enable en = PV(s[pvf.TOP] + ":" + s[pvf.NAME] + "_en") pvdata.append( [s[0], s[pvf.TOP], s[pvf.NAME], s[pvf.PERIOD], wf, en, []]) #add to list, with list for IDS #Call doNode() which works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here) #In this case, it calls my_node() for every element - see below. doNode.doNode(pvdata[mon_line][pvf.TOP], do_node=my_node, v=verbose) #now the pvf.ID array has been filled, try to connect to all the elements for n, chid in enumerate(pvdata[mon_line][pvf.ID]): if not ca.connect_channel(chid, timeout=0.001): if verbose: print pvfull[n], "... Not connected, chid = 0" pvdata[mon_line][pvf.ID][n] = 0 else: if verbose: print pvfull[n], "... Connected, chid = ", chid pvdata[mon_line].append(numpy.zeros(len(pvdata[mon_line][ pvf.ID]))) #create a zero numpy array for the data pvfull = [] #reset the list of names mon_line += 1 #increment the current line number #start a monitor thread for each for l in range(mon_line): t = Thread(target=monitor, args=(l, )) t.start() #do the poll loop here, to cover all monitor threads while mon_line > 0: ca.poll() time.sleep(1.0)
def main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) #add extra args and opts here parser.add_argument("pv", help="pvname") args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity global pvname global nChid pvname = args.pv #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here #In this case, it calls my_node() for every element - see below. doNode.doNode(args.top,do_node=my_node, v=verbose) wave=numpy.zeros(nChid) #create an array for all the values pvname_wf = args.top+":"+pvname+"_wf" #make the names of the PVs for waveform and enable switch pvname_en = args.top+":"+pvname+"_en" print pvname_wf,pvname_en pvwf = PV(pvname_wf) #set the PV pven = PV(pvname_en) #set the PV pven.put(1) for i in range(len(allids)): #connect call the channels if not ca.connect_channel(allids[i],timeout=0.001): allids[i]=0 print "Warning didn't connect to PV =", allnames[i], "ignoring this one" ca.poll() #Not sure exactly what this does! n=0 while n < 100000: for i in range(len(allids)): #print i, allids[i] if allids[i] > 0: ca.get(allids[i], wait=False) #Tell them all to start getting but don't wait ca.poll() for i in range(len(allids)): #now finish getting if allids[i] > 0: val = ca.get_complete(allids[i]) wave[i]=val if verbose: #print allnames[i],val pvwf.put(wave) time.sleep(0.5) if not pven.get(): exit() #print n,pven.get() n+=1
def main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) #add extra args and opts here parser.add_argument("pv", help="pvname") args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity global pvname global nChid pvname = args.pv #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here #In this case, it calls my_node() for every element - see below. doNode.doNode(args.top,do_node=my_node, v=verbose) wave=numpy.zeros(nChid) #create an array for all the values pvname_wf = args.top+":"+pvname+"_wf" #make the names of the PVs for waveform and enable switch pvname_en = args.top+":"+pvname+"_en" print pvname_wf,pvname_en pvwf = PV(pvname_wf) #set the PV pven = PV(pvname_en) #set the PV pven.put(1) for i in range(len(allids)): #connect call the channels if not ca.connect_channel(allids[i],timeout=0.001): allids[i]=0 print "Warning didn't connect to PV =", allnames[i], "ignoring this one" ca.poll() #Not sure exactly what this does! n=0 while n < 100000: for i in range(len(allids)): #print i, allids[i] if allids[i] > 0: ca.get(allids[i], wait=False) #Tell them all to start getting but don't wait ca.poll() for i in range(len(allids)): #now finish getting if allids[i] > 0: val = ca.get_complete(allids[i]) wave[i]=val #if verbose: #print allnames[i],val pvwf.put(wave) time.sleep(0.5) if not pven.get(): exit() #print n,pven.get() n+=1