CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripConfObject.h
Go to the documentation of this file.
1 #ifndef SiStripConfObject_h
2 #define SiStripConfObject_h
3 
4 #include <iostream>
5 #include <vector>
6 #include <map>
7 #include <algorithm>
8 #include <iterator>
9 #include <sstream>
10 
12 
28 {
29  public:
31 
32  template <class valueType>
33  bool put( const std::string & name, const valueType & inputValue )
34  {
35  std::stringstream ss;
36  ss << inputValue;
37  if( parameters.insert(std::make_pair(name, ss.str())).second ) return true;
38  return false;
39  }
40 
41 
45  template <class valueType>
46  bool update( const std::string & name, const valueType & inputValue )
47  {
48  parMap::iterator it = parameters.find(name);
49  if (it == parameters.end()) {
50  std::cout << "WARNING in SiStripConfObject::update: parameter " << name << " not found, "
51  << "so cannot be updated to '" << inputValue << "'." << std::endl;
52  return false;
53  } else {
54  std::stringstream ss;
55  ss << inputValue;
56  it->second = ss.str();
57  return true;
58  }
59  }
60 
61  template <class valueType>
62  valueType get( const std::string & name ) const
63  {
64  valueType returnValue;
65  parMap::const_iterator it = parameters.find(name);
66  std::stringstream ss;
67  if( it != parameters.end() ) {
68  ss << it->second;
69  ss >> returnValue;
70  }
71  else {
72  std::cout << "WARNING: parameter " << name << " not found. Returning default value" << std::endl;
73  }
74  return returnValue;
75  }
76 
77 
78  bool isParameter( const std::string & name ) const
79  {
80  return( parameters.find(name) != parameters.end() );
81  }
82 
84  void printSummary(std::stringstream & ss) const;
86  void printDebug(std::stringstream & ss) const;
87 
88  typedef std::map<std::string, std::string> parMap;
89 
91 };
92 
93 template <>
94 bool SiStripConfObject::put<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue );
95 template <>
96 bool SiStripConfObject::update<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue );
97 template <>
98 std::vector<int> SiStripConfObject::get<std::vector<int> >( const std::string & name ) const;
99 template <>
100 bool SiStripConfObject::put<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue );
101 template <>
102 bool SiStripConfObject::update<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue );
103 template <>
104 std::vector<std::string> SiStripConfObject::get<std::vector<std::string> >( const std::string & name ) const;
105 
106 
107 #endif
void printSummary(std::stringstream &ss) const
Prints the full list of parameters.
bool update(const std::string &name, const valueType &inputValue)
std::map< std::string, std::string > parMap
bool put(const std::string &name, const valueType &inputValue)
void printDebug(std::stringstream &ss) const
Prints the full list of parameters.
tuple cout
Definition: gather_cfg.py:121
bool isParameter(const std::string &name) const