File indexing completed on 2024-11-25 02:29:19
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 import json
0022 import ROOT
0023 from pprint import pprint
0024 from optparse import OptionParser
0025 import CondCore.Utilities.conddblib as conddb
0026
0027
0028 def findPeakIOVs(values):
0029
0030 listOfIOVs=[]
0031 listOfModes=[]
0032 lastMode=1
0033 lastRun=1
0034
0035 latestRun=-1
0036 latestMode=-9999
0037
0038 for value in values:
0039 if (value['y']!=lastMode):
0040 listOfIOVs.append((lastRun,value['x']))
0041 if(lastMode==1):
0042 listOfModes.append('PEAK')
0043 else:
0044 listOfModes.append('DECO')
0045 lastMode=value['y']
0046 lastRun=value['x']
0047 else:
0048 latestRun=value['x']
0049 if(value['y']==1):
0050 latestMode='PEAK'
0051 else:
0052 latestMode='DECO'
0053
0054
0055 listOfIOVs.append((lastRun,999999))
0056 listOfModes.append(latestMode)
0057
0058 return dict(zip(listOfIOVs,listOfModes))
0059
0060
0061 def getTkInDict(runvalues):
0062
0063 isTrackerIn = {}
0064 for entry in runvalues:
0065 isTrackerIn[entry['x']]=entry['y']
0066 return isTrackerIn
0067
0068
0069 def getAllRuns():
0070
0071 con = conddb.connect(url = conddb.make_url("pro"))
0072 session = con.session()
0073 RUNINFO = session.get_dbtype(conddb.RunInfo)
0074 allRuns = session.query(RUNINFO.run_number, RUNINFO.start_time, RUNINFO.end_time).all()
0075 return allRuns
0076
0077
0078 def convert_timedelta(duration):
0079
0080 days, seconds = duration.days, duration.seconds
0081 hours = days * 24 + seconds // 3600
0082 minutes = (seconds % 3600) // 60
0083 seconds = (seconds % 60)
0084 return '{0:02}'.format(hours), '{0:02}'.format(minutes), '{0:02}'.format(seconds)
0085
0086
0087 def main():
0088
0089
0090 parser = OptionParser()
0091 parser.add_option("-f", "--file", dest="filename",
0092 help="open FILE and extract info", metavar="FILE")
0093 parser.add_option("-r", "--runfile", dest="runfilename",
0094 help="open RUNFILE and extract info", metavar="RUNFILE")
0095 parser.add_option("-v", "--verbose",
0096 action="store_true", dest="verbose", default=False,
0097 help="verbose output")
0098 parser.add_option("-p", "--peakOnly",
0099 action="store_true", dest="peakOnly", default=False,
0100 help="Print only runs in PEAK mode")
0101 (options, args) = parser.parse_args()
0102
0103 with open(options.filename) as data_file:
0104 data = json.load(data_file)
0105 values = data["data"]
0106
0107 IOVs = findPeakIOVs(values)
0108 if(options.verbose):
0109 pprint(IOVs)
0110
0111 with open(options.runfilename) as rundata_file:
0112 data = json.load(rundata_file)
0113 runvalues = data["data"]
0114
0115 isTrackerIn = getTkInDict(runvalues)
0116
0117 if(options.verbose):
0118 for value in runvalues:
0119 isTrackerIn = bool(value['y'])
0120 runnumber = int(value['x'])
0121 if(not isTrackerIn):
0122
0123 continue
0124 else:
0125 for key, value in IOVs.items():
0126 if(key[0]<runnumber and key[1]>runnumber):
0127 print(runnumber,",",key[0],"-",key[1],",",value)
0128
0129 allRuns = getAllRuns()
0130 if(options.verbose):
0131 print(allRuns)
0132
0133 sorted_runs = sorted(allRuns)
0134
0135 for run in sorted_runs:
0136 if run[0] not in isTrackerIn:
0137 continue
0138 if(isTrackerIn[run[0]]):
0139
0140 for key, value in IOVs.items():
0141 if(key[0]<run[0] and key[1]>run[0]):
0142 hours, minutes, seconds = convert_timedelta(run[2]-run[1])
0143 if(options.peakOnly):
0144 if(value=='PEAK'):
0145 print(run[0],",",run[1].strftime('%Y-%m-%d'),",",'{}:{}:{}'.format(hours,minutes,seconds),",",key[0],"-",key[1],",",value)
0146 else:
0147 pass
0148 else:
0149 print(run[0],",",run[1].strftime('%Y-%m-%d'),",",'{}:{}:{}'.format(hours,minutes,seconds),",",key[0],"-",key[1],",",value)
0150 else:
0151 pass
0152
0153
0154 if __name__ == "__main__":
0155 main()