CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CondCore/DBCommon/interface/ClassID.h

Go to the documentation of this file.
00001 #ifndef CondCoreDBCommon_ClassID_H
00002 #define CondCoreDBCommon_ClassID_H
00003 #include <typeinfo>
00004 #include<vector>
00005 #include<string>
00006 
00007 namespace cond {
00008 
00009   namespace idCategories {
00010     std::string const dictIDCategory("LCGDictID");
00011     std::string const pythonIDCategory("CondPythonID");
00012   }
00013 
00014 
00015 
00016   char const * className(const std::type_info& t);
00017 
00018   class ClassIDRegistry;
00019 
00020   class ClassInfo {
00021   public:
00022     virtual ~ClassInfo(){}
00023     inline ClassInfo(const std::type_info& t) : tinfo(t) {}
00024     inline ClassInfo(const std::type_info& t, int);
00025     inline const std::type_info& type() const { return tinfo;}
00026     std::string pluginName(std::string const & prefix) const;
00027     virtual std::string resource() const=0;
00028   private:
00029     ClassIDRegistry * registry;
00030     const char * registerMe(const std::type_info& t);
00031     const std::type_info& tinfo;
00032   };
00033   
00034   
00035   class ClassIDRegistry {
00036   public:
00037     typedef ClassInfo Elem;
00038     std::vector<std::string> sids;
00039     std::vector<const char*> csids;
00040     ClassIDRegistry(std::string const & pfix);
00041     
00042     const char * registerMe(const std::type_info& t);
00043     
00044   private:
00045     std::string prefix;
00046     
00047   };
00048 
00049   template<typename T>
00050   struct ClassID : public  ClassInfo {
00051     ClassID() : ClassInfo(typeid(T)) {}
00052     ClassID(char const * res ) : ClassInfo(typeid(T)), m_res(res) {}
00053     ClassID(int i) : ClassInfo(typeid(T),i) {}
00054     virtual std::string resource() const { return m_res;}
00055   private:
00056     std::string m_res;
00057   };
00058   
00059     
00060 }
00061 
00062 // magic: works only if a file local registry exists in the file
00063 #define ELEM_CONSTR(xx_)                                                \
00064   cond::ClassInfo::ClassInfo(const std::type_info& t,int) : tinfo(t) {registry = &xx_;registerMe(t);} 
00065 
00066 
00067 #include "FWCore/PluginManager/interface/PluginFactory.h"
00068 namespace cond{
00069   typedef edmplugin::PluginFactory<ClassInfo*() > ClassInfoFactory;
00070 }
00071 
00072 #define CLASS_ID(type_)  \
00073 namespace{ cond::ClassID<type_>  EDM_PLUGIN_SYM(instance_cld, __LINE__)(0); }   \
00074  DEFINE_EDM_PLUGIN(cond::ClassInfoFactory, cond::ClassID<type_>  , cond::ClassID<type_>().pluginName(cond::idCategories::dictIDCategory).c_str() )
00075 
00076 #define PYTHON_ID(type_, plugName_, uname_)                                     \
00077   namespace pythonID { struct EDM_PLUGIN_SYM(plugName_, uname_)  : public cond::ClassID<type_> { EDM_PLUGIN_SYM(plugName_ , uname_) () : cond::ClassID<type_>(::plugName_){}};} \
00078   DEFINE_EDM_PLUGIN(cond::ClassInfoFactory, EDM_PLUGIN_SYM(pythonID::plugName_, uname_) , EDM_PLUGIN_SYM(pythonID::plugName_, uname_)().pluginName(cond::idCategories::pythonIDCategory).c_str() )
00079 
00080 
00081 #endif //  CondCoreDBCommon_ClassID_H