MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
manager Class Reference

The manager class is responsible for managing configurations and settings. More...

#include <Manager/Manager.h>

Collaboration diagram for manager:
[legend]

Public Member Functions

 manager (std::string const &filename)
 Constructs a manager object with the specified file name.
 
 manager (const YAML::Node ConfigNode)
 Constructs a manager object with the specified YAML.
 
virtual ~manager ()
 Destroys the manager object.
 
void SaveSettings (TFile *const OutputFile)
 Add manager useful information's to TFile, in most cases to Fitter.
 
void Print ()
 Print currently used config.
 
int GetMCStatLLH ()
 Get likelihood type defined in the config.
 
std::string GetFileName ()
 Return name of config.
 
YAML::Node const & raw ()
 Return config.
 
std::string GetName () const
 Get class name.
 
template<typename... Args>
void OverrideSettings (Args &&... args)
 Overrides the configuration settings based on provided arguments.
 

Private Member Functions

void Initialise ()
 Common inialiser for both constructors.
 

Private Attributes

YAML::Node config
 The YAML node containing the configuration data.
 
std::string FileName
 The name of the configuration file.
 

Detailed Description

The manager class is responsible for managing configurations and settings.

See also
For more details, visit the Wiki.
Author
Ed Atkin
Kamil Skwarczynski

Definition at line 16 of file Manager.h.

Constructor & Destructor Documentation

◆ manager() [1/2]

_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ manager::manager ( std::string const &  filename)
explicit

Constructs a manager object with the specified file name.

Parameters
filenameThe name of the configuration file.

Definition at line 9 of file Manager.cpp.

10: config(M3OpenConfig(filename)) {
11// *************************
12 FileName = filename;
13
14 Initialise();
15}
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:560
std::string FileName
The name of the configuration file.
Definition: Manager.h:62
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

◆ manager() [2/2]

manager::manager ( const YAML::Node  ConfigNode)

Constructs a manager object with the specified YAML.

Note
This is primarily used when initializing from a previous chain, allowing the creation of a manager instance based embedded YAML in that chain.
Parameters
ConfigNodeActual YAML config

Definition at line 18 of file Manager.cpp.

18 {
19// *************************
20 config = ConfigNode;
21 FileName = "unknown";
22
23 Initialise();
24}

◆ ~manager()

manager::~manager ( )
virtual

Destroys the manager object.

Definition at line 41 of file Manager.cpp.

41 {
42// *************************
43}

Member Function Documentation

◆ GetFileName()

std::string manager::GetFileName ( )
inline

Return name of config.

Definition at line 39 of file Manager.h.

39{return FileName;}

◆ GetMCStatLLH()

int manager::GetMCStatLLH ( )

Get likelihood type defined in the config.

Definition at line 98 of file Manager.cpp.

98 {
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}
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:25
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:24
TestStatistic
Make an enum of the test statistic that we're using.
@ kNTestStatistics
Number of test statistics.
@ kPoisson
Standard Poisson likelihood .
std::string TestStatistic_ToString(TestStatistic i)
Convert a LLH type to a string.
Custom exception class for MaCh3 errors.

◆ GetName()

std::string manager::GetName ( ) const
inline

Get class name.

Definition at line 43 of file Manager.h.

43{return "Manager";};

◆ Initialise()

void manager::Initialise ( )
private

Common inialiser for both constructors.

Definition at line 27 of file Manager.cpp.

27 {
28// *************************
31
32 MACH3LOG_INFO("Setting config to be: {}", FileName);
33
34 MACH3LOG_INFO("Config is now: ");
36}
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:23
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Definition: MaCh3Logger.h:30
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
Definition: Monitor.cpp:294
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
Definition: Monitor.cpp:11

◆ OverrideSettings()

template<typename... Args>
void manager::OverrideSettings ( Args &&...  args)
inline

Overrides the configuration settings based on provided arguments.

Note
Example usage:
FitManager->OverrideSettings("General", "OutputFile", "Wooimbouttamakeanameformyselfere.root");

Definition at line 51 of file Manager.h.

51 {
52 OverrideConfig(config, std::forward<Args>(args)...);
53 }
void OverrideConfig(YAML::Node node, std::string const &key, TValue val)
Overrides the configuration settings based on provided arguments.
Definition: YamlHelper.h:226

◆ Print()

void manager::Print ( )

Print currently used config.

Definition at line 90 of file Manager.cpp.

90 {
91// *************************
92 MACH3LOG_INFO("---------------------------------");
94 MACH3LOG_INFO("---------------------------------");
95}

◆ raw()

YAML::Node const & manager::raw ( )
inline

Return config.

Definition at line 41 of file Manager.h.

41{return config;}

◆ SaveSettings()

void manager::SaveSettings ( TFile *const  OutputFile)

Add manager useful information's to TFile, in most cases to Fitter.

Parameters
OutputFileThe ROOT TFile to which the information will be added.

Definition at line 49 of file Manager.cpp.

49 {
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}
TMacro YAMLtoTMacro(const YAML::Node &yaml_node, const std::string &name)
Convert a YAML node to a ROOT TMacro object.
Definition: YamlHelper.h:161

Member Data Documentation

◆ config

YAML::Node manager::config
private

The YAML node containing the configuration data.

Definition at line 60 of file Manager.h.

◆ FileName

std::string manager::FileName
private

The name of the configuration file.

Definition at line 62 of file Manager.h.


The documentation for this class was generated from the following files: