32 from __future__
import absolute_import
33 from __future__
import print_function
35 import project_utilities
43 sys.argv = myargv[0:1]
44 if 'TERM' in os.environ:
45 del os.environ[
'TERM']
47 ROOT.gErrorIgnoreLevel = ROOT.kError
54 filename = sys.argv[0]
59 for line
in file.readlines():
60 if line[2:9] ==
'stat.py':
62 elif line[0:6] ==
'######' and doprint:
66 print(line[2:], end=
' ')
72 def analyze(root, level, gtrees, gbranches, doprint, sorttype):
76 keys = root.GetListOfKeys()
78 objname = key.GetName()
79 if objname
not in trees:
80 obj = root.Get(objname)
81 if obj
and obj.InheritsFrom(
'TTree'):
83 if objname ==
'Events':
90 for key
in sorted(trees.keys()):
92 nentry = tree.GetEntriesFast()
94 print(
'%s has %d entries.' % (key, nentry))
99 gtrees[key] = gtrees[key] + nentry
106 print(
'\nBranches of Events tree:\n')
118 print(
' Total bytes Zipped bytes Comp. Branch name')
119 print(
' ----------- ------------ ----- -----------')
121 branches = events.GetListOfBranches()
127 for branch
in branches:
128 branch_class = branch.GetClass().GetName()
132 if branch_class[0: 13] ==
'art::Wrapper<':
136 subbranches = branch.GetListOfBranches()
137 for subbranch
in subbranches:
138 name = subbranch.GetName()
142 if name[-4:] ==
'.obj':
143 ntot = subbranch.GetTotBytes(
"*")
144 nzip = subbranch.GetZipBytes(
"*")
145 ntotall = ntotall + ntot
146 nzipall = nzipall + nzip
149 comp = float(ntot) / float(nzip)
159 branch_tuples[branch_key] = (ntot, nzip, comp, name)
164 if name
in gbranches:
165 gbranches[name][0] = gbranches[name][0] + ntot
166 gbranches[name][1] = gbranches[name][1] + nzip
168 gbranches[name] = [ntot, nzip]
173 subsubbranches = subbranch.GetListOfBranches()
174 for subsubbranch
in subsubbranches:
175 name = subsubbranch.GetName()
176 ntot = subsubbranch.GetTotBytes(
"*")
177 nzip = subsubbranch.GetZipBytes(
"*")
180 comp = float(ntot) / float(nzip)
190 branch_tuples[branch_key] = (ntot, nzip, comp, name)
196 if name
in gbranches:
197 gbranches[name][0] = gbranches[name][0] + ntot
198 gbranches[name][1] = gbranches[name][1] + nzip
200 gbranches[name] = [ntot, nzip]
205 for branch_key
in sorted(branch_tuples.keys()):
206 branch_tuple = branch_tuples[branch_key]
207 ntot = branch_tuple[0]
208 nzip = branch_tuple[1]
209 comp = branch_tuple[2]
210 name = branch_tuple[3]
211 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp, name))
215 name =
'All branches'
218 comp = float(ntotall) / float(nzipall)
221 print(
'%14d%14d%8.2f %s' % (ntotall, nzipall, comp, name))
225 nev = events.GetEntriesFast()
227 nevtot = 1.e-6 * float(ntotall) / float(nev)
228 nevzip = 1.e-6 * float(nzipall) / float(nev)
233 print(
'%10d events.' % nev)
234 print(
'%7.2f Mb average size per event.' % nevtot)
235 print(
'%7.2f Mb average zipped size per event.' % nevzip)
237 if name
in gbranches:
238 gbranches[name][0] = gbranches[name][0] + ntotall
239 gbranches[name][1] = gbranches[name][1] + nzipall
241 gbranches[name] = [ntotall, nzipall]
262 if args[0] ==
'-h' or args[0] ==
'--help':
269 elif args[0] ==
'--level' and len(args) > 1:
276 elif args[0] ==
'--nfile' and len(args) > 1:
280 nfilemax = int(args[1])
283 elif args[0] ==
'--all':
290 elif args[0] ==
'--s1':
297 elif args[0] ==
'--s2':
304 elif args[0] ==
'--s3':
311 elif args[0][0] ==
'-':
315 print(
'Unknown option %s' % args[0])
318 elif args[0][0] ==
'@':
322 filelistname = args[0][1:]
323 if larbatch_posix.exists(filelistname):
324 for filename
in larbatch_posix.readlines(filelistname):
325 input_files.append(filename.strip())
327 print(
'File list %s does not exist.' % filelistname)
334 input_files.append(args[0])
343 for input_file
in input_files:
345 if nfilemax > 0
and nfile >= nfilemax:
349 if not larbatch_posix.exists(input_file):
350 print(
'Input file %s does not exist.' % input_file)
353 print(
'\nOpening %s' % input_file)
354 root = ROOT.TFile.Open(input_file)
355 if not root.IsOpen()
or root.IsZombie():
356 print(
'Failed to open %s' % input_file)
361 analyze(root, level, gtrees, gbranches, all, sorttype)
363 print(
'\n%d files analyzed.' % nfile)
367 print(
'\nTrees from all files:\n')
368 for key
in sorted(gtrees.keys()):
370 print(
'%s has %d total entries.' % (key, nentry))
375 print(
'\nBranches of Events tree from all files:\n')
376 print(
' Total bytes Zipped bytes Comp. Branch name')
377 print(
' ----------- ------------ ----- -----------')
378 allname =
'All branches'
382 for key
in sorted(gbranches.keys()):
384 ntot = gbranches[key][0]
385 nzip = gbranches[key][1]
387 comp = float(ntot) / float(nzip)
397 branch_tuples[branch_key] = (ntot, nzip, comp, key)
402 for branch_key
in sorted(branch_tuples.keys()):
403 branch_tuple = branch_tuples[branch_key]
404 ntot = branch_tuple[0]
405 nzip = branch_tuple[1]
406 comp = branch_tuple[2]
407 name = branch_tuple[3]
408 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp, name))
410 if allname
in gbranches:
411 ntot = gbranches[allname][0]
412 nzip = gbranches[allname][1]
414 comp = float(ntot) / float(nzip)
417 print(
'%14d%14d%8.2f %s' % (ntot, nzip, comp, allname))
421 if 'Events' in gtrees:
422 nev = gtrees[
'Events']
424 nevtot = 1.e-6 * float(ntot) / float(nev)
425 nevzip = 1.e-6 * float(nzip) / float(nev)
430 print(
'%10d events.' % nev)
432 print(
'%7.2f Mb average size per event.' % nevtot)
433 print(
'%7.2f Mb average zipped size per event.' % nevzip)
442 if __name__ ==
'__main__':
443 sys.exit(
main(sys.argv))
do one_file $F done echo for F in find $TOP name CMakeLists txt print
open(RACETRACK) or die("Could not open file $RACETRACK for writing")