ATLAS Offline Software
Database
CoolLumiUtilities
python
LumiGRLParser.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
#
4
# LumiGRLParser.py
5
#
6
# Utility to parse GRL XML file and provide access to useful information in python
7
#
8
import
xml.etree.ElementTree
as
ET
9
10
class
LumiGRLParser
:
11
12
def
__init__
(self, grlfile=None):
13
14
# Holds the element tree for the parsed XML file
15
self.
tree
=
None
16
17
# Name of NamedLumiRange to consider (None works if only one NamedLumiRange is present)
18
self.
lumiRangeName
=
None
19
self.
lumiRange
=
None
20
21
# List of (integer) run numbers
22
self.
runList
= []
23
24
# List of COOL IOV ranges (start, end)
25
# run << 32 & LB
26
self.
iovList
= []
27
28
# Dictionary keyed by runnum containing a list of IOV ranges
29
self.
iovDict
= dict()
30
31
if
grlfile
is
not
None
:
32
self.
parseFile
(grlfile)
33
34
35
def
parseFile
(self, filename):
36
37
self.
tree
= ET.parse(filename)
38
39
self.
runList
= []
40
self.
iovList
= []
41
self.
iovDict
= dict()
42
43
# Return list of runs in GRL
44
if
not
self.
selectRange
():
45
print
(
'LumiGRLParser.parseFile(%s) - Error selecting valid range!'
% filename)
46
return
47
48
# Now, go through this range and find run numbers
49
for
lbc
in
self.
lumiRange
.findall(
'LumiBlockCollection'
):
50
runnum =
int
(lbc.findtext(
'Run'
,
'-1'
))
51
if
runnum < 0:
52
print
(
"LumiGRLParser.parseFile(%s) - Couldn't find Run in valid LumiBlockCollection!"
% filename)
53
continue
54
55
self.
runList
.
append
(runnum)
56
self.
iovDict
[runnum] = []
57
58
for
lbr
in
lbc.findall(
'LBRange'
):
59
lbstart =
int
(lbr.get(
'Start'
,
'-1'
))
60
lbend =
int
(lbr.get(
'End'
,
'-1'
))
61
62
if
lbstart < 0
or
lbend < 0:
63
print
(
"LumiGRLParser.parseFile(%s) - Couldn't find LBRange attributes for run %d!"
% (filename, runnum))
64
continue
65
66
# Must add one to make IOVRange exclusive at end
67
lbend += 1
68
self.
iovDict
[runnum].
append
((lbstart, lbend))
69
70
iovstart = (runnum<<32)+lbstart
71
iovend = (runnum<<32)+lbend
72
self.
iovList
.
append
((iovstart, iovend))
73
74
# Finally sort these
75
self.
runList
.sort()
76
self.
iovList
.sort()
77
78
def
selectRange
(self):
79
80
self.
lumiRange
=
None
81
82
if
self.
tree
is
None
:
83
print
(
'LumiGRLParser.selectRange() - no tree found!'
)
84
return
False
85
86
lumiRangeList = self.
tree
.findall(
'NamedLumiRange'
)
87
if
len(lumiRangeList) == 1:
88
89
if
self.
lumiRangeName
is
not
None
:
90
name = lumiRangeList[0].findtext(
'Name'
,
''
)
91
92
if
name != self.
lumiRangeName
:
93
print
(
"LumiGRLParser.selectRange() - Can't find %s in GRL, only %s!"
% (self.
lumiRangeName
, name))
94
return
False
95
96
self.
lumiRange
= lumiRangeList[0]
97
return
True
98
99
elif
len(lumiRangeList) == 0:
100
101
print
(
'LumiGRLParser.selectRange() - No NamedLumiRange object found!'
)
102
return
False
103
104
# More than one range found
105
if
self.
lumiRangeName
is
None
:
106
print
(
'LumiGRLParser.selectRange() - %d NamedLumiRange objects found, but no lumiRangeName specified!'
% len(lumiRangeList))
107
return
False
108
109
110
# More than one, match by name
111
found =
False
112
for
lbr
in
lumiRangeList:
113
name = lbr.findtext(
'Name'
,
''
)
114
115
if
self.
lumiRangeName
== name:
116
found =
True
117
self.
lumiRange
= lbr
118
break
119
120
if
not
found:
121
print
(
"LumiGRLParser.selectRange() - Couldn't find %s in available NamedLumiRange objects!"
% self.
lumiRangeName
)
122
return
False
123
124
return
True
125
126
# Return sorted list of lumi blocks present in specified run
127
def
lumiBlockList
(self, runnum):
128
129
lbList = []
130
for
iov
in
self.
iovDict
.
get
(runnum, []):
131
lbList.extend(
range
(iov[0], iov[1]))
132
133
return
lbList
134
python.LumiGRLParser.LumiGRLParser.parseFile
def parseFile(self, filename)
Definition:
LumiGRLParser.py:35
dumpHVPathFromNtuple.append
bool append
Definition:
dumpHVPathFromNtuple.py:91
python.LumiGRLParser.LumiGRLParser.lumiRangeName
lumiRangeName
Definition:
LumiGRLParser.py:18
python.LumiGRLParser.LumiGRLParser.lumiBlockList
def lumiBlockList(self, runnum)
Definition:
LumiGRLParser.py:127
python.LumiGRLParser.LumiGRLParser
Definition:
LumiGRLParser.py:10
python.LumiGRLParser.LumiGRLParser.tree
tree
Definition:
LumiGRLParser.py:15
python.LumiGRLParser.LumiGRLParser.__init__
def __init__(self, grlfile=None)
Definition:
LumiGRLParser.py:12
plotBeamSpotVxVal.range
range
Definition:
plotBeamSpotVxVal.py:194
print
void print(char *figname, TCanvas *c1)
Definition:
TRTCalib_StrawStatusPlots.cxx:26
python.CaloAddPedShiftConfig.int
int
Definition:
CaloAddPedShiftConfig.py:45
python.LumiGRLParser.LumiGRLParser.selectRange
def selectRange(self)
Definition:
LumiGRLParser.py:78
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition:
hcg.cxx:127
python.LumiGRLParser.LumiGRLParser.lumiRange
lumiRange
Definition:
LumiGRLParser.py:19
python.LumiGRLParser.LumiGRLParser.iovList
iovList
Definition:
LumiGRLParser.py:26
python.LumiGRLParser.LumiGRLParser.iovDict
iovDict
Definition:
LumiGRLParser.py:29
python.LumiGRLParser.LumiGRLParser.runList
runList
Definition:
LumiGRLParser.py:22
Generated on Mon Sep 29 2025 21:14:14 for ATLAS Offline Software by
1.8.18