7 from xml.dom
import minidom
8 from collections
import OrderedDict
9 from DQUtils.sugar
import RunLumi
11 from AthenaCommon.Logging
import logging
12 log = logging.getLogger(
'ExtractRunDetails.py')
18 Returns start and end of the run read from COOL database
20 from TrigConfStorage.TriggerCoolUtil
import TriggerCoolUtil
21 dbconn = TriggerCoolUtil.GetConnection(
"CONDBR2")
24 f = dbconn.getFolder(
"/TRIGGER/LUMI/LBLB" )
26 since =
RunLumi(runNumber, lbStart)
if lbStart >= 0
else (runNumber<<32)
27 until =
RunLumi(runNumber, lbEnd)
if lbEnd >= 0
else ((runNumber+1)<<32)-1
29 from PyCool
import cool
30 objs = f.browseObjects(since, until, cool.ChannelSelection(0) )
33 timestampDict = OrderedDict()
34 while objs.goToNext():
35 objCurrRef = objs.currentRef()
36 timestampDict[lbCounter] = {
"start":
int(objCurrRef.payload()[
"StartTime"]/1000),
"end":
int(objCurrRef.payload()[
"EndTime"]/1000)}
39 startTime = timestampDict[lbStart][
"start"]
40 endTime = timestampDict[lbEnd][
"end"]
42 from time
import ctime
43 log.info(
"Read start and end of run {0} from COOL: {1} - {2}".
format(runNumber, ctime(startTime/1E6).
replace(
' ',
'_'), ctime(endTime/1E6).
replace(
' ',
'_')))
44 log.debug(
"Timestamps: {0} - {1} ".
format(startTime, endTime))
53 pbeast = libpbeastpy.ServerProxy(server)
54 deadTimeData = pbeast.get_data(
55 'ATLAS',
'CtpBusyInfo',
'ctpcore_objects/CtpcoreBusyInfoObject/fraction',
56 'L1CT.CTP.Instantaneous.BusyFractions/ctpcore_objects\\[9\\]',
57 True, startOfRun, endOfRun)[0].data[
'L1CT.CTP.Instantaneous.BusyFractions/ctpcore_objects[9]']
60 for entry
in deadTimeData:
61 totalDeadtime += entry.value
63 avgDeadtime = totalDeadtime/len(deadTimeData)
65 log.debug(
"Average deadtime per event during this EB run was {0}".
format(avgDeadtime))
69 log.error(
"The pbeast python library was not found! Remember to setup tdaq release")
72 log.error(
"Error when reading from Pbeast! Remember to export pbeast server sso: export PBEAST_SERVER_SSO_SETUP_TYPE=AutoUpdateKerberos")
77 def getPhysicsDeadtimePerLB(startOfRun, endOfRun, lbRangesDict, itemName="L1_TAU8--enabled", server="https://atlasop.cern.ch
"):
80 pbeast = libpbeastpy.ServerProxy(server)
81 physicsDT = pbeast.get_data(
'ATLAS',
'L1_Rate',
'DT',
'ISS_TRP.' + itemName,
False, startOfRun, endOfRun, 0,
True)[0].data[
'ISS_TRP.' + itemName]
85 for lbRange
in lbRangesDict:
88 while physicsDT[entryCounter].ts > lbRangesDict[lbRange][
"start"]
and physicsDT[entryCounter].ts < lbRangesDict[lbRange][
"end"]:
89 if type(physicsDT[entryCounter].value)
is not float:
92 avgDt += physicsDT[entryCounter].value
96 deadtimePerLb[lbRange] = avgDt/counter
if counter > 0
else 1.
101 log.error(
"The pbeast python library was not found! Remember to setup tdaq release")
104 log.error(
"Error when reading from Pbeast! Remember to export pbeast server sso: export PBEAST_SERVER_SSO_SETUP_TYPE=AutoUpdateKerberos")
111 lumiValNode = xmlRoot.createElement(
'lumivalues')
113 deadtimeNode = xmlRoot.createElement(
'deadtime')
114 deadtimeNode.appendChild(xmlRoot.createTextNode(
str(
round(totalDeadtime, 3))))
116 lumiValNode.appendChild(deadtimeNode)
123 filters = xmlRoot.createElement(
'filters')
124 for chain
in chainsDict:
125 f = xmlRoot.createElement(
'filter')
126 fname = xmlRoot.createElement(
'filter_name')
127 fname.appendChild(xmlRoot.createTextNode(chain))
130 for item
in chainsDict[chain]:
131 itemNode = xmlRoot.createElement(
'lv1_filter')
132 itemNode.appendChild(xmlRoot.createTextNode(item))
133 f.appendChild(itemNode)
135 filters.appendChild(f)
141 from PyCool
import cool
142 from TrigConfStorage.TriggerCoolUtil
import TriggerCoolUtil
143 db = TriggerCoolUtil.GetConnection(
'CONDBR2')
144 folder = db.getFolder(
"/TRIGGER/LUMI/OnlPrefLumi")
145 folderIterator = folder.browseObjects(
RunLumi(runNumber, lbStart),
RunLumi(runNumber, lbEnd), cool.ChannelSelection())
148 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_NeventsAll
149 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn
150 cursor = coolDbConn.GetSFODBConnection().
cursor()
151 nEventsPerLB = dict(
GetSFO_NeventsAll(cursor, [runNumber])[runNumber][
'physics_EnhancedBias'])
153 lbNodeList = xmlRoot.createElement(
'lb_list')
156 while folderIterator.goToNext():
157 payload=folderIterator.currentRef().
payload()
158 nEvents = nEventsPerLB[i]
if i
in nEventsPerLB
else 0
159 lbNode =
createLbNode(xmlRoot, i, payload[
"LBAvInstLumi"], payload[
"LBAvEvtsPerBX"], nEvents, deadTimeData[i])
160 lbNodeList.appendChild(lbNode)
161 log.debug(
"Lumiblock {0} lumi {1} pileup {2} events {3}".
format(i, payload[
"LBAvInstLumi"], payload[
"LBAvEvtsPerBX"], nEvents))
170 l = xmlRoot.createElement(
'lb')
171 l.setAttribute(
'id',
str(lbId))
172 l.setAttribute(
'lumi',
str(
round(lumi, 3
if lumi > 1
else 6)))
173 l.setAttribute(
'mu',
str(
round(mu, 3
if mu > 1
else 6)))
174 l.setAttribute(
'deadtime',
str(
round(avgDeadtime, 3)))
175 l.appendChild(xmlRoot.createTextNode(
str(nEvents)))
182 from TrigConfIO.L1TriggerConfigAccess
import BunchGroupSetAccess
183 bgset = BunchGroupSetAccess(dbalias = db, bgskey = key)
185 bgNodeList = xmlRoot.createElement(
'bunchgroups')
186 for bunchgroup
in bgset[
"bunchGroups"]:
188 for entry
in bgset[
"bunchGroups"][bunchgroup][
"bcids"]:
189 bgLength += entry[
"length"]
191 bgNode =
createBgNode(xmlRoot, bgset[
"bunchGroups"][bunchgroup][
"id"], bgset[
"bunchGroups"][bunchgroup][
"name"], bgLength)
192 bgNodeList.appendChild(bgNode)
194 log.debug(
"Bunchgroup {0} length: {1}".
format(bgset[
"bunchGroups"][bunchgroup][
"name"], bgLength))
201 bgNode = xmlRoot.createElement(
'bunchgroup')
202 bgNode.setAttribute(
'id',
str(bgId))
203 bgNode.setAttribute(
'name', name)
204 bgNode.appendChild(xmlRoot.createTextNode(
str(length)))
209 if __name__==
'__main__':
210 from argparse
import ArgumentParser
211 parser = ArgumentParser()
212 parser.add_argument(
'--loglevel', type=int, default=3, help=
'Verbosity level: 1 - VERBOSE, 2 - DEBUG, 3 - INFO')
213 parser.add_argument(
'--physicsDeadtimeItem', type=str, default=
"L1_eEM26M--enabled", help=
'Physics Deadtime Item')
214 parser.add_argument(
'-s',
'--server', default=
'https://atlasop.cern.ch', help=
"Pbeast server url. For GPN: https://atlasop.cern.ch, for P1: http://pc-tdq-bst-05.cern.ch:8080")
215 parser.add_argument(
'flags', nargs=
'*', help=
'Config flag overrides')
216 args = parser.parse_args()
218 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
220 flags.fillFromArgs(args.flags)
222 log.setLevel(args.loglevel)
224 runNumber = flags.Input.RunNumbers[0]
226 for inputFile
in flags.Input.Files:
227 log.debug(
"Processing file {0}".
format(inputFile))
228 bsfile = eformat.istream(inputFile)
231 lumiblocks.add(event.lumi_block())
234 from TrigConfigSvc.TrigConfigSvcCfg
import getTrigConfFromCool
238 root = minidom.Document()
239 xml = root.createElement(
'trigger')
242 log.info(
"Retrieving timestamps of lumiblocks {0} to {1}".
format(
min(lumiblocks),
max(lumiblocks)))
245 (startOfRun, endOfRun) = (lbRanges[
min(lumiblocks)][
"start"], lbRanges[
max(lumiblocks)][
"end"])
247 xml.appendChild(lumiValNode)
251 xml.appendChild(bgNode)
256 xml.appendChild(lumiNode)
259 filename =
"enhanced_bias_run_" +
str(runNumber) +
".xml"
260 root.appendChild(xml)
261 xml_str = root.toprettyxml(indent =
" ")
262 with open(filename,
"w")
as f: