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() !=
'':
313 getattr (ROOT, br.GetClassName())
314 val = getattr(tree, br_name)
316 vals = [_getLeaf (l)
for l
in br.GetListOfLeaves()]
323 if not (val
is None):
326 vals = _pythonize(val, py_name,
True, retvecs)
327 except Exception
as err:
328 print (
"**err** for branch [%s] val=%s (type=%s)" % (
329 br_name, val,
type(val),
334 viter =
sorted(vals, key =
lambda x:
'.'.
join(s
for s
in x[0]
if isinstance_(s, str_)))
338 n = list_(map_(str_, o[0]))
340 yield tree_name, ientry, n, v