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
176 tcsLogger = logging.getLogger(
"TrigConfigSvcUtils.py")
177 tcsLogLevel = tcsLogger.level
178 tcsLogger.setLevel(logging.ERROR)
180 lvl =
int(logging.root.level)
181 logging.root.setLevel(logging.WARNING)
186 items = {}; chainsHLT = {}
187 for name,value
in L1MenuAccess(dbalias =
'TRIGGERDB_RUN3', smkey = info[
'smk']).
items().
items():
188 items[name] = value[
"ctpid"]
189 for name,value
in HLTMenuAccess(dbalias =
'TRIGGERDB_RUN3', smkey = info[
'smk']).
chains().
items():
190 if "L1" not in value[
"l1item"]:
continue
191 chainsHLT[value[
"nameHash"]] = (name,value[
"l1item"])
193 items =
getL1Items(
'oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', info[
'smk'])
194 chainsHLT =
getChainsWithL1seed(
'oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', info[
'smk'])
195 chainsHLT = {k:v
for (k,v)
in six.iteritems (chainsHLT)
if "L1" in v[1]}
200 for lbrange
in info[
'hltpsk']:
201 lbstart, lbend = lbrange[2], lbrange[4]
202 if lbend ==-1: lbend = 2000
205 for name,value
in HLTPrescalesSetAccess(dbalias=
'TRIGGERDB_RUN3',hltpskey=lbrange[0]).
prescales().
items():
209 hltprescales[value[
"hash"]] = (
float(value[
"prescale"]),rerun)
211 hltprescales =
getHLTPrescalesRun2(
'oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', lbrange[0])
212 tmphltList.append(( lbstart, lbend,hltprescales) )
215 for lbrange
in info[
'l1psk']:
216 lbstart, lbend = lbrange[2], lbrange[4]
217 if lbend ==-1: lbend = 2000
219 l1ps = L1PrescalesSetAccess(dbalias=
'TRIGGERDB_RUN3',l1pskey=lbrange[0])
220 l1prescales = {name: l1ps.prescale(name)
for name
in l1ps.itemNames()}
222 l1psname, l1prescales =
getL1Prescales(
'oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_RUN2', lbrange[0])
223 l1prescales =
list(l1prescales)
224 l1prescales = {l1name: l1prescales[
int(l1id)]
for (l1name, l1id)
in six.iteritems (items)}
225 tmpl1List.append(( lbstart, lbend,l1prescales) )
227 logging.root.setLevel(lvl)
228 tcsLogger.setLevel(tcsLogLevel)
231 hltindex, l1index = 0,0
233 while hltindex < len(tmphltList)
and l1index < len(tmpl1List) :
234 if tmphltList[hltindex][1] == tmpl1List[l1index][1]:
235 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmphltList[hltindex][1]
236 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
239 elif tmphltList[hltindex][1] > tmpl1List[l1index][1]:
240 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmpl1List[l1index][1]
241 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
244 lbstart, lbend =
max(tmphltList[hltindex][0],tmpl1List[l1index][0]), tmphltList[hltindex][1]
245 mergedList.append((lbstart, lbend,tmphltList[hltindex][2],tmpl1List[l1index][2]))
249 f =
open(
"liveFractions.txt",
"a")
if os.path.exists(
"liveFractions.txt")
else None
252 for lbstart, lbend, hltprescales, l1prescales
in mergedList:
253 if run
in LBexceptions.exceptions:
254 if any([lbstart>=exc_start
and lbstart<=exc_end
for exc_start, exc_end
in LBexceptions.exceptions[run]]):
continue
255 if any([lbend>=exc_start
and lbend<=exc_end
for exc_start, exc_end
in LBexceptions.exceptions[run]]):
continue
257 for grllbstart,grllbend
in grlblocks:
258 lboverlap = (
min(lbend,grllbend) -
max(lbstart,grllbstart))+1
259 if lboverlap <= 0:
continue
262 for hltid, (hltps, hltrerun)
in six.iteritems (hltprescales):
263 if hltid
not in chainsHLT:
continue
264 if hltps < 1: hltps = 1e99
265 l1seeds = chainsHLT[hltid][1]
267 for l1seed
in l1seeds.split(
","):
268 if l1seed
not in l1prescales
and len(l1seeds) > 10:
continue
269 tmpl1ps = l1prescales[l1seed]
270 if tmpl1ps < 1: tmpl1ps = 1e99
271 l1ps =
min(l1ps, tmpl1ps)
274 if hltps*l1ps < 1e99: efflb = lboverlap/(hltps*l1ps)
276 if not chainsHLT[hltid][0]
in hltMap: hltMap[chainsHLT[hltid][0]] = [l1seeds, 0, hltrerun>0, defaultdict(int)]
277 hltMap[chainsHLT[hltid][0]][1] += efflb
278 hltMap[chainsHLT[hltid][0]][3][run] += efflb
279 if f: f.write(f
"{chainsHLT[hltid][0]},{run},{lbstart},{lbend},{grllbstart},{grllbend},{lboverlap},{l1ps},{hltps}\n")
283 for hlt,(l1,efflb,rerun,efflbByRun)
in six.iteritems (hltMap_prev):
285 hltMap[hlt][1] += efflb
286 hltMap[hlt][2] |= rerun
287 for run,runefflb
in efflbByRun.items():
288 hltMap[hlt][3][run] += runefflb
289 else: hltMap[hlt] = [l1, efflb,rerun, efflbByRun]
290 return hltMap, lbCount