CMS 3D CMS Logo

Public Member Functions | Private Attributes | Friends

hitfit::Defaults_Text Class Reference

A lightweight implementation of the Defaults interface that uses simple ASCII text files. More...

#include <Defaults_Text.h>

Inheritance diagram for hitfit::Defaults_Text:
hitfit::Defaults

List of all members.

Public Member Functions

 Defaults_Text (std::string def_file)
 Constructor, create a Default_Text object from an ASCII text file. Pass an empty string to skip reading a file.
 Defaults_Text (std::string def_file, int argc, char **argv)
 Constructor, create a Default_Text object from an ASCII text file and argument list.
virtual bool exists (std::string name) const
virtual bool get_bool (std::string name) const
virtual double get_float (std::string name) const
virtual int get_int (std::string name) const
virtual std::string get_string (std::string name) const
 ~Defaults_Text ()
 Destructor.

Private Attributes

Defaults_Textrep_rep

Friends

std::ostream & operator<< (std::ostream &s, const Defaults_Text &def)

Detailed Description

A lightweight implementation of the Defaults interface that uses simple ASCII text files.

Create instances of these objects passing in the name of a file. Each line of the file should contain a parameter setting like

name = value

Anything following a `;' or `#' is stried off; leading and trailing whitespaces on value are also removed. Blank lines are ignored.

User can also pass an argument list to the constructor. After the default ASCII input file is read, the argument list will be scanned, to possibly override some of the parameter settings. An argument of the form

--name=value

is equivalent to the parameter setting

name = value

while

--name

is equivalent to

name = 1

and

--noname

is equivalent to

name = 0.

Definition at line 122 of file Defaults_Text.h.


Constructor & Destructor Documentation

hitfit::Defaults_Text::Defaults_Text ( std::string  def_file)

Constructor, create a Default_Text object from an ASCII text file. Pass an empty string to skip reading a file.

Parameters:
def_fileThe ASCII text file to read. Pass an empty string to skip reading a file.

Definition at line 338 of file Defaults_Text.cc.

  : _rep (new Defaults_Textrep (def_file))
{
}
hitfit::Defaults_Text::Defaults_Text ( std::string  def_file,
int  argc,
char **  argv 
)

Constructor, create a Default_Text object from an ASCII text file and argument list.

Parameters:
def_fileThe ASCII text file to read. Pass an empty string to skip reading a file.
argcThe length of the argument list.
argvThe argument list.

Definition at line 353 of file Defaults_Text.cc.

  : _rep (new Defaults_Textrep (def_file, argc, argv))
{
}
hitfit::Defaults_Text::~Defaults_Text ( )

Destructor.

Definition at line 369 of file Defaults_Text.cc.

References _rep.

{
  delete _rep;
}

Member Function Documentation

bool hitfit::Defaults_Text::exists ( std::string  name) const [virtual]

Test to see if parameter name exists.

Parameters:
nameThe name of the parameter.
Return:
true if the parameter exists.
false if the parameter does not exist.

Implements hitfit::Defaults.

Definition at line 378 of file Defaults_Text.cc.

References mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by hitfit::EtaDepResolution::Read().

{
  std::string val;
  return (_rep->_map.find(name) != _rep->_map.end());

}
bool hitfit::Defaults_Text::get_bool ( std::string  name) const [virtual]

Get the value of name as boolean.

Parameters:
nameThe name of the parameter.
Return:
The value of the parameter a C/C++ bool.

Implements hitfit::Defaults.

Definition at line 425 of file Defaults_Text.cc.

References mergeVDriftHistosByStation::name.

{
  string val = _rep->get_val (name);
  if (tolower (val[0]) == 't' || tolower (val[0]) == 'y')
    return true;
  else if (tolower (val[0]) == 'f' || tolower (val[0]) == 'n')
    return false;
  return !!get_int (name);
}
double hitfit::Defaults_Text::get_float ( std::string  name) const [virtual]

Get the value of name as a floating-point of type double.

Parameters:
nameThe name of the parameter.
Return:
The value of the parameter as a floating-point number (C/C++ double).

Implements hitfit::Defaults.

Definition at line 410 of file Defaults_Text.cc.

References mergeVDriftHistosByStation::name.

Referenced by hitfit::EtaDepResolution::Read().

{
  return atof (_rep->get_val (name).c_str());
}
int hitfit::Defaults_Text::get_int ( std::string  name) const [virtual]

Get the value of name as integer.

Parameters:
nameThe name of the parameter.
Return:
The value of the parameter an integer (C/C++ int).

Implements hitfit::Defaults.

Definition at line 395 of file Defaults_Text.cc.

References mergeVDriftHistosByStation::name.

{
  return atoi (_rep->get_val (name).c_str());
}
string hitfit::Defaults_Text::get_string ( std::string  name) const [virtual]

Get the value of name as a string.

Parameters:
nameThe name of the parameter.
Return:
The value of the parameter as a string.

Implements hitfit::Defaults.

Definition at line 445 of file Defaults_Text.cc.

References mergeVDriftHistosByStation::name.

Referenced by hitfit::METTranslatorBase< AMet >::METTranslatorBase(), and hitfit::EtaDepResolution::Read().

{
  return _rep->get_val (name);
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const Defaults_Text def 
) [friend]

Output stream operator. Print out all parameters' names and their values.

Parameters:
sThe output stream to write.
defThe instance to print.
Return:
The output stream s

Definition at line 460 of file Defaults_Text.cc.

{

    for (std::map<std::string,std::string>::const_iterator it = def._rep->_map.begin() ;
     it != def._rep->_map.end() ;
     it++) {
         s << "[" << it->first << "] = [" << it->second << "]\n";
    }

  return s;
}

Member Data Documentation

The internal representation.

Definition at line 218 of file Defaults_Text.h.

Referenced by hitfit::operator<<(), and ~Defaults_Text().