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