|
ATLAS Offline Software
|
◆ AthenaLiteFileInfo()
New lightweight interface to getting a single file's metadata.
Definition at line 23 of file trfFileUtils.py.
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))
◆ HISTEntries()
def python.trfFileUtils.HISTEntries |
( |
|
fileName | ) |
|
Determines number of events in a HIST file.
Basically taken from PyJobTransformsCore.trfutil.MonitorHistFile
- Parameters
-
fileName | Path to the HIST file.
|
- Returns
- Number of events.
None
if the determination failed.
- Note
- Use the PyUtils forking decorator to ensure that ROOT is run completely within a child process and will not 'pollute' the parent python process with unthread-safe bits of code (otherwise strange hangs are observed on subsequent uses of ROOT)
Definition at line 55 of file trfFileUtils.py.
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) )
◆ NTUPEntries()
def python.trfFileUtils.NTUPEntries |
( |
|
fileName, |
|
|
|
treeNames |
|
) |
| |
Determines number of entries in NTUP file with given tree names.
Basically taken from PyJobTransformsCore.trfutil.ntup_entries.
- Parameters
-
fileName | Path to the NTUP file. |
treeNames | Tree name or list of tree names. In the latter case it is checked if all trees contain the same number of events
|
- Returns
- Number of entries.
None
if the determination failed.
- Note
- Use the PyUtils forking decorator to ensure that ROOT is run completely within a child process and will not 'pollute' the parent python process with unthread-safe bits of code (otherwise strange hangs are observed on subsequent uses of ROOT)
Definition at line 153 of file trfFileUtils.py.
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
◆ PHYSVALEntries()
def python.trfFileUtils.PHYSVALEntries |
( |
|
fileName, |
|
|
|
integral = False |
|
) |
| |
Determines number of entries in NTUP_PHYSVAL file.
- Parameters
-
fileName | Path to the PHYSVAL file. |
integral | Returns sum of weights if true |
- Returns
- Number of entries.
- Sum of weights if integral is true.
None
if the determination failed.
- Note
- Use the PyCmt forking decorator to ensure that ROOT is run completely within a child process and will not 'pollute' the parent python process with unthread-safe bits of code (otherwise strange hangs are observed on subsequent uses of ROOT)
Definition at line 249 of file trfFileUtils.py.
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())
◆ PRWEntries()
def python.trfFileUtils.PRWEntries |
( |
|
fileName, |
|
|
|
integral = False |
|
) |
| |
Determines number of entries in PRW file.
- Parameters
-
fileName | Path to the PRW file. |
integral | Returns sum of weights if true |
- Returns
- Number of entries.
- Sum of weights if integral is true.
None
if the determination failed.
- Note
- Use the PyCmt forking decorator to ensure that ROOT is run completely within a child process and will not 'pollute' the parent python process with unthread-safe bits of code (otherwise strange hangs are observed on subsequent uses of ROOT)
Definition at line 206 of file trfFileUtils.py.
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()
◆ ROOTGetSize()
def python.trfFileUtils.ROOTGetSize |
( |
|
filename | ) |
|
Get the size of a file via ROOT's TFile.
Use TFile.Open to retrieve a ROOT filehandle, which will deal with all non-posix filesystems. Return the GetSize() value. The option filetype=raw is added to ensure this works for non-ROOT files too (e.g. BS)
- Note
- Use the PyUtils forking decorator to ensure that ROOT is run completely within a child process and will not 'pollute' the parent python process with unthread-safe bits of code (otherwise strange hangs are observed on subsequent uses of ROOT)
- Parameters
-
filename | Filename to get size of |
- Returns
- fileSize or None if there was a problem
Definition at line 285 of file trfFileUtils.py.
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))
◆ urlType()
def python.trfFileUtils.urlType |
( |
|
filename | ) |
|
Return the LAN access type for a file URL.
- Parameters
-
filename | Name of file to examine |
- Returns
-
Definition at line 316 of file trfFileUtils.py.
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:'):
◆ athFileInterestingKeys
python.trfFileUtils.athFileInterestingKeys |
◆ msg
def PHYSVALEntries(fileName, integral=False)
Determines number of entries in NTUP_PHYSVAL file.
def ROOTGetSize(filename)
Get the size of a file via ROOT's TFile.
TGraphErrors * GetEntries(TH2F *histo)
def import_root(batch=True)
functions --------------------------------------------------------------—
def PRWEntries(fileName, integral=False)
Determines number of entries in PRW file.
def NTUPEntries(fileName, treeNames)
Determines number of entries in NTUP file with given tree names.
def AthenaLiteFileInfo(filename, filetype, retrieveKeys=athFileInterestingKeys)
New lightweight interface to getting a single file's metadata.
def urlType(filename)
Return the LAN access type for a file URL.
def HISTEntries(fileName)
Determines number of events in a HIST file.