6#include "HnSparseStress.hh"
14HnSparseStress::HnSparseStress() : TObject() {}
16Bool_t HnSparseStress::Generate(THnSparse * h, Long64_t size, Long64_t start)
22 if (h ==
nullptr)
return kFALSE;
24 if (size == 0) fNFilledMax = kMaxLong64;
28 Printf(
"dimensions=%d chunkSize=%d nFillMax=%lld start=%lld", h->GetNdimensions(), h->GetChunkSize(),
31 Double_t cCenter[h->GetNdimensions()];
32 Int_t cStart[h->GetNdimensions()];
36 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
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 !!!",
43 allBins *= h->GetAxis(i)->GetNbins();
45 if (fDebugLevel > 0) Printf(
"MaxNumberOfBins=%lld", allBins);
47 Long64_t startIndex = start;
49 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
50 allBins /= h->GetAxis(i)->GetNbins();
52 bx = startIndex / allBins;
53 startIndex -= (bx * allBins);
56 Printf(
"i=%d x=%d startIndex=%lld allBins=%lld cStart[%d]=%d", i, bx, startIndex, allBins, i,
61 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
62 Printf(
"i=%d %d", i, cStart[i]);
66 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
73 Printf(
"fNFilledMax=%lld filled=%d", fNFilledMax, h->GetNbins());
74 GenerateRecursiveLoop(h, h->GetNdimensions() - 1, cCenter, cStart);
77 fTimerTotal.Print(
"m");
82bool HnSparseStress::GenerateRecursiveLoop(THnSparse * h, Int_t iDim, Double_t * coord, Int_t * start)
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]);
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(),
102 if (fNFilledMax > 0 && filled >= fNFilledMax)
return true;
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;
111 if (iBin == h->GetAxis(iDim)->GetNbins()) start[iDim] = 0;
117bool HnSparseStress::StressRecursiveLoop(
HnSparse * h, Int_t & iDim, Int_t * coord)
123 Long64_t nBinsSizeBytes =
sizeof(Double_t) * h->GetNbins();
124 if (fNBytesMax > 0 && nBinsSizeBytes > fNBytesMax)
return true;
126 if (iDim >= h->GetNdimensions())
return true;
127 if (coord[h->GetNdimensions() - 1] > h->GetAxis(h->GetNdimensions() - 1)->GetNbins()) {
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(),
141 if (coord[iDim] < h->GetAxis(iDim)->GetNbins()) {
148 return StressRecursiveLoop(h, ++iDim, coord);
150Bool_t HnSparseStress::Stress(
HnSparse * h, Long64_t size,
bool bytes)
156 if (h ==
nullptr)
return kFALSE;
158 Long64_t nFill = size;
163 Printf(
"dimensions=%d chunkSize=%d nFill=%lld maxSize=%lld", h->GetNdimensions(), h->GetChunkSize(), nFill,
166 Int_t c[h->GetNdimensions()];
167 Double_t cCenter[h->GetNdimensions()];
168 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
174 Bool_t finish = kFALSE;
176 for (Long64_t iFill = 0; iFill < nFill; ++iFill) {
178 finish = StressRecursiveLoop(h, dim, c);
181 PrintBin(h->GetNdimensions(), cCenter,
"Hello");
186 fTimerTotal.Print(
"m");
190void HnSparseStress::PrintBin(Int_t n, Double_t * c,
const char * msg)
197 for (Int_t i = 0; i < n; ++i) {
198 s.append(TString::Format(
"%.3f,", c[i]).Data());
200 s.resize(s.size() - 1);
204 Printf(
"%s", s.data());