CMS 3D CMS Logo

edmplugin::PluginManager Class Reference

#include <FWCore/PluginManager/interface/PluginManager.h>

List of all members.

Public Types

typedef std::map< std::string,
Infos
CategoryToInfos
typedef std::vector< PluginInfoInfos
typedef std::vector< std::string > SearchPath

Public Member Functions

const CategoryToInfoscategoryToInfos () const
 The container is ordered by category, then plugin name and then by precidence order of the plugin files.
const SharedLibraryload (const std::string &iCategory, const std::string &iPlugin)
const boost::filesystem::path & loadableFor (const std::string &iCategory, const std::string &iPlugin)
const SharedLibrarytryToLoad (const std::string &iCategory, const std::string &iPlugin)
 ~PluginManager ()

Static Public Member Functions

static PluginManagerconfigure (const Config &)
static PluginManagerget ()
static bool isAvailable ()
static const std::string & loadingFile ()
 file name of the shared object being loaded
static const std::string & staticallyLinkedLoadingFileName ()
 if the value returned from loadingFile matches this string then the file is statically linked

Public Attributes

sigc::signal< void, const
std::string &, const
std::string & > 
askedToLoadCategoryWithPlugin_
sigc::signal< void, const
boost::filesystem::path & > 
goingToLoad_
sigc::signal< void, const
SharedLibrary & > 
justLoaded_

Private Member Functions

const boost::filesystem::path & loadableFor_ (const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
void newFactory (const PluginFactoryBase *)
const PluginManageroperator= (const PluginManager &)
 PluginManager (const PluginManager &)
 PluginManager (const Config &)

Static Private Member Functions

static std::string & loadingLibraryNamed_ ()
static PluginManager *& singleton ()

Private Attributes

CategoryToInfos categoryToInfos_
std::map
< boost::filesystem::path,
boost::shared_ptr
< SharedLibrary > > 
loadables_
SearchPath searchPath_

Friends

class DummyFriend

Classes

class  Config


Detailed Description

Definition at line 38 of file PluginManager.h.


Member Typedef Documentation

typedef std::map<std::string, Infos > edmplugin::PluginManager::CategoryToInfos

Definition at line 44 of file PluginManager.h.

typedef std::vector<PluginInfo> edmplugin::PluginManager::Infos

Definition at line 43 of file PluginManager.h.

typedef std::vector<std::string> edmplugin::PluginManager::SearchPath

Definition at line 42 of file PluginManager.h.


Constructor & Destructor Documentation

PluginManager::~PluginManager (  ) 

Definition at line 98 of file PluginManager.cc.

00099 {
00100 }

PluginManager::PluginManager ( const Config iConfig  )  [private]

Definition at line 44 of file PluginManager.cc.

References edmplugin::PluginFactoryManager::begin(), edmplugin::standard::cachefileName(), categoryToInfos_, dir, e, edmplugin::PluginFactoryManager::end(), Exception, file, DBSPlugin::get(), i, loadingLibraryNamed_(), newFactory(), edmplugin::PluginFactoryManager::newFactory_, path(), SiStripLorentzAngle_cfi::read, and searchPath_.

00044                                                                :
00045   searchPath_( iConfig.searchPath() )
00046 {
00047     const boost::filesystem::path kCacheFile(standard::cachefileName());
00048     //NOTE: This may not be needed :/
00049     PluginFactoryManager* pfm = PluginFactoryManager::get();
00050     pfm->newFactory_.connect(boost::bind(boost::mem_fn(&PluginManager::newFactory),this,_1));
00051 
00052     // When building a single big executable the plugins are already registered in the 
00053     // PluginFactoryManager, we therefore only need to populate the categoryToInfos_ map
00054     // with the relevant information.
00055     for (PluginFactoryManager::const_iterator i = pfm->begin(), e = pfm->end(); i != e; ++i)
00056     {
00057         categoryToInfos_[(*i)->category()] = (*i)->available();
00058     }
00059 
00060     //read in the files
00061     //Since we are looping in the 'precidence' order then the lists in categoryToInfos_ will also be
00062     // in that order
00063     std::set<std::string> alreadySeen;
00064     for(SearchPath::const_iterator itPath=searchPath_.begin(), itEnd = searchPath_.end();
00065         itPath != itEnd;
00066         ++itPath) {
00067       //take care of the case where the same path is passed in multiple times
00068       if (alreadySeen.find(*itPath) != alreadySeen.end() ) {
00069         continue;
00070       }
00071       alreadySeen.insert(*itPath);
00072       boost::filesystem::path dir(*itPath,boost::filesystem::no_check);
00073       if( exists( dir) ) {
00074         if(not is_directory(dir) ) {
00075           throw cms::Exception("PluginManagerBadPath") <<"The path '"<<dir.native_file_string()<<"' for the PluginManager is not a directory";
00076         }
00077         boost::filesystem::path cacheFile = dir/kCacheFile;
00078         
00079         if(exists(cacheFile) ) {
00080           std::ifstream file(cacheFile.native_file_string().c_str());
00081           if(not file) {
00082             throw cms::Exception("PluginMangerCacheProblem")<<"Unable to open the cache file '"<<cacheFile.native_file_string()
00083             <<"'. Please check permissions on file";
00084           }
00085           CacheParser::read(file, dir, categoryToInfos_);          
00086         }
00087       }
00088     }
00089     //Since this should not be called until after 'main' has started, we can set the value
00090     loadingLibraryNamed_()="<loaded by another plugin system>";
00091 }

edmplugin::PluginManager::PluginManager ( const PluginManager  )  [private]


Member Function Documentation

const CategoryToInfos& edmplugin::PluginManager::categoryToInfos (  )  const [inline]

The container is ordered by category, then plugin name and then by precidence order of the plugin files.

Therefore the first match on category and plugin name will be the proper file to load

Definition at line 72 of file PluginManager.h.

References categoryToInfos_.

Referenced by PrintLoadingPlugins::askedToLoad(), fillRecordToTypeMap(), edm::pset::IncludeFileFinder::IncludeFileFinder(), edm::RootAutoLibraryLoader::loadAll(), edm::service::LoadAllDictionaries::LoadAllDictionaries(), main(), and edm::registerTypes().

00072                                                      {
00073         return categoryToInfos_;
00074       }

PluginManager & PluginManager::configure ( const Config iConfig  )  [static]

Definition at line 282 of file PluginManager.cc.

References Exception, s, and edmplugin::PluginManager::Config::searchPath().

Referenced by stor::StorageManager::configureAction(), AutoLibraryLoader::enable(), StorageFactory::getMaker(), edm::pset::IncludeFileFinder::IncludeFileFinder(), VisEventProcessorService::init(), HPDNoiseLibraryReader::initializeServices(), mcdbGetInputFile(), and edm::ProblemTracker::ProblemTracker().

00283 {
00284   PluginManager*& s = singleton();
00285   if( 0 != s ){
00286     throw cms::Exception("PluginManagerReconfigured");
00287   }
00288   
00289   Config realConfig = iConfig;
00290   if (realConfig.searchPath().empty() ) {
00291     throw cms::Exception("PluginManagerEmptySearchPath");
00292   }
00293   s = new PluginManager (realConfig);
00294   return *s;
00295 }

PluginManager * PluginManager::get ( void   )  [static]

Definition at line 272 of file PluginManager.cc.

References Exception.

Referenced by edmplugin::PluginFactoryBase::checkProperLoadable(), fillRecordToTypeMap(), edm::pset::IncludeFileFinder::IncludeFileFinder(), edm::RootAutoLibraryLoader::loadAll(), edm::service::LoadAllDictionaries::LoadAllDictionaries(), main(), and edm::registerTypes().

00273 {
00274   PluginManager* manager = singleton();
00275   if(0==manager) {
00276     throw cms::Exception("PluginManagerNotConfigured")<<"PluginManager::get() was called before PluginManager::configure.";
00277   }
00278   return manager;
00279 }

bool PluginManager::isAvailable (  )  [static]

Definition at line 319 of file PluginManager.cc.

Referenced by edmplugin::PluginFactoryBase::checkProperLoadable(), stor::StorageManager::configureAction(), StorageFactory::getMaker(), edm::pset::IncludeFileFinder::IncludeFileFinder(), HPDNoiseLibraryReader::initializeServices(), and edm::ProblemTracker::ProblemTracker().

00320 {
00321   return 0 != singleton();
00322 }

const SharedLibrary & PluginManager::load ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 218 of file PluginManager.cc.

References p, path(), ptr, and s.

00220 {
00221   askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
00222   const boost::filesystem::path& p = loadableFor(iCategory,iPlugin);
00223   
00224   //have we already loaded this?
00225   std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded = 
00226     loadables_.find(p);
00227   if(itLoaded == loadables_.end()) {
00228     //try to make one
00229     goingToLoad_(p);
00230     Sentry s(loadingLibraryNamed_(), p.native_file_string());
00231     //boost::filesystem::path native(p.native_file_string(),boost::filesystem::no_check);
00232     boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
00233     loadables_[p]=ptr;
00234     justLoaded_(*ptr);
00235     return *ptr;
00236   }
00237   return *(itLoaded->second);
00238 }

const boost::filesystem::path & PluginManager::loadableFor ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 134 of file PluginManager.cc.

00136 {
00137   bool throwIfFail = true;
00138   return loadableFor_(iCategory, iPlugin,throwIfFail);
00139 }

const boost::filesystem::path & PluginManager::loadableFor_ ( const std::string &  iCategory,
const std::string &  iPlugin,
bool ioThrowIfFailElseSucceedStatus 
) [private]

Definition at line 142 of file PluginManager.cc.

References Exception, i, edmplugin::PluginInfo::name_, path(), and range.

00145 {
00146   const bool throwIfFail = ioThrowIfFailElseSucceedStatus;
00147   ioThrowIfFailElseSucceedStatus = true;
00148   CategoryToInfos::iterator itFound = categoryToInfos_.find(iCategory);
00149   if(itFound == categoryToInfos_.end()) {
00150     if(throwIfFail) {
00151       throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin<<
00152       "' because the category '"<<iCategory<<"' has no known plugins";
00153     } else {
00154       ioThrowIfFailElseSucceedStatus = false;
00155       static boost::filesystem::path s_path;
00156       return s_path;
00157     }
00158   }
00159   
00160   PluginInfo i;
00161   i.name_ = iPlugin;
00162   typedef std::vector<PluginInfo>::iterator PIItr;
00163   std::pair<PIItr,PIItr> range = std::equal_range(itFound->second.begin(),
00164                                                   itFound->second.end(),
00165                                                   i,
00166                                                   PICompare() );
00167   
00168   if(range.first == range.second) {
00169     if(throwIfFail) {
00170       throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin
00171       <<"'. Please check spelling of name.";
00172     } else {
00173       ioThrowIfFailElseSucceedStatus = false;
00174       static boost::filesystem::path s_path;
00175       return s_path;
00176     }
00177   }
00178   
00179   if(range.second - range.first > 1 ) {
00180     //see if the come from the same directory
00181     if(range.first->loadable_.branch_path() == (range.first+1)->loadable_.branch_path()) {
00182       //std::cout<<range.first->name_ <<" " <<(range.first+1)->name_<<std::endl;
00183       throw cms::Exception("MultiplePlugins")<<"The plugin '"<<iPlugin<<"' is found in multiple files \n"
00184       " '"<<range.first->loadable_.leaf()<<"'\n '"
00185       <<(range.first+1)->loadable_.leaf()<<"'\n"
00186       "in directory '"<<range.first->loadable_.branch_path().native_file_string()<<"'.\n"
00187       "The code must be changed so the plugin only appears in one plugin file. "
00188       "You will need to remove the macro which registers the plugin so it only appears in"
00189       " one of these files.\n"
00190       "  If none of these files register such a plugin, "
00191       "then the problem originates in a library to which all these files link.\n"
00192       "The plugin registration must be removed from that library since plugins are not allowed in regular libraries.";
00193     }
00194   }
00195   
00196   return range.first->loadable_;
00197 }

static const std::string& edmplugin::PluginManager::loadingFile (  )  [inline, static]

file name of the shared object being loaded

Definition at line 82 of file PluginManager.h.

References loadingLibraryNamed_().

Referenced by edmplugin::PluginFactory< R *(Arg)>::registerPMaker(), edmplugin::PluginFactory< R *(void)>::registerPMaker(), and edmplugin::PluginFactory< R *(Arg1, Arg2)>::registerPMaker().

00082                                             { 
00083         return loadingLibraryNamed_();}

std::string & PluginManager::loadingLibraryNamed_ (  )  [static, private]

Definition at line 306 of file PluginManager.cc.

Referenced by loadingFile(), and PluginManager().

00307 {
00308   static std::string s_name(staticallyLinkedLoadingFileName());
00309   return s_name;
00310 }

void PluginManager::newFactory ( const PluginFactoryBase  )  [private]

Definition at line 118 of file PluginManager.cc.

Referenced by PluginManager().

00119 {
00120 }

const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager  )  [private]

PluginManager *& PluginManager::singleton (  )  [static, private]

Definition at line 312 of file PluginManager.cc.

00313 {
00314   static PluginManager* s_singleton;
00315   return s_singleton;
00316 }

const std::string & PluginManager::staticallyLinkedLoadingFileName (  )  [static]

if the value returned from loadingFile matches this string then the file is statically linked

Definition at line 299 of file PluginManager.cc.

Referenced by edmplugin::PluginFactoryBase::checkProperLoadable().

00300 {
00301   static std::string s_name("static");
00302   return s_name;
00303 }

const SharedLibrary * PluginManager::tryToLoad ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 241 of file PluginManager.cc.

References p, path(), ptr, and s.

00243 {
00244   askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
00245   bool ioThrowIfFailElseSucceedStatus = false;
00246   const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus);
00247   
00248   if( not ioThrowIfFailElseSucceedStatus ) {
00249     return 0;
00250   }
00251   
00252   //have we already loaded this?
00253   std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded = 
00254     loadables_.find(p);
00255   if(itLoaded == loadables_.end()) {
00256     //try to make one
00257     goingToLoad_(p);
00258     Sentry s(loadingLibraryNamed_(), p.native_file_string());
00259     //boost::filesystem::path native(p.native_file_string(),boost::filesystem::no_check);
00260     boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
00261     loadables_[p]=ptr;
00262     justLoaded_(*ptr);
00263     return ptr.get();
00264   }
00265   return (itLoaded->second).get();
00266 }


Friends And Related Function Documentation

friend class DummyFriend [friend]

Definition at line 40 of file PluginManager.h.


Member Data Documentation

sigc::signal<void,const std::string&,const std::string&> edmplugin::PluginManager::askedToLoadCategoryWithPlugin_

Definition at line 97 of file PluginManager.h.

Referenced by PrintLoadingPlugins::PrintLoadingPlugins().

CategoryToInfos edmplugin::PluginManager::categoryToInfos_ [private]

Definition at line 115 of file PluginManager.h.

Referenced by categoryToInfos(), and PluginManager().

sigc::signal<void,const boost::filesystem::path&> edmplugin::PluginManager::goingToLoad_

Definition at line 95 of file PluginManager.h.

Referenced by PrintLoadingPlugins::PrintLoadingPlugins().

sigc::signal<void,const SharedLibrary&> edmplugin::PluginManager::justLoaded_

Definition at line 96 of file PluginManager.h.

std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> > edmplugin::PluginManager::loadables_ [private]

Definition at line 113 of file PluginManager.h.

SearchPath edmplugin::PluginManager::searchPath_ [private]

Definition at line 112 of file PluginManager.h.

Referenced by PluginManager().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:46:41 2009 for CMSSW by  doxygen 1.5.4