GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TUserSettings Class Reference

Detailed Description

The TUserSettings class defines user settings that can be read from text or root files. It stores them in separate maps for booleans, integers, floats, and strings as well as vectors of those types.

For helpers the reading of the user settings is done in the TGRSIHelper class and made available as the member fUserSettings. Code to read the user setting "MyDouble" into the member variable fMyMemberVariable in the helper's constructor could be:

if(fUserSettings != nullptr) {
fMyMemberVariable = fUserSettings->GetDouble("MyDouble", 1.);
}

See the AngularCorrelationHelper's header file for more.

In general the user settings can be accessed via the static function TUserSettings* TGRSIOptions::UserSettings().

If TGRSIOptions are not available, the user settings can be read using the constructor:

userSettings = new TUserSettings(filename);
TUserSettings()=default

or using the ReadSettings function:

userSettings->ReadSettings(filename);

where userSettings is of type TUserSettings* and filename is either a std::string or char*.

The settings file is expected to have the format parameter name: value where parameter name is a string w/o whitespace and value is the value of the parameter the type of the value (bool, int, double, std::string, or vectors of these types) will be determined automatically. Vectors are comma separated values of one type. The default type is std::string. Any lines starting with '#' or '//' or without a colon will be ignored. See "examples/AngularCorrelationSettings.par" for an example of a settings file.

Definition at line 63 of file TUserSettings.h.

Public Member Functions

 TUserSettings ()=default
 
 TUserSettings (const std::string &settingsFile)
 
 TUserSettings (const TUserSettings &)=default
 
 TUserSettings (TUserSettings &&) noexcept=default
 
 ~TUserSettings ()=default
 
void Clear (Option_t *="") override
 
bool empty ()
 
template<typename T >
Get (const std::string &parameter) const
 
bool GetBool (const std::string &parameter, bool quiet=false) const
 
std::vector< bool > GetBoolVector (const std::string &parameter, bool quiet=false) const
 
double GetDouble (const std::string &parameter, bool quiet=false) const
 
double GetDouble (const std::string &parameter, double def) const
 
std::vector< double > GetDoubleVector (const std::string &parameter, bool quiet=false) const
 
int GetInt (const std::string &parameter, bool quiet=false) const
 
int GetInt (const std::string &parameter, int def) const
 
std::vector< int > GetIntVector (const std::string &parameter, bool quiet=false) const
 
std::string GetString (const std::string &parameter, bool quiet=false) const
 
std::string GetString (const std::string &parameter, std::string def) const
 
std::vector< std::string > GetStringVector (const std::string &parameter, bool quiet=false) const
 
TUserSettingsoperator= (const TUserSettings &)=default
 
TUserSettingsoperator= (TUserSettings &&) noexcept=default
 
void Print (Option_t *opt="") const override
 
bool ReadSettings (const std::string &settingsFile)
 
void SetBool (const std::string &parameter, bool value)
 
void SetBoolVector (const std::string &parameter, const std::vector< bool > &value)
 
void SetDouble (const std::string &parameter, double value)
 
void SetDoubleVector (const std::string &parameter, const std::vector< double > &value)
 
void SetInt (const std::string &parameter, int value)
 
void SetIntVector (const std::string &parameter, const std::vector< int > &value)
 
void SetString (const std::string &parameter, const std::string &value)
 
void SetStringVector (const std::string &parameter, const std::vector< std::string > &value)
 

Private Member Functions

void ParseValue (const std::string &name, const std::string &value, bool vector)
 

Private Attributes

std::map< std::string, bool > fBool
 
std::map< std::string, std::vector< bool > > fBoolVector
 
std::map< std::string, double > fDouble
 
std::map< std::string, std::vector< double > > fDoubleVector
 
std::map< std::string, int > fInt
 
std::map< std::string, std::vector< int > > fIntVector
 
std::vector< std::string > fSettingsFiles
 
std::map< std::string, std::string > fString
 
std::map< std::string, std::vector< std::string > > fStringVector
 
+ Inheritance diagram for TUserSettings:
+ Collaboration diagram for TUserSettings:

Constructor & Destructor Documentation

◆ TUserSettings() [1/4]

TUserSettings::TUserSettings ( )
default

◆ TUserSettings() [2/4]

TUserSettings::TUserSettings ( const std::string & settingsFile)
inlineexplicit

Definition at line 66 of file TUserSettings.h.

References ReadSettings().

◆ TUserSettings() [3/4]

TUserSettings::TUserSettings ( const TUserSettings & )
default

◆ TUserSettings() [4/4]

TUserSettings::TUserSettings ( TUserSettings && )
defaultnoexcept

◆ ~TUserSettings()

TUserSettings::~TUserSettings ( )
default

Member Function Documentation

◆ Clear()

void TUserSettings::Clear ( Option_t * = "")
inlineoverride

Definition at line 143 of file TUserSettings.h.

References fBool, fBoolVector, fDouble, fDoubleVector, fInt, fIntVector, fString, and fStringVector.

Referenced by TGRSIOptions::Clear().

◆ empty()

bool TUserSettings::empty ( )
inline

Definition at line 79 of file TUserSettings.h.

References fBool, fBoolVector, fDouble, fDoubleVector, fInt, fIntVector, fString, and fStringVector.

Referenced by TGRSIOptions::WriteToFile().

◆ Get()

template<typename T >
T TUserSettings::Get ( const std::string & parameter) const
inline

◆ GetBool()

bool TUserSettings::GetBool ( const std::string & parameter,
bool quiet = false ) const

◆ GetBoolVector()

std::vector< bool > TUserSettings::GetBoolVector ( const std::string & parameter,
bool quiet = false ) const

Definition at line 171 of file TUserSettings.cxx.

References fBoolVector, and Print().

Referenced by Get().

◆ GetDouble() [1/2]

double TUserSettings::GetDouble ( const std::string & parameter,
bool quiet = false ) const

◆ GetDouble() [2/2]

double TUserSettings::GetDouble ( const std::string & parameter,
double def ) const
inline

Definition at line 115 of file TUserSettings.h.

References fDouble.

◆ GetDoubleVector()

std::vector< double > TUserSettings::GetDoubleVector ( const std::string & parameter,
bool quiet = false ) const

Definition at line 197 of file TUserSettings.cxx.

References fDoubleVector, and Print().

Referenced by Get().

◆ GetInt() [1/2]

int TUserSettings::GetInt ( const std::string & parameter,
bool quiet = false ) const

◆ GetInt() [2/2]

int TUserSettings::GetInt ( const std::string & parameter,
int def ) const
inline

Definition at line 107 of file TUserSettings.h.

References fInt.

◆ GetIntVector()

std::vector< int > TUserSettings::GetIntVector ( const std::string & parameter,
bool quiet = false ) const

◆ GetString() [1/2]

std::string TUserSettings::GetString ( const std::string & parameter,
bool quiet = false ) const

Definition at line 158 of file TUserSettings.cxx.

References fString, and Print().

Referenced by Get().

◆ GetString() [2/2]

std::string TUserSettings::GetString ( const std::string & parameter,
std::string def ) const
inline

Definition at line 123 of file TUserSettings.h.

References fString.

◆ GetStringVector()

std::vector< std::string > TUserSettings::GetStringVector ( const std::string & parameter,
bool quiet = false ) const

Definition at line 210 of file TUserSettings.cxx.

References fStringVector, and Print().

Referenced by Get().

◆ operator=() [1/2]

TUserSettings & TUserSettings::operator= ( const TUserSettings & )
default

◆ operator=() [2/2]

TUserSettings & TUserSettings::operator= ( TUserSettings && )
defaultnoexcept

◆ ParseValue()

void TUserSettings::ParseValue ( const std::string & name,
const std::string & value,
bool vector )
private

Definition at line 61 of file TUserSettings.cxx.

References fBool, fBoolVector, fDouble, fDoubleVector, fInt, fIntVector, fString, and fStringVector.

Referenced by ReadSettings().

◆ Print()

void TUserSettings::Print ( Option_t * opt = "") const
override

◆ ReadSettings()

bool TUserSettings::ReadSettings ( const std::string & settingsFile)

Read user settings from text file. The file is expected to have the format parameter name: value where parameter name is a string w/o whitespace and value is the value of the parameter the type of the value (bool, int, double, std::string, or vectors of these types) will be determined automatically vectors are comma separated values of one type the default type will be std::string any lines starting with '#' or '//' or without a colon will be ignored

Definition at line 12 of file TUserSettings.cxx.

References fSettingsFiles, ParseValue(), and trim().

Referenced by TUserSettings(), and TGRSIOptions::FileAutoDetect().

◆ SetBool()

void TUserSettings::SetBool ( const std::string & parameter,
bool value )
inline

Definition at line 133 of file TUserSettings.h.

References fBool.

◆ SetBoolVector()

void TUserSettings::SetBoolVector ( const std::string & parameter,
const std::vector< bool > & value )
inline

Definition at line 137 of file TUserSettings.h.

References fBoolVector.

◆ SetDouble()

void TUserSettings::SetDouble ( const std::string & parameter,
double value )
inline

Definition at line 135 of file TUserSettings.h.

References fDouble.

◆ SetDoubleVector()

void TUserSettings::SetDoubleVector ( const std::string & parameter,
const std::vector< double > & value )
inline

Definition at line 139 of file TUserSettings.h.

References fDoubleVector.

◆ SetInt()

void TUserSettings::SetInt ( const std::string & parameter,
int value )
inline

Definition at line 134 of file TUserSettings.h.

References fInt.

◆ SetIntVector()

void TUserSettings::SetIntVector ( const std::string & parameter,
const std::vector< int > & value )
inline

Definition at line 138 of file TUserSettings.h.

References fIntVector.

◆ SetString()

void TUserSettings::SetString ( const std::string & parameter,
const std::string & value )
inline

Definition at line 136 of file TUserSettings.h.

References fString.

◆ SetStringVector()

void TUserSettings::SetStringVector ( const std::string & parameter,
const std::vector< std::string > & value )
inline

Definition at line 140 of file TUserSettings.h.

References fStringVector.

Member Data Documentation

◆ fBool

std::map<std::string, bool> TUserSettings::fBool
private

Definition at line 159 of file TUserSettings.h.

Referenced by Clear(), empty(), GetBool(), ParseValue(), Print(), and SetBool().

◆ fBoolVector

std::map<std::string, std::vector<bool> > TUserSettings::fBoolVector
private

Definition at line 163 of file TUserSettings.h.

Referenced by Clear(), empty(), GetBoolVector(), ParseValue(), Print(), and SetBoolVector().

◆ fDouble

std::map<std::string, double> TUserSettings::fDouble
private

Definition at line 161 of file TUserSettings.h.

Referenced by Clear(), empty(), GetDouble(), GetDouble(), ParseValue(), Print(), and SetDouble().

◆ fDoubleVector

std::map<std::string, std::vector<double> > TUserSettings::fDoubleVector
private

Definition at line 165 of file TUserSettings.h.

Referenced by Clear(), empty(), GetDoubleVector(), ParseValue(), Print(), and SetDoubleVector().

◆ fInt

std::map<std::string, int> TUserSettings::fInt
private

Definition at line 160 of file TUserSettings.h.

Referenced by Clear(), empty(), GetInt(), GetInt(), ParseValue(), Print(), and SetInt().

◆ fIntVector

std::map<std::string, std::vector<int> > TUserSettings::fIntVector
private

Definition at line 164 of file TUserSettings.h.

Referenced by Clear(), empty(), GetIntVector(), ParseValue(), Print(), and SetIntVector().

◆ fSettingsFiles

std::vector<std::string> TUserSettings::fSettingsFiles
private

Definition at line 168 of file TUserSettings.h.

Referenced by Print(), and ReadSettings().

◆ fString

std::map<std::string, std::string> TUserSettings::fString
private

Definition at line 162 of file TUserSettings.h.

Referenced by Clear(), empty(), GetString(), GetString(), ParseValue(), Print(), and SetString().

◆ fStringVector

std::map<std::string, std::vector<std::string> > TUserSettings::fStringVector
private

Definition at line 166 of file TUserSettings.h.

Referenced by Clear(), empty(), GetStringVector(), ParseValue(), Print(), and SetStringVector().