CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
trivialParser.cc
Go to the documentation of this file.
1 //#include "Calibration/EcalAlCaRecoProducers/interface/trivialParser.h"
3 #include <iostream>
4 #include <cstdlib>
5 
7 {
8  parse (configFile) ;
9  print ("[ctor] ") ;
10 }
11 
12 
13 // ------------------------------------------------------------
14 
15 
16 double
18 {
19  if (m_config.count (name)) return m_config[name] ;
20  std::cerr << "[trivialParser] no value for "
21  << name
22  << " found\n" ;
23  return -999999. ;
24 }
25 
26 
27 // ------------------------------------------------------------
28 
29 
30 void
32 {
33  std::ifstream input (configFile.c_str ()) ;
34  do {
35  std::string linea = getNextLine (input) ;
36  if (linea.empty ()) continue ;
37  std::string name (linea,0,linea.find ('=',0)) ;
38  eraseSpaces (name) ;
39  std::string valuestring (linea,linea.find ('=', 0) + 1,
40  linea.size () - linea.find ('=', 0) - 1) ;
41  eraseSpaces (valuestring) ;
42  double value = strtod ( valuestring.c_str (), NULL ) ;
43  m_config [name] = value ;
44  } while (!input.eof () ) ;
45 }
46 
47 
48 // ------------------------------------------------------------
49 
50 
53 {
54 // std::cerr << "PG prima cerca " << std::endl ;
55  std::string singleLine ;
56  do {
57  getline (input, singleLine,'\n') ;
58 // std::cerr << "PG guardo " << singleLine << std::endl ;
59  } while ((
60  singleLine.find ('#',0) != std::string::npos ||
61  singleLine.find ('=',0) == std::string::npos ||
62  singleLine.size () < 3
63  ) &&
64  !input.eof ()) ;
65 // std::cerr << "PG trovato " << singleLine << std::endl ;
66  return singleLine ;
67 }
68 
69 
70 // ------------------------------------------------------------
71 
72 
73 void
75 {
76  std::cerr << "read parameters: " << std::endl ;
77  for (std::map<std::string, double>::const_iterator mapIT = m_config.begin () ;
78  mapIT != m_config.end () ;
79  ++mapIT)
80  {
81  std::cerr << prefix << mapIT->first << " = " << mapIT->second << "\n" ;
82  }
83 }
84 
85 
86 // ------------------------------------------------------------
87 
88 
89 void
91 {
92  while (word.find (' ',0) != std::string::npos)
93  {
94  word.erase (word.find (' ',0), 1) ;
95  }
96  return ;
97 }
98 
std::map< std::string, double > m_config
container for the output
Definition: trivialParser.h:25
void print(std::string prefix="")
print the read params
#define NULL
Definition: scimark2.h:8
double getVal(std::string name)
return the value for that parameter
trivialParser(std::string configFile)
ctor
Definition: trivialParser.cc:6
void parse(std::string configFile)
parse the cfg file
std::string getNextLine(std::ifstream &input)
returns the next not commented line
void eraseSpaces(std::string &word)
get rid of spaces