CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getHLTPrescaleColumns.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  psMap = {}
27  aa=""
28  if len(res)>0:
29  for uu in range(3,len(res_split)-1):
30  if uu % 2 == 1:
31  aa = aa + res_split[uu] + "\t"
32  psMap[path] = aa
33  else:
34  psMap[path] = 0
35  return psMap
36 
37 
38 def queryRR():
39  stderr.write("Querying run registry for range [%d, %d], group name like %s ...\n" % (options.firstRun, options.lastRun, options.groupName))
40  import xmlrpclib
41  import xml.dom.minidom
42  server = xmlrpclib.ServerProxy(options.rrurl)
43  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))
44  ret = {}
45  xml_data = xml.dom.minidom.parseString(run_data)
46  xml_runs = xml_data.documentElement.getElementsByTagName("RUN_DATASET")
47  for xml_run in xml_runs:
48  ret[xml_run.getElementsByTagName("RUN_NUMBER")[0].firstChild.nodeValue] = xml_run.getElementsByTagName("RUN_HLTKEY")[0].firstChild.nodeValue
49  return ret
50 
51 runKeys = queryRR()
52 prescaleTable = {}
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 not prescaleTable.has_key(key):
59  prescaleTable[key] = getPrescalesFromKey(key)
60  psfactor = 1
61  if prescaleTable[key].has_key(path): psfactor = prescaleTable[key][path]
62  print "%s\t%s" % (run, psfactor)
63  jsout[run] = psfactor
64 
65 if options.jsonOut:
66  stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
67  import json
68  jsonFile = open(options.jsonOut, "w")
69  jsonFile.write(json.dumps(jsout))
70  jsonFile.close()
def getPrescalesFromKey
my $pyPrintTable = &quot;echo &#39;for X in process.PrescaleService.prescaleTable: print \&quot;%s %s" % (X...