CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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("--rrurl", dest="rrurl", help="run registry xmlrpc url", metavar="URL", default="http://cms-service-runregistry-api.web.cern.ch/cms-service-runregistry-api/xmlrpc")
11 parser.add_option("--jsonOut", dest="jsonOut", help="dump prescales in JSON format on FILE", metavar="FILE")
12 (options, args) = parser.parse_args()
13 if len(args) != 1:
14  parser.print_usage()
15  exit(2)
16 path = args[0]
17 
18 
19 edmCfgFromDB = "edmConfigFromDB --orcoff --format summary.ascii --paths " + path;
20 ## my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"\%s \%s\" % (X.pathName.value(), X.prescales[0])'";
22  #stderr.write("\t%s ...\n" % key);
23  cmd = ( edmCfgFromDB +" --configName "+key + " | grep -i "+ path + " | tail -1 | awk ' $2 ==\"%s\" {print $NL}' " ) % path
24  res = commands.getoutput(cmd)
25  res_split = res.split()
26  psCols = []
27  if len(res)>0:
28  for uu in range(3,len(res_split)-1):
29  if uu % 2 == 1:
30  psCols.append(res_split[uu])
31  return psCols
32 
33 
34 def queryRR():
35  stderr.write("Querying run registry for range [%d, %d], group name like %s ...\n" % (options.firstRun, options.lastRun, options.groupName))
36  import xmlrpclib
37  import xml.dom.minidom
38  server = xmlrpclib.ServerProxy(options.rrurl)
39  run_data = server.DataExporter.export('RUN', 'GLOBAL', 'xml_datasets', "{runNumber} >= %d AND {runNumber} <= %d AND {groupName} like '%s' AND {datasetName} = '/Global/Online/ALL'" % (options.firstRun, options.lastRun, options.groupName))
40  ret = {}
41  xml_data = xml.dom.minidom.parseString(run_data)
42  xml_runs = xml_data.documentElement.getElementsByTagName("RUN_DATASET")
43  for xml_run in xml_runs:
44  ret[xml_run.getElementsByTagName("RUN_NUMBER")[0].firstChild.nodeValue] = xml_run.getElementsByTagName("RUN_HLTKEY")[0].firstChild.nodeValue
45  return ret
46 
47 def readIndex():
48  asciiFile=open("columns.txt","read")
49  mapIndex={}
50  fl="go"
51  while fl:
52  fl=asciiFile.readline()
53  if len(fl)>0:
54  ll=fl.split()
55  runnumber=ll[0]
56  pindex=ll[1]
57  mapIndex[runnumber]=pindex
58  asciiFile.close()
59  return mapIndex
60 
61 
62 MapIndex=readIndex()
63 runKeys = queryRR()
64 prescaleTable = {}
65 Absent = []
66 runs = runKeys.keys(); runs.sort()
67 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
68 jsout = {}
69 for run in runs:
70  key = runKeys[run]
71  if not prescaleTable.has_key(key):
72  prescaleTable[key] = getPrescalesFromKey(key)
73  psfactor = 1
74  absent=0
75  if len(prescaleTable[key]) == 0:
76  psfactor = 0
77  else:
78  if MapIndex.has_key(run):
79  index = int(MapIndex[run])
80  psfactor = prescaleTable[key][index]
81  else:
82  if int(run) < 138564:
83  index = 0
84  psfactor = prescaleTable[key][index]
85  else:
86  #print "... the run ",run," is not found in columns.txt ... Index is set to zero, need to check independently..."
87  index=0
88  psfactor = prescaleTable[key][index]
89  Absent.append(run)
90  absent=1
91  if absent==0:
92  print "%s\t%s" % (run, psfactor)
93  else:
94  print "%s\t%s\t (*)" % (run, psfactor)
95  jsout[run] = psfactor
96 
97 if len(Absent)>0:
98  print ""
99  print "(*) The following runs were not found in columns.txt (the run may be too recent, or the prescale index is not in OMDS)."
100  print "For these runs, the prescale_index was assumed to be zero. You need to check independently."
101  for r in Absent:
102  print "\t",r
103  print ""
104 
105 if options.jsonOut:
106  stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
107  import json
108  jsonFile = open(options.jsonOut, "w")
109  jsonFile.write(json.dumps(jsout))
110  jsonFile.close()
def getPrescalesFromKey
my $pyPrintTable = &quot;echo &#39;for X in process.PrescaleService.prescaleTable: print \&quot;%s %s" % (X...