7 #include <nlohmann/json.hpp>
12 using json = nlohmann::json;
16 Printf(
"%s v%d.%d.%d-%s", NDMSPC_NAME, NDMSPC_VERSION_MAJOR(NDMSPC_VERSION), NDMSPC_VERSION_MINOR(NDMSPC_VERSION),
17 NDMSPC_VERSION_PATCH(NDMSPC_VERSION), NDMSPC_VERSION_RELEASE);
20 [[noreturn]]
void help(
int rc = 0)
23 Printf(
"\nUsage: [OPTION]...");
25 Printf(
" -c, --config[=VALUE] ndh config file");
26 Printf(
"\n -h, --help display this help and exit");
27 Printf(
" -v, --version output version information and exit");
28 Printf(
"\nExamples:");
29 Printf(
" %s-import -c ndh.yaml", NDMSPC_NAME);
30 Printf(
" Using ndh.yaml config file");
31 Printf(
"\nReport bugs at <https://gitlab.com/ndmspc/ndmspc>");
32 Printf(
"General help using GNU software: <https://www.gnu.org/gethelp/>");
37 int main(
int argc,
char ** argv)
42 std::string configFile =
"";
43 std::string filename =
"";
44 std::string objname =
"";
45 std::vector<Int_t> axisSplit = {};
46 std::string outputFilename =
"";
49 config[
"input"][
"filename"] =
50 "root://eos.ndmspc.io//eos/ndmspc/scratch/alice.cern.ch/user/a/alitrain/PWGLF/LF_pp_AOD/"
51 "987/phi_leading_3s/AnalysisResults.root";
52 config[
"input"][
"objname"] =
"Unlike";
53 config[
"split"][
"axes"] = {1, 2};
54 config[
"output"][
"filename"] =
"/tmp/ndh.root";
58 std::string shortOpts =
"hvc:W;";
59 struct option longOpts[] = {{
"help", no_argument,
nullptr,
'h'},
60 {
"version", no_argument,
nullptr,
'v'},
61 {
"config", required_argument,
nullptr,
'c'},
62 {
nullptr, 0,
nullptr, 0}};
66 nextOption = getopt_long(argc, argv, shortOpts.c_str(), longOpts,
nullptr);
75 case 'c': configFile = optarg;
break;
78 }
while (nextOption != -1);
82 if (!configFile.empty()) {
83 Printf(
"Loading config file '%s' ...", configFile.data());
84 std::ifstream f(configFile);
86 Printf(
"Error: Cannot open config file '%s' !!!", configFile.data());
88 json cfgJson = json::parse(f);
89 config.merge_patch(cfgJson);
92 std::cout << config << std::endl;
94 filename = config[
"input"][
"filename"].get<std::string>();
95 objname = config[
"input"][
"objname"].get<std::string>();
96 axisSplit = config[
"split"][
"axes"].get<std::vector<int>>();
97 outputFilename = config[
"output"][
"filename"].get<std::string>();
101 h.Import(axisSplit, filename.data(), objname.data());
103 TFile * f = TFile::Open(outputFilename.data());
104 TTree * t = (TTree *)f->Get(
"ndh");
105 THnSparse * ss =
nullptr;
106 t->SetBranchAddress(
"h", &ss);
108 for (Int_t i = 0; i < t->GetEntries(); i++) {
113 t->GetUserInfo()->Print();
void SetOutputFileName(const char *fn)
Setting output file name.