8 from __future__
import print_function
10 __doc__ =
"ASCII-fy a ROOT file"
11 __author__ =
"Sebastien Binet"
15 import PyUtils.acmdlib
as acmdlib
17 @acmdlib.command(name=
'dump-root')
18 @acmdlib.argument(
'fname',
19 help=
'path to the ROOT file to dump')
20 @acmdlib.argument(
'-t',
'--tree-name',
22 help=
'name of the TTree to dump (default:all)')
23 @acmdlib.argument(
'--entries',
25 help=
"""a list of entries (indices, not event numbers) or an expression leading to such a list, to compare (default:all).
26 ex: --entries='0:10' to get the first 10 events
27 --entries='10:20:2' to get the even events between 10 and 20
28 --entries='range(10)' to get the first 10 events
29 --entries=10 to get the first 10 events
30 --entries=0,2,1 to get the entry 0, then 2 then 1
32 @acmdlib.argument(
'-v',
'--verbose',
35 help=
"""Enable verbose printout""")
37 """dump the content of a ROOT file into an ASCII format.
40 import PyUtils.RootUtils
as ru
41 root = ru.import_root()
43 _inspect = root.RootUtils.PyROOTInspector.pyroot_inspect2
45 import PyUtils.Logging
as L
46 msg = L.logging.getLogger(
'dump-root')
47 msg.setLevel(L.logging.INFO)
49 msg.info(
'fname: [%s]', args.fname)
50 root_file = root.TFile.Open(args.fname)
51 if (root_file
is None or
52 not isinstance(root_file, root.TFile)
or not root_file.IsOpen()):
53 msg.error(
'could not open [%s]', args.fname)
58 tree_names = args.tree_name.split(
',')
61 keys = [k.GetName()
for k
in root_file.GetListOfKeys()]
64 if isinstance(o, root.TTree):
67 msg.info(
'dumping trees: %s', tree_names)
69 for tree_name
in tree_names:
70 f = ru.RootFileDumper(args.fname, tree_name)
71 nentries = f.tree.GetEntries()
73 nentries = args.entries
74 for d
in f.dump(tree_name, nentries):
75 tree_name, ientry, name, data = d
76 n =
'.'.
join(map(str, [tree_name,
"%03i"%ientry]+name))
77 print (
'%s %r' %(n, data))