5 #include "HnSparseStress.h"
14 HnSparseStress::HnSparseStress() : TObject() {}
16 Bool_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(), fNFilledMax,
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 !!!", kMaxLong64);
42 allBins *= h->GetAxis(i)->GetNbins();
44 if (fDebugLevel > 0) Printf(
"MaxNumberOfBins=%lld", allBins);
46 Long64_t startIndex = start;
48 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
49 allBins /= h->GetAxis(i)->GetNbins();
51 bx = startIndex / allBins;
52 startIndex -= (bx * allBins);
55 Printf(
"i=%d x=%d startIndex=%lld allBins=%lld cStart[%d]=%d", i, bx, startIndex, allBins, i, cStart[i]);
59 for (Int_t i = h->GetNdimensions() - 1; i >= 0; --i) {
60 Printf(
"i=%d %d", i, cStart[i]);
64 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
71 Printf(
"fNFilledMax=%lld filled=%lld", fNFilledMax, h->GetNbins());
72 GenerateRecursiveLoop(h, h->GetNdimensions() - 1, cCenter, cStart);
75 fTimerTotal.Print(
"m");
80 bool HnSparseStress::GenerateRecursiveLoop(THnSparse * h, Int_t iDim, Double_t * coord, Int_t * start)
86 if (iDim < 0)
return true;
87 for (Int_t iBin = start[iDim] + 1; iBin <= h->GetAxis(iDim)->GetNbins(); iBin++) {
88 coord[iDim] = h->GetAxis(iDim)->GetBinCenter(iBin);
89 if (fDebugLevel > 1) Printf(
"iDim=%d iBin=%d center=%f", iDim, iBin, coord[iDim]);
93 for (Int_t iAxis = 0; iAxis < h->GetNdimensions(); iAxis++) {
94 coord[iAxis] = gRandom->Uniform(h->GetAxis(iAxis)->GetXmin(), h->GetAxis(iAxis)->GetXmax());
98 Long64_t filled = h->GetNbins();
99 if (fPrintRefresh > 0 && filled % fPrintRefresh == 0)
100 PrintBin(h->GetNdimensions(), coord,
101 TString::Format(
"%03.2f MB filled=%e [chunkSize=%e nChunks=%d]",
102 sizeof(Double_t) * (Double_t)filled / (1024 * 1024), (Double_t)filled,
103 (Double_t)h->GetChunkSize(), h->GetNChunks())
105 if (fNFilledMax > 0 && filled >= fNFilledMax)
return true;
108 if (fDebugLevel > 1) Printf(
"iDim=%d", iDim);
109 coord[iDim] = h->GetAxis(iDim)->GetBinCenter(iBin);
110 bool finished = GenerateRecursiveLoop(h, iDim - 1, coord, start);
111 if (finished)
return true;
114 if (iBin == h->GetAxis(iDim)->GetNbins()) start[iDim] = 0;
120 bool HnSparseStress::StressRecursiveLoop(
HnSparse * h, Int_t & iDim, Int_t * coord)
126 Long64_t nBinsSizeBytes =
sizeof(Double_t) * h->GetNbins();
127 if (fNBytesMax > 0 && nBinsSizeBytes > fNBytesMax)
return true;
129 if (iDim >= h->GetNdimensions())
return true;
130 if (coord[h->GetNdimensions() - 1] > h->GetAxis(h->GetNdimensions() - 1)->GetNbins()) {
134 if (nBinsSizeBytes > 0 && nBinsSizeBytes % (10 * 1024 * 1024) == 0) {
135 Printf(
"%03.2f MB [chunks=%d binsFilled=%lld]", (Double_t)nBinsSizeBytes / (1024 * 1024), h->GetNChunks(),
144 if (coord[iDim] < h->GetAxis(iDim)->GetNbins()) {
151 return StressRecursiveLoop(h, ++iDim, coord);
153 Bool_t HnSparseStress::Stress(
HnSparse * h, Long64_t size,
bool bytes)
159 if (h ==
nullptr)
return kFALSE;
161 Long64_t nFill = size;
166 Printf(
"dimensions=%d chunkSize=%d nFill=%lld maxSize=%lld", h->GetNdimensions(), h->GetChunkSize(), nFill,
169 Int_t c[h->GetNdimensions()];
170 Double_t cCenter[h->GetNdimensions()];
171 for (Int_t i = 0; i < h->GetNdimensions(); ++i) {
177 Bool_t finish = kFALSE;
179 for (Long64_t iFill = 0; iFill < nFill; ++iFill) {
181 finish = StressRecursiveLoop(h, dim, c);
184 PrintBin(h->GetNdimensions(), cCenter,
"Hello");
189 fTimerTotal.Print(
"m");
193 void HnSparseStress::PrintBin(Int_t n, Double_t * c,
const char * msg)
200 for (Int_t i = 0; i < n; ++i) {
201 s.append(TString::Format(
"%.3f,", c[i]).Data());
203 s.resize(s.size() - 1);
207 Printf(
"%s", s.data());