All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
rootstat Namespace Reference

Functions

def help
 
def analyze
 
def main
 

Variables

 myargv = sys.argv
 

Function Documentation

def rootstat.analyze (   root,
  level,
  gtrees,
  gbranches,
  doprint,
  sorttype 
)

Definition at line 72 of file rootstat.py.

72 
73 def analyze(root, level, gtrees, gbranches, doprint, sorttype):
74 
75  trees = {}
76  events = None
77  keys = root.GetListOfKeys()
78  for key in keys:
79  objname = key.GetName()
80  if objname not in trees:
81  obj = root.Get(objname)
82  if obj and obj.InheritsFrom('TTree'):
83  trees[objname] = obj
84  if objname == 'Events':
85  events = obj
86 
87  # Print summary of trees.
88 
89  if doprint:
90  print('\nTrees:\n')
91  for key in sorted(trees.keys()):
92  tree = trees[key]
93  nentry = tree.GetEntriesFast()
94  if doprint:
95  print('%s has %d entries.' % (key, nentry))
96 
97  # Remember information about trees.
98 
99  if key in gtrees:
100  gtrees[key] = gtrees[key] + nentry
101  else:
102  gtrees[key] = nentry
103 
104  # Print summary of branches in Events tree.
105 
106  if doprint:
107  print('\nBranches of Events tree:\n')
108 
109  # If level is zero, we are done (don't analyze branches).
110 
111  if level == 0:
112  return
113 
114  if events:
115 
116  branch_tuples = {}
117 
118  if doprint:
119  print(' Total bytes Zipped bytes Comp. Branch name')
120  print(' ----------- ------------ ----- -----------')
121 
122  branches = events.GetListOfBranches()
123  ntotall = 0
124  nzipall = 0
125 
126  # Loop over branche of Events tree.
127 
128  for branch in branches:
129  branch_class = branch.GetClass().GetName()
130 
131  # Only look at data products (class art::Wrapper<T>).
132 
133  if branch_class[0: 13] == 'art::Wrapper<':
134 
135  # Loop over subbranches.
136 
137  subbranches = branch.GetListOfBranches()
138  for subbranch in subbranches:
139  name = subbranch.GetName()
140 
141  # Only look at '.obj' subbranch (wrapped object).
142 
143  if name[-4:] == '.obj':
144  ntot = subbranch.GetTotBytes("*")
145  nzip = subbranch.GetZipBytes("*")
146  ntotall = ntotall + ntot
147  nzipall = nzipall + nzip
148  if doprint:
149  if nzip != 0:
150  comp = float(ntot) / float(nzip)
151  else:
152  comp = 0.
153  branch_key = None
154  if sorttype == 1:
155  branch_key = ntot
156  elif sorttype == 2:
157  branch_key = nzip
158  else:
159  branch_key = name
160  branch_tuples[branch_key] = (ntot, nzip, comp, name)
161  #print('%14d%14d%8.2f %s' % (ntot, nzip, comp, name))
162 
163  # Remember information about branches.
164 
165  if name in gbranches:
166  gbranches[name][0] = gbranches[name][0] + ntot
167  gbranches[name][1] = gbranches[name][1] + nzip
168  else:
169  gbranches[name] = [ntot, nzip]
170 
171  # Loop over subsubbranches (attributes of wrapped object).
172 
173  if level > 1:
174  subsubbranches = subbranch.GetListOfBranches()
175  for subsubbranch in subsubbranches:
176  name = subsubbranch.GetName()
177  ntot = subsubbranch.GetTotBytes("*")
178  nzip = subsubbranch.GetZipBytes("*")
179  if doprint:
180  if nzip != 0:
181  comp = float(ntot) / float(nzip)
182  else:
183  comp = 0.
184  branch_key = None
185  if sorttype == 1:
186  branch_key = ntot
187  elif sorttype == 2:
188  branch_key = nzip
189  else:
190  branch_key = name
191  branch_tuples[branch_key] = (ntot, nzip, comp, name)
192  #print('%14d%14d%8.2f %s' % (ntot, nzip, comp,
193  # subsubbranch.GetName()))
194 
195  # Remember information about branches.
196 
197  if name in gbranches:
198  gbranches[name][0] = gbranches[name][0] + ntot
199  gbranches[name][1] = gbranches[name][1] + nzip
200  else:
201  gbranches[name] = [ntot, nzip]
202 
203  # Print sorted information about branches.
204 
205  if doprint:
206  for branch_key in sorted(branch_tuples.keys()):
207  branch_tuple = branch_tuples[branch_key]
208  ntot = branch_tuple[0]
209  nzip = branch_tuple[1]
210  comp = branch_tuple[2]
211  name = branch_tuple[3]
212  print('%14d%14d%8.2f %s' % (ntot, nzip, comp, name))
213 
214  # Do summary of all branches.
215 
216  name = 'All branches'
217  if doprint:
218  if nzipall != 0:
219  comp = float(ntotall) / float(nzipall)
220  else:
221  comp = 0.
222  print('%14d%14d%8.2f %s' % (ntotall, nzipall, comp, name))
223 
224  # Print average event size.
225 
226  nev = events.GetEntriesFast()
227  if nev != 0:
228  nevtot = 1.e-6 * float(ntotall) / float(nev)
229  nevzip = 1.e-6 * float(nzipall) / float(nev)
230  else:
231  nevtot = 0.
232  nevzip = 0.
233  print()
234  print('%10d events.' % nev)
235  print('%7.2f Mb average size per event.' % nevtot)
236  print('%7.2f Mb average zipped size per event.' % nevzip)
237 
238  if name in gbranches:
239  gbranches[name][0] = gbranches[name][0] + ntotall
240  gbranches[name][1] = gbranches[name][1] + nzipall
241  else:
242  gbranches[name] = [ntotall, nzipall]
243 
244 
245  # Done.
246 
247  return
248 
249 # Main program.
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def analyze
Definition: rootstat.py:72
def rootstat.help ( )

Definition at line 52 of file rootstat.py.

52 
53 def help():
54 
55  filename = sys.argv[0]
56  file = open(filename)
57 
58  doprint=0
59 
60  for line in file.readlines():
61  if line[2:9] == 'stat.py':
62  doprint = 1
63  elif line[0:6] == '######' and doprint:
64  doprint = 0
65  if doprint:
66  if len(line) > 2:
67  print(line[2:], end=' ')
68  else:
69  print()
70 
71 # Analyze root file.
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def help
Definition: rootstat.py:52
open(RACETRACK) or die("Could not open file $RACETRACK for writing")
def rootstat.main (   argv)

Definition at line 250 of file rootstat.py.

251 def main(argv):
252 
253  # Parse arguments.
254 
255  input_files = []
256  level = 1
257  nfilemax = 0
258  all = 0
259  sorttype = 2
260 
261  args = argv[1:]
262  while len(args) > 0:
263  if args[0] == '-h' or args[0] == '--help':
264 
265  # Help.
266 
267  help()
268  return 0
269 
270  elif args[0] == '--level' and len(args) > 1:
271 
272  # Analyze level.
273 
274  level = int(args[1])
275  del args[0:2]
276 
277  elif args[0] == '--nfile' and len(args) > 1:
278 
279  # Number of files.
280 
281  nfilemax = int(args[1])
282  del args[0:2]
283 
284  elif args[0] == '--all':
285 
286  # All files flag.
287 
288  all = 1
289  del args[0]
290 
291  elif args[0] == '--s1':
292 
293  # Sort flag.
294 
295  sorttype = 1
296  del args[0]
297 
298  elif args[0] == '--s2':
299 
300  # Sort flag.
301 
302  sorttype = 2
303  del args[0]
304 
305  elif args[0] == '--s3':
306 
307  # Sort flag.
308 
309  sorttype = 3
310  del args[0]
311 
312  elif args[0][0] == '-':
313 
314  # Unknown option.
315 
316  print('Unknown option %s' % args[0])
317  return 1
318 
319  elif args[0][0] == '@':
320 
321  # Read in file list to input files.
322 
323  filelistname = args[0][1:]
324  if larbatch_posix.exists(filelistname):
325  for filename in larbatch_posix.readlines(filelistname):
326  input_files.append(filename.strip())
327  else:
328  print('File list %s does not exist.' % filelistname)
329  return 1
330  del args[0]
331  else:
332 
333  # Add single file to input files.
334 
335  input_files.append(args[0])
336  del args[0]
337 
338  # Loop over input files.
339 
340  gtrees = {}
341  gbranches = {}
342  nfile = 0
343 
344  for input_file in input_files:
345 
346  if nfilemax > 0 and nfile >= nfilemax:
347  break
348  nfile = nfile + 1
349 
350  if not larbatch_posix.exists(input_file):
351  print('Input file %s does not exist.' % input_file)
352  return 1
353 
354  print('\nOpening %s' % input_file)
355  root = ROOT.TFile.Open(input_file)
356  if not root.IsOpen() or root.IsZombie():
357  print('Failed to open %s' % input_file)
358  return 1
359 
360  # Analyze this file.
361 
362  analyze(root, level, gtrees, gbranches, all, sorttype)
363 
364  print('\n%d files analyzed.' % nfile)
365 
366  # Print summary of trees.
367 
368  print('\nTrees from all files:\n')
369  for key in sorted(gtrees.keys()):
370  nentry = gtrees[key]
371  print('%s has %d total entries.' % (key, nentry))
372 
373  # Print summary of branches.
374 
375  if level > 0:
376  print('\nBranches of Events tree from all files:\n')
377  print(' Total bytes Zipped bytes Comp. Branch name')
378  print(' ----------- ------------ ----- -----------')
379  allname = 'All branches'
380  ntot = 0
381  nzip = 0
382  branch_tuples = {}
383  for key in sorted(gbranches.keys()):
384  if key != allname:
385  ntot = gbranches[key][0]
386  nzip = gbranches[key][1]
387  if nzip != 0:
388  comp = float(ntot) / float(nzip)
389  else:
390  comp = 0.
391  branch_key = None
392  if sorttype == 1:
393  branch_key = ntot
394  elif sorttype == 2:
395  branch_key = nzip
396  else:
397  branch_key = key
398  branch_tuples[branch_key] = (ntot, nzip, comp, key)
399  #print('%14d%14d%8.2f %s' % (ntot, nzip, comp, key))
400 
401  # Print sorted information about branches.
402 
403  for branch_key in sorted(branch_tuples.keys()):
404  branch_tuple = branch_tuples[branch_key]
405  ntot = branch_tuple[0]
406  nzip = branch_tuple[1]
407  comp = branch_tuple[2]
408  name = branch_tuple[3]
409  print('%14d%14d%8.2f %s' % (ntot, nzip, comp, name))
410 
411  if allname in gbranches:
412  ntot = gbranches[allname][0]
413  nzip = gbranches[allname][1]
414  if nzip != 0:
415  comp = float(ntot) / float(nzip)
416  else:
417  comp = 0.
418  print('%14d%14d%8.2f %s' % (ntot, nzip, comp, allname))
419 
420  # Print average event size.
421 
422  if 'Events' in gtrees:
423  nev = gtrees['Events']
424  if nev != 0:
425  nevtot = 1.e-6 * float(ntot) / float(nev)
426  nevzip = 1.e-6 * float(nzip) / float(nev)
427  else:
428  nevtot = 0.
429  nevzip = 0.
430  print()
431  print('%10d events.' % nev)
432  if level > 0:
433  print('%7.2f Mb average size per event.' % nevtot)
434  print('%7.2f Mb average zipped size per event.' % nevzip)
435 
436 
437  # Done.
438 
439  return 0
440 
441 # Invoke main program.
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def help
Definition: rootstat.py:52
def main
Definition: rootstat.py:250
def analyze
Definition: rootstat.py:72

Variable Documentation

rootstat.myargv = sys.argv

Definition at line 42 of file rootstat.py.