CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

trivialParser Class Reference

#include <trivialParser.h>

List of all members.

Public Member Functions

double getVal (std::string name)
 return the value for that parameter
 trivialParser (std::string configFile)
 ctor

Private Member Functions

void eraseSpaces (std::string &word)
 get rid of spaces
std::string getNextLine (std::ifstream &input)
 returns the next not commented line
void parse (std::string configFile)
 parse the cfg file
void print (std::string prefix="")
 print the read params

Private Attributes

std::map< std::string, double > m_config
 container for the output

Detailed Description

This parser is really fragile!!

Definition at line 13 of file trivialParser.h.


Constructor & Destructor Documentation

trivialParser::trivialParser ( std::string  configFile) [explicit]

ctor

Definition at line 6 of file trivialParser.cc.

References parse(), and print().

{
  parse (configFile) ;
  print ("[ctor] ") ;
}

Member Function Documentation

void trivialParser::eraseSpaces ( std::string &  word) [private]

get rid of spaces

Definition at line 90 of file trivialParser.cc.

Referenced by parse().

{
  while (word.find (' ',0) != std::string::npos) 
    { 
      word.erase (word.find (' ',0), 1) ; 
    }
  return ;    
}
std::string trivialParser::getNextLine ( std::ifstream &  input) [private]

returns the next not commented line

Definition at line 52 of file trivialParser.cc.

Referenced by parse().

{
//  std::cerr << "PG prima cerca " << std::endl ;
  std::string singleLine ;
  do {
    getline (input, singleLine,'\n') ;
//    std::cerr << "PG guardo " << singleLine << std::endl ;
  } while ((
             singleLine.find ('#',0) != std::string::npos || 
             singleLine.find ('=',0) == std::string::npos || 
             singleLine.size () < 3
           ) &&
           !input.eof ()) ;
//  std::cerr << "PG trovato " << singleLine << std::endl ;
  return singleLine ;
}
double trivialParser::getVal ( std::string  name)

return the value for that parameter

Definition at line 17 of file trivialParser.cc.

References dtNoiseDBValidation_cfg::cerr, and m_config.

{
  if (m_config.count (name)) return m_config[name] ;
  std::cerr << "[trivialParser] no value for " 
            << name
            << " found\n" ;
  return -999999. ;
}
void trivialParser::parse ( std::string  configFile) [private]

parse the cfg file

Definition at line 31 of file trivialParser.cc.

References eraseSpaces(), getNextLine(), LaserDQM_cfg::input, m_config, mergeVDriftHistosByStation::name, NULL, and relativeConstraints::value.

Referenced by trivialParser().

{
  std::ifstream input (configFile.c_str ()) ;  
  do {
    std::string linea = getNextLine (input) ;
    if (linea.empty ()) continue ;
    std::string name (linea,0,linea.find ('=',0)) ;
    eraseSpaces (name) ;
    std::string valuestring (linea,linea.find ('=', 0) + 1,
                             linea.size () - linea.find ('=', 0) - 1) ;
    eraseSpaces (valuestring) ;
    double value = strtod ( valuestring.c_str (), NULL ) ;
    m_config [name] = value ;
  } while (!input.eof () ) ;
}
void trivialParser::print ( std::string  prefix = "") [private]

print the read params

Definition at line 74 of file trivialParser.cc.

References dtNoiseDBValidation_cfg::cerr, and m_config.

Referenced by trivialParser().

{
  std::cerr << "read parameters: " << std::endl ;
  for (std::map<std::string, double>::const_iterator mapIT = m_config.begin () ;
       mapIT != m_config.end () ;
       ++mapIT)
    {
      std::cerr << prefix << mapIT->first << " = " << mapIT->second << "\n" ;
    }
}

Member Data Documentation

std::map<std::string,double> trivialParser::m_config [private]

container for the output

Definition at line 25 of file trivialParser.h.

Referenced by getVal(), parse(), and print().