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