00001
00002
00003 '''
00004
00005 size of headers in mixed (or any) data in file.root
00006 using TTree::Print()
00007
00008 options can be obtained with
00009 nuwa.py -m"howBig --help"
00010
00011 usage:
00012 nuwa.py -l 5 --no-history -n 1 -m "howBig " file.root
00013
00014
00015
00016 Notes:
00017 Apparently must process one execution cycle "-n 1" to ensure file.root is read.
00018 Use of "-l 5" and cd "--no-history" just avoids copious and uninteresting output.
00019 '''
00020
00021 __all__ = ['howBig']
00022
00023 from DybPython.DybPythonAlg import DybPythonAlg
00024 from GaudiPython import SUCCESS, FAILURE
00025 from GaudiPython import gbl, loaddict
00026
00027 from DybPython.Util import irange
00028 from GaudiKernel import SystemOfUnits as units
00029 import PyCintex
00030 import re
00031 import ROOT
00032 import math
00033
00034 printLevel = 0
00035
00036 class howBig(DybPythonAlg):
00037
00038 def __init__(self,name):
00039
00040 DybPythonAlg.__init__(self,name)
00041
00042 return
00043
00044
00045 def initialize(self):
00046 print "Initializing the howBig: ", self.name()
00047 status = DybPythonAlg.initialize(self)
00048 if status.isFailure(): return status
00049
00050 global printlevel
00051
00052 return SUCCESS
00053
00054 def execute(self):
00055
00056 return SUCCESS
00057
00058 def finalize(self):
00059
00060
00061
00062 self.infileObj = gbl.gDirectory
00063
00064
00065
00066 self.filename = self.infileObj.GetName()
00067 if self.filename.count( 'PyROOT' ) > 0 :
00068 print "\n ERROR It looks like you did not read any events. You need to read at least one event for howBig to work ERROR \n"
00069 return FAILURE
00070
00071 print "\n Contents of ",self.filename
00072 self.filename += ":/"
00073 self.TotBytes = 0
00074 self.ZipBytes = 0
00075 self.process_path("")
00076 nt = self.TotBytes
00077 nz = self.ZipBytes
00078 if printlevel == 0 or printlevel == 1 :
00079 print "{2:10.2f}MB(on disk) {1:10.2f}MB(uncompressed) {0:30} \n".format( 'TOTALS', nt/1e6, nz/1e6 )
00080
00081
00082 status = DybPythonAlg.finalize(self)
00083 return status
00084
00085 def process_path(self, itemPath) :
00086 ''' process path in root file. cribbed from Dan '''
00087
00088
00089 filePath = self.filename
00090 if len(itemPath)>0 :
00091 filePath += "/" + itemPath
00092 content = self.infileObj.Get(filePath)
00093 if not content and itemPath=="":
00094 filePath += ":/"
00095 content = self.infileObj
00096 if not content :
00097 print "Failed to get item at ",filePath
00098 return
00099 if content.IsA().InheritsFrom("TTree") :
00100 name = content.GetName()
00101 nt = content.GetTotBytes()
00102 self.TotBytes += nt
00103 nz = content.GetZipBytes()
00104 self.ZipBytes += nz
00105 if printlevel > 1 :
00106 content.Print()
00107 if printlevel == 1 :
00108 print "{2:10.2f}MB(on disk) {1:10.2f}MB(uncompressed) {0:30}".format( name, nt/1e6, nz/1e6 )
00109
00110 elif content.IsA().InheritsFrom("TDirectory") :
00111 keylist = content.GetListOfKeys()
00112 for key in keylist :
00113 dirItem = key.ReadObj()
00114 dirItemPath = None
00115 if len(itemPath)>0:
00116 dirItemPath = itemPath + "/" + dirItem.GetName()
00117 else :
00118 dirItemPath = dirItem.GetName()
00119 self.process_path( dirItemPath )
00120 else:
00121 print "Not processing",filePath,"of type",content.ClassName()
00122
00123
00124 return
00125
00126 def configure(argv=[]) :
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 from optparse import OptionParser
00137 parser = OptionParser()
00138
00139 parser.add_option("-p","--print-level",
00140 default=1, type="int",
00141 help="Set print level. 0=minimal(Totals only), 1=more(per Header totals), 2=most (same as TTree->Print()). [default: %default]")
00142
00143 (options,args) = parser.parse_args(args=argv)
00144
00145 global printlevel
00146 printlevel = options.print_level
00147 print " Set output print level to ",printlevel
00148
00149
00150 from Gaudi.Configuration import ApplicationMgr
00151 theApp = ApplicationMgr()
00152
00153
00154
00155
00156 return
00157
00158 def run(app):
00159 '''Configure and add this algorithm to job'''
00160
00161
00162 import sys
00163
00164
00165 plotBasics = howBig("HowBig")
00166 app.addAlgorithm(plotBasics)
00167
00168 pass