ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/macros/validation/treeSizeVal.C
Revision: 1.1
Committed: Wed Sep 17 12:48:38 2008 UTC (16 years, 7 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008, Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a, Mit_006, Mit_005, Mit_004
Log Message:
Added first version of tree size validation macro

File Contents

# User Rev Content
1 bendavid 1.1 // $Id: runObjectCleaner.C,v 1.1 2008/08/08 11:23:17 sixie 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 rawCurrentBasketSize = 0;
23     // if (recursion==0)
24     // rawCurrentBasketSize = branch->GetTotalSize() - branch->GetTotBytes();
25    
26     //TBasket* currentBasket = branch->GetBasket(branch->GetReadBasket());
27     //currentBasket->SetWriteMode();
28     //rawCurrentBasketSize = currentBasket->WriteBuffer();
29    
30     //branch->WriteBasket(currentBasket);
31    
32     //branch->Print();
33    
34    
35    
36     //branch->Print();
37     // if (currentBasket->GetNevBuf())
38     //rawCurrentBasketSize = currentBasket->GetBufferRef()->Length();
39     // rawCurrentBasketSize = currentBasket->GetObjlen();
40     //Long64_t altRawBasketSize = currentBasket->GetBufferRef()->Length();
41    
42     Long64_t totBytes = branch->GetTotBytes();
43     //Long64_t totBytes = branch->GetTotBytes() + altRawBasketSize;
44     TObjArray *subBranches = branch->GetListOfBranches();
45     for (UInt_t i = 0; i<subBranches->GetEntries(); ++i) {
46     TBranch *subBranch = (TBranch*)subBranches->At(i);
47     totBytes += RawBytes(subBranch, recursion+1);
48     }
49     return totBytes;
50     }
51    
52     Long64_t ZipBytes(TBranch* branch, Double_t ratio, UInt_t recursion=0) {
53    
54     Long64_t zipBytes = branch->GetZipBytes();
55    
56    
57    
58     TBasket* currentBasket = branch->GetBasket(branch->GetReadBasket());
59     currentBasket->SetWriteMode();
60     branch->WriteBasket(currentBasket);
61     //Long64_t zipBasketSize = currentBasket->GetNbytes();
62    
63     //printf("Simple basket raw size = %i\n", rawCurrentBasketSize);
64     //printf("objlen basket raw size = %i\n", altRawBasketSize);
65    
66     // Int_t basketSize = branch->GetBasketSize();
67    
68     //Long64_t basketZipEstimate = TMath::Min(((Double_t)rawCurrentBasketSize)/ratio, (Double_t)basketSize);
69     //printf("basket zip estimate = %i\n",basketZipEstimate);
70    
71     Long64_t totBytes = branch->GetZipBytes();
72     //Long64_t totBytes = branch->GetZipBytes() + altRawBasketSize;
73     TObjArray *subBranches = branch->GetListOfBranches();
74     for (UInt_t i = 0; i<subBranches->GetEntries(); ++i) {
75     TBranch *subBranch = (TBranch*)subBranches->At(i);
76     totBytes += ZipBytes(subBranch, ratio, recursion+1);
77     }
78     return totBytes;
79     }
80    
81     Long64_t TotSize(TBranch* branch) {
82     Long64_t totBytes = branch->GetTotalSize();
83     TObjArray *subBranches = branch->GetListOfBranches();
84     for (UInt_t i = 0; i<subBranches->GetEntries(); ++i) {
85     TBranch *subBranch = (TBranch*)subBranches->At(i);
86     //totBytes += TotSize(subBranch);
87     }
88     return totBytes;
89     }
90    
91    
92     void AppendPrefix(TBranch* branch, std::string prefix) {
93     //branch->GetTree()->SetBranchStatus(branch->GetName(),1);
94     //branch->ResetBit(kDoNotProcess);
95     std::string name = prefix + branch->GetName();
96     branch->SetName(name.c_str());
97     TObjArray *subBranches = branch->GetListOfBranches();
98     for (UInt_t i = 0; i<subBranches->GetEntries(); ++i) {
99     TBranch *subBranch = (TBranch*)subBranches->At(i);
100     AppendPrefix(subBranch, prefix);
101     }
102    
103     return;
104    
105     }
106    
107     void treeSizeVal(const char *file = "/server/02a/bendavid/OAK/XX-MITDATASET-XX_000.root")
108     {
109     using namespace mithep;
110     gDebugMask = Debug::kAnalysis;
111     gDebugLevel = 1;
112    
113     TFile *infile = new TFile(file,"READ");
114     //TFile *tmpfile = new TFile("/tmp/bendavid/tmpfile.root","RECREATE");
115    
116     TTree *events = (TTree*)infile->Get("Events");
117     TTree *runs = (TTree*)infile->Get("Runs");
118     TTree *fwMetaData = (TTree*)infile->Get("FWMetaData");
119    
120     //TPie fileRaw, fileZip;
121    
122     const char **treeLabels = new const char*[3];
123     treeLabels[0] = "Events";
124     treeLabels[1] = "Runs";
125     treeLabels[2] = "FWMetaData";
126    
127     Double_t rawTreeSizes[] = { events->GetTotBytes(), runs->GetTotBytes(), fwMetaData->GetTotBytes() };
128     Double_t zipTreeSizes[] = { events->GetZipBytes(), runs->GetZipBytes(), fwMetaData->GetZipBytes() };
129    
130     TPie *fileRaw = new TPie("fileRaw", "Top Level Tree Sizes - Raw", 3, rawTreeSizes);
131     fileRaw->SetLabels(treeLabels);
132     new TCanvas();
133     fileRaw->Draw("3d");
134    
135     TPie *fileZip = new TPie("fileZip", "Top Level Tree Sizes - Compressed", 3, zipTreeSizes);
136     fileZip->SetLabels(treeLabels);
137     new TCanvas();
138     fileZip->Draw("3d");
139    
140     Long64_t eventsRawSize = events->GetTotBytes();
141     Long64_t eventsZipSize = events->GetZipBytes();
142    
143     Double_t eventsCompression = (Double_t)eventsRawSize/eventsZipSize;
144    
145     infile->Cp(file, "tmpFile.root");
146     infile->Close();
147     TFile *tmpfile = new TFile("tmpFile.root","UPDATE");
148    
149     events = (TTree*)tmpfile->Get("Events");
150    
151     TObjArray *evtBranches = events->GetListOfBranches();
152     UInt_t nBranches = evtBranches->GetEntries();
153     UInt_t nEvents = events->GetEntries();
154    
155     Double_t *rawBranchSizes = new Double_t[nBranches];
156     Double_t *zipBranchSizes = new Double_t[nBranches];
157     const char **branchLabels = new const char*[nBranches];
158    
159     Double_t *rawDataBranchSizes = new Double_t[nBranches];
160     Double_t *zipDataBranchSizes = new Double_t[nBranches];
161    
162    
163    
164    
165    
166    
167    
168    
169     Long64_t rawTotal = 0;
170     Long64_t zipTotal = 0;
171    
172     Long64_t zipDataTotal=0;
173    
174     for (UInt_t i=0; i<nBranches; ++i) {
175    
176    
177     TBranch* branch = (TBranch*)evtBranches->At(i);
178     // events->SetBranchStatus("*",0);
179     // const char* branchName = branch->GetName();
180     // std::string prefix = branchName;
181     // prefix += "-SpaceVal-";
182     // AppendPrefix(branch,prefix);
183     //
184     // std::string branchSearch = prefix + "*";
185     // events->SetBranchStatus(branchSearch.c_str(),1);
186    
187     //TFile *tmpFile = new TFile("tmpFile.root","RECREATE");
188    
189     //branch->SetFile(tmpFile);
190    
191     //TBasket* basket = branch->GetBasket(branch->GetReadBasket());
192    
193     //basket->SetWriteMode();
194     // basket->WriteBuffer();
195    
196     //basket->WriteFile(1, tmpFile);
197    
198     // branch->Print();
199    
200     // tmpFile->Close();
201    
202     //TTree *eventSubset = events->CloneTree();
203     //TTree *eventSubset = events;
204    
205     //tmpFile->Write();
206     //tmpFile->Close();
207     // eventSubset->Write();
208     // eventSubset->Print();
209    
210     //Long64_t branchSizeRaw = eventSubset->GetTotBytes();
211     // Long64_t branchSizeZip = eventSubset->GetTotBytes();
212    
213    
214    
215     //Long64_t branchSizeTotal = TotSize(branch);
216    
217     Long64_t branchSizeZip = ZipBytes(branch, eventsCompression);
218     Long64_t branchSizeRaw = RawBytes(branch);
219    
220     rawTotal += branchSizeRaw;
221     zipTotal += branchSizeZip;
222    
223    
224     printf("%s BranchSizeRaw = %i\n",branch->GetName(),branchSizeRaw);
225     printf("%s BranchSizeZip = %i\n",branch->GetName(),branchSizeZip);
226     // //printf("%s BranchSizeZipSimple = %i\n",branch->GetName(),branchSizeZipSimple);
227     // printf("%s BranchSizeTotal = %i\n",branch->GetName(),branchSizeTotal);
228     rawBranchSizes[i] = (Double_t)branchSizeRaw/nEvents/1024.0;
229     zipBranchSizes[i] = (Double_t)branchSizeZip/nEvents/1024.0;
230     branchLabels[i] = branch->GetName();
231    
232     if (i!=1) {
233     rawDataBranchSizes[i] = (Double_t)branchSizeRaw/nEvents/1024.0;
234     zipDataBranchSizes[i] = (Double_t)branchSizeZip/nEvents/1024.0;
235     zipDataTotal+=branchSizeZip;
236    
237     }
238    
239    
240     //tmpFile->Close();
241    
242     }
243    
244     printf("Event Size Raw = %i\n" , eventsRawSize);
245     printf("Total Raw Size = %i\n", rawTotal);
246    
247     printf("Event Size Zip = %i\n" , eventsZipSize);
248     printf("Total Zip Size = %i\n", zipTotal);
249    
250     Double_t avgEvent = (Double_t)zipTotal/nEvents/1024.0;
251     printf("Average Event Size = %f kBytes\n",avgEvent);
252    
253     Double_t avgDataEvent = (Double_t)zipDataTotal/nEvents/1024.0;
254     printf("Average Event Size (data) = %f kBytes\n",avgDataEvent);
255    
256    
257     TPie *branchRaw = new TPie("branchRaw", "Event Branch Sizes - Raw", nBranches, rawBranchSizes);
258     branchRaw->SetLabels(branchLabels);
259     new TCanvas();
260     branchRaw->Draw("3d");
261    
262     TPie *branchZip = new TPie("branchZip", "Event Branch Sizes - Zip", nBranches, zipBranchSizes);
263     branchZip->SetLabels(branchLabels);
264     branchZip->SetLabelsOffset(0.1);
265     branchZip->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
266     new TCanvas();
267     branchZip->Draw("3dr");
268    
269     TPie *branchDataRaw = new TPie("branchDataRaw", "Event Branch Sizes - Raw", nBranches, rawDataBranchSizes);
270     branchDataRaw->SetLabels(branchLabels);
271    
272     new TCanvas();
273     branchDataRaw->Draw("3d");
274    
275     TPie *branchDataZip = new TPie("branchDataZip", "Event Branch Sizes - Zip", nBranches, zipDataBranchSizes);
276     branchDataZip->SetLabels(branchLabels);
277     branchDataZip->SetLabelsOffset(0.1);
278     branchDataZip->SetLabelFormat("#splitline{%val (%perc)}{%txt}");
279    
280     new TCanvas();
281     branchDataZip->Draw("3dr");
282    
283     //tmpfile->Close();
284    
285     }