303 def readDetailsFromTRP(inputFile, runNumber, maxRanges, itemName="L1_eEM26M--enabled", server="https://atlasop.cern.ch
"): log.info("Reading run details from TRP")
309 for timeRange
in inputFile.GetListOfKeys():
310 rangeObj = timeRange.ReadObj()
311 if not rangeObj.IsA().InheritsFrom(ROOT.TDirectory.Class()):
continue
312 rangeName = rangeObj.GetName()
314 for table
in rangeObj.GetListOfKeys():
315 tableObj = table.ReadObj()
316 if "Global" not in tableObj.GetName():
continue
318 dirKey =
set(key.ReadObj().GetName()
for key
in tableObj.GetListOfKeys()
if key.ReadObj().GetName().startswith(
'LumiBlock'))
319 lumiBlockDict[rangeName] =
sorted(dirKey)
321 if not lumiBlockDict:
322 log.error(
"No lumiblocks were found in the input file")
326 from DQUtils.sugar
import RunLumi
327 from time
import ctime
328 from PyCool
import cool
329 from TrigConfStorage.TriggerCoolUtil
import TriggerCoolUtil
330 dbconn = TriggerCoolUtil.GetConnection(
"CONDBR2")
334 f = dbconn.getFolder(
"/TRIGGER/LUMI/LBLB" )
335 for lbRange
in lumiBlockDict:
336 startLb =
int(
min(lumiBlockDict[lbRange]).
replace(
'LumiBlock_',
''))
337 endLb =
int(
max(lumiBlockDict[lbRange]).
replace(
'LumiBlock_',
''))
338 log.debug(
"For range {0} first lumiblock is {1} and last {2}".
format(lbRange, startLb, endLb))
340 since =
RunLumi(runNumber, startLb)
341 until =
RunLumi(runNumber, endLb)
343 objs = f.browseObjects(since, until, cool.ChannelSelection(0))
345 objCurrRef = objs.currentRef()
346 startTime =
int(objCurrRef.payload()[
"StartTime"]/1000)
348 while objs.goToNext():
349 objCurrRef = objs.currentRef()
351 endTime =
int(objCurrRef.payload()[
"EndTime"]/1000)
353 lbRangeTsDict[lbRange] = {
"start": startTime,
"end" : endTime}
355 log.debug(
"Read start and end of range {0} from COOL: {1} - {2}".
format(lbRange, ctime(startTime/1E6).
replace(
' ',
'_'), ctime(endTime/1E6).
replace(
' ',
'_')))
359 lbRangeDetailsDict = {}
360 physicsDeadtimeGlobal = []
364 pbeast = libpbeastpy.ServerProxy(server)
366 for lbRange
in lbRangeTsDict:
367 lbStart = lbRangeTsDict[lbRange][
"start"]
368 lbEnd = lbRangeTsDict[lbRange][
"end"]
371 physicsDeadtimeTRP = pbeast.get_data(
'ATLAS',
'L1_Rate',
'DT',
'ISS_TRP.' + itemName,
False, lbStart, lbEnd, 0,
True)
373 if len(physicsDeadtimeTRP) == 0:
374 log.error(
"Deadtime not found for item {0} for range {1}".
format(itemName, lbRange))
375 physicsDeadtimeAvg = -1
377 physicsDeadtimeTRP = physicsDeadtimeTRP[0].data[
'ISS_TRP.' + itemName]
378 physicsDeadtimeArray = []
379 for entry
in physicsDeadtimeTRP:
381 if entry.ts < lbStart
or entry.ts > lbEnd:
383 if type(entry.value)
is not float:
386 physicsDeadtimeArray.append(entry.value)
387 physicsDeadtimeGlobal.append(entry.value)
389 physicsDeadtimeAvg =
sum(physicsDeadtimeArray)/len(physicsDeadtimeArray)
if len(physicsDeadtimeArray) > 0
else 1.
392 pileupPbeast = pbeast.get_data(
'OLC',
'OCLumi',
'Mu',
'OLC.OLCApp/ATLAS_PREFERRED_LBAv_PHYS',
False, lbStart, lbEnd)[0].data[
'OLC.OLCApp/ATLAS_PREFERRED_LBAv_PHYS']
394 for entry
in pileupPbeast:
395 if entry.ts < lbStart
or entry.ts > lbEnd:
397 if type(entry.value)
is not float:
400 pileupArr.append(entry.value)
401 pileupGlobal.append(entry.value)
403 pileupAvg =
sum(pileupArr)/len(pileupArr)
if len(pileupArr) > 0
else -1
404 lbRangeDetailsDict[lbRange] = {
"avgPileup" :
round(pileupAvg, 3),
"minPileup" :
round(
min(pileupArr), 3),
405 "maxPileup" :
round(
max(pileupArr), 3),
"deadtime" :
round(physicsDeadtimeAvg, 3)}
407 except ImportError
as e:
408 log.error(
"The pbeast python library was not found! Remember to setup tdaq release!")
411 except RuntimeError
as e:
412 if "Sign in to your account" in str(e):
413 log.error(
"PBeast authentication failed! Remember to export pbeast server sso: export PBEAST_SERVER_SSO_SETUP_TYPE=AutoUpdateKerberos")
414 elif "cannot create CERN SSO cookie" in str(e):
415 log.error(
"PBeast authentication requires the cookies, please setup")
417 log.error(
"Error when reading from Pbeast! ")
421 log.debug(
"The final lumiblock dictionary is {0}".
format(lbRangeDetailsDict))
423 physicsDeadtimeGlobalAvg =
sum(physicsDeadtimeGlobal)/len(physicsDeadtimeGlobal)
if len(physicsDeadtimeGlobal) > 0
else 1.
424 pileupGlobalAvg =
sum(pileupGlobal)/len(pileupGlobal)
if len(pileupGlobal) > 0
else 1.
426 startTs = lbRangeTsDict[
min(lbRangeTsDict.keys())][
"start"]/1E6
427 endTs = lbRangeTsDict[
max(lbRangeTsDict.keys())][
"end"]/1E6
428 monitoredTime = datetime.timedelta(seconds=(
int(endTs - startTs)))
429 additionalDetails = {
430 "DataRangeStart" : ctime(startTs),
431 "DataRangeEnd" : ctime(endTs),
432 "DataRangeDuration" :
"{0}:{1}".
format(
int(monitoredTime.total_seconds()//3600),
int((monitoredTime.total_seconds()%3600)//60)),
433 "GlobalMeanPileup" :
round(pileupGlobalAvg, 3),
434 "GlobalMinPileup" :
round(
min(pileupGlobal), 3),
435 "GlobalMaxPileup" :
round(
max(pileupGlobal), 3),
436 "GlobalMeanDeadtime" :
round(physicsDeadtimeGlobalAvg, 3)
439 return {
"Global" : additionalDetails,
"PerLb" : lbRangeDetailsDict}