File indexing completed on 2023-03-17 11:09:53
0001
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
0022 def getPrescalesFromKey(key):
0023
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 psCols = []
0028 if len(res)>0:
0029 for uu in range(3,len(res_split)-1):
0030 if uu % 2 == 1:
0031 psCols.append(res_split[uu])
0032 return psCols
0033
0034 from .queryRR import queryRR
0035
0036 def readIndex():
0037 asciiFile=open("columns.txt","read")
0038 mapIndex={}
0039 fl="go"
0040 while fl:
0041 fl=asciiFile.readline()
0042 if len(fl)>0:
0043 ll=fl.split()
0044 runnumber=ll[0]
0045 pindex=ll[1]
0046 mapIndex[runnumber]=pindex
0047 asciiFile.close()
0048 return mapIndex
0049
0050
0051 MapIndex=readIndex()
0052 runKeys = queryRR(options.firstRun,options.lastRun,options.groupName)
0053 prescaleTable = {}
0054 Absent = []
0055 runs = runKeys.keys(); runs.sort()
0056 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
0057 jsout = {}
0058 for run in runs:
0059 key = runKeys[run]
0060 if key not in prescaleTable:
0061 prescaleTable[key] = getPrescalesFromKey(key)
0062 psfactor = 1
0063 absent=0
0064 if len(prescaleTable[key]) == 0:
0065 psfactor = 0
0066 else:
0067 if run in MapIndex:
0068 index = int(MapIndex[run])
0069 psfactor = prescaleTable[key][index]
0070 else:
0071 if int(run) < 138564:
0072 index = 0
0073 psfactor = prescaleTable[key][index]
0074 else:
0075
0076 index=0
0077 psfactor = prescaleTable[key][index]
0078 Absent.append(run)
0079 absent=1
0080 if absent==0:
0081 print("%s\t%s" % (run, psfactor))
0082 else:
0083 print("%s\t%s\t (*)" % (run, psfactor))
0084 jsout[run] = psfactor
0085
0086 if len(Absent)>0:
0087 print("")
0088 print("(*) The following runs were not found in columns.txt (the run may be too recent, or the prescale index is not in OMDS).")
0089 print("For these runs, the prescale_index was assumed to be zero. You need to check independently.")
0090 for r in Absent:
0091 print("\t",r)
0092 print("")
0093
0094 if options.jsonOut:
0095 stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
0096 import json
0097 jsonFile = open(options.jsonOut, "w")
0098 jsonFile.write(json.dumps(jsout))
0099 jsonFile.close()