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