4 """Print number of histograms in ROOT file"""
13 return sum([1
for i
in range(N)
if h.At(i)!=0])
16 return (h.GetXaxis().GetLabels()
is not None)
19 l = h.GetXaxis().GetLabels()
20 return (l
is not None and h.GetXaxis().GetNbins()!=l.GetSize())
23 list=dir.GetListOfKeys()
26 cname=key.GetClassName()
27 if cname==
'TDirectoryFile':
28 addDirList(dir.GetDirectory(name),path+name+
'/',hists)
31 if not h.InheritsFrom(
'TH1'):
continue
32 if opts.labeled
is True and not hasLabels(h):
continue
34 if opts.empty
is True and h.GetEntries()>0:
continue
35 b =
filledBins(h)
if opts.filled
else h.GetSize()
36 hists[path+name]=(cname,b)
46 """Return dict {Alg : (nHists,Bins)}"""
48 for entry
in sorted(hists):
49 name = nameFunc(entry)
50 bins = hists[entry][1]
61 return byName(hists,
lambda h : h.split(
'/',2)[1])
66 parser = optparse.OptionParser(description=__doc__,
67 usage=
'%prog [Options] file [path]')
69 parser.add_option(
'-t',
'--total', action=
'store_true',
70 help=
'Print total number of histograms and bins')
72 parser.add_option(
'-b',
'--bins', action=
'store_true',
73 help=
'Sort by number of bins')
75 parser.add_option(
'-n',
'--byName', action=
'store_true',
76 help=
'Show histograms [default]')
78 parser.add_option(
'-a',
'--byAlg', action=
'store_true',
79 help=
'Show total histograms per algorithm')
81 parser.add_option(
'-f',
'--filled', action=
'store_true',
82 help=
'Show number of filled bins instead of total bins')
84 parser.add_option(
'-l',
'--labeled', action=
'store_true',
85 help=
'Only show histograms with text labels')
87 parser.add_option(
'-m',
'--misslabel', action=
'store_true',
88 help=
'Only show labeled histograms with at least one unlabeled bin')
90 parser.add_option(
'-e',
'--empty', action=
'store_true',
91 help=
'Only show histograms with zero entries')
94 (opts, args) = parser.parse_args()
104 hists =
list(args[0],path)
105 if opts.bins: sortKey =
lambda x : x[1][1]
108 if not opts.byAlg: opts.byName =
True
110 if opts.byName
is True:
111 for h,v
in sorted(hists.items(), key=sortKey):
112 print(
'%-80s %10s %10s' % (h,v[0],v[1]))
114 if opts.byAlg
is True:
116 for h,v
in sorted(algs.items(), key=sortKey):
117 print(
'%-80s %10s %10s' % (h,v[0],v[1]))
121 print(
"Total histograms: %15s" % len(hists))
122 print(
"Total %sbins: %15s" % (
"filled " if opts.filled
else "",
sum([h[1]
for h
in hists.values()])))
125 if __name__ ==
'__main__':
132 except KeyboardInterrupt: