167 def fillHLTmap( info, hltMap_prev , lbCount, run, grlblocks):
168 from TrigConfigSvc.TrigConfigSvcUtils
import getL1Items, getL1Prescales
170 from TrigConfIO.L1TriggerConfigAccess
import L1MenuAccess,L1PrescalesSetAccess
171 from TrigConfIO.HLTTriggerConfigAccess
import HLTMenuAccess,HLTPrescalesSetAccess
173 from collections
import defaultdict
175 lvl =
int(logging.root.level)
176 logging.root.setLevel(logging.WARNING)
181 items = {}; chainsHLT = {}
182 for name,value
in L1MenuAccess(dbalias =
'TRIGGERDB_RUN3', smkey = info[
'smk']).
items().
items():
183 items[name] = value[
"ctpid"]
184 for name,value
in HLTMenuAccess(dbalias =
'TRIGGERDB_RUN3', smkey = info[
'smk']).
chains().
items():
185 if "L1" not in value[
"l1item"]:
continue
186 chainsHLT[value[
"nameHash"]] = (name,value[
"l1item"])
190 chainsHLT = {k:v
for (k,v)
in six.iteritems (chainsHLT)
if "L1" in v[1]}
195 for lbrange
in info[
'hltpsk']:
196 lbstart, lbend = lbrange[2], lbrange[4]
197 if lbend ==-1: lbend = 2000
200 for name,value
in HLTPrescalesSetAccess(dbalias=
'TRIGGERDB_RUN3',hltpskey=lbrange[0]).
prescales().
items():
203 hltprescales[value[
"hash"]] = (value[
"prescale"],rerun)
206 tmphltList.append(( lbstart, lbend,hltprescales) )
209 for lbrange
in info[
'l1psk']:
210 lbstart, lbend = lbrange[2], lbrange[4]
211 if lbend ==-1: lbend = 2000
213 l1ps = L1PrescalesSetAccess(dbalias=
'TRIGGERDB_RUN3',l1pskey=lbrange[0])
214 l1prescales = {name: l1ps.prescale(name)
for name
in l1ps.itemNames()}
217 l1prescales = {l1name: l1prescales[
int(l1id)]
for (l1name, l1id)
in six.iteritems (items)}
218 tmpl1List.append(( lbstart, lbend,l1prescales) )
220 logging.root.setLevel(lvl)
223 hltindex, l1index = 0,0
225 while hltindex < len(tmphltList)
and l1index < len(tmpl1List) :
226 if tmphltList[hltindex][1] == tmpl1List[l1index][1]:
227 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmphltList[hltindex][1]
228 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
231 elif tmphltList[hltindex][1] > tmpl1List[l1index][1]:
232 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmpl1List[l1index][1]
233 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
236 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmphltList[hltindex][1]
237 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
241 f =
open(
"liveFractions.txt",
"a")
if os.path.exists(
"liveFractions.txt")
else None
244 for lbstart, lbend, hltprescales, l1prescales
in mergedList:
245 if run
in LBexceptions.exceptions:
246 if any([lbstart>=exc_start
and lbstart<=exc_end
for exc_start, exc_end
in LBexceptions.exceptions[run]]):
continue
247 if any([lbend>=exc_start
and lbend<=exc_end
for exc_start, exc_end
in LBexceptions.exceptions[run]]):
continue
249 for grllbstart,grllbend
in grlblocks:
250 lboverlap = (
min(lbend,grllbend) -
max(lbstart,grllbstart))+1
251 if lboverlap <= 0:
continue
254 for hltid, (hltps, hltrerun)
in six.iteritems (hltprescales):
255 if hltid
not in chainsHLT:
continue
256 if hltps < 1: hltps = 1e99
257 l1seeds = chainsHLT[hltid][1]
259 for l1seed
in l1seeds.split(
","):
260 if l1seed
not in l1prescales
and len(l1seeds) > 10:
continue
261 tmpl1ps = l1prescales[l1seed]
262 if tmpl1ps < 1: tmpl1ps = 1e99
263 l1ps =
min(l1ps, tmpl1ps)
266 if hltps*l1ps < 1e99: efflb = lboverlap/(hltps*l1ps)
268 if not chainsHLT[hltid][0]
in hltMap: hltMap[chainsHLT[hltid][0]] = [l1seeds, 0, hltrerun>0, defaultdict(int)]
269 hltMap[chainsHLT[hltid][0]][1] += efflb
270 hltMap[chainsHLT[hltid][0]][3][run] += efflb
271 if f: f.write(f
"{chainsHLT[hltid][0]},{run},{lbstart},{lbend},{grllbstart},{grllbend},{lboverlap},{l1ps},{hltps}\n")
275 for hlt,(l1,efflb,rerun,efflbByRun)
in six.iteritems (hltMap_prev):
277 hltMap[hlt][1] += efflb
278 hltMap[hlt][2] |= rerun
279 for run,runefflb
in efflbByRun.items():
280 hltMap[hlt][3][run] += runefflb
281 else: hltMap[hlt] = [l1, efflb,rerun, efflbByRun]
282 return hltMap, lbCount