CMS 3D CMS Logo

getHLTprescales.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from sys import stderr, exit
3 import commands
4 
5 from optparse import OptionParser
6 parser = OptionParser(usage="usage: %prog [options] Trigger_Path")
7 parser.add_option("--firstRun", dest="firstRun", help="first run", type="int", metavar="RUN", default="1")
8 parser.add_option("--lastRun", dest="lastRun", help="last run", type="int", metavar="RUN", default="9999999")
9 parser.add_option("--groupName", dest="groupName", help="select runs of name like NAME", metavar="NAME", default="Collisions%")
10 parser.add_option("--jsonOut", dest="jsonOut", help="dump prescales in JSON format on FILE", metavar="FILE")
11 (options, args) = parser.parse_args()
12 if len(args) != 1:
13  parser.print_usage()
14  exit(2)
15 path = args[0]
16 
17 
18 edmCfgFromDB = "edmConfigFromDB --orcoff --format summary.ascii --paths " + path;
19 ## my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"\%s \%s\" % (X.pathName.value(), X.prescales[0])'";
21  #stderr.write("\t%s ...\n" % key);
22  cmd = ( edmCfgFromDB +" --configName "+key + " | grep -i "+ path + " | tail -1 | awk ' $2 ==\"%s\" {print $NL}' " ) % path
23  res = commands.getoutput(cmd)
24  res_split = res.split()
25  psCols = []
26  if len(res)>0:
27  for uu in range(3,len(res_split)-1):
28  if uu % 2 == 1:
29  psCols.append(res_split[uu])
30  return psCols
31 
32 from queryRR import queryRR
33 
34 def readIndex():
35  asciiFile=open("columns.txt","read")
36  mapIndex={}
37  fl="go"
38  while fl:
39  fl=asciiFile.readline()
40  if len(fl)>0:
41  ll=fl.split()
42  runnumber=ll[0]
43  pindex=ll[1]
44  mapIndex[runnumber]=pindex
45  asciiFile.close()
46  return mapIndex
47 
48 
49 MapIndex=readIndex()
50 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
51 prescaleTable = {}
52 Absent = []
53 runs = runKeys.keys(); runs.sort()
54 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
55 jsout = {}
56 for run in runs:
57  key = runKeys[run]
58  if key not in prescaleTable:
59  prescaleTable[key] = getPrescalesFromKey(key)
60  psfactor = 1
61  absent=0
62  if len(prescaleTable[key]) == 0:
63  psfactor = 0
64  else:
65  if run in MapIndex:
66  index = int(MapIndex[run])
67  psfactor = prescaleTable[key][index]
68  else:
69  if int(run) < 138564:
70  index = 0
71  psfactor = prescaleTable[key][index]
72  else:
73  #print "... the run ",run," is not found in columns.txt ... Index is set to zero, need to check independently..."
74  index=0
75  psfactor = prescaleTable[key][index]
76  Absent.append(run)
77  absent=1
78  if absent==0:
79  print "%s\t%s" % (run, psfactor)
80  else:
81  print "%s\t%s\t (*)" % (run, psfactor)
82  jsout[run] = psfactor
83 
84 if len(Absent)>0:
85  print ""
86  print "(*) The following runs were not found in columns.txt (the run may be too recent, or the prescale index is not in OMDS)."
87  print "For these runs, the prescale_index was assumed to be zero. You need to check independently."
88  for r in Absent:
89  print "\t",r
90  print ""
91 
92 if options.jsonOut:
93  stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
94  import json
95  jsonFile = open(options.jsonOut, "w")
96  jsonFile.write(json.dumps(jsout))
97  jsonFile.close()
def getPrescalesFromKey(key)
my $pyPrintTable = "echo &#39;for X in process.PrescaleService.prescaleTable: print \"%s %s" % (X...