NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
NAGASH::ConfigTool Class Reference

provide interface to config objects in NAGASH. More...

#include "NAGASH/ConfigTool.h"

Public Member Functions

 ConfigTool ()
 
 ConfigTool (ConfigTool &&c)=default
 
 ConfigTool (const char *inputfilename)
 Constructor.
 
 ConfigTool (const ConfigTool &c)=default
 
template<typename T >
void BookPar (const TString &name, const T &value)
 Book parameter with given name and value.
 
template<class T >
GetPar (const TString &name, bool *doexist=nullptr) const
 Get the parameter with given name and type.
 
std::shared_ptr< MSGToolMSGUser () const
 Get the MSGTool pointer.
 
ConfigTooloperator= (ConfigTool &&c)=default
 
ConfigTooloperator= (const ConfigTool &c)=default
 
void RemovePar (const TString &name)
 Remove the parameter with given name.
 
void SetMSG (std::shared_ptr< MSGTool > MSG)
 Set the MSGTool.
 

Private Member Functions

template<typename T >
void BookParFile (const TString &name, const T &value)
 Book parameter from input file.
 
std::string Exec (std::string command)
 
void ReadConfigFromFile (const TString &filename)
 Read config info from given file.
 

Private Attributes

std::vector< TString > InputMD5Sum
 
std::shared_ptr< MSGToolmsg = nullptr
 
std::map< TString, std::any > ParMap
 
std::map< TString, std::any > ParMapFile
 

Detailed Description

provide interface to config objects in NAGASH.

This class is intended to book and get parameters as well as read parameters from outside config file. Also, this class maintains a MSGTool so that after reading the input config file, correct MSGTool can be constructed (output level, log file name, etc).

This tool can read config info from given config file. The config file should be organized like following:

# This is a comment
# any parameter should be booked in one line as :
# type name value1 value2 value3 ....
# there are totally 10 types supported :
# int long bool double string intvec longvec boolvec doublevec stringvec
# the following parameters are reserved parameters which can be read by NAGASH framework internally
include PathToOtherConfig # include other config file if you want
int Nthread 5 # number of threads for Analysis::ThreadPool
long EvtMax 1000 # number of entry you want to read in
bool CreateLog 0 # create log file or print to screen
bool OpenLog 0 # open log file, if it does not exist, create a new one
string LogFileName MyAnaOut.log # log file name
string MSGLevel INFO # message level
intvec FileSelection 1 # the file index in the file list that you want to loop over, start at 1
string FileSelectionPattern pattern # the file with name matched the pattern will be used to loop over
MSGLevel
class to define different message level
Definition MSGTool.h:14

After construction, parameters can be get by GetPar() method.

Definition at line 13 of file ConfigTool.h.

Constructor & Destructor Documentation

◆ ConfigTool() [1/4]

NAGASH::ConfigTool::ConfigTool ( )
inline

Definition at line 16 of file ConfigTool.h.

◆ ConfigTool() [2/4]

ConfigTool::ConfigTool ( const char *  inputfilename)

Constructor.

Parameters
inputfilenamename of the config file.

Definition at line 47 of file ConfigTool.cxx.

◆ ConfigTool() [3/4]

NAGASH::ConfigTool::ConfigTool ( const ConfigTool c)
default

◆ ConfigTool() [4/4]

NAGASH::ConfigTool::ConfigTool ( ConfigTool &&  c)
default

Member Function Documentation

◆ BookPar()

template<typename T >
void NAGASH::ConfigTool::BookPar ( const TString &  name,
const T &  value 
)
inline

Book parameter with given name and value.

Template Parameters
Ttype of the parameter.
Parameters
namename of the parameter.
valuevalue of the parameter.

Definition at line 63 of file ConfigTool.h.

◆ BookParFile()

template<typename T >
void NAGASH::ConfigTool::BookParFile ( const TString &  name,
const T &  value 
)
inlineprivate

Book parameter from input file.

Template Parameters
Ttype of the parameter.
Parameters
namename of the parameter.
valuevalue of the parameter.

Definition at line 87 of file ConfigTool.h.

◆ Exec()

std::string ConfigTool::Exec ( std::string  command)
private

Definition at line 274 of file ConfigTool.cxx.

◆ GetPar()

template<class T >
T NAGASH::ConfigTool::GetPar ( const TString &  name,
bool *  doexist = nullptr 
) const
inline

Get the parameter with given name and type.

For parameters read from config file, you should get them like :

ConfigTool config("config.dat");
auto intType = config.GetPar<int>("intType");
auto longType = config.GetPar<long>("longType");
auto boolType = config.GetPar<bool>("boolType");
auto doubleType = config.GetPar<double>("doubleType");
auto stringType = config.GetPar<TString>("stringType");
auto intvecType = config.GetPar<std::vector<int>>("intvecType");
auto longvecType = config.GetPar<std::vector<long>>("longvecType");
auto boolvecType = config.GetPar<std::vector<bool>>("boolvecType");
auto doublevecType = config.GetPar<std::vector<double>>("doublevecType");
auto stringvecType = config.GetPar<std::vector<TString>>("stringvecType");
provide interface to config objects in NAGASH.
Definition ConfigTool.h:14
Template Parameters
Tthe type of the parameter.
Parameters
[in]namethe name of the parameter.
[out]doexistthe parameter exist or not.
Returns
the parameter you want to get, or null value if the parameter does not exist.

Definition at line 129 of file ConfigTool.h.

◆ MSGUser()

std::shared_ptr< MSGTool > NAGASH::ConfigTool::MSGUser ( ) const
inline

Get the MSGTool pointer.

Returns
the pointer of MSGTool.

Definition at line 44 of file ConfigTool.h.

◆ operator=() [1/2]

ConfigTool & NAGASH::ConfigTool::operator= ( ConfigTool &&  c)
default

◆ operator=() [2/2]

ConfigTool & NAGASH::ConfigTool::operator= ( const ConfigTool c)
default

◆ ReadConfigFromFile()

void ConfigTool::ReadConfigFromFile ( const TString &  filename)
private

Read config info from given file.

Parameters
filenameinput file name

Definition at line 107 of file ConfigTool.cxx.

◆ RemovePar()

void NAGASH::ConfigTool::RemovePar ( const TString &  name)
inline

Remove the parameter with given name.

Parameters
namethe name of the parameter to be removed.

Definition at line 52 of file ConfigTool.h.

◆ SetMSG()

void NAGASH::ConfigTool::SetMSG ( std::shared_ptr< MSGTool MSG)
inline

Set the MSGTool.

Parameters
MSGinput pointer of MSGTool.

Definition at line 48 of file ConfigTool.h.

Member Data Documentation

◆ InputMD5Sum

std::vector<TString> NAGASH::ConfigTool::InputMD5Sum
private

Definition at line 34 of file ConfigTool.h.

◆ msg

std::shared_ptr<MSGTool> NAGASH::ConfigTool::msg = nullptr
mutableprivate

Definition at line 35 of file ConfigTool.h.

◆ ParMap

std::map<TString, std::any> NAGASH::ConfigTool::ParMap
private

Definition at line 32 of file ConfigTool.h.

◆ ParMapFile

std::map<TString, std::any> NAGASH::ConfigTool::ParMapFile
private

Definition at line 33 of file ConfigTool.h.


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