Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:58

0001 #ifndef ConfObject_h
0002 #define ConfObject_h
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <iostream>
0007 #include <vector>
0008 #include <map>
0009 #include <algorithm>
0010 #include <iterator>
0011 #include <sstream>
0012 
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 
0015 /**
0016  * Author M. De Mattia - 16/11/2009
0017  *
0018  * Simple class used to store configuration values. <br>
0019  * It stores a map<std::string, std::string> with all the parameters and their values. <br>
0020  * The put and get methods are provided to store and access the parameters. <br>
0021  * The put method retuns a bool which is true if the insertion was successuful. If the parameter
0022  * is already existing the insertion will not happen and the return value will be false. <br>
0023  * The get method is templated and works like the getParameter<type> of the framework. <br>
0024  * The isParameter method can be used to check whether a parameter exists. It will return a
0025  * bool with the result. <br>
0026  * The printSummary and printDebug method return both the full list of parameters. <br>
0027  */
0028 
0029 class ConfObject {
0030 public:
0031   ConfObject() {}
0032 
0033   template <class valueType>
0034   bool put(const std::string& name, const valueType& inputValue) {
0035     std::stringstream ss;
0036     ss << inputValue;
0037     if (parameters.insert(std::make_pair(name, ss.str())).second)
0038       return true;
0039     return false;
0040   }
0041 
0042   template <class valueType>
0043   valueType get(const std::string& name) const {
0044     valueType returnValue;
0045     parMap::const_iterator it = parameters.find(name);
0046     std::stringstream ss;
0047     if (it != parameters.end()) {
0048       ss << it->second;
0049       ss >> returnValue;
0050     } else {
0051       std::cout << "WARNING: parameter " << name << " not found. Returning default value" << std::endl;
0052     }
0053     return returnValue;
0054   }
0055 
0056   bool isParameter(const std::string& name) const { return (parameters.find(name) != parameters.end()); }
0057 
0058   /// Prints the full list of parameters
0059   void printSummary(std::stringstream& ss) const;
0060   /// Prints the full list of parameters
0061   void printDebug(std::stringstream& ss) const;
0062 
0063   typedef std::map<std::string, std::string> parMap;
0064 
0065   parMap parameters;
0066 
0067   COND_SERIALIZABLE;
0068 };
0069 
0070 #endif