ndmspc 0.20250128.0
Loading...
Searching...
No Matches
Core.cxx
1#include <TSystem.h>
2#include "Core.h"
3#include "Utils.h"
4
6ClassImp(Ndmspc::Core);
8
9namespace Ndmspc {
10
12json gCfg;
13
14bool Core::LoadConfig(std::string config, std::string userConfig, std::string environment, std::string userConfigRaw)
15{
16 std::string fileContent = Utils::OpenRawFile(config);
17 if (!fileContent.empty()) {
18 gCfg = json::parse(fileContent);
19 Printf("Using config file '%s' ...", config.c_str());
20 if (!userConfig.empty()) {
21 std::string fileContentUser = Ndmspc::Utils::OpenRawFile(userConfig);
22 if (!fileContentUser.empty()) {
23 json userCfg = json::parse(fileContentUser);
24 gCfg.merge_patch(userCfg);
25 Printf("User config file '%s' was merged ...", userConfig.c_str());
26 }
27 else {
28 Printf("Warning: User config '%s' was specified, but it was not open !!!", userConfig.c_str());
29 return false;
30 }
31 }
32 }
33 else {
34 Printf("Error: Problem opening config file '%s' !!! Exiting ...", config.c_str());
35 return false;
36 }
37
38 for (auto & cut : gCfg["ndmspc"]["cuts"]) {
39 if (!cut["rebin"].is_number_integer()) gCfg["ndmspc"]["cuts"][cut["axis"].get<std::string>()] = 1;
40 Int_t rebin = 1;
41 Int_t rebin_start = 1;
42 if (cut["rebin"].is_number_integer()) rebin = cut["rebin"].get<Int_t>();
43 if (cut["rebin_start"].is_number_integer()) rebin_start = cut["rebin_start"].get<Int_t>();
44 if (rebin > 1 && rebin_start >= rebin) {
45 Printf("Error: rebin_start=%d is greater than rebin=%d for axis '%s' !!! Please set rebin_start to lower then "
46 "rebin !!! Exiting ...",
47 rebin_start, rebin, cut["axis"].get<std::string>().c_str());
48 gSystem->Exit(1);
49 }
50 }
51
52 if (!environment.empty()) {
53 gCfg["ndmspc"]["environment"] = environment;
54 LoadEnvironment(environment);
55 }
56 else if (gCfg["ndmspc"]["environment"].is_string() && !gCfg["ndmspc"]["environment"].get<std::string>().empty()) {
57 environment = gCfg["ndmspc"]["environment"].get<std::string>();
58 LoadEnvironment(environment);
59 }
60
61 if (!userConfigRaw.empty()) {
62 json userCfgRaw = json::parse(userConfigRaw);
63 gCfg.merge_patch(userCfgRaw);
64 Printf("Config raw '%s' was merged...", userConfigRaw.c_str());
65 }
66
67 return true;
68}
69bool Core::LoadEnvironment(std::string environment)
70{
71 if (gCfg["ndmspc"]["environments"][environment].is_object()) {
72 Printf("Using environment '%s' ...", environment.c_str());
73 json myCfg = gCfg["ndmspc"]["environments"][environment];
74 gCfg.merge_patch(myCfg);
75 }
76 else {
77 if (!environment.compare("default")) {
78 // Printf("Warning: No environment specified !!! Setting it to 'default' !!!");
79 return true;
80 }
81 Printf("Error: Environment '%s' was not found !!! Exiting ...", environment.c_str());
82 return false;
83 }
84 return true;
85}
86} // namespace Ndmspc
Core object.
Definition Core.h:18