166def fillHLTmap( info, hltMap_prev , lbCount, run, grlblocks):
167 from TrigConfigSvc.TrigConfigSvcUtils import getL1Items, getL1Prescales
168
169 from TrigConfIO.L1TriggerConfigAccess import L1MenuAccess,L1PrescalesSetAccess
170 from TrigConfIO.HLTTriggerConfigAccess import HLTMenuAccess,HLTPrescalesSetAccess
171
172 from collections import defaultdict
173
174
175 tcsLogger = logging.getLogger("TrigConfigSvcUtils.py")
176 tcsLogLevel = tcsLogger.level
177 tcsLogger.setLevel(logging.ERROR)
178
179 lvl = int(logging.root.level)
180 logging.root.setLevel(logging.WARNING)
181
182
183
184 if run > 400000:
185 items = {}; chainsHLT = {}
186 for name,value in L1MenuAccess(dbalias = 'TRIGGERDB_RUN3', smkey = info['smk']).items().items():
187 items[name] = value["ctpid"]
188 for name,value in HLTMenuAccess(dbalias = 'TRIGGERDB_RUN3', smkey = info['smk']).chains().items():
189 if "L1" not in value["l1item"]: continue
190 chainsHLT[value["nameHash"]] = (name,value["l1item"])
191 else:
192 items = getL1Items('oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', info['smk'])
193 chainsHLT = getChainsWithL1seed('oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', info['smk'])
194 chainsHLT = {k:v for (k,v) in chainsHLT.items() if "L1" in v[1]}
195
196
197
198 tmphltList = []
199 for lbrange in info['hltpsk']:
200 lbstart, lbend = lbrange[2], lbrange[4]
201 if lbend ==-1: lbend = 2000
202 if run > 400000:
203 hltprescales = {}
204 for name,value in HLTPrescalesSetAccess(dbalias='TRIGGERDB_RUN3',hltpskey=lbrange[0]).prescales().items():
205 rerun=-1.0
206
207
208 hltprescales[value["hash"]] = (float(value["prescale"]),rerun)
209 else:
210 hltprescales = getHLTPrescalesRun2('oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', lbrange[0])
211 tmphltList.append(( lbstart, lbend,hltprescales) )
212
213 tmpl1List = []
214 for lbrange in info['l1psk']:
215 lbstart, lbend = lbrange[2], lbrange[4]
216 if lbend ==-1: lbend = 2000
217 if run > 400000:
218 l1ps = L1PrescalesSetAccess(dbalias='TRIGGERDB_RUN3',l1pskey=lbrange[0])
219 l1prescales = {name: l1ps.prescale(name) for name in l1ps.itemNames()}
220 else:
221 l1psname, l1prescales = getL1Prescales('oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', lbrange[0])
222 l1prescales = list(l1prescales)
223 l1prescales = {l1name: l1prescales[int(l1id)] for (l1name, l1id) in items.items()}
224 tmpl1List.append(( lbstart, lbend,l1prescales) )
225
226 logging.root.setLevel(lvl)
227 tcsLogger.setLevel(tcsLogLevel)
228
229
230 hltindex, l1index = 0,0
231 mergedList = []
232 while hltindex < len(tmphltList) and l1index < len(tmpl1List) :
233 if tmphltList[hltindex][1] == tmpl1List[l1index][1]:
234 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmphltList[hltindex][1]
235 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
236 hltindex += 1
237 l1index += 1
238 elif tmphltList[hltindex][1] > tmpl1List[l1index][1]:
239 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmpl1List[l1index][1]
240 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
241 l1index += 1
242 else:
243 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmphltList[hltindex][1]
244 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
245 hltindex += 1
246
247
248 f = open("liveFractions.txt","a") if os.path.exists("liveFractions.txt") else None
249
250 hltMap = {}
251 for lbstart, lbend, hltprescales, l1prescales in mergedList:
252 if run in LBexceptions.exceptions:
253 if any([lbstart>=exc_start and lbstart<=exc_end for exc_start, exc_end in LBexceptions.exceptions[run]]): continue
254 if any([lbend>=exc_start and lbend<=exc_end for exc_start, exc_end in LBexceptions.exceptions[run]]): continue
255
256 for grllbstart,grllbend in grlblocks:
257 lboverlap = (
min(lbend,grllbend) -
max(lbstart,grllbstart))+1
258 if lboverlap <= 0: continue
259
260 lbCount += lboverlap
261 for hltid, (hltps, hltrerun) in hltprescales.items():
262 if hltid not in chainsHLT: continue
263 if hltps < 1: hltps = 1e99
264 l1seeds = chainsHLT[hltid][1]
265 l1ps = 1e99
266 for l1seed in l1seeds.split(","):
267 if l1seed not in l1prescales and len(l1seeds) > 10: continue
268 tmpl1ps = l1prescales[l1seed]
269 if tmpl1ps < 1: tmpl1ps = 1e99
270 l1ps =
min(l1ps, tmpl1ps)
271
272
273 if hltps*l1ps < 1e99: efflb = lboverlap/(hltps*l1ps)
274 else: efflb = 0
275 if not chainsHLT[hltid][0] in hltMap: hltMap[chainsHLT[hltid][0]] = [l1seeds, 0, hltrerun>0, defaultdict(int)]
276 hltMap[chainsHLT[hltid][0]][1] += efflb
277 hltMap[chainsHLT[hltid][0]][3][run] += efflb
278 if f: f.write(f"{chainsHLT[hltid][0]},{run},{lbstart},{lbend},{grllbstart},{grllbend},{lboverlap},{l1ps},{hltps}\n")
279
280 if f: f.close()
281
282 for hlt,(l1,efflb,rerun,efflbByRun) in hltMap_prev.items():
283 if hlt in hltMap:
284 hltMap[hlt][1] += efflb
285 hltMap[hlt][2] |= rerun
286 for run,runefflb in efflbByRun.items():
287 hltMap[hlt][3][run] += runefflb
288 else: hltMap[hlt] = [l1, efflb,rerun, efflbByRun]
289 return hltMap, lbCount
290
291