ndmspc 0.20240624.0
Loading...
Searching...
No Matches
ndh-stress.cxx
1#include <TFile.h>
2#include <TH2.h>
3#include "HnSparse.h"
4#include "HnSparseStress.h"
5#include "ndmspc.h"
6
7int main(int argc, char ** argv)
8{
9 Printf("%s v%d.%d.%d-%s", NDMSPC_NAME, NDMSPC_VERSION_MAJOR(NDMSPC_VERSION), NDMSPC_VERSION_MINOR(NDMSPC_VERSION),
10 NDMSPC_VERSION_PATCH(NDMSPC_VERSION), NDMSPC_VERSION_RELEASE);
11
12 Long64_t size = 1e5;
13 bool bytes = false;
14 std::string filename = "/tmp/HnSparse.root";
15 bool projections = false;
16
17 int nDim = 10;
18 int nBins = 1000;
19 double min = -nBins / 2;
20 double max = nBins / 2;
21 Long64_t chunkSize = 1024 * 1024;
22
23 Int_t bins[nDim];
24 Double_t mins[nDim];
25 Double_t maxs[nDim];
26 for (Int_t i = 0; i < nDim; i++) {
27 bins[i] = nBins;
28 mins[i] = min;
29 maxs[i] = max;
30 }
31
32 NDH::HnSparseD * h = new NDH::HnSparseD("hNStress", "hNStress", nDim, bins, mins, maxs, chunkSize);
33
35
36 TStopwatch timeStress;
37 timeStress.Start();
38 stress.Stress(h, size, bytes);
39 timeStress.Stop();
40 timeStress.Print("m");
41 h->Print();
42 Long64_t nBinsSizeBytes = sizeof(Double_t) * h->GetNbins();
43 Printf("size : %03.2f MB (%lld B)", (double)nBinsSizeBytes / (1024 * 1024), nBinsSizeBytes);
44
45 TStopwatch timeWrite;
46 timeWrite.Start();
47 TFile * f = TFile::Open(filename.data(), "RECREATE");
48 f->SetCompressionSettings(ROOT::RCompressionSetting::EDefaults::kUseAnalysis);
49 Printf("Writing histogram ...");
50 h->Write();
51 if (projections) {
52 Printf("Creating and writing projections ...");
53 for (Int_t i = 0; i < nDim; i++) {
54 ((TH1 *)h->Projection(i))->Write();
55 for (Int_t j = 0; j < nDim; j++) {
56 if (i == j) continue;
57 ((TH2 *)h->Projection(j, i))->Write();
58 }
59 }
60 }
61 f->Close();
62 timeWrite.Stop();
63 timeWrite.Print("m");
64 Printf("Output was saved in '%s' size : %.2f MB (%lld B)", filename.data(),
65 (double)f->GetBytesWritten() / (1024 * 1024), f->GetBytesWritten());
66
67 return 0;
68}
HnSparseStress object.
virtual Bool_t Stress(HnSparse *h, Long64_t size=1e3, bool bytes=false)