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