ndh 0.0.7
Loading...
Searching...
No Matches
HnSparseStress.cc
1#include <TAxis.h>
2
3#include "ndh.hh"
4#include "HnSparse.hh"
5
6#include "HnSparseStress.hh"
7
9ClassImp(NDH::HnSparseStress);
11
12namespace NDH {
13
14HnSparseStress::HnSparseStress() : TObject() {}
15
16Bool_t HnSparseStress::Generate(THnSparse * h, Long64_t size, Long64_t start)
17{
21
22 if (h == nullptr) return kFALSE;
23
24 if (size == 0) fNFilledMax = kMaxLong64;
25
26 fNFilledMax = size;
27 if (fDebugLevel > 0)
28 Printf("dimensions=%d chunkSize=%d nFillMax=%lld start=%lld", h->GetNdimensions(), h->GetChunkSize(),
29 fNFilledMax, start);
30
31 Double_t cCenter[h->GetNdimensions()];
32 Int_t cStart[h->GetNdimensions()];
33
34 if (start > 0) {
35 Long64_t allBins = 1;
36 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
37
38 if (allBins > kMaxLong64 / h->GetAxis(i)->GetNbins()) {
39 Printf("Error: Product of all bins is higer then %lld !!! Do not use --start in this case !!!",
40 kMaxLong64);
41 return kFALSE;
42 }
43 allBins *= h->GetAxis(i)->GetNbins();
44 }
45 if (fDebugLevel > 0) Printf("MaxNumberOfBins=%lld", allBins);
46
47 Long64_t startIndex = start;
48 Int_t bx = 0;
49 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
50 allBins /= h->GetAxis(i)->GetNbins();
51
52 bx = startIndex / allBins;
53 startIndex -= (bx * allBins);
54 cStart[i] = bx;
55 if (fDebugLevel > 0)
56 Printf("i=%d x=%d startIndex=%lld allBins=%lld cStart[%d]=%d", i, bx, startIndex, allBins, i,
57 cStart[i]);
58 }
59
60 if (fDebugLevel > 0)
61 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
62 Printf("i=%d %d", i, cStart[i]);
63 }
64 }
65 else {
66 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
67 cStart[i] = 0;
68 }
69 }
70
71 fTimerTotal.Start();
72 fTimer.Start();
73 Printf("fNFilledMax=%lld filled=%d", fNFilledMax, h->GetNbins());
74 GenerateRecursiveLoop(h, h->GetNdimensions() - 1, cCenter, cStart);
75 fTimer.Stop();
76 fTimerTotal.Stop();
77 fTimerTotal.Print("m");
78
79 return kTRUE;
80}
81
82bool HnSparseStress::GenerateRecursiveLoop(THnSparse * h, Int_t iDim, Double_t * coord, Int_t * start)
83{
87
88 if (iDim < 0) return true;
89 for (Int_t iBin = start[iDim] + 1; iBin <= h->GetAxis(iDim)->GetNbins(); iBin++) {
90 coord[iDim] = h->GetAxis(iDim)->GetBinCenter(iBin);
91 if (fDebugLevel > 1) Printf("iDim=%d iBin=%d center=%f", iDim, iBin, coord[iDim]);
92
93 if (iDim == 0) {
94 h->Fill(coord);
95 Long64_t filled = h->GetNbins();
96 if (fPrintRefresh > 0 && filled % fPrintRefresh == 0)
97 PrintBin(h->GetNdimensions(), coord,
98 TString::Format("%03.2f MB filled=%lld [chunkSize=%lld nChunks=%d]",
99 sizeof(Double_t) * (Double_t)filled / (1024 * 1024), filled, h->GetChunkSize(),
100 h->GetNChunks())
101 .Data());
102 if (fNFilledMax > 0 && filled >= fNFilledMax) return true;
103 }
104 else {
105 if (fDebugLevel > 1) Printf("iDim=%d", iDim);
106 coord[iDim] = h->GetAxis(iDim)->GetBinCenter(iBin);
107 bool finished = GenerateRecursiveLoop(h, iDim - 1, coord, start);
108 if (finished) return true;
109 }
110
111 if (iBin == h->GetAxis(iDim)->GetNbins()) start[iDim] = 0;
112 }
113
114 return false;
115}
116
117bool HnSparseStress::StressRecursiveLoop(HnSparse * h, Int_t & iDim, Int_t * coord)
118{
122
123 Long64_t nBinsSizeBytes = sizeof(Double_t) * h->GetNbins();
124 if (fNBytesMax > 0 && nBinsSizeBytes > fNBytesMax) return true;
125
126 if (iDim >= h->GetNdimensions()) return true;
127 if (coord[h->GetNdimensions() - 1] > h->GetAxis(h->GetNdimensions() - 1)->GetNbins()) {
128 return true;
129 }
130
131 if (nBinsSizeBytes > 0 && nBinsSizeBytes % (10 * 1024 * 1024) == 0) {
132 Printf("%03.2f MB [chunks=%d binsFilled=%lld]", (Double_t)nBinsSizeBytes / (1024 * 1024), h->GetNChunks(),
133 h->GetNbins());
134 fTimer.Stop();
135 fTimer.Print("m");
136 fTimer.Reset();
137 fTimer.Start();
138 }
139
140 // Printf("iDim=%d nBins=%d", iDim, GetAxis(iDim)->GetNbins());
141 if (coord[iDim] < h->GetAxis(iDim)->GetNbins()) {
142 coord[iDim]++;
143 coord[iDim - 1] = 0;
144 iDim = 0;
145 return false;
146 }
147
148 return StressRecursiveLoop(h, ++iDim, coord);
149}
150Bool_t HnSparseStress::Stress(HnSparse * h, Long64_t size, bool bytes)
151{
155
156 if (h == nullptr) return kFALSE;
157
158 Long64_t nFill = size;
159 if (bytes) {
160 fNBytesMax = size;
161 nFill = kMaxLong64;
162 }
163 Printf("dimensions=%d chunkSize=%d nFill=%lld maxSize=%lld", h->GetNdimensions(), h->GetChunkSize(), nFill,
164 fNBytesMax);
165
166 Int_t c[h->GetNdimensions()];
167 Double_t cCenter[h->GetNdimensions()];
168 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
169 c[i] = 100;
170 }
171
172 fTimerTotal.Start();
173 fTimer.Start();
174 Bool_t finish = kFALSE;
175 Int_t dim;
176 for (Long64_t iFill = 0; iFill < nFill; ++iFill) {
177 dim = 0;
178 finish = StressRecursiveLoop(h, dim, c);
179 if (finish) break;
180
181 PrintBin(h->GetNdimensions(), cCenter, "Hello");
182 h->GetBin(cCenter);
183 }
184 fTimer.Stop();
185 fTimerTotal.Stop();
186 fTimerTotal.Print("m");
187
188 return kTRUE;
189}
190void HnSparseStress::PrintBin(Int_t n, Double_t * c, const char * msg)
191{
195
196 std::string s = "[";
197 for (Int_t i = 0; i < n; ++i) {
198 s.append(TString::Format("%.3f,", c[i]).Data());
199 }
200 s.resize(s.size() - 1);
201 s.append("] : ");
202 s.append(msg);
203
204 Printf("%s", s.data());
205}
206
207} // namespace NDH
HnSparseStress object.
HnSparse object.
Definition HnSparse.hh:18