ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/macros/validation/treeSizeVal.C
Revision: 1.2
Committed: Mon Jul 20 03:57:55 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, HEAD
Branch point for: Mit_025c_branch
Changes since 1.1: +32 -123 lines
Log Message:
Fix compile warnings and error. Not sure if WriteBasket with arg 0 makes sense

File Contents

# Content
1 // $Id: treeSizeVal.C,v 1.1 2008/09/17 12:48:38 bendavid Exp $
2
3 #if !defined(__CINT__) || defined(__MAKECINT__)
4 #include <TROOT.h>
5 #include <TFile.h>
6 #include <TTree.h>
7 #include <TBranch.h>
8 #include <TBasket.h>
9 #include <TCanvas.h>
10 #include <TPie.h>
11
12 #include "MitAna/DataUtil/interface/Debug.h"
13 #include "MitAna/TreeMod/interface/Analysis.h"
14 #endif
15
16
17 extern "C" void R__zip (Int_t cxlevel, Int_t *nin, char *bufin, Int_t *lout, char *bufout, Int_t *nout);
18
19 //--------------------------------------------------------------------------------------------------
20 Long64_t RawBytes(TBranch* branch, UInt_t recursion=0)
21 {
22 Long64_t totBytes = branch->GetTotBytes();
23 //Long64_t totBytes = branch->GetTotBytes() + altRawBasketSize;
24 TObjArray *subBranches = branch->GetListOfBranches();
25 for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
26 TBranch *subBranch = (TBranch*)subBranches->At(i);
27 totBytes += RawBytes(subBranch, recursion+1);
28 }
29 return totBytes;
30 }
31
32 Long64_t ZipBytes(TBranch* branch, Double_t ratio, UInt_t recursion=0)
33 {
34 TBasket* currentBasket = branch->GetBasket(branch->GetReadBasket());
35 currentBasket->SetWriteMode();
36 branch->WriteBasket(currentBasket,0);
37
38 Long64_t totBytes = branch->GetZipBytes();
39 //Long64_t totBytes = branch->GetZipBytes() + altRawBasketSize;
40 TObjArray *subBranches = branch->GetListOfBranches();
41 for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
42 TBranch *subBranch = (TBranch*)subBranches->At(i);
43 totBytes += ZipBytes(subBranch, ratio, recursion+1);
44 }
45 return totBytes;
46 }
47
48 Long64_t TotSize(TBranch* branch)
49 {
50 Long64_t totBytes = branch->GetTotalSize();
51 TObjArray *subBranches = branch->GetListOfBranches();
52 if (0) {
53 for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
54 TBranch *subBranch = (TBranch*)subBranches->At(i);
55 totBytes += TotSize(subBranch);
56 }
57 }
58 return totBytes;
59 }
60
61
62 void AppendPrefix(TBranch* branch, std::string prefix)
63 {
64 std::string name = prefix + branch->GetName();
65 branch->SetName(name.c_str());
66 TObjArray *subBranches = branch->GetListOfBranches();
67 for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
68 TBranch *subBranch = (TBranch*)subBranches->At(i);
69 AppendPrefix(subBranch, prefix);
70 }
71 }
72
73 void treeSizeVal(const char *file)
74 {
75 using namespace mithep;
76 gDebugMask = Debug::kAnalysis;
77 gDebugLevel = 1;
78
79 TFile *infile = new TFile(file,"READ");
80 //TFile *tmpfile = new TFile("/tmp/bendavid/tmpfile.root","RECREATE");
81
82 TTree *events = (TTree*)infile->Get("Events");
83 TTree *runs = (TTree*)infile->Get("Runs");
84 TTree *fwMetaData = (TTree*)infile->Get("FWMetaData");
85
86 //TPie fileRaw, fileZip;
87 const char **treeLabels = new const char*[3];
88 treeLabels[0] = "Events";
89 treeLabels[1] = "Runs";
90 treeLabels[2] = "FWMetaData";
91
92 Double_t rawTreeSizes[] = { events->GetTotBytes(), runs->GetTotBytes(), fwMetaData->GetTotBytes() };
93 Double_t zipTreeSizes[] = { events->GetZipBytes(), runs->GetZipBytes(), fwMetaData->GetZipBytes() };
94
95 TPie *fileRaw = new TPie("fileRaw", "Top Level Tree Sizes - Raw", 3, rawTreeSizes);
96 fileRaw->SetLabels(treeLabels);
97 new TCanvas();
98 fileRaw->Draw("3d");
99
100 TPie *fileZip = new TPie("fileZip", "Top Level Tree Sizes - Compressed", 3, zipTreeSizes);
101 fileZip->SetLabels(treeLabels);
102 new TCanvas();
103 fileZip->Draw("3d");
104
105 Long64_t eventsRawSize = events->GetTotBytes();
106 Long64_t eventsZipSize = events->GetZipBytes();
107
108 Double_t eventsCompression = (Double_t)eventsRawSize/eventsZipSize;
109
110 infile->Cp(file, "tmpFile.root");
111 infile->Close();
112 TFile *tmpfile = new TFile("tmpFile.root","UPDATE");
113
114 events = (TTree*)tmpfile->Get("Events");
115
116 TObjArray *evtBranches = events->GetListOfBranches();
117 UInt_t nBranches = evtBranches->GetEntries();
118 UInt_t nEvents = events->GetEntries();
119
120 Double_t *rawBranchSizes = new Double_t[nBranches];
121 Double_t *zipBranchSizes = new Double_t[nBranches];
122 const char **branchLabels = new const char*[nBranches];
123
124 Double_t *rawDataBranchSizes = new Double_t[nBranches];
125 Double_t *zipDataBranchSizes = new Double_t[nBranches];
126
127 Long64_t rawTotal = 0;
128 Long64_t zipTotal = 0;
129
130 Long64_t zipDataTotal=0;
131
132 for (UInt_t i=0; i<nBranches; ++i) {
133
134 TBranch* branch = (TBranch*)evtBranches->At(i);
135
136 Long64_t branchSizeZip = ZipBytes(branch, eventsCompression);
137 Long64_t branchSizeRaw = RawBytes(branch);
138
139 rawTotal += branchSizeRaw;
140 zipTotal += branchSizeZip;
141
142 printf("%s BranchSizeRaw = %lld\n",branch->GetName(),branchSizeRaw);
143 printf("%s BranchSizeZip = %lld\n",branch->GetName(),branchSizeZip);
144 // printf("%s BranchSizeZipSimple = %i\n",branch->GetName(),branchSizeZipSimple);
145 // printf("%s BranchSizeTotal = %i\n",branch->GetName(),branchSizeTotal);
146 rawBranchSizes[i] = (Double_t)branchSizeRaw/nEvents/1024.0;
147 zipBranchSizes[i] = (Double_t)branchSizeZip/nEvents/1024.0;
148 branchLabels[i] = branch->GetName();
149
150 if (i!=1) {
151 rawDataBranchSizes[i] = (Double_t)branchSizeRaw/nEvents/1024.0;
152 zipDataBranchSizes[i] = (Double_t)branchSizeZip/nEvents/1024.0;
153 zipDataTotal+=branchSizeZip;
154 }
155 }
156
157 printf("Event Size Raw = %lld\n", eventsRawSize);
158 printf("Total Raw Size = %lld\n", rawTotal);
159
160 printf("Event Size Zip = %lld\n", eventsZipSize);
161 printf("Total Zip Size = %lld\n", zipTotal);
162
163 Double_t avgEvent = (Double_t)zipTotal/nEvents/1024.0;
164 printf("Average Event Size = %f kBytes\n",avgEvent);
165
166 Double_t avgDataEvent = (Double_t)zipDataTotal/nEvents/1024.0;
167 printf("Average Event Size (data) = %f kBytes\n",avgDataEvent);
168
169 TPie *branchRaw = new TPie("branchRaw", "Event Branch Sizes - Raw", nBranches, rawBranchSizes);
170 branchRaw->SetLabels(branchLabels);
171 new TCanvas();
172 branchRaw->Draw("3d");
173
174 TPie *branchZip = new TPie("branchZip", "Event Branch Sizes - Zip", nBranches, zipBranchSizes);
175 branchZip->SetLabels(branchLabels);
176 branchZip->SetLabelsOffset(0.1);
177 branchZip->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
178 new TCanvas();
179 branchZip->Draw("3dr");
180
181 TPie *branchDataRaw = new TPie("branchDataRaw", "Event Branch Sizes - Raw", nBranches, rawDataBranchSizes);
182 branchDataRaw->SetLabels(branchLabels);
183
184 new TCanvas();
185 branchDataRaw->Draw("3d");
186
187 TPie *branchDataZip = new TPie("branchDataZip", "Event Branch Sizes - Zip", nBranches, zipDataBranchSizes);
188 branchDataZip->SetLabels(branchLabels);
189 branchDataZip->SetLabelsOffset(0.1);
190 branchDataZip->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
191
192 new TCanvas();
193 branchDataZip->Draw("3dr");
194 }