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

Private Member Functions

void Initialise ()
 Common inialiser for both constructors. More...
 

Private Attributes

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

Detailed Description

The manager class is responsible for managing configurations and settings.

Author
Ed Atkin
Kamil Skwarczynski

Definition at line 16 of file Manager.h.

Constructor & Destructor Documentation

◆ Manager() [1/2]

Manager::Manager ( std::string const &  filename)
inlineexplicit

Constructs a manager object with the specified file name.

Parameters
filenameThe name of the configuration file.

Definition at line 20 of file Manager.h.

21  : config(M3OpenConfig(filename)) {
22  FileName = filename;
23 
24  Initialise();
25  };
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:589
void Initialise()
Common inialiser for both constructors.
Definition: Manager.cpp:18
YAML::Node config
The YAML node containing the configuration data.
Definition: Manager.h:66
std::string FileName
The name of the configuration file.
Definition: Manager.h:68

◆ Manager() [2/2]

_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ 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 9 of file Manager.cpp.

9  {
10 // *************************
11  config = ConfigNode;
12  FileName = "unknown";
13 
14  Initialise();
15 }

◆ ~Manager()

Manager::~Manager ( )
virtual

Destroys the manager object.

Definition at line 32 of file Manager.cpp.

32  {
33 // *************************
34 }

Member Function Documentation

◆ GetFileName()

std::string Manager::GetFileName ( ) const
inline

Return name of config.

Definition at line 45 of file Manager.h.

45 {return FileName;}

◆ GetMCStatLLH()

int Manager::GetMCStatLLH ( ) const

Get likelihood type defined in the config.

Definition at line 89 of file Manager.cpp.

89  {
90 // *************************
91  int mc_stat_llh = kNTestStatistics;
92  if (config["LikelihoodOptions"])
93  {
94  auto likelihood = GetFromManager<std::string>(config["LikelihoodOptions"]["TestStatistic"], "Barlow-Beeston", __FILE__ , __LINE__);
95  mc_stat_llh = TestStatFromString(likelihood);
96  } else {
97  MACH3LOG_WARN("Didn't find a TestStatistic specified");
98  MACH3LOG_WARN("Defaulting to using a {} likelihood", TestStatistic_ToString(kPoisson));
99  mc_stat_llh = kPoisson;
100  }
101  return mc_stat_llh;
102 }
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:36
TestStatistic TestStatFromString(const std::string &likelihood)
Convert a string to a TestStatistic enum.
std::string TestStatistic_ToString(const TestStatistic TestStat)
Convert a LLH type to a string.
@ kNTestStatistics
Number of test statistics.
@ kPoisson
Standard Poisson likelihood .

◆ GetName()

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

Get class name.

Definition at line 49 of file Manager.h.

49 {return "Manager";};

◆ Initialise()

void Manager::Initialise ( )
private

Common inialiser for both constructors.

Definition at line 18 of file Manager.cpp.

18  {
19 // *************************
22 
23  MACH3LOG_INFO("Setting config to be: {}", FileName);
24 
25  MACH3LOG_INFO("Config is now: ");
27 }
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Definition: MaCh3Logger.h:61
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
Definition: Monitor.cpp:311
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
Definition: Monitor.cpp:13

◆ 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 57 of file Manager.h.

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

◆ Print()

void Manager::Print ( ) const

Print currently used config.

Definition at line 81 of file Manager.cpp.

81  {
82 // *************************
83  MACH3LOG_INFO("---------------------------------");
85  MACH3LOG_INFO("---------------------------------");
86 }

◆ raw()

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

Return config.

Definition at line 47 of file Manager.h.

47 {return config;}

◆ SaveSettings()

void Manager::SaveSettings ( TFile *const  OutputFile) const

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 40 of file Manager.cpp.

40  {
41 // *************************
42  std::string OutputFilename = std::string(OutputFile->GetName());
43  OutputFile->cd();
44 
45  // EM: embed the config used for this app
46  TMacro ConfigSave = YAMLtoTMacro(config, "MaCh3_Config");
47  ConfigSave.Write();
48 
49  // The Branch!
50  TTree *SaveBranch = new TTree("Settings", "Settings");
51 
52  // Fill the doubles
53  SaveBranch->Branch("Output", &OutputFilename);
54 
55  // Get settings defined by pre-processor directives, e.g. CPU MP and GPU
56  #ifdef MULTITHREAD
57  bool cpu_mp_on = true;
58  int n_cpus = omp_get_max_threads();
59  #else
60  bool cpu_mp_on = false;
61  int n_cpus = 1;
62  #endif
63 
64  #ifdef MaCh3_CUDA
65  bool gpu_on = true;
66  #else
67  bool gpu_on = false;
68  #endif
69 
70  SaveBranch->Branch("GPU", &gpu_on);
71  SaveBranch->Branch("CPUMP", &cpu_mp_on);
72  SaveBranch->Branch("nCPUs", &n_cpus);
73 
74  SaveBranch->Fill();
75  SaveBranch->Write();
76 
77  delete SaveBranch;
78 }
TMacro YAMLtoTMacro(const YAML::Node &yaml_node, const std::string &name)
Convert a YAML node to a ROOT TMacro object.
Definition: YamlHelper.h:167

Member Data Documentation

◆ config

YAML::Node Manager::config
private

The YAML node containing the configuration data.

Definition at line 66 of file Manager.h.

◆ FileName

std::string Manager::FileName
private

The name of the configuration file.

Definition at line 68 of file Manager.h.


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