CMS 3D CMS Logo

trivialParser.cc
Go to the documentation of this file.
1 //#include "Calibration/EcalAlCaRecoProducers/interface/trivialParser.h"
3 #include <iostream>
4 #include <cstdlib>
5 
8  print("[ctor] ");
9 }
10 
11 // ------------------------------------------------------------
12 
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 }
19 
20 // ------------------------------------------------------------
21 
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 }
36 
37 // ------------------------------------------------------------
38 
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 }
51 
52 // ------------------------------------------------------------
53 
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 }
60 
61 // ------------------------------------------------------------
62 
64  while (word.find(' ', 0) != std::string::npos) {
65  word.erase(word.find(' ', 0), 1);
66  }
67  return;
68 }
void print(std::string prefix="")
print the read params
static std::string const input
Definition: EdmProvDump.cc:47
double getVal(std::string name)
return the value for that parameter
uint64_t word
trivialParser(std::string configFile)
ctor
Definition: trivialParser.cc:6
void parse(std::string configFile)
parse the cfg file
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