CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
trivialParser Class Reference

#include <trivialParser.h>

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

Detailed Description

This parser is really fragile!!

Definition at line 12 of file trivialParser.h.

Constructor & Destructor Documentation

◆ trivialParser()

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

ctor

Definition at line 6 of file trivialParser.cc.

References beamspotdip_dqm_sourceclient-live_cfg::configFile, parse(), and print().

6  {
8  print("[ctor] ");
9 }
void print(std::string prefix="")
print the read params
void parse(std::string configFile)
parse the cfg file

Member Function Documentation

◆ eraseSpaces()

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

get rid of spaces

Definition at line 63 of file trivialParser.cc.

Referenced by parse().

63  {
64  while (word.find(' ', 0) != std::string::npos) {
65  word.erase(word.find(' ', 0), 1);
66  }
67  return;
68 }
uint64_t word

◆ getNextLine()

std::string trivialParser::getNextLine ( std::ifstream &  input)
private

returns the next not commented line

Definition at line 39 of file trivialParser.cc.

References input, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by parse().

39  {
40  // std::cerr << "PG prima cerca " << std::endl ;
41  std::string singleLine;
42  do {
43  getline(input, singleLine, '\n');
44  // std::cerr << "PG guardo " << singleLine << std::endl ;
45  } while ((singleLine.find('#', 0) != std::string::npos || singleLine.find('=', 0) == std::string::npos ||
46  singleLine.size() < 3) &&
47  !input.eof());
48  // std::cerr << "PG trovato " << singleLine << std::endl ;
49  return singleLine;
50 }
static std::string const input
Definition: EdmProvDump.cc:47

◆ getVal()

double trivialParser::getVal ( std::string  name)

return the value for that parameter

Definition at line 13 of file trivialParser.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, m_config, and Skims_PA_cff::name.

13  {
14  if (m_config.count(name))
15  return m_config[name];
16  std::cerr << "[trivialParser] no value for " << name << " found\n";
17  return -999999.;
18 }
std::map< std::string, double > m_config
container for the output
Definition: trivialParser.h:21

◆ parse()

void trivialParser::parse ( std::string  configFile)
private

parse the cfg file

Definition at line 22 of file trivialParser.cc.

References beamspotdip_dqm_sourceclient-live_cfg::configFile, eraseSpaces(), getNextLine(), input, m_config, Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, and relativeConstraints::value.

Referenced by trivialParser().

22  {
23  std::ifstream input(configFile.c_str());
24  do {
25  std::string linea = getNextLine(input);
26  if (linea.empty())
27  continue;
28  std::string name(linea, 0, linea.find('=', 0));
30  std::string valuestring(linea, linea.find('=', 0) + 1, linea.size() - linea.find('=', 0) - 1);
31  eraseSpaces(valuestring);
32  double value = strtod(valuestring.c_str(), nullptr);
33  m_config[name] = value;
34  } while (!input.eof());
35 }
static std::string const input
Definition: EdmProvDump.cc:47
Definition: value.py:1
std::string getNextLine(std::ifstream &input)
returns the next not commented line
std::map< std::string, double > m_config
container for the output
Definition: trivialParser.h:21
void eraseSpaces(std::string &word)
get rid of spaces

◆ print()

void trivialParser::print ( std::string  prefix = "")
private

print the read params

Definition at line 54 of file trivialParser.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, m_config, and hcallasereventfilter2012_cfi::prefix.

Referenced by trivialParser().

54  {
55  std::cerr << "read parameters: " << std::endl;
56  for (std::map<std::string, double>::const_iterator mapIT = m_config.begin(); mapIT != m_config.end(); ++mapIT) {
57  std::cerr << prefix << mapIT->first << " = " << mapIT->second << "\n";
58  }
59 }
std::map< std::string, double > m_config
container for the output
Definition: trivialParser.h:21

Member Data Documentation

◆ m_config

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

container for the output

Definition at line 21 of file trivialParser.h.

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