1 |
loizides |
1.2 |
// $Id: treeSizeVal.C,v 1.1 2008/09/17 12:48:38 bendavid Exp $
|
2 |
bendavid |
1.1 |
|
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 |
loizides |
1.2 |
Long64_t RawBytes(TBranch* branch, UInt_t recursion=0)
|
21 |
|
|
{
|
22 |
bendavid |
1.1 |
Long64_t totBytes = branch->GetTotBytes();
|
23 |
|
|
//Long64_t totBytes = branch->GetTotBytes() + altRawBasketSize;
|
24 |
|
|
TObjArray *subBranches = branch->GetListOfBranches();
|
25 |
loizides |
1.2 |
for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
|
26 |
bendavid |
1.1 |
TBranch *subBranch = (TBranch*)subBranches->At(i);
|
27 |
|
|
totBytes += RawBytes(subBranch, recursion+1);
|
28 |
|
|
}
|
29 |
|
|
return totBytes;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
loizides |
1.2 |
Long64_t ZipBytes(TBranch* branch, Double_t ratio, UInt_t recursion=0)
|
33 |
|
|
{
|
34 |
bendavid |
1.1 |
TBasket* currentBasket = branch->GetBasket(branch->GetReadBasket());
|
35 |
|
|
currentBasket->SetWriteMode();
|
36 |
loizides |
1.2 |
branch->WriteBasket(currentBasket,0);
|
37 |
bendavid |
1.1 |
|
38 |
|
|
Long64_t totBytes = branch->GetZipBytes();
|
39 |
|
|
//Long64_t totBytes = branch->GetZipBytes() + altRawBasketSize;
|
40 |
|
|
TObjArray *subBranches = branch->GetListOfBranches();
|
41 |
loizides |
1.2 |
for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
|
42 |
bendavid |
1.1 |
TBranch *subBranch = (TBranch*)subBranches->At(i);
|
43 |
|
|
totBytes += ZipBytes(subBranch, ratio, recursion+1);
|
44 |
|
|
}
|
45 |
|
|
return totBytes;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
loizides |
1.2 |
Long64_t TotSize(TBranch* branch)
|
49 |
|
|
{
|
50 |
bendavid |
1.1 |
Long64_t totBytes = branch->GetTotalSize();
|
51 |
|
|
TObjArray *subBranches = branch->GetListOfBranches();
|
52 |
loizides |
1.2 |
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 |
bendavid |
1.1 |
}
|
58 |
|
|
return totBytes;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
|
62 |
loizides |
1.2 |
void AppendPrefix(TBranch* branch, std::string prefix)
|
63 |
|
|
{
|
64 |
bendavid |
1.1 |
std::string name = prefix + branch->GetName();
|
65 |
|
|
branch->SetName(name.c_str());
|
66 |
|
|
TObjArray *subBranches = branch->GetListOfBranches();
|
67 |
loizides |
1.2 |
for (Int_t i = 0; i<subBranches->GetEntries(); ++i) {
|
68 |
bendavid |
1.1 |
TBranch *subBranch = (TBranch*)subBranches->At(i);
|
69 |
|
|
AppendPrefix(subBranch, prefix);
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
loizides |
1.2 |
void treeSizeVal(const char *file)
|
74 |
bendavid |
1.1 |
{
|
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 |
loizides |
1.2 |
Long64_t branchSizeZip = ZipBytes(branch, eventsCompression);
|
137 |
|
|
Long64_t branchSizeRaw = RawBytes(branch);
|
138 |
bendavid |
1.1 |
|
139 |
|
|
rawTotal += branchSizeRaw;
|
140 |
|
|
zipTotal += branchSizeZip;
|
141 |
|
|
|
142 |
loizides |
1.2 |
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 |
bendavid |
1.1 |
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 |
loizides |
1.2 |
rawDataBranchSizes[i] = (Double_t)branchSizeRaw/nEvents/1024.0;
|
152 |
|
|
zipDataBranchSizes[i] = (Double_t)branchSizeZip/nEvents/1024.0;
|
153 |
|
|
zipDataTotal+=branchSizeZip;
|
154 |
bendavid |
1.1 |
}
|
155 |
|
|
}
|
156 |
|
|
|
157 |
loizides |
1.2 |
printf("Event Size Raw = %lld\n", eventsRawSize);
|
158 |
|
|
printf("Total Raw Size = %lld\n", rawTotal);
|
159 |
bendavid |
1.1 |
|
160 |
loizides |
1.2 |
printf("Event Size Zip = %lld\n", eventsZipSize);
|
161 |
|
|
printf("Total Zip Size = %lld\n", zipTotal);
|
162 |
bendavid |
1.1 |
|
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 |
|
|
}
|