4 from __future__
import print_function
5 from past.builtins
import long
7 """ Simple module for interaction with the luminosity metadata in a file. """
13 """ Python (run,block)/(run,event) type object based on the LumiBlockRange_p1 persistency format.
15 LumiBlockRanges are stored as encoded run and (luminosity) block
16 numbers. Since the conventional run-based accessors for IOVTime
17 are run() and event(), event() is provided *as a synonym* for block.
19 This class is initialized with an IOVTime *as stored* in the
20 persistent object LumiBlockRange_p1 (Note, it does not work on the
23 Warning: although PyRunLumiP1 inherits from long, addition and
24 subtraction are not well defined and should be treated with care!
25 Nevertheless, *incrementing* a PyRunLumiP1 gives a basically intuitive
30 return int(self >> 32)
32 return int(self & 0xFFFFFFFF)
42 def ListFromFile(filename="FewEventsLumi.pool.root", label = "LumiBlockCollection_p1_LumiBlocks", metadatatree="MetaData"):
43 """ Returns a list of RunLumiBlock ranges (stored as python tuples of type PyRunLumiP1) from the named file.
45 The file should have metadata stored internally as a ROOT tree
46 (named 'Stream' by default). It can be a POOL file or other generic
49 Note: This function does not access the MetaDataStore. Please use
50 a LumiBlock AlgTool for that.
54 a = ROOT.TFile.Open(filename)
58 T = a.Get(metadatatree)
59 T.SetBranchStatus(
"*",0)
60 T.SetBranchStatus(label,1)
61 T.SetBranchStatus(
"vector<LumiBlockRange_p1>",1)
62 T.SetBranchStatus(
"vector<LumiBlockRange_p1>.m_start",1)
63 T.SetBranchStatus(
"vector<LumiBlockRange_p1>.m_stop",1)
65 except AttributeError:
66 print(
"There is no tree named", metadatatree,
"in file" ,filename)
67 if a.__repr__() !=
'None':
68 print(8*
'--',
"Contents:", 8*
'--')
77 iterRange = getattr( T, label ).
size()
78 except AttributeError
as a:
80 print(
"The tree", metadatatree,
"in file" ,filename,
"has no vector<LumiBlockRange_p1>.m_start branch, so I don't understand its format.")
82 for i
in range(iterRange):
83 LumiRangeList += [ (
PyRunLumiP1( getattr( T, label )[i].m_start ),
PyRunLumiP1( getattr( T, label )[i].m_stop ))]
84 return [ x
for x
in LumiRangeList ]
88 """ An example function. It prints the list returned by ListFromFile. """
90 for (x,y)
in LumiRangeList:
print(x,
'to', y)
93 if __name__ ==
'__main__':
95 ll1 =
ListFromFile( sys.argv[1],
"LumiBlockCollection_p1_LumiBlocks",
"MetaData" )
96 ll2 =
ListFromFile( sys.argv[1],
"LumiBlockCollection_p1_IncompleteLumiBlocks",
"MetaData" )