ATLAS Offline Software
Loading...
Searching...
No Matches
histSizes Namespace Reference

Functions

 filledBins (h)
 hasLabels (h)
 missingLabels (h)
 addDirList (dir, path, hists)
 list (name, path='/')
 byName (hists, nameFunc)
 byAlg (hists)
 main ()

Variables

 opts = None
 code
 msg

Detailed Description

Print number of histograms in ROOT file

Function Documentation

◆ addDirList()

histSizes.addDirList ( dir,
path,
hists )

Definition at line 22 of file histSizes.py.

22def addDirList(dir,path,hists):
23 list=dir.GetListOfKeys()
24 for key in list:
25 name=key.GetName()
26 cname=key.GetClassName()
27 if cname=='TDirectoryFile':
28 addDirList(dir.GetDirectory(name),path+name+'/',hists)
29 else:
30 h = key.ReadObj()
31 if not h.InheritsFrom('TH1'): continue
32 if opts.labeled is True and not hasLabels(h): continue
33 if opts.misslabel is True and not missingLabels(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)
37

◆ byAlg()

histSizes.byAlg ( hists)

Definition at line 60 of file histSizes.py.

60def byAlg(hists):
61 return byName(hists, lambda h : h.split('/',2)[1])
62
63

◆ byName()

histSizes.byName ( hists,
nameFunc )
Return dict {Alg : (nHists,Bins)}

Definition at line 45 of file histSizes.py.

45def byName(hists, nameFunc):
46 """Return dict {Alg : (nHists,Bins)}"""
47 algs = {}
48 for entry in sorted(hists):
49 name = nameFunc(entry)
50 bins = hists[entry][1]
51
52 if name in algs:
53 algs[name][0] += 1
54 algs[name][1] += bins
55 else:
56 algs[name] = [1,bins]
57
58 return algs
59

◆ filledBins()

histSizes.filledBins ( h)

Definition at line 11 of file histSizes.py.

11def filledBins(h):
12 N = h.GetSize()
13 return sum([1 for i in range(N) if h.At(i)!=0])
14

◆ hasLabels()

histSizes.hasLabels ( h)

Definition at line 15 of file histSizes.py.

15def hasLabels(h):
16 return (h.GetXaxis().GetLabels() is not None)
17

◆ list()

histSizes.list ( name,
path = '/' )

Definition at line 38 of file histSizes.py.

38def list(name,path='/'):
39 file=ROOT.TFile(name)
40 file.cd(path)
41 hists={}
42 addDirList(ROOT.gDirectory,path,hists)
43 return hists
44

◆ main()

histSizes.main ( )

Definition at line 64 of file histSizes.py.

64def main():
65 import optparse
66 parser = optparse.OptionParser(description=__doc__,
67 usage='%prog [Options] file [path]')
68
69 parser.add_option('-t', '--total', action='store_true',
70 help='Print total number of histograms and bins')
71
72 parser.add_option('-b', '--bins', action='store_true',
73 help='Sort by number of bins')
74
75 parser.add_option('-n', '--byName', action='store_true',
76 help='Show histograms [default]')
77
78 parser.add_option('-a', '--byAlg', action='store_true',
79 help='Show total histograms per algorithm')
80
81 parser.add_option('-f', '--filled', action='store_true',
82 help='Show number of filled bins instead of total bins')
83
84 parser.add_option('-l', '--labeled', action='store_true',
85 help='Only show histograms with text labels')
86
87 parser.add_option('-m', '--misslabel', action='store_true',
88 help='Only show labeled histograms with at least one unlabeled bin')
89
90 parser.add_option('-e', '--empty', action='store_true',
91 help='Only show histograms with zero entries')
92
93 global opts
94 (opts, args) = parser.parse_args()
95
96 if len(args)==1:
97 path = '/'
98 elif len(args)==2:
99 path = args[1]
100 else:
101 parser.print_help()
102 return 1
103
104 hists = list(args[0],path)
105 if opts.bins: sortKey = lambda x : x[1][1]
106 else: sortKey = None
107
108 if not opts.byAlg: opts.byName = True
109
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]))
113
114 if opts.byAlg is True:
115 algs = byAlg(hists)
116 for h,v in sorted(algs.items(), key=sortKey):
117 print('%-80s %10s %10s' % (h,v[0],v[1]))
118
119 if opts.total:
120 print()
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()])))
123
124
void print(char *figname, TCanvas *c1)
int main()
Definition hello.cxx:18

◆ missingLabels()

histSizes.missingLabels ( h)

Definition at line 18 of file histSizes.py.

18def missingLabels(h):
19 l = h.GetXaxis().GetLabels()
20 return (l is not None and h.GetXaxis().GetNbins()!=l.GetSize())
21

Variable Documentation

◆ code

histSizes.code

Definition at line 129 of file histSizes.py.

◆ msg

histSizes.msg

Definition at line 129 of file histSizes.py.

◆ opts

histSizes.opts = None

Definition at line 9 of file histSizes.py.