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.

6  {
7  parse(configFile);
8  print("[ctor] ");
9 }

References parse(), and print().

Member Function Documentation

◆ eraseSpaces()

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

get rid of spaces

Definition at line 63 of file trivialParser.cc.

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

Referenced by parse().

◆ getNextLine()

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

returns the next not commented line

Definition at line 39 of file trivialParser.cc.

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 }

References input, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by parse().

◆ getVal()

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

return the value for that parameter

Definition at line 13 of file trivialParser.cc.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, m_config, and Skims_PA_cff::name.

◆ parse()

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

parse the cfg file

Definition at line 22 of file trivialParser.cc.

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 }

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

Referenced by trivialParser().

◆ print()

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

print the read params

Definition at line 54 of file trivialParser.cc.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, m_config, and ZMuMuAnalysisNtupler_cff::prefix.

Referenced by trivialParser().

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().

input
static const std::string input
Definition: EdmProvDump.cc:48
trivialParser::eraseSpaces
void eraseSpaces(std::string &word)
get rid of spaces
Definition: trivialParser.cc:63
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
trivialParser::getNextLine
std::string getNextLine(std::ifstream &input)
returns the next not commented line
Definition: trivialParser.cc:39
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trivialParser::print
void print(std::string prefix="")
print the read params
Definition: trivialParser.cc:54
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
value
Definition: value.py:1
trivialParser::parse
void parse(std::string configFile)
parse the cfg file
Definition: trivialParser.cc:22
relativeConstraints.value
value
Definition: relativeConstraints.py:53
trivialParser::m_config
std::map< std::string, double > m_config
container for the output
Definition: trivialParser.h:21
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
ZMuMuAnalysisNtupler_cff.prefix
prefix
Definition: ZMuMuAnalysisNtupler_cff.py:14