CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/FWCore/PluginManager/src/PluginCapabilities.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     PluginManager
00004 // Class  :     PluginCapabilities
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Fri Apr  6 12:36:24 EDT 2007
00011 // $Id: PluginCapabilities.cc,v 1.6 2011/08/24 12:28:53 eulisse Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "FWCore/PluginManager/interface/PluginCapabilities.h"
00018 #include "FWCore/PluginManager/interface/SharedLibrary.h"
00019 #include "FWCore/PluginManager/interface/PluginManager.h"
00020 #include "FWCore/Utilities/interface/Exception.h"
00021 
00022 namespace edmplugin {
00023 //
00024 // constants, enums and typedefs
00025 //
00026 
00027 //
00028 // static data member definitions
00029 //
00030 
00031 //
00032 // constructors and destructor
00033 //
00034 PluginCapabilities::PluginCapabilities()
00035 {
00036   finishedConstruction();
00037 }
00038 
00039 // PluginCapabilities::PluginCapabilities(const PluginCapabilities& rhs)
00040 // {
00041 //    // do actual copying here;
00042 // }
00043 
00044 PluginCapabilities::~PluginCapabilities()
00045 {
00046 }
00047 
00048 //
00049 // assignment operators
00050 //
00051 // const PluginCapabilities& PluginCapabilities::operator=(const PluginCapabilities& rhs)
00052 // {
00053 //   //An exception safe implementation is
00054 //   PluginCapabilities temp(rhs);
00055 //   swap(rhs);
00056 //
00057 //   return *this;
00058 // }
00059 
00060 //
00061 // member functions
00062 //
00063 bool 
00064 PluginCapabilities::tryToFind(const SharedLibrary& iLoadable)
00065 {
00066   void* sym;
00067   if( not iLoadable.symbol("SEAL_CAPABILITIES",sym) ) {
00068     return false;
00069   }
00070   
00071   const char** names;
00072   int size;
00073   //reinterpret_cast<void (*)(const char**&,int&)>(sym)(names,size);
00074   reinterpret_cast<void (*)(const char**&,int&)>(reinterpret_cast<unsigned long>(sym))(names,size);
00075 
00076   PluginInfo info;
00077   for(int i=0; i < size; ++i) {
00078     std::string name(names[i]);
00079     classToLoadable_[name]=iLoadable.path();
00080     
00081     //NOTE: can't use newPlugin(name) to do the work since it assumes
00082     //  we haven't yet returned from PluginManager::load method
00083     info.name_ = name;
00084     info.loadable_ = iLoadable.path();
00085     this->newPluginAdded_(category(),info);
00086   }
00087   return true;
00088 }
00089 
00090 void 
00091 PluginCapabilities::load(const std::string& iName)
00092 {
00093   if(classToLoadable_.end() == classToLoadable_.find(iName) ) {
00094     const SharedLibrary& lib = PluginManager::get()->load(category(),
00095                                                           iName);
00096     //read the items from the 'capabilities' symbol
00097     if(not tryToFind(lib) ) {
00098       throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName <<"' is supposed to be in file\n '"
00099       <<lib.path().string()<<"'\n but no dictionaries are in that file.\n"
00100       "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib.path().string()<<"'.";
00101     }
00102     
00103     if(classToLoadable_.end() == classToLoadable_.find(iName)) {
00104       throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName<<"' is supposed to be in file\n '"
00105       <<lib.path().string()<<"'\n but was not found.\n"
00106       "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib.path().string()<<"'.";
00107     }
00108   }
00109 }
00110 
00111 bool
00112 PluginCapabilities::tryToLoad(const std::string& iName)
00113 {
00114   if(classToLoadable_.end() == classToLoadable_.find(iName) ) {
00115     const SharedLibrary* lib = PluginManager::get()->tryToLoad(category(),
00116                                                           iName);
00117     if( 0 == lib) {
00118       return false;
00119     }
00120     //read the items from the 'capabilities' symbol
00121     if(not tryToFind(*lib) ) {
00122       throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName <<"' is supposed to be in file\n '"
00123       <<lib->path().string()<<"'\n but no dictionaries are in that file.\n"
00124       "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib->path().string()<<"'.";
00125     }
00126     
00127     if(classToLoadable_.end() == classToLoadable_.find(iName)) {
00128       throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName<<"' is supposed to be in file\n '"
00129       <<lib->path().string()<<"'\n but was not found.\n"
00130       "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib->path().string()<<"'.";
00131     }
00132   }
00133   return true;
00134 }
00135 //
00136 // const member functions
00137 //
00138 std::vector<PluginInfo> 
00139 PluginCapabilities::available() const
00140 {
00141   PluginInfo info;
00142   std::vector<PluginInfo> infos;
00143   infos.reserve(classToLoadable_.size());
00144   
00145   for(std::map<std::string, boost::filesystem::path>::const_iterator it = classToLoadable_.begin();
00146       it != classToLoadable_.end();
00147       ++it) {
00148     info.name_ = it->first;
00149     info.loadable_ = it->second;
00150     infos.push_back(info);
00151   }
00152   return infos;
00153 }
00154 
00155 const std::string& 
00156 PluginCapabilities::category() const
00157 {
00158   static const std::string s_cat("Capability");
00159   return s_cat;
00160 }
00161 
00162 //
00163 // static member functions
00164 //
00165 PluginCapabilities*
00166 PluginCapabilities::get() {
00167   static PluginCapabilities s_instance;
00168   return &s_instance;
00169 }
00170 
00171 }