|
def | __init__ (self, fname, tree_name="CollectionTree") |
|
def | dump (self, tree_name, itr_entries, leaves=None, retvecs=False, sortleaves=True) |
|
A helper class to dump in more or less human readable form the content of
any TTree.
Definition at line 198 of file RootUtils.py.
◆ __init__()
def python.RootUtils.RootFileDumper.__init__ |
( |
|
self, |
|
|
|
fname, |
|
|
|
tree_name = "CollectionTree" |
|
) |
| |
Definition at line 204 of file RootUtils.py.
204 def __init__(self, fname, tree_name="CollectionTree"):
205 object.__init__(self)
212 self.root_file = ROOT.TFile.Open(fname)
213 if (self.root_file
is None or
214 not isinstance(self.root_file, ROOT.TFile)
or
215 not self.root_file.IsOpen()):
216 raise IOError(
'could not open [%s]'% fname)
218 self.tree = self.root_file.
Get(tree_name)
219 if self.tree
is None or not isinstance(self.tree, ROOT.TTree):
220 raise AttributeError(
'no tree [%s] in file [%s]', tree_name, fname)
224 keys = [k.GetName()
for k
in self.root_file.GetListOfKeys()]
226 o = self.root_file.
Get(k)
227 if isinstance(o, ROOT.TTree):
◆ dump()
def python.RootUtils.RootFileDumper.dump |
( |
|
self, |
|
|
|
tree_name, |
|
|
|
itr_entries, |
|
|
|
leaves = None , |
|
|
|
retvecs = False , |
|
|
|
sortleaves = True |
|
) |
| |
Definition at line 233 of file RootUtils.py.
233 def dump(self, tree_name, itr_entries, leaves=None, retvecs=False, sortleaves=True):
236 import AthenaPython.PyAthena
as PyAthena
237 _pythonize = PyAthena.RootUtils.PyROOTInspector.pyroot_inspect2
239 self.tree = self.root_file.
Get(tree_name)
240 if self.tree
is None or not isinstance(self.tree, ROOT.TTree):
241 raise AttributeError(
'no tree [%s] in file [%s]', tree_name, self.root_file.GetName())
244 nentries = tree.GetEntries()
245 branches =
sorted([b.GetName().rstrip(
'\0')
for b
in tree.GetListOfBranches()])
246 if leaves
is None: leaves = branches
247 else: leaves = [
str(b).rstrip(
'\0')
for b
in leaves]
250 if isinstance(itr_entries, str):
251 if ':' in itr_entries:
259 from itertools
import islice
260 itr_entries = islice(
range(nentries),
261 *map(toint, itr_entries.split(
':')))
262 elif (
'range' in itr_entries
or
264 itr_entries = eval(itr_entries)
267 _n =
int(itr_entries)
268 itr_entries =
range(_n)
270 print (
"** err ** invalid 'itr_entries' argument. will iterate over all entries.")
271 itr_entries =
range(nentries)
272 elif isinstance(itr_entries, list):
273 itr_entries = itr_entries
275 itr_entries =
range(itr_entries)
280 isinstance_ = isinstance
282 for ientry
in itr_entries:
283 hdr =
":: entry [%05i]..." % (ientry,)
286 err = tree.LoadTree(ientry)
288 print (
"**err** loading tree for entry",ientry)
292 nbytes = tree.GetEntry(ientry)
294 print (
"**err** reading entry [%s] of tree [%s]" % (ientry, tree_name))
295 hdr =
":: entry [%05i]... [ERR]" % (ientry,)
300 for br_name
in leaves:
301 hdr =
":: branch [%s]..." % (br_name,)
306 br = tree.GetBranch (br_name)
307 if br.GetClassName() !=
'':
308 val = getattr(tree, br_name)
310 vals = [_getLeaf (l)
for l
in br.GetListOfLeaves()]
317 if not (val
is None):
320 vals = _pythonize(val, py_name,
True, retvecs)
321 except Exception
as err:
322 print (
"**err** for branch [%s] val=%s (type=%s)" % (
323 br_name, val,
type(val),
328 viter =
sorted(vals, key =
lambda x:
'.'.
join(s
for s
in x[0]
if isinstance_(s, str_)))
332 n = list_(map_(str_, o[0]))
334 yield tree_name, ientry, n, v
◆ _trees
python.RootUtils.RootFileDumper._trees |
|
private |
◆ allgood
python.RootUtils.RootFileDumper.allgood |
◆ root_file
python.RootUtils.RootFileDumper.root_file |
◆ tree
python.RootUtils.RootFileDumper.tree |
The documentation for this class was generated from the following file:
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...