CMS 3D CMS Logo

getHLTprescales.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 from __future__ import absolute_import
4 from sys import stderr, exit
5 import commands
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 = commands.getoutput(cmd)
26  res_split = res.split()
27  psCols = []
28  if len(res)>0:
29  for uu in range(3,len(res_split)-1):
30  if uu % 2 == 1:
31  psCols.append(res_split[uu])
32  return psCols
33 
34 from .queryRR import queryRR
35 
36 def readIndex():
37  asciiFile=open("columns.txt","read")
38  mapIndex={}
39  fl="go"
40  while fl:
41  fl=asciiFile.readline()
42  if len(fl)>0:
43  ll=fl.split()
44  runnumber=ll[0]
45  pindex=ll[1]
46  mapIndex[runnumber]=pindex
47  asciiFile.close()
48  return mapIndex
49 
50 
51 MapIndex=readIndex()
52 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
53 prescaleTable = {}
54 Absent = []
55 runs = runKeys.keys(); runs.sort()
56 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
57 jsout = {}
58 for run in runs:
59  key = runKeys[run]
60  if key not in prescaleTable:
61  prescaleTable[key] = getPrescalesFromKey(key)
62  psfactor = 1
63  absent=0
64  if len(prescaleTable[key]) == 0:
65  psfactor = 0
66  else:
67  if run in MapIndex:
68  index = int(MapIndex[run])
69  psfactor = prescaleTable[key][index]
70  else:
71  if int(run) < 138564:
72  index = 0
73  psfactor = prescaleTable[key][index]
74  else:
75  #print "... the run ",run," is not found in columns.txt ... Index is set to zero, need to check independently..."
76  index=0
77  psfactor = prescaleTable[key][index]
78  Absent.append(run)
79  absent=1
80  if absent==0:
81  print("%s\t%s" % (run, psfactor))
82  else:
83  print("%s\t%s\t (*)" % (run, psfactor))
84  jsout[run] = psfactor
85 
86 if len(Absent)>0:
87  print("")
88  print("(*) The following runs were not found in columns.txt (the run may be too recent, or the prescale index is not in OMDS).")
89  print("For these runs, the prescale_index was assumed to be zero. You need to check independently.")
90  for r in Absent:
91  print("\t",r)
92  print("")
93 
94 if options.jsonOut:
95  stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
96  import json
97  jsonFile = open(options.jsonOut, "w")
98  jsonFile.write(json.dumps(jsout))
99  jsonFile.close()
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
getHLTprescales.readIndex
def readIndex()
Definition: getHLTprescales.py:36
getHLTprescales.getPrescalesFromKey
def getPrescalesFromKey(key)
my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"%s %s" % (X....
Definition: getHLTprescales.py:22
createfilelist.int
int
Definition: createfilelist.py:10
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
queryRR
Definition: queryRR.py:1