2 Print information about objects in a ROOT file. 4 from __future__
import absolute_import
5 from __future__
import print_function
7 from .version
import __version__
9 from ROOT
import Double
11 from .
import argparse
16 saved_argv = sys.argv[:]
17 sys.argv = [sys.argv[0],
'-b']
18 from ROOT
import TFile, TH1, TDirectory, gDirectory
22 '''Recursive function to find all contents in a given ROOT file''' 23 keys = in_tfile.GetDirectory(full_path).GetListOfKeys()
26 classname = key.GetClassName()
27 if 'TDirectory' in classname:
32 if options.name
and name != options.name:
continue 33 full_name =
'/'.
join([full_path,name])
34 obj = in_tfile.Get(full_name)
37 simple_name = full_name[2:]
38 print(
"%s" % simple_name, end=
' ')
39 for arg
in [x[2:]
for x
in sys.argv
if x.startswith(
"--")]:
40 if "classname" == arg:
41 print(
"%s" % classname, end=
' ')
42 if obj.InheritsFrom(
'TH1'):
44 print(
" %i" % obj.GetEntries(), end=
' ')
46 if obj.InheritsFrom(
'TH2'):
49 for j
in reversed(range(obj.GetNbinsY())):
52 [
str(obj.GetBinContent(i+1, j+1))
for i
in range(obj.GetNbinsX())]), end=
' ')
55 [
str(obj.GetBinContent(i+1))
for i
in range(obj.GetNbinsX())]), end=
' ')
57 if obj.InheritsFrom(
'TH2'):
58 for j
in reversed(range(obj.GetNbinsY())):
61 [
str(obj.GetBinError(i+1, j+1))
for i
in range(obj.GetNbinsX())]), end=
' ')
64 [
str(obj.GetBinError(i+1))
for i
in range(obj.GetNbinsX())]), end=
' ')
65 if "bincenter" == arg:
67 [
str(obj.GetBinCenter(i+1))
for i
in range(obj.GetNbinsX())]), end=
' ')
69 print(
" %i" % obj.GetMaximum(), end=
' ')
71 print(
" %i" % obj.GetMinimum(), end=
' ')
73 print(
" %i" % obj.GetBinContent(obj.GetNbinsX()), end=
' ')
74 if "underflow" == arg:
75 print(
" %i" % obj.GetBinContent(0), end=
' ')
76 if obj.InheritsFrom(
'TGraph'):
78 x, y = Double(0), Double(0)
81 for i
in range(obj.GetN()):
83 xvals.append(copy.copy(x))
84 yvals.append(copy.copy(y))
85 for point
in zip(xvals,yvals):
86 print(
" (%d, %d)" % point, end=
' ')
90 parser = argparse.ArgumentParser(description=
'Print information from an SC2 replay file.')
91 parser.add_argument(
'filenames', metavar=
'filename', type=str, nargs=
'+',
92 help=
"Names of one or more root files")
93 parser.add_argument(
'--bincenter', action=
"store_true", default=
False,
94 help=
"Get Bin Centers from each bin in each histogram")
95 parser.add_argument(
'--classname', action=
"store_true", default=
False,
96 help=
"Get type from each object in root file")
97 parser.add_argument(
'--contents', action=
"store_true", default=
False,
98 help=
"Get Bin Contents from each bin in each histogram")
99 parser.add_argument(
'--errors', action=
"store_true", default=
False,
100 help=
"Get Bin Errors from each bin in each histogram")
101 parser.add_argument(
'--entries', action=
"store_true", default=
False,
102 help=
"Get Entries from each histogram")
103 parser.add_argument(
'--max', action=
"store_true", default=
False,
104 help=
"Get Maximum value from each histogram")
105 parser.add_argument(
'--min', action=
"store_true", default=
False,
106 help=
"Get Minimum value from each histogram")
107 parser.add_argument(
'--name', default=
None,
108 help=
"Get information only from object with matching name")
109 parser.add_argument(
'--overflow', action=
"store_true", default=
False,
110 help=
"Get value of overflow bin from each histogram")
111 parser.add_argument(
'--underflow', action=
"store_true", default=
False,
112 help=
"Get value of underflow bin from each histogram")
113 arguments = parser.parse_args()
114 for arg
in arguments.filenames:
115 if arg[-5:] !=
".root":
116 raise TypeError(
"Arguments must include root file names")
117 filenames_from_interface = [x
for x
in arguments.filenames
if x[-5:] ==
".root"]
118 if len(filenames_from_interface) == 0:
121 for filename
in filenames_from_interface:
122 if not os.path.exists(filename):
123 print(
"%s does not exist." % filename)
125 tfile = TFile(filename,
"read")
132 if __name__ ==
'__main__':
def recurse_thru_file(in_tfile, options, full_path='/')
S & print(S &os, JobReport::InputFile const &f)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
static std::string join(char **cmd)