CMS 3D CMS Logo

getHLTPrescaleColumns.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 from __future__ import print_function
3 from __future__ import absolute_import
4 from sys import stderr, exit
5 import subprocess
6 
7 from optparse import OptionParser
8 parser = OptionParser(usage="usage: %prog [options] Trigger_Path")
9 parser.add_option("--firstRun", dest="firstRun", help="first run", type="int", metavar="RUN", default="1")
10 parser.add_option("--lastRun", dest="lastRun", help="last run", type="int", metavar="RUN", default="9999999")
11 parser.add_option("--groupName", dest="groupName", help="select runs of name like NAME", metavar="NAME", default="Collisions%")
12 parser.add_option("--jsonOut", dest="jsonOut", help="dump prescales in JSON format on FILE", metavar="FILE")
13 (options, args) = parser.parse_args()
14 if len(args) != 1:
15  parser.print_usage()
16  exit(2)
17 path = args[0]
18 
19 
20 edmCfgFromDB = "edmConfigFromDB --orcoff --format summary.ascii --paths " + path;
21 
23  #stderr.write("\t%s ...\n" % key);
24  cmd = ( edmCfgFromDB +" --configName "+key + " | grep -i "+ path + " | tail -1 | awk ' $2 ==\"%s\" {print $NL}' " ) % path
25  res = subprocess.getoutput(cmd)
26  res_split = res.split()
27  psMap = {}
28  aa=""
29  if len(res)>0:
30  for uu in range(3,len(res_split)-1):
31  if uu % 2 == 1:
32  aa = aa + res_split[uu] + "\t"
33  psMap[path] = aa
34  else:
35  psMap[path] = 0
36  return psMap
37 
38 from .queryRR import queryRR
39 
40 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
41 prescaleTable = {}
42 runs = runKeys.keys(); runs.sort()
43 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
44 jsout = {}
45 for run in runs:
46  key = runKeys[run]
47  if key not in prescaleTable:
48  prescaleTable[key] = getPrescalesFromKey(key)
49  psfactor = 1
50  if path in prescaleTable[key]: psfactor = prescaleTable[key][path]
51  print("%s\t%s" % (run, psfactor))
52  jsout[run] = psfactor
53 
54 if options.jsonOut:
55  stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
56  import json
57  jsonFile = open(options.jsonOut, "w")
58  jsonFile.write(json.dumps(jsout))
59  jsonFile.close()
def getPrescalesFromKey(key)
my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"%s %s" % (X...
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def exit(msg="")