12 import os, re, operator, ROOT
13 from optparse
import OptionParser
24 parser = OptionParser( usage =
"usage: %prog [-f] xAOD.pool.root" )
25 parser.add_option(
"-f",
"--file",
27 help =
"The path to the xAOD file to analyse" )
28 ( options, args ) = parser.parse_args()
32 "MetaData" : [
"^DataHeader",
"(.*)_mems$",
"(.*)_timings$",
"^Token$",
"^RawInfoSummaryForTag$"],
33 "Trig" : [
"^HLT",
"^LVL1",
"^xTrig",
"^Trig",
"^CTP_Decision",
"^TrigInDetTrackTruthMap",
"^TrigNavigation",
".*TriggerTowers",
"TileTTL1MBTS",
"^TileL2Cnt",
"RoIBResult"],
34 "MET" : [
"^MET",
"^METMAP",
"JEMEtSums"],
35 "EvtId" : [
"^ByteStreamEventInfo",
"^EventInfo",
"^McEventInfo",
"^LumiBlockN",
"^EventWeight",
"^RunNumber",
"^ConditionsRun",
"^EventTime",
"^BunchId",
"^EventNumber"],
36 "tau" : [
"^Tau",
"^DiTauJets"],
37 "PFO" : [
"(.*)EventShape$",
"^AntiKt4EMPFlowJets",
"^JetETMissChargedParticleFlowObjects",
"^JetETMissNeutralParticleFlowObjects",
"^JetETMissLCNeutralParticleFlowObjects"],
38 "egamma" : [
"^GSF",
"^ForwardElectron",
"^egamma",
"^Electron",
"^Photon"],
39 "Muon" : [
"^Muon",
"^TileMuObj",
"^MS",
"^SlowMuons",
".*Stau",
"(.*)MuonTrackParticles$",
"MUCTPI_RDO",
"^RPC",
"^TGC",
"^MDT",
"^CSC",
"^sTGC",
"^MM",
".*MuonMeasurements$",
"^ExtrapolatedMuonTracks",
"^CombinedMuonTracks"],
41 "InDet" : [
"^InDet",
"^PrimaryVertices",
"^ComTime_TRT",
"^Pixel",
"^TRT",
"^SCT",
"^BCM",
"^CTP",
"^Tracks",
"^ResolvedForwardTracks",
"^SplitClusterAmbiguityMap"],
42 "Jet" : [
"^CamKt",
"^AntiKt",
"^Jet"],
43 "CaloTopo" : [
"CaloCalTopoCluster"],
44 "Calo" : [
"^LAr",
"^AODCellContainer",
"^MBTSContainer",
"^CaloCompactCellContainer",
"^E4prContainer",
"^TileCellVec",
"^TileDigits"],
45 "Truth" : [
"^Truth",
"Truth$",
"TruthMap$",
"TruthCollection$",
"^PRD_MultiTruth",
"TracksTruth$",
".*TrackTruth$",
"TrackTruthCollection"]
50 fileNames = [ arg
for arg
in args
if arg[ 0 ] !=
"-" ]
52 if ( options.fileName ==
None )
and ( len( fileNames ) == 0 ):
55 if options.fileName !=
None:
57 os.path.expandvars( os.path.expanduser( options.fileName ) ) )
59 fileNames =
set( fileNames )
62 ROOT.gErrorIgnoreLevel = ROOT.kError
65 for fileName
in fileNames:
79 def __init__( self, name, memSize, diskSize, nEntries ):
81 object.__init__( self )
116 f = ROOT.TFile.Open( fileName,
"READ" )
117 if not f
or f.IsZombie():
118 raise "Couldn't open file %s" % fileName
121 t = f.Get(
"CollectionTree" )
123 raise "Couldn't find 'CollectionTree; in file %s" % fileName
130 entries = t.GetEntries()
133 branches = t.GetListOfBranches()
134 for i
in range( branches.GetEntries() ):
136 branch = branches.At( i )
138 if branch.GetEntries() != entries:
139 raise "Found %i entries in branch %s instead of %i" % \
140 ( branch.GetEntries(), branch.GetName(), entries )
142 brName = branch.GetName()
144 m = re.match(
"(.*)Aux\..*", branch.GetName() )
146 brName = m.group( 1 )
149 m = re.match(
"(.*)AuxDyn\..*", branch.GetName() )
151 brName = m.group( 1 )
154 if brName
in infoForCont.keys():
155 infoForCont[ brName ]._memSize += branch.GetTotBytes(
"*" )
156 infoForCont[ brName ]._diskSize += branch.GetZipBytes(
"*" )
159 branch.GetTotBytes(
"*" ),
160 branch.GetZipBytes(
"*" ),
167 for cName
in infoForCont.keys():
168 orderedData += [ infoForCont[ cName ] ]
170 orderedData.sort( key = operator.attrgetter(
"_diskSize" ) )
176 print(
" File: %s" % fileName )
178 print(
" Memory size Disk Size Size/Event Compression "
179 "Entries Name (Type)" )
181 for d
in orderedData:
183 intBr = t.GetBranch( d.name() )
184 className =
"<!!!Interface missing!!!>"
186 className = intBr.GetClassName()
189 nameType =
"%s (%s)" % ( d.name(), className )
194 catName =
'*Unknown*'
196 for categ
in categoryStrings:
197 for pattern
in categoryStrings[ categ ]:
201 m = re.match(pattern, d.name())
215 nameType +=
' [' + catName +
']'
219 if catName
in categData.keys():
220 categData[ catName ]._memSize += d._memSize
221 categData[ catName ]._diskSize += d._diskSize
223 categData[ catName ] = \
230 memSize = memSize + d.memSize()
231 diskSize = diskSize + d.diskSize()
233 print(
" %12.2f kB %12.2f kB %7.2f kB/event %5.2f %8i %s" % \
234 ( d.memSize(), d.diskSize(),
235 d.diskSizePerEntry(),
237 d.nEntries(), nameType ) )
240 print(
" %12.2f kB %12.2f kB %7.2f kB/event Total" % \
241 ( memSize, diskSize, diskSize/entries ) )
248 for br
in categData.keys():
249 categorizedData += [ categData[ br ] ]
251 categorizedData.sort( key = operator.attrgetter(
"_diskSize" ) )
254 print(
" Categorized data" )
256 print(
" Disk Size Fraction Category Name" )
263 for d
in categorizedData:
265 dsPerEvt = d.diskSize() / d.nEntries()
266 dsPerEvtFrac = d.diskSize() / diskSize
267 totDiskSize += dsPerEvt
270 dsFrac += [dsPerEvtFrac]
272 print(
"%12.3f kb %12.3f %s" % ( dsPerEvt, dsPerEvtFrac, d.name() ) )
274 print(
"%12.3f kb %12.3f %s" % ( totDiskSize , frac,
"Total" ) )
281 print(
"CSV for categories disk size/evt and fraction:" )
284 b = [
'{:<0.3f}'.
format(i)
for i
in ds[::-1]]
286 b = [
'{:<0.3f}'.
format(i)
for i
in dsFrac[::-1]]
294 if __name__ ==
"__main__":