Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-27 04:17:59

0001 #!/usr/bin/env python3 
0002 from __future__ import print_function
0003 from __future__ import absolute_import
0004 from sys import stderr, exit
0005 import subprocess
0006 
0007 from optparse import OptionParser
0008 parser = OptionParser(usage="usage: %prog [options] Trigger_Path")
0009 parser.add_option("--firstRun",  dest="firstRun",  help="first run", type="int", metavar="RUN", default="1")
0010 parser.add_option("--lastRun",   dest="lastRun",   help="last run",  type="int", metavar="RUN", default="9999999")
0011 parser.add_option("--groupName", dest="groupName", help="select runs of name like NAME", metavar="NAME", default="Collisions%")
0012 parser.add_option("--jsonOut",   dest="jsonOut",   help="dump prescales in JSON format on FILE", metavar="FILE")
0013 (options, args) = parser.parse_args()
0014 if len(args) != 1:
0015     parser.print_usage()
0016     exit(2)
0017 path = args[0]
0018 
0019 
0020 edmCfgFromDB = "edmConfigFromDB --orcoff --format summary.ascii --paths " + path;
0021 ## my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"\%s \%s\" % (X.pathName.value(), X.prescales[0])'";
0022 def getPrescalesFromKey(key):
0023     #stderr.write("\t%s ...\n" % key);
0024     cmd = ( edmCfgFromDB +" --configName "+key + " | grep -i "+ path + " | tail -1 | awk ' $2 ==\"%s\" {print $NL}' " ) % path
0025     res = subprocess.getoutput(cmd)
0026     res_split = res.split()
0027     psMap = {}
0028     aa=""
0029     if len(res)>0:
0030         for uu in range(3,len(res_split)-1):
0031             if uu % 2 == 1:
0032                 aa = aa + res_split[uu] + "\t"
0033         psMap[path] = aa
0034     else:
0035         psMap[path] = 0
0036     return psMap
0037 
0038 from .queryRR import queryRR
0039 
0040 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
0041 prescaleTable = {}
0042 runs = runKeys.keys(); runs.sort()
0043 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
0044 jsout = {}
0045 for run in runs:
0046     key = runKeys[run]
0047     if key not in prescaleTable:
0048         prescaleTable[key] = getPrescalesFromKey(key)
0049     psfactor = 1
0050     if path in prescaleTable[key]: psfactor = prescaleTable[key][path]
0051     print("%s\t%s" % (run, psfactor))
0052     jsout[run] = psfactor
0053 
0054 if options.jsonOut:
0055     stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
0056     import json
0057     jsonFile = open(options.jsonOut, "w")
0058     jsonFile.write(json.dumps(jsout))
0059     jsonFile.close()