Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:21

0001 #!/usr/bin/env python3 
0002 from sys import stderr, exit
0003 import subprocess
0004 
0005 from optparse import OptionParser
0006 parser = OptionParser(usage="usage: %prog [options] Trigger_Path")
0007 parser.add_option("--firstRun",  dest="firstRun",  help="first run", type="int", metavar="RUN", default="1")
0008 parser.add_option("--lastRun",   dest="lastRun",   help="last run",  type="int", metavar="RUN", default="9999999")
0009 parser.add_option("--groupName", dest="groupName", help="select runs of name like NAME", metavar="NAME", default="Collisions%")
0010 parser.add_option("--jsonOut",   dest="jsonOut",   help="dump prescales in JSON format on FILE", metavar="FILE")
0011 (options, args) = parser.parse_args()
0012 if len(args) != 1:
0013     parser.print_usage()
0014     exit(2)
0015 path = args[0]
0016 
0017 
0018 edmCfgFromDB = "edmConfigFromDB  --orcoff --format summary.ascii --paths " + path;
0019 ## my $pyPrintTable = "echo 'for X in process.PrescaleService.prescaleTable: print \"\%s \%s\" % (X.pathName.value(), X.prescales[0])'";
0020 def getPrescalesFromKey(key):
0021     #stderr.write("\t%s ...\n" % key);
0022     cmd = ( edmCfgFromDB +" --configName "+key + " | grep -i "+ path + " | tail -1 | awk ' $2 ==\"%s\" {print $NL}' " ) % path
0023     res = subprocess.getoutput(cmd)
0024     res_split = res.split()
0025     psCols = []
0026     if len(res)>0:
0027         for uu in range(3,len(res_split)-1):
0028             if uu % 2 == 1:
0029                 psCols.append(res_split[uu])
0030     return psCols
0031 
0032 from .queryRR import queryRR
0033 
0034 def readIndex():
0035     asciiFile=open("columns.txt","read")
0036     mapIndex={}
0037     fl="go"
0038     while fl:
0039         fl=asciiFile.readline()
0040         if len(fl)>0:
0041             ll=fl.split()
0042             runnumber=ll[0]
0043             pindex=ll[1]
0044             mapIndex[runnumber]=pindex
0045     asciiFile.close()
0046     return mapIndex
0047 
0048 
0049 MapIndex=readIndex()
0050 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
0051 prescaleTable = {}
0052 Absent = []
0053 runs = runKeys.keys(); runs.sort()
0054 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
0055 jsout = {}
0056 for run in runs:
0057     key = runKeys[run]
0058     if key not in prescaleTable:
0059         prescaleTable[key] = getPrescalesFromKey(key)
0060     psfactor = 1
0061     absent=0
0062     if len(prescaleTable[key]) == 0:
0063         psfactor = 0
0064     else:
0065         if run in MapIndex:
0066             index = int(MapIndex[run])
0067             psfactor = prescaleTable[key][index]
0068         else:
0069             if int(run) < 138564:
0070                 index = 0
0071                 psfactor = prescaleTable[key][index]
0072             else:
0073                 #print "... the run ",run," is not found in columns.txt ... Index is set to zero, need to check independently..."
0074                 index=0
0075                 psfactor = prescaleTable[key][index]
0076                 Absent.append(run)
0077                 absent=1
0078     if absent==0:
0079         print("%s\t%s" % (run, psfactor))
0080     else:
0081         print("%s\t%s\t (*)" % (run, psfactor))
0082     jsout[run] = psfactor
0083 
0084 if len(Absent)>0:
0085     print("")
0086     print("(*) The following runs were not found in columns.txt (the run may be too recent, or the prescale index is not in OMDS).")
0087     print("For these runs, the prescale_index was assumed to be zero. You need to check independently.")
0088     for r in Absent:
0089         print("\t",r)
0090     print("")
0091 
0092 if options.jsonOut:
0093     stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
0094     import json
0095     jsonFile = open(options.jsonOut, "w")
0096     jsonFile.write(json.dumps(jsout))
0097     jsonFile.close()