Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:39

0001 #ifndef SiStripConfObject_h
0002 #define SiStripConfObject_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 class TrackerTopology;
0016 
0017 /**
0018  * Author M. De Mattia - 16/11/2009
0019  *
0020  * Simple class used to store configuration values. <br>
0021  * It stores a map<std::string, std::string> with all the parameters and their values. <br>
0022  * The put and get methods are provided to store and access the parameters. <br>
0023  * The put method retuns a bool which is true if the insertion was successuful. If the parameter
0024  * is already existing the insertion will not happen and the return value will be false. <br>
0025  * The get method is templated and works like the getParameter<type> of the framework. <br>
0026  * The isParameter method can be used to check whether a parameter exists. It will return a
0027  * bool with the result. <br>
0028  * The printSummary and printDebug method return both the full list of parameters. <br>
0029  */
0030 
0031 class SiStripConfObject {
0032 public:
0033   SiStripConfObject() {}
0034 
0035   template <class valueType>
0036   bool put(const std::string& name, const valueType& inputValue) {
0037     std::stringstream ss;
0038     ss << inputValue;
0039     if (parameters.insert(std::make_pair(name, ss.str())).second)
0040       return true;
0041     return false;
0042   }
0043 
0044   /// Updating the value stored as 'name' with 'inputValue'.
0045   /// False if parameter 'name' does not exist (and nothing is done then - use put(..) instead!),
0046   /// otherwise true.
0047   template <class valueType>
0048   bool update(const std::string& name, const valueType& inputValue) {
0049     parMap::iterator it = parameters.find(name);
0050     if (it == parameters.end()) {
0051       std::cout << "WARNING in SiStripConfObject::update: parameter " << name << " not found, "
0052                 << "so cannot be updated to '" << inputValue << "'." << std::endl;
0053       return false;
0054     } else {
0055       std::stringstream ss;
0056       ss << inputValue;
0057       it->second = ss.str();
0058       return true;
0059     }
0060   }
0061 
0062   template <class valueType>
0063   valueType get(const std::string& name) const {
0064     valueType returnValue = 0;
0065     parMap::const_iterator it = parameters.find(name);
0066     std::stringstream ss;
0067     if (it != parameters.end()) {
0068       ss << it->second;
0069       ss >> returnValue;
0070     } else {
0071       std::cout << "WARNING: parameter " << name << " not found. Returning default value" << std::endl;
0072     }
0073     return returnValue;
0074   }
0075 
0076   bool isParameter(const std::string& name) const { return (parameters.find(name) != parameters.end()); }
0077 
0078   /// Prints the full list of parameters
0079   void printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0080   /// Prints the full list of parameters
0081   void printDebug(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0082 
0083   typedef std::map<std::string, std::string> parMap;
0084 
0085   parMap parameters;
0086 
0087   COND_SERIALIZABLE;
0088 };
0089 
0090 template <>
0091 std::string SiStripConfObject::get<std::string>(const std::string& name) const;
0092 template <>
0093 bool SiStripConfObject::put<std::vector<int> >(const std::string& name, const std::vector<int>& inputValue);
0094 template <>
0095 bool SiStripConfObject::update<std::vector<int> >(const std::string& name, const std::vector<int>& inputValue);
0096 template <>
0097 std::vector<int> SiStripConfObject::get<std::vector<int> >(const std::string& name) const;
0098 template <>
0099 bool SiStripConfObject::put<std::vector<std::string> >(const std::string& name,
0100                                                        const std::vector<std::string>& inputValue);
0101 template <>
0102 bool SiStripConfObject::update<std::vector<std::string> >(const std::string& name,
0103                                                           const std::vector<std::string>& inputValue);
0104 template <>
0105 std::vector<std::string> SiStripConfObject::get<std::vector<std::string> >(const std::string& name) const;
0106 
0107 #endif