CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Alignment/CommonAlignment/interface/AlignSetup.h

Go to the documentation of this file.
00001 #ifndef Alignment_CommonAlignment_AlignSetup_h
00002 #define Alignment_CommonAlignment_AlignSetup_h
00003 
00019 #include <map>
00020 #include <sstream>
00021 
00022 #include "FWCore/Utilities/interface/Exception.h"
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024 
00025 template <class Type>
00026 class AlignSetup
00027 {
00028   typedef typename std::map<std::string, Type> Container;
00029 
00030 public:
00031 
00033   AlignSetup() {}
00034 
00037   Type& get( const std::string& name = "" );
00038 
00041   Type& find( const std::string& name = "" );
00042 
00044   void dump( void ) const;
00045 
00046 private:
00047   Container theStore;
00048 };
00049 
00050 
00051 template <class Type>
00052 Type& AlignSetup<Type>::get(const std::string& name)
00053 {
00054   return theStore[name];
00055 }
00056 
00057 template <class Type>
00058 Type& AlignSetup<Type>::find(const std::string& name)                
00059 {
00060   typename Container::iterator o = theStore.find(name);
00061 
00062   if (theStore.end() == o) {
00063       std::ostringstream knownKeys;
00064       for (typename Container::const_iterator it = theStore.begin(); it != theStore.end(); ++it) {
00065         knownKeys << (it != theStore.begin() ? ", " : "") << it->first;
00066       }
00067       throw cms::Exception("AlignSetupError")
00068         << "Cannot find an object of name " << name << " in AlignSetup, know only "
00069         << knownKeys.str() << ".";
00070     }
00071   
00072   return o->second;
00073 }
00074 
00075 template <class Type>
00076 void AlignSetup<Type>::dump( void ) const
00077 {
00078   edm::LogInfo("AlignSetup") << "Printing out AlignSetup: ";
00079   for ( typename Container::const_iterator it = theStore.begin();
00080         it != theStore.end(); ++it ) {
00081     edm::LogVerbatim("AlignSetup") << it->first << std::endl;
00082   }
00083 }
00084 
00085 #endif