10 msg = logging.getLogger(__name__)
15 import PyUtils.Decorators
as _decos
17 from PyUtils.RootUtils
import import_root
20 athFileInterestingKeys = [
'file_size',
'file_guid',
'file_type',
'nentries']
24 msg.debug(
'Calling AthenaLiteFileInfo for {0} (type {1})'.
format(filename, filetype))
25 from PyUtils.MetaReader
import read_metadata
30 msg.debug(
'read_metadata came back for {0}'.
format(filename))
31 metaDict[filename] = {}
32 for key
in retrieveKeys:
33 msg.debug(
'Looking for key {0}'.
format(key))
36 metaDict[filename][key] = metaval.lower()
if key ==
'file_type' else metaval
38 msg.warning(
'Missing key in athFile info: {0}'.
format(key))
39 except (ValueError, AssertionError, ReferenceError):
40 msg.error(
'Problem in getting metadata for {0}'.
format(filename))
42 msg.debug(
'Returning {0}'.
format(metaDict))
59 fname = root.TFile.Open(fileName,
'READ')
61 if not (isinstance(fname, root.TFile)
and fname.IsOpen()):
65 keys = fname.GetListOfKeys()
71 if name.startswith(
'run_')
and name !=
'run_multiple':
73 if rundir
is not None:
74 msg.warning(
'Found two run_ directories in HIST file %s: %s and %s', fileName, rundir, name)
82 msg.warning(
'Unable to find run directory in HIST file %s', fileName )
86 msg.info(
'Using run directory %s for event counting of HIST file %s. ', rundir, fileName )
88 hpath =
'%s/GLOBAL/DQTDataFlow/events_lb' % rundir
90 if 'tmp.HIST_' in fileName:
91 msg.info(
'Special case for temporary HIST file {0}. '.
format( fileName ) )
92 h = fname.Get(
'{0}'.
format(rundir))
93 for directories
in h.GetListOfKeys() :
94 if 'lb' in directories.GetName():
95 msg.info(
'Using {0} in tmp HIST file {1}. '.
format(directories.GetName(), fileName ) )
96 hpath = rundir+
'/'+
str(directories.GetName())+
'/GLOBAL/DQTDataFlow/events_lb'
97 possibleLBs.append(hpath)
99 msg.info(
'Classical case for HIST file {0}. '.
format( fileName ) )
100 possibleLBs.append(hpath)
102 if len(possibleLBs) == 0:
103 msg.warning(
'Unable to find events_lb histogram in HIST file %s', fileName )
106 for hpath
in possibleLBs:
109 if not isinstance( h, root.TH1 ):
110 msg.warning(
'Unable to retrieve %s in HIST file %s.', hpath, fileName )
114 nBinsX = h.GetNbinsX()
117 for i
in range(1, nBinsX):
120 msg.warning(
'Negative number of events for step %s in HIST file %s.', h.GetXaxis().GetBinLabel(i), fileName )
132 msg.warning(
'Mismatch in events per step in HIST file %s; most recent step seen is %s.', fileName, h.GetXaxis().GetBinLabel(i) )
155 if not isinstance( treeNames, list ):
156 treeNames=[treeNames]
160 fname = root.TFile.Open(fileName,
'READ')
162 if not (isinstance(fname, root.TFile)
and fname.IsOpen()):
168 for treeName
in treeNames:
170 tree = fname.Get(treeName)
172 if not isinstance(tree, root.TTree):
175 num = tree.GetEntriesFast()
178 msg.warning(
'GetEntriesFast returned non positive value for tree %s in NTUP file %s.', treeName, fileName )
181 if prevNum
is not None and prevNum != num:
182 msg.warning(
"Found diffferent number of entries in tree %s and tree %s of file %s.", treeName, prevTree, fileName )
192 return numberOfEntries
210 fname = root.TFile.Open(fileName,
'READ')
212 if not (isinstance(fname, root.TFile)
and fname.IsOpen()):
217 for key
in fname.GetListOfKeys():
218 if key.GetName()==
'PileupReweighting':
219 rundir = fname.Get(
'PileupReweighting')
223 if rundir
is None:
return None
226 for key
in rundir.GetListOfKeys():
227 if 'pileup' in key.GetName():
228 msg.debug(
'Working on file '+fileName+
' histo '+key.GetName())
230 total += rundir.Get(key.GetName()).Integral()
232 total += rundir.Get(key.GetName()).
GetEntries()
253 fname = root.TFile.Open(fileName,
'READ')
255 if not (isinstance(fname, root.TFile)
and fname.IsOpen()):
258 aipc = fname.Get(
"/EventInfo/EventInfo_actualInteractionsPerCrossing")
269 return aipc.Integral()
272 return int(aipc.GetEntries())
289 msg.debug(
'Calling TFile.Open for {0}'.
format(filename))
290 extraparam =
'?filetype=raw'
291 if filename.startswith(
"https")
or filename.startswith(
"davs"):
293 pos = filename.find(
"?")
295 extraparam =
'&filetype=raw'
297 extraparam =
'?filetype=raw'
299 extraparam =
'?filetype=raw'
300 fname = root.TFile.Open(filename + extraparam,
'READ')
301 fsize = fname.GetSize()
302 msg.debug(
'Got size {0} from TFile.GetSize'.
format(fsize))
303 except ReferenceError:
304 msg.error(
'Failed to get size of {0}'.
format(filename))
317 if filename.startswith(
'dcap:'):
319 if filename.startswith(
'root:'):
321 if filename.startswith(
'rfio:'):
323 if filename.startswith(
'file:'):
325 if filename.startswith(
'https:'):
327 if filename.startswith(
'davs:'):