File indexing completed on 2023-03-17 10:46:26
0001
0002
0003 '''
0004 Script used to find all Strip Tracker PEAK runs
0005
0006 Usage:
0007
0008 create the list of SiStripLatency::singleReadOutMode() IOVs / values with:
0009
0010 getPayloadData.py --plugin pluginSiStripLatency_PayloadInspector --plot plot_SiStripIsPeakModeHistory --tag SiStripLatency_GR10_v2_hlt --time_type Run --iovs '{"start_iov": "1", "end_iov": "400000"}' --db Prod --test > & log.json
0011
0012 create the list of runs with the Strip Tracker in global DAQ
0013
0014 getPayloadData.py --plugin pluginRunInfo_PayloadInspector --plot plot_RunInfoTrackerHistory --tag runinfo_31X_hlt --time_type Run --iovs '{"start_iov": "1", "end_iov": "400000"}' --db Prod --test > & isTrackerin.json
0015
0016 followed by:
0017
0018 python findPeakRuns.py -f log.json -r isTrackerIn.json > & allTrackerRuns.csv &
0019 '''
0020
0021 from __future__ import print_function
0022 import json
0023 import ROOT
0024 from pprint import pprint
0025 from optparse import OptionParser
0026 import CondCore.Utilities.conddblib as conddb
0027
0028
0029 def findPeakIOVs(values):
0030
0031 listOfIOVs=[]
0032 listOfModes=[]
0033 lastMode=1
0034 lastRun=1
0035
0036 latestRun=-1
0037 latestMode=-9999
0038
0039 for value in values:
0040 if (value['y']!=lastMode):
0041 listOfIOVs.append((lastRun,value['x']))
0042 if(lastMode==1):
0043 listOfModes.append('PEAK')
0044 else:
0045 listOfModes.append('DECO')
0046 lastMode=value['y']
0047 lastRun=value['x']
0048 else:
0049 latestRun=value['x']
0050 if(value['y']==1):
0051 latestMode='PEAK'
0052 else:
0053 latestMode='DECO'
0054
0055
0056 listOfIOVs.append((lastRun,999999))
0057 listOfModes.append(latestMode)
0058
0059 return dict(zip(listOfIOVs,listOfModes))
0060
0061
0062 def getTkInDict(runvalues):
0063
0064 isTrackerIn = {}
0065 for entry in runvalues:
0066 isTrackerIn[entry['x']]=entry['y']
0067 return isTrackerIn
0068
0069
0070 def getAllRuns():
0071
0072 con = conddb.connect(url = conddb.make_url("pro"))
0073 session = con.session()
0074 RUNINFO = session.get_dbtype(conddb.RunInfo)
0075 allRuns = session.query(RUNINFO.run_number, RUNINFO.start_time, RUNINFO.end_time).all()
0076 return allRuns
0077
0078
0079 def convert_timedelta(duration):
0080
0081 days, seconds = duration.days, duration.seconds
0082 hours = days * 24 + seconds // 3600
0083 minutes = (seconds % 3600) // 60
0084 seconds = (seconds % 60)
0085 return '{0:02}'.format(hours), '{0:02}'.format(minutes), '{0:02}'.format(seconds)
0086
0087
0088 def main():
0089
0090
0091 parser = OptionParser()
0092 parser.add_option("-f", "--file", dest="filename",
0093 help="open FILE and extract info", metavar="FILE")
0094 parser.add_option("-r", "--runfile", dest="runfilename",
0095 help="open RUNFILE and extract info", metavar="RUNFILE")
0096 parser.add_option("-v", "--verbose",
0097 action="store_true", dest="verbose", default=False,
0098 help="verbose output")
0099 parser.add_option("-p", "--peakOnly",
0100 action="store_true", dest="peakOnly", default=False,
0101 help="Print only runs in PEAK mode")
0102 (options, args) = parser.parse_args()
0103
0104 with open(options.filename) as data_file:
0105 data = json.load(data_file)
0106 values = data["data"]
0107
0108 IOVs = findPeakIOVs(values)
0109 if(options.verbose):
0110 pprint(IOVs)
0111
0112 with open(options.runfilename) as rundata_file:
0113 data = json.load(rundata_file)
0114 runvalues = data["data"]
0115
0116 isTrackerIn = getTkInDict(runvalues)
0117
0118 if(options.verbose):
0119 for value in runvalues:
0120 isTrackerIn = bool(value['y'])
0121 runnumber = int(value['x'])
0122 if(not isTrackerIn):
0123
0124 continue
0125 else:
0126 for key, value in IOVs.items():
0127 if(key[0]<runnumber and key[1]>runnumber):
0128 print(runnumber,",",key[0],"-",key[1],",",value)
0129
0130 allRuns = getAllRuns()
0131 if(options.verbose):
0132 print(allRuns)
0133
0134 sorted_runs = sorted(allRuns)
0135
0136 for run in sorted_runs:
0137 if run[0] not in isTrackerIn:
0138 continue
0139 if(isTrackerIn[run[0]]):
0140
0141 for key, value in IOVs.items():
0142 if(key[0]<run[0] and key[1]>run[0]):
0143 hours, minutes, seconds = convert_timedelta(run[2]-run[1])
0144 if(options.peakOnly):
0145 if(value=='PEAK'):
0146 print(run[0],",",run[1].strftime('%Y-%m-%d'),",",'{}:{}:{}'.format(hours,minutes,seconds),",",key[0],"-",key[1],",",value)
0147 else:
0148 pass
0149 else:
0150 print(run[0],",",run[1].strftime('%Y-%m-%d'),",",'{}:{}:{}'.format(hours,minutes,seconds),",",key[0],"-",key[1],",",value)
0151 else:
0152 pass
0153
0154
0155 if __name__ == "__main__":
0156 main()