test
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("--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  psMap = {}
26  aa=""
27  if len(res)>0:
28  for uu in range(3,len(res_split)-1):
29  if uu % 2 == 1:
30  aa = aa + res_split[uu] + "\t"
31  psMap[path] = aa
32  else:
33  psMap[path] = 0
34  return psMap
35 
36 from queryRR import queryRR
37 
38 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
39 prescaleTable = {}
40 runs = runKeys.keys(); runs.sort()
41 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
42 jsout = {}
43 for run in runs:
44  key = runKeys[run]
45  if not prescaleTable.has_key(key):
46  prescaleTable[key] = getPrescalesFromKey(key)
47  psfactor = 1
48  if prescaleTable[key].has_key(path): psfactor = prescaleTable[key][path]
49  print "%s\t%s" % (run, psfactor)
50  jsout[run] = psfactor
51 
52 if options.jsonOut:
53  stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
54  import json
55  jsonFile = open(options.jsonOut, "w")
56  jsonFile.write(json.dumps(jsout))
57  jsonFile.close()
def getPrescalesFromKey
my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"%s %s" % (X...