CMS 3D CMS Logo

List of all members | 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

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. More...
 
 Defaults_Text (std::string def_file, int argc, char **argv)
 Constructor, create a Default_Text object from an ASCII text file and argument list. More...
 
bool exists (std::string name) const override
 
bool get_bool (std::string name) const override
 
double get_float (std::string name) const override
 
int get_int (std::string name) const override
 
std::string get_string (std::string name) const override
 
 ~Defaults_Text () override
 Destructor. More...
 
- Public Member Functions inherited from hitfit::Defaults
 Defaults ()
 
virtual ~Defaults ()
 

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 117 of file Defaults_Text.h.

Constructor & Destructor Documentation

◆ Defaults_Text() [1/2]

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 320 of file Defaults_Text.cc.

330  : _rep(new Defaults_Textrep(def_file)) {}

◆ Defaults_Text() [2/2]

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 332 of file Defaults_Text.cc.

344  : _rep(new Defaults_Textrep(def_file, argc, argv)) {}

◆ ~Defaults_Text()

hitfit::Defaults_Text::~Defaults_Text ( )
override

Destructor.

Definition at line 346 of file Defaults_Text.cc.

350  {
351  delete _rep;
352  }

References _rep.

Member Function Documentation

◆ exists()

bool hitfit::Defaults_Text::exists ( std::string  name) const
overridevirtual

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 354 of file Defaults_Text.cc.

364  {
366  return (_rep->_map.find(name) != _rep->_map.end());
367  }

References Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

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

◆ get_bool()

bool hitfit::Defaults_Text::get_bool ( std::string  name) const
overridevirtual

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 397 of file Defaults_Text.cc.

407  {
408  string val = _rep->get_val(name);
409  if (tolower(val[0]) == 't' || tolower(val[0]) == 'y')
410  return true;
411  else if (tolower(val[0]) == 'f' || tolower(val[0]) == 'n')
412  return false;
413  return !!get_int(name);
414  }

References Skims_PA_cff::name, and heppy_batch::val.

◆ get_float()

double hitfit::Defaults_Text::get_float ( std::string  name) const
overridevirtual

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 383 of file Defaults_Text.cc.

393  {
394  return atof(_rep->get_val(name).c_str());
395  }

References Skims_PA_cff::name.

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

◆ get_int()

int hitfit::Defaults_Text::get_int ( std::string  name) const
overridevirtual

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 369 of file Defaults_Text.cc.

379  {
380  return atoi(_rep->get_val(name).c_str());
381  }

References Skims_PA_cff::name.

◆ get_string()

string hitfit::Defaults_Text::get_string ( std::string  name) const
overridevirtual

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 416 of file Defaults_Text.cc.

426  {
427  return _rep->get_val(name);
428  }

References Skims_PA_cff::name.

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

Friends And Related Function Documentation

◆ operator<<

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 430 of file Defaults_Text.cc.

441  {
442  for (std::map<std::string, std::string>::const_iterator it = def._rep->_map.begin(); it != def._rep->_map.end();
443  it++) {
444  s << "[" << it->first << "] = [" << it->second << "]\n";
445  }
446 
447  return s;
448  }

Member Data Documentation

◆ _rep

Defaults_Textrep* hitfit::Defaults_Text::_rep
private

The internal representation.

Definition at line 212 of file Defaults_Text.h.

Referenced by ~Defaults_Text().

cmsBatch.argv
argv
Definition: cmsBatch.py:279
dir2webdir.argc
argc
Definition: dir2webdir.py:39
hitfit::Defaults_Textrep::get_val
string get_val(string name) const
Definition: Defaults_Text.cc:265
hitfit::Defaults_Text::_rep
Defaults_Textrep * _rep
Definition: Defaults_Text.h:212
alignCSCRings.s
s
Definition: alignCSCRings.py:92
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
hitfit::Defaults_Textrep::_map
std::map< std::string, std::string > _map
Definition: Defaults_Text.cc:135
heppy_batch.val
val
Definition: heppy_batch.py:351
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
spu::def
int def(FILE *, FILE *, int)
Definition: SherpackUtilities.cc:14
hitfit::Defaults_Text::get_int
int get_int(std::string name) const override
Definition: Defaults_Text.cc:369