Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "FWCore/PluginManager/interface/PluginFactoryBase.h"
00018 #include "FWCore/PluginManager/interface/PluginManager.h"
00019 #include "FWCore/Utilities/interface/Exception.h"
00020 #include "FWCore/PluginManager/interface/PluginFactoryManager.h"
00021
00022
00023 namespace edmplugin {
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 PluginFactoryBase::~PluginFactoryBase()
00042 {
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 void
00061 PluginFactoryBase::finishedConstruction()
00062 {
00063 PluginFactoryManager::get()->addFactory(this);
00064 }
00065
00066 void
00067 PluginFactoryBase::newPlugin(const std::string& iName)
00068 {
00069 PluginInfo info;
00070 info.loadable_=boost::filesystem::path(PluginManager::loadingFile());
00071 info.name_=iName;
00072 newPluginAdded_(category(),info);
00073 }
00074
00075
00076 PluginFactoryBase::Plugins::const_iterator
00077 PluginFactoryBase::findPMaker(const std::string& iName) const
00078 {
00079
00080 Plugins::const_iterator itFound = m_plugins.find(iName);
00081 if(itFound == m_plugins.end()) {
00082 std::string lib = PluginManager::get()->load(this->category(),iName).path().string();
00083 itFound = m_plugins.find(iName);
00084 if(itFound == m_plugins.end()) {
00085 throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
00086 <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
00087 }
00088 } else {
00089 checkProperLoadable(iName,itFound->second.front().second);
00090 }
00091 return itFound;
00092 }
00093
00094
00095 PluginFactoryBase::Plugins::const_iterator
00096 PluginFactoryBase::tryToFindPMaker(const std::string& iName) const
00097 {
00098
00099 Plugins::const_iterator itFound = m_plugins.find(iName);
00100 if(itFound == m_plugins.end()) {
00101 const SharedLibrary* slib = PluginManager::get()->tryToLoad(this->category(),iName);
00102 if(0!=slib) {
00103 std::string lib = slib->path().string();
00104 itFound = m_plugins.find(iName);
00105 if(itFound == m_plugins.end()) {
00106 throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
00107 <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
00108 }
00109 }
00110 } else {
00111 checkProperLoadable(iName,itFound->second.front().second);
00112 }
00113 return itFound;
00114 }
00115
00116 void
00117 PluginFactoryBase::fillInfo(const PMakers &makers,
00118 PluginInfo& iInfo,
00119 std::vector<PluginInfo>& iReturn ) const {
00120 for(PMakers::const_iterator it = makers.begin();
00121 it != makers.end();
00122 ++it) {
00123 iInfo.loadable_ = it->second;
00124 iReturn.push_back(iInfo);
00125 }
00126 }
00127
00128 void
00129 PluginFactoryBase::fillAvailable(std::vector<PluginInfo>& iReturn) const {
00130 PluginInfo info;
00131 for( Plugins::const_iterator it = m_plugins.begin();
00132 it != m_plugins.end();
00133 ++it) {
00134 info.name_ = it->first;
00135 fillInfo(it->second,
00136 info, iReturn);
00137 }
00138 }
00139
00140 void
00141 PluginFactoryBase::checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const
00142 {
00143
00144
00145 if (iLoadedFrom != PluginManager::staticallyLinkedLoadingFileName() &&
00146 PluginManager::isAvailable()) {
00147 if( iLoadedFrom != PluginManager::get()->loadableFor(category(),iName).string() ) {
00148 throw cms::Exception("WrongPluginLoaded")<<"The plugin '"<<iName<<"' should have been loaded from\n '"
00149 <<PluginManager::get()->loadableFor(category(),iName).string()
00150 <<"'\n but instead it was already loaded from\n '"
00151 <<iLoadedFrom<<"'\n because some other plugin was loaded from the latter loadables.\n"
00152 "To work around the problem the plugin '"<<iName<<"' should only be defined in one of these loadables.";
00153 }
00154 }
00155 }
00156
00157
00158 void
00159 PluginFactoryBase::registerPMaker(void* iPMaker, const std::string& iName) {
00160 m_plugins[iName].push_back(std::pair<void*,std::string>(iPMaker,PluginManager::loadingFile()));
00161 newPlugin(iName);
00162 }
00163
00164 std::vector<PluginInfo>
00165 PluginFactoryBase::available() const {
00166 std::vector<PluginInfo> returnValue;
00167 returnValue.reserve(m_plugins.size());
00168 fillAvailable(returnValue);
00169 return returnValue;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179 }