4 from past.builtins
import long
6 """ Simple module for interaction with the luminosity metadata in a file. """
12 """ Python (run,block)/(run,event) type object based on the LumiBlockRange_p1 persistency format.
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.
18 This class is initialized with an IOVTime *as stored* in the
19 persistent object LumiBlockRange_p1 (Note, it does not work on the
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
29 return int(self >> 32)
31 return int(self & 0xFFFFFFFF)
41 def 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.
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
48 Note: This function does not access the MetaDataStore. Please use
49 a LumiBlock AlgTool for that.
53 a = ROOT.TFile.Open(filename)
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)
64 except AttributeError:
65 print(
"There is no tree named", metadatatree,
"in file" ,filename)
66 if a.__repr__() !=
'None':
67 print(8*
'--',
"Contents:", 8*
'--')
76 iterRange = getattr( T, label ).
size()
77 except AttributeError
as a:
79 print(
"The tree", metadatatree,
"in file" ,filename,
"has no vector<LumiBlockRange_p1>.m_start branch, so I don't understand its format.")
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 ]
87 """ An example function. It prints the list returned by ListFromFile. """
89 for (x,y)
in LumiRangeList:
print(x,
'to', y)
92 if __name__ ==
'__main__':
94 ll1 =
ListFromFile( sys.argv[1],
"LumiBlockCollection_p1_LumiBlocks",
"MetaData" )
95 ll2 =
ListFromFile( sys.argv[1],
"LumiBlockCollection_p1_IncompleteLumiBlocks",
"MetaData" )