29 from __future__
import absolute_import
30 from __future__
import print_function
32 import project_utilities
40 sys.argv = myargv[0:1]
41 if 'TERM' in os.environ:
42 del os.environ[
'TERM']
44 ROOT.gErrorIgnoreLevel = ROOT.kError
51 filename = sys.argv[0]
56 for line
in file.readlines():
57 if line[2:9] ==
'stat.py':
59 elif line[0:6] ==
'######' and doprint:
63 print(line[2:], end=
' ')
69 def analyze(root, level, gtrees, gbranches, doprint):
73 keys = root.GetListOfKeys()
75 objname = key.GetName()
76 if objname
not in trees:
77 obj = root.Get(objname)
78 if obj
and obj.InheritsFrom(
'TTree'):
80 if objname ==
'Events':
87 for key
in sorted(trees.keys()):
89 nentry = tree.GetEntriesFast()
91 print(
'%s has %d entries.' % (key, nentry))
96 gtrees[key] = gtrees[key] + nentry
103 print(
'\nBranches of Events tree:\n')
113 print(
' Total bytes Zipped bytes Comp. Branch name')
114 print(
' ----------- ------------ ----- -----------')
116 branches = events.GetListOfBranches()
122 for branch
in branches:
123 branch_class = branch.GetClass().GetName()
127 if branch_class[0: 13] ==
'art::Wrapper<':
131 subbranches = branch.GetListOfBranches()
132 for subbranch
in subbranches:
133 name = subbranch.GetName()
137 if name[-4:] ==
'.obj':
138 ntot = subbranch.GetTotBytes(
"*")
139 nzip = subbranch.GetZipBytes(
"*")
140 ntotall = ntotall + ntot
141 nzipall = nzipall + nzip
147 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp, name))
151 if name
in gbranches:
152 gbranches[name][0] = gbranches[name][0] + ntot
153 gbranches[name][1] = gbranches[name][1] + nzip
155 gbranches[name] = [ntot, nzip]
160 subsubbranches = subbranch.GetListOfBranches()
161 for subsubbranch
in subsubbranches:
162 name = subsubbranch.GetName()
163 ntot = subsubbranch.GetTotBytes(
"*")
164 nzip = subsubbranch.GetZipBytes(
"*")
170 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp,
171 subsubbranch.GetName()))
175 if name
in gbranches:
176 gbranches[name][0] = gbranches[name][0] + ntot
177 gbranches[name][1] = gbranches[name][1] + nzip
179 gbranches[name] = [ntot, nzip]
183 name =
'All branches' 189 print(
'%14d%14d%8.2f %s' % (ntotall, nzipall, comp, name))
193 nev = events.GetEntriesFast()
201 print(
'%10d events.' % nev)
202 print(
'%7.2f Mb average size per event.' % nevtot)
203 print(
'%7.2f Mb average zipped size per event.' % nevzip)
205 if name
in gbranches:
206 gbranches[name][0] = gbranches[name][0] + ntotall
207 gbranches[name][1] = gbranches[name][1] + nzipall
209 gbranches[name] = [ntotall, nzipall]
229 if args[0] ==
'-h' or args[0] ==
'--help':
236 elif args[0] ==
'--level' and len(args) > 1:
243 elif args[0] ==
'--nfile' and len(args) > 1:
247 nfilemax =
int(args[1])
250 elif args[0] ==
'--all':
257 elif args[0][0] ==
'-':
261 print(
'Unknown option %s' % args[0])
264 elif args[0][0] ==
'@':
268 filelistname = args[0][1:]
269 if larbatch_posix.exists(filelistname):
270 for filename
in larbatch_posix.readlines(filelistname):
271 input_files.append(filename.strip())
273 print(
'File list %s does not exist.' % filelistname)
280 input_files.append(args[0])
289 for input_file
in input_files:
291 if nfilemax > 0
and nfile >= nfilemax:
295 if not larbatch_posix.exists(input_file):
296 print(
'Input file %s does not exist.' % input_file)
299 print(
'\nOpening %s' % input_file)
300 root = ROOT.TFile.Open(input_file)
301 if not root.IsOpen()
or root.IsZombie():
302 print(
'Failed to open %s' % input_file)
307 analyze(root, level, gtrees, gbranches, all)
309 print(
'\n%d files analyzed.' % nfile)
313 print(
'\nTrees from all files:\n')
314 for key
in sorted(gtrees.keys()):
316 print(
'%s has %d total entries.' % (key, nentry))
321 print(
'\nBranches of Events tree from all files:\n')
322 print(
' Total bytes Zipped bytes Comp. Branch name')
323 print(
' ----------- ------------ ----- -----------')
324 allname =
'All branches' 327 for key
in sorted(gbranches.keys()):
329 ntot = gbranches[key][0]
330 nzip = gbranches[key][1]
335 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp, key))
336 if allname
in gbranches:
337 ntot = gbranches[allname][0]
338 nzip = gbranches[allname][1]
343 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp, allname))
347 if 'Events' in gtrees:
348 nev = gtrees[
'Events']
356 print(
'%10d events.' % nev)
358 print(
'%7.2f Mb average size per event.' % nevtot)
359 print(
'%7.2f Mb average zipped size per event.' % nevzip)
368 if __name__ ==
'__main__':
369 sys.exit(
main(sys.argv))
def analyze(root, level, gtrees, gbranches, doprint)
int open(const char *, int)
Opens a file descriptor.