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 
5 
6 #include <iostream>
7 #include <vector>
8 #include <map>
9 #include <algorithm>
10 #include <iterator>
11 #include <sstream>
12 
14 
30 {
31  public:
33 
34  template <class valueType>
35  bool put( const std::string & name, const valueType & inputValue )
36  {
37  std::stringstream ss;
38  ss << inputValue;
39  if( parameters.insert(std::make_pair(name, ss.str())).second ) return true;
40  return false;
41  }
42 
43 
47  template <class valueType>
48  bool update( const std::string & name, const valueType & inputValue )
49  {
50  parMap::iterator it = parameters.find(name);
51  if (it == parameters.end()) {
52  std::cout << "WARNING in SiStripConfObject::update: parameter " << name << " not found, "
53  << "so cannot be updated to '" << inputValue << "'." << std::endl;
54  return false;
55  } else {
56  std::stringstream ss;
57  ss << inputValue;
58  it->second = ss.str();
59  return true;
60  }
61  }
62 
63  template <class valueType>
64  valueType get( const std::string & name ) const
65  {
66  valueType returnValue = 0;
67  parMap::const_iterator it = parameters.find(name);
68  std::stringstream ss;
69  if( it != parameters.end() ) {
70  ss << it->second;
71  ss >> returnValue;
72  }
73  else {
74  std::cout << "WARNING: parameter " << name << " not found. Returning default value" << std::endl;
75  }
76  return returnValue;
77  }
78 
79  bool isParameter( const std::string & name ) const
80  {
81  return( parameters.find(name) != parameters.end() );
82  }
83 
85  void printSummary(std::stringstream & ss) const;
87  void printDebug(std::stringstream & ss) const;
88 
89  typedef std::map<std::string, std::string> parMap;
90 
92 
94 };
95 
96 template <>
97 std::string SiStripConfObject::get<std::string>( const std::string & name ) const;
98 template <>
99 bool SiStripConfObject::put<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue );
100 template <>
101 bool SiStripConfObject::update<std::vector<int> >( const std::string & name, const std::vector<int> & inputValue );
102 template <>
103 std::vector<int> SiStripConfObject::get<std::vector<int> >( const std::string & name ) const;
104 template <>
105 bool SiStripConfObject::put<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue );
106 template <>
107 bool SiStripConfObject::update<std::vector<std::string> >( const std::string & name, const std::vector<std::string> & inputValue );
108 template <>
109 std::vector<std::string> SiStripConfObject::get<std::vector<std::string> >( const std::string & name ) const;
110 
111 
112 #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