CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/PhysicsTools/FWLite/interface/VariableMapCont.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #if !defined(VariableMapCont_H)
00004 #define VariableMapCont_H
00005 
00006 #include <map>
00007 #include <vector>
00008 #include <string>
00009 
00010 namespace optutl
00011 {
00012 
00013 class VariableMapCont
00014 {
00015    public:
00017       // Public Constants //
00019 
00020       // typedefs
00021       typedef std::vector< int >                   IVec;
00022       typedef std::vector< double >                DVec;
00023       typedef std::vector< std::string >           SVec;
00024       typedef std::map< std::string, int >         SIMap;
00025       typedef std::map< std::string, double >      SDMap;
00026       typedef std::map< std::string, bool >        SBMap;
00027       typedef std::map< std::string, std::string > SSMap;
00028       typedef std::map< std::string, IVec >        SIVecMap;
00029       typedef std::map< std::string, DVec >        SDVecMap;
00030       typedef std::map< std::string, SVec >        SSVecMap;
00031       // Iterators
00032       typedef IVec::iterator            IVecIter;
00033       typedef DVec::iterator            DVecIter;
00034       typedef SVec::iterator            SVecIter;
00035       typedef SIMap::iterator           SIMapIter;
00036       typedef SDMap::iterator           SDMapIter;
00037       typedef SBMap::iterator           SBMapIter;
00038       typedef SSMap::iterator           SSMapIter;
00039       typedef SIVecMap::iterator        SIVecMapIter;
00040       typedef SDVecMap::iterator        SDVecMapIter;
00041       typedef SSVecMap::iterator        SSVecMapIter;
00042       // constant iterators
00043       typedef IVec::const_iterator      IVecConstIter;
00044       typedef DVec::const_iterator      DVecConstIter;
00045       typedef SVec::const_iterator      SVecConstIter;
00046       typedef SIMap::const_iterator     SIMapConstIter;
00047       typedef SDMap::const_iterator     SDMapConstIter;
00048       typedef SBMap::const_iterator     SBMapConstIter;
00049       typedef SSMap::const_iterator     SSMapConstIter;
00050       typedef SIVecMap::const_iterator  SIVecMapConstIter;
00051       typedef SDVecMap::const_iterator  SDVecMapConstIter;
00052       typedef SSVecMap::const_iterator  SSVecMapConstIter;
00053    
00054 
00055       // constants
00056       static const int         kDefaultInteger;
00057       static const double      kDefaultDouble;
00058       static const std::string kDefaultString;
00059       static const bool        kDefaultBool;
00060       static const IVec        kEmptyIVec;
00061       static const DVec        kEmptyDVec;
00062       static const SVec        kEmptySVec;
00063 
00064       enum OptionType
00065       {
00066          kNone = 0,
00067          kInteger,
00068          kDouble,
00069          kString,
00070          kBool,
00071          kIntegerVector,
00072          kDoubleVector,
00073          kStringVector,
00074          kNumOptionTypes
00075       };
00076 
00078       // friends //
00080       // tells particle data how to print itself out
00081       friend std::ostream& operator<< (std::ostream& o_stream, 
00082                                        const VariableMapCont &rhs);
00083 
00085       //            _         //
00086       // |\/|      |_         //
00087       // |  |EMBER | UNCTIONS //
00088       //                      //
00090 
00092       // Constructors and Destructor //
00094       VariableMapCont();
00095 
00097       // Regular Member Functions //
00099 
00100       // prints out '--help' screen, then exits.
00101       void help();
00102 
00103       // returns OptionType (or kNone (0)) of a given option.  
00104       OptionType hasVariable (std::string key);
00105       OptionType hasOption (std::string key)
00106       { return hasVariable (key); }
00107 
00108 
00109       // Add variable to option maps.  'key' is passed in by copy
00110       // because it is modified in place.
00111       void addOption (std::string key, OptionType type,
00112                       const std::string &description = "");
00113       void addOption (std::string key, OptionType type,
00114                       const std::string &description, 
00115                       int defaultValue);
00116       void addOption (std::string key, OptionType type,
00117                       const std::string &description, 
00118                       double defaultValue);
00119       void addOption (std::string key, OptionType type,
00120                       const std::string &description, 
00121                       const std::string &defaultValue);
00122       void addOption (std::string key, OptionType type,
00123                       const std::string &description, 
00124                       const char *defaultValue);
00125       void addOption (std::string key, OptionType type,
00126                       const std::string &description, 
00127                       bool defaultValue);
00128       //   addVariable works just like addOption, but has no description.
00129       void addVariable (std::string key, OptionType type)
00130       { addOption (key, type, ""); }
00131       void addVariable (std::string key, OptionType type, int defaultValue)
00132       { addOption (key, type, "", defaultValue); }
00133       void addVariable (std::string key, OptionType type, double defaultValue)
00134       { addOption (key, type, "", defaultValue); }
00135       void addVariable (std::string key, OptionType type, 
00136                         const std::string &defaultValue)
00137       { addOption (key, type, "", defaultValue); }
00138       void addVariable (std::string key, OptionType type, 
00139                         const char *defaultValue)
00140       { addOption (key, type, "", defaultValue); }
00141       void addVariable (std::string key, OptionType type, bool defaultValue)
00142       { addOption (key, type, "", defaultValue); }
00143 
00144 
00145       // some of the guts of above
00146       void _checkKey (std::string &key, const std::string &description = "");
00147 
00148       int         &integerValue  (std::string key);
00149       double      &doubleValue   (std::string key);
00150       std::string &stringValue   (std::string key);
00151       bool        &boolValue     (std::string key);
00152       IVec        &integerVector (std::string key);
00153       DVec        &doubleVector  (std::string key);
00154       SVec        &stringVector  (std::string key);
00155 
00157       // Static Member Functions //
00159 
00160       // converts a string to lower case characters
00161       static void lowercaseString(std::string &arg); 
00162 
00163       // converts a single character to lower case
00164       static char toLower (char &ch);
00165 
00166 
00167    protected:
00168 
00169       // returns true if a variable has been modified from the command
00170       // line.
00171       bool _valueHasBeenModified (const std::string &key);
00172 
00174       // Private Member Data //
00176 
00177       SIMap     m_integerMap;
00178       SDMap     m_doubleMap;
00179       SSMap     m_stringMap;
00180       SBMap     m_boolMap;
00181       SIVecMap  m_integerVecMap;
00182       SDVecMap  m_doubleVecMap;
00183       SSVecMap  m_stringVecMap;
00184       SBMap     m_variableModifiedMap;
00185       SSMap     m_variableDescriptionMap;
00186 
00187 };
00188 
00189 }
00190 #endif // VariableMapCont_H