ndmspc 0.20250304.0
Loading...
Searching...
No Matches
ndh-gen.cxx
1#include <getopt.h>
2#include <TFile.h>
3#include <TH2.h>
4#include "HnSparse.h"
5#include "HnSparseStress.h"
6#include "ndmspc.h"
7
8void version()
9{
10 Printf("%s v%s-%s", NDMSPC_NAME, NDMSPC_VERSION, NDMSPC_VERSION_RELEASE);
11}
12
13[[noreturn]] void help(int rc = 0)
14{
15 version();
16 Printf("\nUsage: [OPTION]...");
17 Printf("\nOptions:");
18 Printf(" -d, --dimentsions[=VALUE] number of dimensions (default: 2)");
19 Printf(" -b, --bins[=VALUE] number of bins per axis (default: 5)");
20 Printf(" -f, --fill[=VALUE] fill size (default : 1e5)");
21 Printf(" -s, --start[=VALUE] start (default : 0)");
22 Printf(" -r, --reserve[=VALUE] reserve bins (default : 0 - nothing is reserved)");
23 Printf(" -p, --print-refresh[=VALUE] print refresh (default : 1)");
24 Printf(" -c, --chunk[=VALUE] chunk size (default : 1024*16)");
25 Printf(" -o, --output[=VALUE] output filename (default: \"\")");
26 Printf(" -z, --fill-random fill random");
27 Printf("\n -h, --help display this help and exit");
28 Printf(" -v, --version output version information and exit");
29 Printf(" -x, --debug[=VALUE] debug level");
30 Printf("\nExamples:");
31 Printf(" %s-gen -s 1e5", NDMSPC_NAME);
32 Printf(" Generate default histogram with 1e5 entries");
33 Printf("\nReport bugs at <https://gitlab.com/ndmspc/ndmspc>");
34 Printf("General help using GNU software: <https://www.gnu.org/gethelp/>");
35
36 exit(rc);
37}
38int main(int argc, char ** argv)
39{
40
41 // ***** Default values START *****
43 Int_t debug = 0;
44 Int_t nPrintRefresh = 1;
45 std::string filename = "";
46
47 int nDim = 2;
48 int nBins = 5;
49 Long64_t nFill = 1e5;
50 Long64_t startFill = 0;
51 std::string start_str;
52 Int_t chunkSize = 1024 * 16;
53 Long64_t nBinsReserved = 0;
54 bool fillRandom = false;
55 // ***** Default values END *****
56
57 std::string shortOpts = "hvzd:b:f:s:o:x:r:p:c:W;";
58 struct option longOpts[] = {{"help", no_argument, nullptr, 'h'},
59 {"version", no_argument, nullptr, 'v'},
60 {"dims", required_argument, nullptr, 'd'},
61 {"bins", required_argument, nullptr, 'b'},
62 {"fill", required_argument, nullptr, 'f'},
63 {"start", required_argument, nullptr, 's'},
64 {"fill-random", no_argument, nullptr, 'z'},
65 {"output", required_argument, nullptr, 'o'},
66 {"debug", required_argument, nullptr, 'x'},
67 {"reserve", required_argument, nullptr, 'r'},
68 {"print-refresh", required_argument, nullptr, 'p'},
69 {"chunk", required_argument, nullptr, 'c'},
70 {nullptr, 0, nullptr, 0}};
71
72 int nextOption = 0;
73 do {
74 nextOption = getopt_long(argc, argv, shortOpts.c_str(), longOpts, nullptr);
75 switch (nextOption) {
76 case -1:
77 case 0: break;
78 case 'h': help();
79 case 'v':
80 version();
81 exit(0);
82 break;
83 case 'd': nDim = atoi(optarg); break;
84 case 'b': nBins = atoi(optarg); break;
85 case 'f': nFill = (Long64_t)atof(optarg); break;
86 case 's': start_str = optarg; break;
87 case 'o': filename = optarg; break;
88 case 'x': debug = atoi(optarg); break;
89 case 'z': fillRandom = true; break;
90 case 'r': nBinsReserved = (Long64_t)atof(optarg); break;
91 case 'p': nPrintRefresh = (Int_t)atof(optarg); break;
92 case 'c': chunkSize = (Int_t)atof(optarg); break;
93 default: help(1);
94 }
95 } while (nextOption != -1);
96
97 // Handling start (supports 1x, 2x, ...)
98 if (!start_str.empty()) {
99 if (start_str[start_str.length() - 1] == 'x') {
100 start_str.pop_back();
101 startFill = (Long64_t)(atof(start_str.data()) * nFill);
102 }
103 else {
104 startFill = (Long64_t)atof(start_str.data());
105 }
106 }
107
108 version();
109
110 double min = -(Double_t)nBins / 2;
111 double max = (Double_t)nBins / 2;
112
113 Int_t bins[nDim];
114 Double_t mins[nDim];
115 Double_t maxs[nDim];
116 for (Int_t i = 0; i < nDim; i++) {
117 bins[i] = nBins;
118 mins[i] = min;
119 maxs[i] = max;
120 }
121
123 new Ndmspc::Ndh::HnSparseD("hTest", "Testing histogram", nDim, bins, mins, maxs, chunkSize);
124 if (nBinsReserved) h->ReserveBins(nBinsReserved);
126 stress.SetDebugLevel(debug);
127 stress.SetPrintRefresh(nPrintRefresh);
128 stress.SetRandomFill(fillRandom);
129 Printf("Starting to fill at %lld random=%d...", startFill, fillRandom);
130 if (!stress.Generate(h, nFill, startFill)) return 1;
131 h->Print();
132 Long64_t nBinsSizeBytes = sizeof(Double_t) * h->GetNbins();
133
134 if (!filename.empty()) {
135 Printf("Saving output to file '%s' ...", filename.data());
136 TFile * f = TFile::Open(filename.data(), "RECREATE");
137 h->Write();
138 Printf("Memory : %03.2f MB (%lld B) File: %03.2f MB (%lld B)", (double)nBinsSizeBytes / (1024 * 1024),
139 nBinsSizeBytes, (double)f->GetFileBytesWritten() / (1024 * 1024), f->GetFileBytesWritten());
140 f->Close();
141 }
142 else {
143 Printf("Memory : %03.2f MB (%lld B)", (double)nBinsSizeBytes / (1024 * 1024), nBinsSizeBytes);
144 }
145
146 return 0;
147}
HnSparseStress object.
void SetPrintRefresh(Int_t n)
Setting print refresh.
virtual Bool_t Generate(THnSparse *h, Long64_t size=1e3, Long64_t start=1e3)
void SetRandomFill(bool rf)
Setting fill random flag.
void SetDebugLevel(Int_t debug)
Setting debug level.
void ReserveBins(Long64_t nBins)
Definition HnSparse.cxx:145