ATLAS Offline Software
Loading...
Searching...
No Matches
LumiQuery.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3# module LumiQuery
4from past.builtins import long
5
6""" Simple module for interaction with the luminosity metadata in a file. """
7
8global LumiRangeList
9LumiRangeList = []
10
11class PyRunLumiP1(long):
12 """ Python (run,block)/(run,event) type object based on the LumiBlockRange_p1 persistency format.
13
14 LumiBlockRanges are stored as encoded run and (luminosity) block
15 numbers. Since the conventional run-based accessors for IOVTime
16 are run() and event(), event() is provided *as a synonym* for block.
17
18 This class is initialized with an IOVTime *as stored* in the
19 persistent object LumiBlockRange_p1 (Note, it does not work on the
20 transient object!)
21
22 Warning: although PyRunLumiP1 inherits from long, addition and
23 subtraction are not well defined and should be treated with care!
24 Nevertheless, *incrementing* a PyRunLumiP1 gives a basically intuitive
25 result.)
26
27 """
28 def run(self):
29 return int(self >> 32)
30 def block(self):
31 return int(self & 0xFFFFFFFF)
32 def event(self):
33 return self.block()
34 def __str__(self):
35 return 'R='+ str(self.run()) + '; LB=' + str(self.event())
36 def __repr__(self):
37 return self.__hex__().__repr__() + '->(' + repr(self.run()) + ':' + repr(self.event()) + ')'
38
39
40
41def ListFromFile(filename="FewEventsLumi.pool.root", label = "LumiBlockCollection_p1_LumiBlocks", metadatatree="MetaData"):
42 """ Returns a list of RunLumiBlock ranges (stored as python tuples of type PyRunLumiP1) from the named file.
43
44 The file should have metadata stored internally as a ROOT tree
45 (named 'Stream' by default). It can be a POOL file or other generic
46 ntuple file.
47
48 Note: This function does not access the MetaDataStore. Please use
49 a LumiBlock AlgTool for that.
50 """
51
52 import ROOT
53 a = ROOT.TFile.Open(filename)
54 global LumiRangeList
55 LumiRangeList = []
56 try:
57 T = a.Get(metadatatree)
58 T.SetBranchStatus("*",0)
59 T.SetBranchStatus(label,1)
60 T.SetBranchStatus("vector<LumiBlockRange_p1>",1)
61 T.SetBranchStatus("vector<LumiBlockRange_p1>.m_start",1)
62 T.SetBranchStatus("vector<LumiBlockRange_p1>.m_stop",1)
63 T.GetEntry(0)
64 except AttributeError:
65 print("There is no tree named", metadatatree, "in file" ,filename)
66 if a.__repr__() != 'None':
67 print(8*'--', "Contents:", 8*'--')
68 a.ls()
69 return
70
71
75 try:
76 iterRange = getattr( T, label ).size() #T.GetLeaf("vector<LumiBlockRange_p1>.m_start").GetLen()
77 except AttributeError as a:
78 print(a)
79 print("The tree", metadatatree, "in file" ,filename, "has no vector<LumiBlockRange_p1>.m_start branch, so I don't understand its format.")
80 return
81 for i in range(iterRange):
82 LumiRangeList += [ (PyRunLumiP1( getattr( T, label )[i].m_start ),PyRunLumiP1( getattr( T, label )[i].m_stop ))]
83 return [ x for x in LumiRangeList ]
84
85
87 """ An example function. It prints the list returned by ListFromFile. """
88 for (x,y) in LumiRangeList: print(x, 'to', y)
89
90
91if __name__ == '__main__':
92 import sys
93 ll1 = ListFromFile( sys.argv[1], "LumiBlockCollection_p1_LumiBlocks", "MetaData" )
94 ll2 = ListFromFile( sys.argv[1], "LumiBlockCollection_p1_IncompleteLumiBlocks", "MetaData" )
void print(char *figname, TCanvas *c1)
ListFromFile(filename="FewEventsLumi.pool.root", label="LumiBlockCollection_p1_LumiBlocks", metadatatree="MetaData")
Definition LumiQuery.py:41
Definition run.py:1