TMEGeneratorOptions Class Reference

#include <TMEGeneratorOptions.h>

Inheritance diagram for TMEGeneratorOptions:
modules::options

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
OptionsList_t
 Helper typedef, intended for the list of key-value pairs for each option.
typedef std::vector
< OptionsList_t::iterator > 
OptionsOrder_t
 Helper typedef, intended to keep the order of option declaration.

Public Member Functions

 TMEGeneratorOptions (const std::string &name)
 ~TMEGeneratorOptions ()
 TMEGeneratorOptions (const std::string &name, const modules::options *opts)
TMEGeneratorOptionsoperator= (const modules::options &rhs)
std::string StringDescription () const
 Flatten all options into a string.
void SetOption (const std::string &key, const std::string &value)
 Set the value of an option.
bool AppendToOption (const std::string &key, const std::string &value)
 Append a new value to a list.
void AddArgument (const int &number, const std::string &value)
 Set the value of an argument.



int GetInt (const std::string &name, int defVal, const std::string &range="") const
 Get the named option as an int.
int GetInt (const std::string &name, const std::string &range="") const
 Get the named option as an int, which MUST exist.
double GetDouble (const std::string &name, double defVal, const std::string &range="") const
 Get the named option as a double.
double GetDouble (const std::string &name, const std::string &range="") const
 Get the named option as a double, which MUST exist.
std::string GetString (const std::string &name, const std::string &defVal) const
 Get the named option as a string.
std::string GetString (const std::string &name) const
 Get the named option as a string.
bool GetBool (const std::string &name, bool defVal) const
 Get the named option as a bool.
bool GetBool (const std::string &name) const
 Get the named option as a bool.
int GetVectorStringsByWhiteSpace (const std::string &name, std::vector< std::string > &vect) const
 Fill a vector of strings with whitespace delimited tokens found in the named option.
int GetVectorStringsByDelimiter (const std::string &name, std::vector< std::string > &vect, const char *delim=":") const
 Fill a vector of strings with tokens found in the named option @ Uses strtok so not suitable for multi-threading (if we ever do something like that).
bool HasOption (const std::string &name) const
 Check if a named option has been set.
bool GetFlag (const std::string &name) const
 Check if a flag option has been set.
bool GetNumOptions () const
 Get the number of options managed by this options list.
std::string GetOption (const std::string &name, bool complain=false) const
 Returns the unprocessed value assigned to name.
OptionsList_t::const_iterator begin () const
 Get a const iterator to the first key-value pair (sorted alphabetically by.
OptionsList_t::const_iterator end () const
 Get a const iterator to the last key-value pair (sorted alphabetically by key).
void DumpOptions (const std::string &prefix=" ") const
 Print all options managed by this list to cout.
void SetAlias (const std::string &alias)
 Set the alias option for this module.
std::string GetAlias (const std::string &defVal="") const
 Get the alias option for this module.

Protected Attributes

std::string fModuleName

Detailed Description

Class to handle options for a TME generator Inherite from the options class for modules to share the implementation and interface.

Definition at line 9 of file TMEGeneratorOptions.h.


Member Typedef Documentation

typedef std::map<std::string,std::string> modules::options::OptionsList_t [inherited]

Helper typedef, intended for the list of key-value pairs for each option.

Definition at line 29 of file ModulesOptions.h.

typedef std::vector<OptionsList_t::iterator> modules::options::OptionsOrder_t [inherited]

Helper typedef, intended to keep the order of option declaration.

Definition at line 31 of file ModulesOptions.h.


Constructor & Destructor Documentation

TMEGeneratorOptions::TMEGeneratorOptions ( const std::string &  name  )  [inline]

Definition at line 11 of file TMEGeneratorOptions.h.

00011                                                   :
00012                 modules::options(name){};
        ~TMEGeneratorOptions(){};

TMEGeneratorOptions::~TMEGeneratorOptions (  )  [inline]

Definition at line 13 of file TMEGeneratorOptions.h.

00013 {};

TMEGeneratorOptions::TMEGeneratorOptions ( const std::string &  name,
const modules::options opts 
) [inline]

Definition at line 15 of file TMEGeneratorOptions.h.

References operator=().

00015                                                                          :
00016         modules::options(name){
00017             modules::options::operator=(*opts);
00018         }


Member Function Documentation

void modules::options::AddArgument ( const int &  number,
const std::string &  value 
) [inherited]

Set the value of an argument.

If the module has not specified a name for this argument, the key for this option is set to number ALCAP_REGISTER_MODULE

Parameters:
number The number of the argument to set
value The new value of the argument

Reimplemented in TAPGeneratorOptions, and TDPGeneratorOptions.

Definition at line 117 of file ModulesOptions.cpp.

References modules::options::fModuleName, TemplateFactory< BaseModule, OptionsType >::GetArgumentName(), modules::factory::Instance(), and modules::options::SetOption().

Referenced by modules::reader::AddModule().

00117                                                                           {
00118     // Get the name of this argument
00119     std::string name = modules::factory::Instance()->GetArgumentName(fModuleName,number);
00120     // Set the value of the corresponding option
00121     modules::options::SetOption(name,option);
00122 }

bool modules::options::AppendToOption ( const std::string &  key,
const std::string &  value 
) [inherited]

Append a new value to a list.

The new value is separated from the previous one with: " : "

Parameters:
key The name of the option to add to
value The value to append
Returns:
true if a value existed already and false if not

Definition at line 124 of file ModulesOptions.cpp.

References modules::options::fOptions.

Referenced by modules::reader::AddOption().

00124                                                                                  {
00125     // Get the option 
00126     OptionsList_t::iterator it= fOptions.find(name);
00127 
00128     // If no option exists return false
00129     if(it==fOptions.end()) return false;
00130 
00131     // Add the value to it
00132     it->second+=" : "+option;
00133     return true;
00134 }

OptionsList_t::const_iterator modules::options::begin (  )  const [inline, inherited]

Get a const iterator to the first key-value pair (sorted alphabetically by.

Definition at line 184 of file ModulesOptions.h.

References modules::options::fOptions.

Referenced by ExportPulse::BeforeFirstEntry().

00184 {return fOptions.begin();};

void modules::options::DumpOptions ( const std::string &  prefix = "     "  )  const [inherited]

Print all options managed by this list to cout.

Parameters:
prefix Appended before each line is printed

Definition at line 105 of file ModulesOptions.cpp.

References modules::options::fOrder.

Referenced by load_config_file(), and modules::navigator::MakeModules().

00105                                                             {
00106     //std::cout<<"key  "<<" = "<<" value "<<std::endl;
00107     OptionsOrder_t::const_iterator it;
00108     for(it=fOrder.begin();it!=fOrder.end();it++){
00109         std::cout<<prefix<<(*it)->first;
00110         if((*it)->second!=""){
00111            std::cout<<" = "<<(*it)->second;
00112         }
00113         std::cout<<std::endl;
00114     }
00115 }

OptionsList_t::const_iterator modules::options::end (  )  const [inline, inherited]

Get a const iterator to the last key-value pair (sorted alphabetically by key).

Definition at line 186 of file ModulesOptions.h.

References modules::options::fOptions.

Referenced by ExportPulse::BeforeFirstEntry().

00186 {return fOptions.end();};

std::string modules::options::GetAlias ( const std::string &  defVal = ""  )  const [inline, inherited]

Get the alias option for this module.

Definition at line 198 of file ModulesOptions.h.

References modules::options::GetString().

Referenced by BaseModule::BaseModule().

00198 {return GetString("alias",defVal);};

bool modules::options::GetBool ( const std::string &  name  )  const [inherited]

Get the named option as a bool.

Parameters:
name Name of the option to get

Definition at line 74 of file ModulesOptions.cpp.

References modules::options::GetString(), and modules::parser::IsTrue().

00074                                                       {
00075     return modules::parser::IsTrue(GetString(name));
00076 }

bool modules::options::GetBool ( const std::string &  name,
bool  defVal 
) const [inherited]

Get the named option as a bool.

Parameters:
name Name of the option to get
defVal Value to use if not found

Definition at line 78 of file ModulesOptions.cpp.

References modules::options::GetString(), and modules::parser::IsTrue().

Referenced by BaseModule::BaseModule(), FirstCompleteAPGenerator::FirstCompleteAPGenerator(), modules::options::GetFlag(), PulseViewer::PulseViewer(), TemplateCreator::TemplateCreator(), and TME_Al50_EvdE::TME_Al50_EvdE().

00078                                                                   {
00079     return modules::parser::IsTrue(GetString(name,Form("%d",defVal)));
00080 }

double modules::options::GetDouble ( const std::string &  name,
const std::string &  range = "" 
) const [inherited]

Get the named option as a double, which MUST exist.

Throws module::missing_option if the named option doesn't exist.

Use the range string to specify a validity range. Behind the scenes this uses ROOTs TFormula so any boolean operation is valid. Within the expression, either use the option's name as specified by the first argument to this method, or use "x". If the value fails the validity check, the modules::bad_value exception is thrown

Parameters:
name Name of the option to get
range Optional range for acceptable values

Definition at line 54 of file ModulesOptions.cpp.

00054                                                                                   {
00055     return GetOption<double>(name,0,true,range);
00056 }

double modules::options::GetDouble ( const std::string &  name,
double  defVal,
const std::string &  range = "" 
) const [inherited]

Get the named option as a double.

Use the range string to specify a validity range. Behind the scenes this uses ROOTs TFormula so any boolean operation is valid. Within the expression, either use the option's name as specified by the first argument to this method, or use "x". If the value fails the validity check, the modules::bad_value exception is thrown

Parameters:
name Name of the option to get
defVal Value to use if not found
range Optional range for acceptable values

Definition at line 57 of file ModulesOptions.cpp.

Referenced by FixedWindowMEGenerator::FixedWindowMEGenerator(), GaussFitAPGenerator::GaussFitAPGenerator(), MaxTimeDiffDPGenerator::MaxTimeDiffDPGenerator(), PlotIntegralRatios::PlotIntegralRatios(), PlotTDPs::PlotTDPs(), PulseCandidateFinder::PulseCandidateFinder(), TemplateConvolveAPGenerator::TemplateConvolveAPGenerator(), TemplateCreator::TemplateCreator(), TemplateFitAPGenerator::TemplateFitAPGenerator(), and GeSpectrum::ThrowIfInputsInsane().

00057                                                                                                  {
00058     return GetOption<double>(name,defVal,false,range);
00059 }

bool modules::options::GetFlag ( const std::string &  name  )  const [inline, inherited]

Check if a flag option has been set.

If the option is present with no value return true, else return true if the value gives boolean true

Parameters:
name Name of option to use
Returns:
true if option was set, false if not

Definition at line 243 of file ModulesOptions.h.

References modules::options::GetBool(), modules::options::GetOption(), and modules::options::HasOption().

Referenced by TemplateCreator::ChannelSet::ChannelSet(), ExportPulse::ExportPulse(), PlotTDPs::PlotTDPs(), PulseCandidateFinder::PulseCandidateFinder(), PulseViewer::PulseViewer(), TemplateConvolveAPGenerator::TemplateConvolveAPGenerator(), TemplateFitAPGenerator::TemplateFitAPGenerator(), and TVMuonEventGenerator::TVMuonEventGenerator().

00243                                                              {
00244     return (HasOption(name) && (GetOption(name).empty() || GetBool(name)));
00245 }

int modules::options::GetInt ( const std::string &  name,
const std::string &  range = "" 
) const [inherited]

Get the named option as an int, which MUST exist.

Throws module::missing_option if the named option doesn't exist.

Use the range string to specify a validity range. Behind the scenes this uses ROOTs TFormula so any boolean operation is valid. Within the expression, either use the option's name as specified by the first argument to this method, or use "x". If the value fails the validity check, the modules::bad_value exception is thrown

Parameters:
name Name of the option to get
range Optional range for acceptable values

Definition at line 47 of file ModulesOptions.cpp.

00047                                                                             {
00048     return GetOption<int>(name,0,true,range);
00049 }

int modules::options::GetInt ( const std::string &  name,
int  defVal,
const std::string &  range = "" 
) const [inherited]

Get the named option as an int.

Use the range string to specify a validity range. Behind the scenes this uses ROOTs TFormula so any boolean operation is valid. Within the expression, either use the option's name as specified by the first argument to this method, or use "x". If the value fails the validity check, the modules::bad_value exception is thrown

Parameters:
name Name of the option to get
defVal Value to use if not found
range Optional range for acceptable values

Definition at line 50 of file ModulesOptions.cpp.

Referenced by PulseCandidateFinder::PulseCandidateFinder(), PulseViewer::PulseViewer(), TemplateConvolveAPGenerator::TemplateConvolveAPGenerator(), TemplateCreator::TemplateCreator(), and TemplateFitAPGenerator::TemplateFitAPGenerator().

00050                                                                                         {
00051     return GetOption<int>(name,defVal,false,range);
00052 }

bool modules::options::GetNumOptions (  )  const [inline, inherited]

Get the number of options managed by this options list.

Definition at line 177 of file ModulesOptions.h.

References modules::options::fOptions.

Referenced by MakeAnalysedPulses::AddGenerator().

00177 {return fOptions.size();};

std::string modules::options::GetOption ( const std::string &  name,
bool  complain = false 
) const [inherited]

Returns the unprocessed value assigned to name.

Parameters:
name Name of the option to get

Definition at line 15 of file ModulesOptions.cpp.

References modules::options::fModuleName, and modules::options::fOptions.

Referenced by BaseModule::BaseModule(), modules::options::GetFlag(), modules::options::GetOption(), modules::options::GetString(), modules::options::GetVectorStringsByDelimiter(), and modules::options::GetVectorStringsByWhiteSpace().

00015                                                                            {
00016     OptionsList_t::const_iterator it = fOptions.find(key);
00017     if(it==fOptions.end()){
00018         if(complain){
00019             throw missing_option(fModuleName,key);
00020         }
00021         return "";
00022     }
00023     return it->second;
00024 }

std::string modules::options::GetString ( const std::string &  name  )  const [inherited]

Get the named option as a string.

Trims whitespace from the front and back of the option

Parameters:
name Name of the option to get

Definition at line 61 of file ModulesOptions.cpp.

References modules::options::GetOption(), and modules::parser::TrimWhiteSpaceBeforeAfter().

00061                                                              {
00062     std::string ret_val=GetOption(name,true);
00063     modules::parser::TrimWhiteSpaceBeforeAfter(ret_val);
00064     return ret_val;
00065 }

std::string modules::options::GetString ( const std::string &  name,
const std::string &  defVal 
) const [inherited]

Get the named option as a string.

Trims whitespace from the front and back of the option (but not for the default value if the modules file didn't specify anything)

Parameters:
name Name of the option to get
defVal Value to use if not found

Definition at line 67 of file ModulesOptions.cpp.

References modules::options::GetOption(), and modules::parser::TrimWhiteSpaceBeforeAfter().

Referenced by MakeDetectorPulses::BeforeFirstEntry(), CalcCoarseTimeOffset::CalcCoarseTimeOffset(), modules::options::GetAlias(), modules::options::GetBool(), LoadPulses::LoadPulses(), MakeDetectorPulses::MakeDetectorPulses(), MakeMuonEvents::MakeMuonEvents(), PlotAmpVsTDiff::PlotAmpVsTDiff(), PlotTDP_TDiff::PlotTDP_TDiff(), PulseViewer::PulseViewer(), TemplateConvolveAPGenerator::TemplateConvolveAPGenerator(), TemplateCreator::TemplateCreator(), TemplateFitAPGenerator::TemplateFitAPGenerator(), and GeSpectrum::ThrowIfInputsInsane().

00067                                                                                      {
00068     std::string ret_val=GetOption(name,false);
00069     modules::parser::TrimWhiteSpaceBeforeAfter(ret_val);
00070     if(ret_val=="") ret_val=defVal;
00071     return ret_val;
00072 }

int modules::options::GetVectorStringsByDelimiter ( const std::string &  name,
std::vector< std::string > &  vect,
const char *  delim = ":" 
) const [inherited]

Fill a vector of strings with tokens found in the named option @ Uses strtok so not suitable for multi-threading (if we ever do something like that).

Parameters:
name Name of option to use
vect vector to fill with tokens
delim c-string of chars to use as delimiter
Returns:
Number of tokens pushed in to vect

Definition at line 92 of file ModulesOptions.cpp.

References modules::options::GetOption().

Referenced by MakeAnalysedPulses::BeforeFirstEntry(), ExportPulse::BeforeFirstEntry(), and TemplateCreator::TemplateCreator().

00092                                                                                                                         {
00093     char line[2048];
00094     strcpy(line,GetOption(name).c_str());
00095     char* word = strtok(line,delim);
00096     int num_tokens=0;
00097     for(;word != NULL; num_tokens++) {
00098             //std::cout<<"ModulesOptions:GetVectorStringsByDelimiter() "<<word<<std::endl;
00099         vect.push_back(word);
00100         word = strtok(NULL,delim);
00101     }
00102     return num_tokens;
00103 }

int modules::options::GetVectorStringsByWhiteSpace ( const std::string &  name,
std::vector< std::string > &  vect 
) const [inherited]

Fill a vector of strings with whitespace delimited tokens found in the named option.

Parameters:
name Name of option to use
vect vector to fill with tokens
Returns:
Number of tokens pushed in to vect

Definition at line 82 of file ModulesOptions.cpp.

References modules::options::GetOption().

Referenced by MakeAnalysedPulses::MakeAnalysedPulses(), and MakeDetectorPulses::MakeDetectorPulses().

00082                                                                                                       {
00083     std::stringstream ss(GetOption(name));
00084     std::string val;
00085     int num_tokens=0;
00086     for(;ss>>val; num_tokens++) {
00087       vect.push_back(val);
00088     }
00089     return num_tokens;
00090 }

bool modules::options::HasOption ( const std::string &  name  )  const [inline, inherited]

Check if a named option has been set.

Parameters:
name Name of option to use
Returns:
true if option was set, false if not

Definition at line 239 of file ModulesOptions.h.

References modules::options::fOptions.

Referenced by BaseModule::BaseModule(), MakeDetectorPulses::BeforeFirstEntry(), MakeAnalysedPulses::BeforeFirstEntry(), modules::options::GetFlag(), PulseCandidateFinder::PulseCandidateFinder(), TemplateFitAPGenerator::TemplateFitAPGenerator(), and TVAnalysedPulseGenerator::TVAnalysedPulseGenerator().

00239                                                                {
00240     return fOptions.find(name)!=fOptions.end();
00241 }

TMEGeneratorOptions& TMEGeneratorOptions::operator= ( const modules::options rhs  )  [inline]

Definition at line 20 of file TMEGeneratorOptions.h.

Referenced by TMEGeneratorOptions().

00020                                                              {
00021         modules::options::operator=(rhs);
00022         return *this;
00023     }

void modules::options::SetAlias ( const std::string &  alias  )  [inline, inherited]

Set the alias option for this module.

Definition at line 196 of file ModulesOptions.h.

References modules::options::SetOption().

Referenced by modules::reader::AddModule().

00196 {SetOption("alias",alias);};

void modules::options::SetOption ( const std::string &  key,
const std::string &  value 
) [inline, inherited]

Set the value of an option.

If a previous value was set, it is replaced by this one

Parameters:
key The name of the option to set
value The new value

Definition at line 232 of file ModulesOptions.h.

References modules::options::fOptions, and modules::options::fOrder.

Referenced by TDPGeneratorOptions::AddArgument(), TAPGeneratorOptions::AddArgument(), modules::options::AddArgument(), modules::reader::AddOption(), FirstCompleteAPGenerator::FirstCompleteAPGenerator(), MakeAnalysedPulses::MakeAnalysedPulses(), and modules::options::SetAlias().

00232                                                                                    {
00233     // if a new key was added, store an iterator in the order list
00234     OptionsList_t::iterator it = fOptions.find(name);
00235     fOptions[name]=option;
00236     if(it==fOptions.end()) fOrder.push_back(fOptions.find(name));
00237 }

std::string modules::options::StringDescription (  )  const [inherited]

Flatten all options into a string.

Used to provide unique identifiers of a module or generator, based on it's configuration

Definition at line 141 of file ModulesOptions.cpp.

References modules::options::fOrder.

Referenced by BaseModule::BaseModule(), TVAnalysedPulseGenerator::TVAnalysedPulseGenerator(), and TVDetectorPulseGenerator::TVDetectorPulseGenerator().

00141                                                 {
00142     const char* key_val_sep="=";
00143     const char* start_key_val="{";
00144     const char* stop_key_val="}";
00145     OptionsOrder_t::const_iterator it;
00146     std::string description;
00147     for(it=fOrder.begin();it!=fOrder.end();it++){
00148         description+=start_key_val;
00149         description+=(*it)->first;
00150         if((*it)->second!=""){
00151             description+=key_val_sep;
00152             description+=(*it)->second;
00153         }
00154         description+=stop_key_val;
00155     }
00156     return description;
00157 }


Member Data Documentation

std::string modules::options::fModuleName [protected, inherited]

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

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1