7 #include "HnSparseStress.h"
15 HnSparseStress::HnSparseStress() : TObject() {}
17 Bool_t HnSparseStress::Generate(THnSparse * h, Long64_t size, Long64_t start)
23 if (h ==
nullptr)
return kFALSE;
25 if (size == 0) fNFilledMax = kMaxLong64;
29 Printf(
"dimensions=%d chunkSize=%d nFillMax=%lld start=%lld", h->GetNdimensions(), h->GetChunkSize(),
32 Double_t cCenter[h->GetNdimensions()];
33 Int_t cStart[h->GetNdimensions()];
37 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
39 if (allBins > kMaxLong64 / h->GetAxis(i)->GetNbins()) {
40 Printf(
"Error: Product of all bins is higer then %lld !!! Do not use --start in this case !!!",
44 allBins *= h->GetAxis(i)->GetNbins();
46 if (fDebugLevel > 0) Printf(
"MaxNumberOfBins=%lld", allBins);
48 Long64_t startIndex = start;
50 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
51 allBins /= h->GetAxis(i)->GetNbins();
53 bx = startIndex / allBins;
54 startIndex -= (bx * allBins);
57 Printf(
"i=%d x=%d startIndex=%lld allBins=%lld cStart[%d]=%d", i, bx, startIndex, allBins, i,
62 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
63 Printf(
"i=%d %d", i, cStart[i]);
67 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
74 Printf(
"fNFilledMax=%lld filled=%lld", fNFilledMax, h->GetNbins());
75 GenerateRecursiveLoop(h, h->GetNdimensions() - 1, cCenter, cStart);
78 fTimerTotal.Print(
"m");
83 bool HnSparseStress::GenerateRecursiveLoop(THnSparse * h, Int_t iDim, Double_t * coord, Int_t * start)
89 if (iDim < 0)
return true;
90 for (Int_t iBin = start[iDim] + 1; iBin <= h->GetAxis(iDim)->GetNbins(); iBin++) {
91 coord[iDim] = h->GetAxis(iDim)->GetBinCenter(iBin);
92 if (fDebugLevel > 1) Printf(
"iDim=%d iBin=%d center=%f", iDim, iBin, coord[iDim]);
96 for (Int_t iAxis = 0; iAxis < h->GetNdimensions(); iAxis++) {
97 coord[iAxis] = gRandom->Uniform(h->GetAxis(iAxis)->GetXmin(), h->GetAxis(iAxis)->GetXmax());
101 Long64_t filled = h->GetNbins();
102 if (fPrintRefresh > 0 && filled % fPrintRefresh == 0)
103 PrintBin(h->GetNdimensions(), coord,
104 TString::Format(
"%03.2f MB filled=%e [chunkSize=%e nChunks=%d]",
105 sizeof(Double_t) * (Double_t)filled / (1024 * 1024), (Double_t)filled,
106 (Double_t)h->GetChunkSize(), h->GetNChunks())
108 if (fNFilledMax > 0 && filled >= fNFilledMax)
return true;
111 if (fDebugLevel > 1) Printf(
"iDim=%d", iDim);
112 coord[iDim] = h->GetAxis(iDim)->GetBinCenter(iBin);
113 bool finished = GenerateRecursiveLoop(h, iDim - 1, coord, start);
114 if (finished)
return true;
117 if (iBin == h->GetAxis(iDim)->GetNbins()) start[iDim] = 0;
123 bool HnSparseStress::StressRecursiveLoop(
HnSparse * h, Int_t & iDim, Int_t * coord)
129 Long64_t nBinsSizeBytes =
sizeof(Double_t) * h->GetNbins();
130 if (fNBytesMax > 0 && nBinsSizeBytes > fNBytesMax)
return true;
132 if (iDim >= h->GetNdimensions())
return true;
133 if (coord[h->GetNdimensions() - 1] > h->GetAxis(h->GetNdimensions() - 1)->GetNbins()) {
137 if (nBinsSizeBytes > 0 && nBinsSizeBytes % (10 * 1024 * 1024) == 0) {
138 Printf(
"%03.2f MB [chunks=%d binsFilled=%lld]", (Double_t)nBinsSizeBytes / (1024 * 1024), h->GetNChunks(),
147 if (coord[iDim] < h->GetAxis(iDim)->GetNbins()) {
154 return StressRecursiveLoop(h, ++iDim, coord);
156 Bool_t HnSparseStress::Stress(
HnSparse * h, Long64_t size,
bool bytes)
162 if (h ==
nullptr)
return kFALSE;
164 Long64_t nFill = size;
169 Printf(
"dimensions=%d chunkSize=%d nFill=%lld maxSize=%lld", h->GetNdimensions(), h->GetChunkSize(), nFill,
172 Int_t c[h->GetNdimensions()];
173 Double_t cCenter[h->GetNdimensions()];
174 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
180 Bool_t finish = kFALSE;
182 for (Long64_t iFill = 0; iFill < nFill; ++iFill) {
184 finish = StressRecursiveLoop(h, dim, c);
187 PrintBin(h->GetNdimensions(), cCenter,
"Hello");
192 fTimerTotal.Print(
"m");
196 void HnSparseStress::PrintBin(Int_t n, Double_t * c,
const char * msg)
203 for (Int_t i = 0; i < n; ++i) {
204 s.append(TString::Format(
"%.3f,", c[i]).Data());
206 s.resize(s.size() - 1);
210 Printf(
"%s", s.data());