CMS 3D CMS Logo

ClassInfoLoader.cc

Go to the documentation of this file.
00001 #include "CondCore/DBCommon/interface/ClassInfoLoader.h"
00002 #include "CondCore/DBCommon/interface/ClassID.h"
00003 #include "CondCore/DBCommon/interface/Exception.h"
00004 
00005 #include "StorageSvc/DbReflex.h"
00006 
00007 #include "FWCore/PluginManager/interface/PluginManager.h"
00008 
00009 
00010 namespace cond {
00011 
00012   // decode token
00013   std::string classID(std::string const & token) {
00014     static std::string const clid("CLID=");
00015     std::string::size_type s = token.find(clid) + clid.size();
00016     std::string::size_type e = token.find(']',s);
00017     return token.substr(s,e-s);
00018 
00019   }
00020 
00021   // find and return
00022   boost::shared_ptr<ClassInfo> classInfo(std::string const & token) {
00023     static std::string const prefix = cond::idCategories::dictIDCategory + "/";
00024     std::string pluginName = prefix + classID(token);
00025     return boost::shared_ptr<ClassInfo>(ClassInfoFactory::get()->create(pluginName));
00026   }
00027   
00028   // load plugin (delete classInfo)
00029   bool loadClassByToken(std::string const & token) {
00030      boost::shared_ptr<ClassInfo> ci = classInfo(token);
00031      // will never return false as pluginMgr throw!
00032      return ci.get()!=0;
00033   }
00034 
00035 
00036   namespace {
00037     std::string const errmsg("Unable to load class for token ");
00038     std::string const orimsg(". Original error msg was ");
00039 
00040   }
00041 
00042   ROOT::Reflex::Type reflexTypeByToken(std::string const & token) {
00043     const pool::Guid guid(cond::classID(token));
00044     {
00045       // look if already loaded
00046       ROOT::Reflex::Type type = pool::DbReflex::forGuid(guid);
00047       if (type) return type;
00048     }
00049     try {
00050       // plugin mgr will throw fist: still
00051       if (!cond::loadClassByToken(token)) 
00052         throw cond::Exception(errmsg+token);
00053     }
00054     catch (cms::Exception const & e) {
00055       throw cond::Exception(errmsg+token+orimsg+e.what());
00056     }
00057     ROOT::Reflex::Type type = pool::DbReflex::forGuid(guid);
00058     if (!type) throw cond::Exception(errmsg+token +". Problem with DbReflex");
00059     return type;
00060   }
00061 
00062 }

Generated on Tue Jun 9 17:26:05 2009 for CMSSW by  doxygen 1.5.4