MaCh3  2.2.3
Reference Guide
Manager.cpp
Go to the documentation of this file.
1 #include "Manager/Manager.h"
2 
4 // ROOT include
5 #include "TFile.h"
7 
8 // *************************
9 manager::manager(std::string const &filename)
10 : config(M3OpenConfig(filename)) {
11 // *************************
12  FileName = filename;
13 
14  Initialise();
15 }
16 
17 // *************************
18 manager::manager(const YAML::Node ConfigNode) {
19 // *************************
20  config = ConfigNode;
21  FileName = "unknown";
22 
23  Initialise();
24 }
25 
26 // *************************
28 // *************************
31 
32  MACH3LOG_INFO("Setting config to be: {}", FileName);
33 
34  MACH3LOG_INFO("Config is now: ");
36 }
37 
38 
39 // *************************
40 // Empty destructor, for now...
42 // *************************
43 }
44 
45 // *************************
46 // Save all the settings of the class to an output file
47 // Reflection in C++ is a bit of a pain :(
48 // Outputfile is the TFile pointer we write to
49 void manager::SaveSettings(TFile* const OutputFile) {
50 // *************************
51  std::string OutputFilename = std::string(OutputFile->GetName());
52  OutputFile->cd();
53 
54  // EM: embed the config used for this app
55  TMacro ConfigSave = YAMLtoTMacro(config, "MaCh3_Config");
56  ConfigSave.Write();
57 
58  // The Branch!
59  TTree *SaveBranch = new TTree("Settings", "Settings");
60 
61  // Fill the doubles
62  SaveBranch->Branch("Output", &OutputFilename);
63 
64  // Get settings defined by pre-processor directives, e.g. CPU MP and GPU
65  #ifdef MULTITHREAD
66  bool cpu_mp_on = true;
67  int n_cpus = omp_get_max_threads();
68  #else
69  bool cpu_mp_on = false;
70  int n_cpus = 1;
71  #endif
72 
73  #ifdef MaCh3_CUDA
74  bool gpu_on = true;
75  #else
76  bool gpu_on = false;
77  #endif
78 
79  SaveBranch->Branch("GPU", &gpu_on);
80  SaveBranch->Branch("CPUMP", &cpu_mp_on);
81  SaveBranch->Branch("nCPUs", &n_cpus);
82 
83  SaveBranch->Fill();
84  SaveBranch->Write();
85 
86  delete SaveBranch;
87 }
88 
89 // *************************
91 // *************************
92  MACH3LOG_INFO("---------------------------------");
94  MACH3LOG_INFO("---------------------------------");
95 }
96 
97 // *************************
99 // *************************
100  int mc_stat_llh = kNTestStatistics;
101  if (config["LikelihoodOptions"])
102  {
103  auto likelihood = GetFromManager<std::string>(config["LikelihoodOptions"]["TestStatistic"], "Barlow-Beeston", __FILE__ , __LINE__);
104 
105  for(int i = 0; i < kNTestStatistics; i++) {
106  if(likelihood == TestStatistic_ToString(TestStatistic(i))) {
107  mc_stat_llh = TestStatistic(i);
108  break;
109  }
110  }
111  if(mc_stat_llh == kNTestStatistics)
112  {
113  MACH3LOG_ERROR("Wrong form of test-statistic specified!");
114  MACH3LOG_ERROR("You gave {} and I only support:", likelihood);
115  for(int i = 0; i < kNTestStatistics; i++)
116  {
118  }
119  throw MaCh3Exception(__FILE__ , __LINE__ );
120  }
121  } else {
122  MACH3LOG_WARN("Didn't find a TestStatistic specified");
123  MACH3LOG_WARN("Defaulting to using a {} likelihood", TestStatistic_ToString(kPoisson));
124  mc_stat_llh = kPoisson;
125  }
126  return mc_stat_llh;
127 }
128 
129 
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:109
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
Definition: Core.h:120
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:25
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Definition: MaCh3Logger.h:51
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:26
std::string config
Definition: ProcessMCMC.cpp:29
std::string TestStatistic_ToString(const TestStatistic TestStat)
Convert a LLH type to a string.
TestStatistic
Make an enum of the test statistic that we're using.
@ kNTestStatistics
Number of test statistics.
@ kPoisson
Standard Poisson likelihood .
TMacro YAMLtoTMacro(const YAML::Node &yaml_node, const std::string &name)
Convert a YAML node to a ROOT TMacro object.
Definition: YamlHelper.h:162
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:561
Custom exception class for MaCh3 errors.
void SaveSettings(TFile *const OutputFile)
Add manager useful information's to TFile, in most cases to Fitter.
Definition: Manager.cpp:49
std::string FileName
The name of the configuration file.
Definition: Manager.h:62
void Print()
Print currently used config.
Definition: Manager.cpp:90
int GetMCStatLLH()
Get likelihood type defined in the config.
Definition: Manager.cpp:98
manager(std::string const &filename)
Constructs a manager object with the specified file name.
Definition: Manager.cpp:9
YAML::Node config
The YAML node containing the configuration data.
Definition: Manager.h:60
void Initialise()
Common inialiser for both constructors.
Definition: Manager.cpp:27
virtual ~manager()
Destroys the manager object.
Definition: Manager.cpp:41
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
Definition: Monitor.cpp:295
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
Definition: Monitor.cpp:12