CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getHLTkey.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from sys import stderr, exit
3 import commands
4 
5 
6 #
7 # E.P., 27 July 2010
8 # query to the Run Reistry taken from a script by Giovanni Petrucianni
9 #
10 
11 
12 from optparse import OptionParser
13 parser = OptionParser(usage="usage: %prog [options] ")
14 parser.add_option("--firstRun", dest="firstRun", help="first run", type="int", metavar="RUN", default="1")
15 parser.add_option("--lastRun", dest="lastRun", help="last run", type="int", metavar="RUN", default="9999999")
16 parser.add_option("--groupName", dest="groupName", help="select runs of name like NAME", metavar="NAME", default="Collisions%")
17 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")
18 parser.add_option("--HLTkey", dest="HLTkey", help="name of the HLTkey e.g. /cdaq/physics/Run2010/v3.1/HLT_1.6E30/V1",metavar="HLT")
19 parser.add_option("--perKey", action="store_true",default=False,dest="perKey",help="list the runs per HLT key",metavar="perKey")
20 (options, args) = parser.parse_args()
21 
22 def queryRR():
23  stderr.write("Querying run registry for range [%d, %d], group name like %s ...\n" % (options.firstRun, options.lastRun, options.groupName))
24  import xmlrpclib
25  import xml.dom.minidom
26  server = xmlrpclib.ServerProxy(options.rrurl)
27  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))
28  ret = {}
29  xml_data = xml.dom.minidom.parseString(run_data)
30  xml_runs = xml_data.documentElement.getElementsByTagName("RUN_DATASET")
31  for xml_run in xml_runs:
32  ret[xml_run.getElementsByTagName("RUN_NUMBER")[0].firstChild.nodeValue] = xml_run.getElementsByTagName("RUN_HLTKEY")[0].firstChild.nodeValue
33  return ret
34 
35 runKeys = queryRR()
36 runs = runKeys.keys(); runs.sort()
37 
38 if options.perKey:
39  runsPerKey={}
40  for run in runs:
41  key = runKeys[run]
42  if not key in runsPerKey.keys():
43  tmpruns=[]
44  tmpruns.append(run)
45  runsPerKey[key] = tmpruns
46  else:
47  runsPerKey[key].append(run)
48  theKeys = runsPerKey.keys()
49  for key in theKeys:
50  theruns = runsPerKey[key]
51  topr=""
52  for r in theruns:
53  topr=topr+"\t"+r
54  print key,topr
55  exit(1)
56 
57 if options.HLTkey:
58  HLTkey = options.HLTkey
59  print "List of runs taken with HLT key = ",HLTkey
60 for run in runs:
61  key = runKeys[run]
62 
63  if not options.HLTkey:
64  print run,key
65  else:
66  if key == options.HLTkey:
67  print run
def queryRR
Definition: getHLTkey.py:22