]>
Commit | Line | Data |
---|---|---|
457c0713 | 1 | /// \file MakeTreeStat.C |
2 | /// | |
3 | /// Macro to get the size of the Tree | |
4 | /// As a improvment to tree->Print() function, this algorithm | |
5 | /// gives the size of all of the branchces and in addition print them | |
6 | /// sorted according total tree size (MEMORY USAGE if one event in tree) | |
7 | /// or zip size (THE storage size on disk) | |
8 | /// | |
9 | /// Printed statistic: | |
10 | /// 1. Order | |
11 | /// 2. TotSize (in memory) + fraction of total size | |
12 | /// 3. ZipSize (in memory) + fraction of zip size | |
13 | /// 4. Compression ratio | |
14 | /// | |
15 | /// Usage: | |
16 | /// | |
17 | /// 1. Enable macro | |
18 | /// | |
19 | /// ~~~ | |
20 | /// .L $ALICE_ROOT/TPC/macros/MakeTreeStat.C+ | |
21 | /// ~~~ | |
22 | /// | |
23 | /// 2. Open the tree (eg.) | |
24 | /// | |
25 | /// ~~~{.cpp} | |
26 | /// TFile f("AliESDs.root"); | |
27 | /// TTree * tree = (TTree*)f.Get("esdTree"); | |
28 | /// ~~~ | |
29 | /// | |
30 | /// 3. Print statistic (sorting according secon argument - either zip Bytes (kTRUE or TotSize (kFALSE) | |
31 | /// | |
32 | /// ~~~{.cpp} | |
33 | /// MakeStat(tree, kTRUE); | |
34 | /// ~~~ | |
35 | /// | |
36 | /// \author M.Ivanov, GSI, m.ivanov@gsi.de | |
79661724 | 37 | |
79661724 | 38 | |
39 | ||
40 | ||
41 | ||
42 | ||
43 | ||
44 | #include "TFile.h" | |
45 | #include "TTree.h" | |
46 | #include "TBranch.h" | |
47 | #include "TMath.h" | |
48 | #include "TArrayF.h" | |
49 | #include "TObjArray.h" | |
50 | #include "TObjString.h" | |
51 | ||
52 | ||
53 | ||
54 | ||
79661724 | 55 | TTree *fTree; // tree of interest |
56 | TObjArray aReport; // array with branch statistic | |
57 | TArrayF totSize; // total size for branch | |
58 | TArrayF zipSize; // zip Size for branch | |
59 | TArrayF zipRatio; // zip Ratio for branch | |
60 | ||
61 | void MakeStat(TTree *tree, Bool_t zipSort); | |
62 | ||
63 | ||
64 | ||
65 | void PrintSorted(Bool_t zipSort){ | |
457c0713 | 66 | /// print statistic |
67 | ||
79661724 | 68 | Int_t entries = aReport.GetEntries(); |
69 | Int_t* indexes = new Int_t[entries]; | |
70 | if (zipSort) TMath::Sort(entries,zipSize.GetArray(),indexes,kTRUE); | |
71 | else{ | |
72 | TMath::Sort(entries,totSize.GetArray(),indexes,kTRUE); | |
73 | } | |
af2fa8a2 | 74 | Float_t zipBytes = zipSize[indexes[0]]; |
75 | Float_t totBytes = totSize[indexes[0]]; | |
79661724 | 76 | Float_t ratioT = 100.*zipBytes/totBytes; |
77 | for (Int_t i=entries-1; i>=0; i--){ | |
78 | Int_t ib = indexes[i]; | |
79 | Float_t ratio0= 100.*totSize[ib]/totBytes; | |
80 | Float_t ratio1= 100.*zipSize[ib]/zipBytes; | |
2c32afa0 | 81 | if (i==0) { |
79661724 | 82 | printf("\n------------------------------------------------------------\n"); |
2c32afa0 | 83 | printf("%d \t\t%5.f(%.2f\%) \t\t%5.f(%.2f\%) \t%.2f \t%s\n",i, |
84 | totSize[ib],100., zipSize[ib],100., 100.*zipRatio[ib], aReport.At(ib)->GetName()); | |
85 | }else{ | |
79661724 | 86 | printf("%d \t\t%5.f(%.2f\%) \t\t%5.f(%.2f\%) \t%.2f \t%s\n",i, |
87 | totSize[ib],ratio0, zipSize[ib],ratio1, 100.*zipRatio[ib], aReport.At(ib)->GetName()); | |
2c32afa0 | 88 | } |
79661724 | 89 | } |
90 | ||
91 | ||
92 | } | |
93 | ||
94 | ||
af2fa8a2 | 95 | void AddToReport(const char *prefix,const char * name, Float_t size[2], Float_t ratio){ |
457c0713 | 96 | /// add branch info to array |
97 | ||
af2fa8a2 | 98 | char fullname[10000]; |
99 | sprintf(fullname,"%s.%s",prefix,name); | |
100 | aReport.AddLast(new TObjString(fullname)); | |
79661724 | 101 | Int_t entry = aReport.GetEntries(); |
102 | if (totSize.GetSize()<entry){ | |
103 | totSize.Set(entry*2); | |
104 | zipSize.Set(entry*2); | |
105 | zipRatio.Set(entry*2); | |
106 | } | |
107 | totSize[entry-1]=Float_t(size[0]); | |
108 | zipSize[entry-1]=Float_t(size[1]); | |
109 | zipRatio[entry-1]=Float_t(ratio); | |
110 | } | |
111 | ||
112 | ||
113 | ||
114 | ||
115 | ||
116 | void MakeStat(const char *prefix, TBranch * branch, Float_t* size, Float_t mratio); | |
117 | ||
118 | ||
119 | ||
120 | void MakeStat(TTree *tree, Bool_t zipSort){ | |
457c0713 | 121 | /// make recursve loop over tree branches |
122 | ||
79661724 | 123 | fTree= tree; |
124 | aReport.Clear(); | |
125 | TObjArray * array = tree->GetListOfBranches(); | |
126 | Float_t size[2]={0,0}; | |
127 | char * prefix =""; | |
128 | Float_t mratio=tree->GetZipBytes()/float(tree->GetTotBytes()); | |
129 | for (Int_t i=0; i<array->GetEntries(); i++){ | |
130 | MakeStat(prefix,(TBranch*)array->At(i),size, mratio); | |
131 | } | |
132 | Float_t ratio= (size[0]>0) ? size[1]/Float_t(size[0]): 0; | |
133 | // printf("Sum :\t%f\t%f\t%f\t%s.%s\t\n", float(size[0]), float(size[1]),ratio, prefix,tree->GetName()); | |
134 | ||
af2fa8a2 | 135 | AddToReport(prefix, tree->GetName(),size,ratio); |
79661724 | 136 | PrintSorted(zipSort); |
137 | } | |
138 | ||
139 | ||
140 | void MakeStat(const char *prefix, TBranch * branch, Float_t *size, Float_t mratio){ | |
457c0713 | 141 | /// Recursive function to get size of the branches |
142 | /// and ratios | |
143 | ||
79661724 | 144 | TObjArray * array = branch->GetListOfBranches(); |
145 | Float_t bsizeSum[2]={0,0}; | |
146 | ||
147 | if (!array || array->GetEntries()==0){ | |
148 | Float_t bsize[2] = {0,0}; | |
149 | bsize[0]=branch->GetTotalSize(); | |
150 | bsize[1]=branch->GetZipBytes(); | |
151 | if (bsize[1]>0){ | |
152 | Float_t ratio= (bsize[0]>0) ? bsize[1]/Float_t(bsize[0]): 0; | |
153 | // printf("Term:\t%f\t%f\t%f\t%s.%s\t\n",float(bsize[0]), float(bsize[1]),ratio, prefix,branch->GetName()); | |
af2fa8a2 | 154 | AddToReport(prefix, branch->GetName(),bsize,ratio); |
79661724 | 155 | //branch->Print(); |
156 | size[0]+=bsize[0]; | |
157 | size[1]+=bsize[1]; | |
158 | }else{ | |
159 | Float_t ratio= mratio; | |
160 | //printf("Ter?:\t%f\t%f\t%f\t%s.%s\t\n",float(bsize[0]), float(-1),ratio, prefix,branch->GetName()); | |
af2fa8a2 | 161 | AddToReport(prefix, branch->GetName(),bsize,ratio); |
79661724 | 162 | //branch->Print(); |
163 | size[0]+=bsize[0]; | |
164 | size[1]+=TMath::Nint(bsize[0]*mratio); | |
165 | } | |
166 | ||
167 | return; | |
168 | } | |
169 | for (Int_t i=0; i<array->GetEntries(); i++){ | |
170 | Float_t bsize[2] = {0,0}; | |
171 | TString str=prefix; | |
172 | str+= branch->GetName(); | |
173 | MakeStat(str.Data(),(TBranch*)array->At(i), bsize, mratio); | |
174 | bsizeSum[0]+=bsize[0]; | |
175 | bsizeSum[1]+=bsize[1]; | |
176 | size[0]+=bsize[0]; | |
177 | size[1]+=bsize[1]; | |
178 | } | |
179 | Float_t ratio= (size[0]>0) ? size[1]/Float_t(size[0]): 0; | |
180 | //printf("Sum :\t%f\t%f\t%f\t%s.%s\t\n", float(bsizeSum[0]), float(bsizeSum[1]),ratio, prefix,branch->GetName()); | |
af2fa8a2 | 181 | AddToReport(prefix,branch->GetName(),bsizeSum,ratio); |
79661724 | 182 | } |