CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends

edmplugin::PluginManager Class Reference

#include <PluginManager.h>

List of all members.

Classes

class  Config

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
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

edm::signalslot::Signal< void(const
std::string &, const
std::string &)> 
askedToLoadCategoryWithPlugin_
edm::signalslot::Signal< void(const
boost::filesystem::path &)> 
goingToLoad_
edm::signalslot::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 Config &)
 PluginManager (const PluginManager &)

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

Detailed Description

Definition at line 37 of file PluginManager.h.


Member Typedef Documentation

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

Definition at line 43 of file PluginManager.h.

Definition at line 42 of file PluginManager.h.

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

Definition at line 41 of file PluginManager.h.


Constructor & Destructor Documentation

PluginManager::~PluginManager ( )

Definition at line 107 of file PluginManager.cc.

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

Definition at line 44 of file PluginManager.cc.

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

Referenced by configure().

                                                               :
  searchPath_( iConfig.searchPath() )
{
    const boost::filesystem::path kCacheFile(standard::cachefileName());
    //NOTE: This may not be needed :/
    PluginFactoryManager* pfm = PluginFactoryManager::get();
    pfm->newFactory_.connect(boost::bind(boost::mem_fn(&PluginManager::newFactory),this,_1));

    // When building a single big executable the plugins are already registered in the 
    // PluginFactoryManager, we therefore only need to populate the categoryToInfos_ map
    // with the relevant information.
    for (PluginFactoryManager::const_iterator i = pfm->begin(), e = pfm->end(); i != e; ++i)
    {
        categoryToInfos_[(*i)->category()] = (*i)->available();
    }

    //read in the files
    //Since we are looping in the 'precidence' order then the lists in categoryToInfos_ will also be
    // in that order
    bool foundAtLeastOneCacheFile = false;
    std::set<std::string> alreadySeen;
    for(SearchPath::const_iterator itPath=searchPath_.begin(), itEnd = searchPath_.end();
        itPath != itEnd;
        ++itPath) {
      //take care of the case where the same path is passed in multiple times
      if (alreadySeen.find(*itPath) != alreadySeen.end() ) {
        continue;
      }
      alreadySeen.insert(*itPath);
      boost::filesystem::path dir(*itPath);
      if( exists( dir) ) {
        if(not is_directory(dir) ) {
          throw cms::Exception("PluginManagerBadPath") <<"The path '"<<dir.string()<<"' for the PluginManager is not a directory";
        }
        boost::filesystem::path cacheFile = dir/kCacheFile;
        
        if(exists(cacheFile) ) {
          std::ifstream file(cacheFile.string().c_str());
          if(not file) {
            throw cms::Exception("PluginMangerCacheProblem")<<"Unable to open the cache file '"<<cacheFile.string()
            <<"'. Please check permissions on file";
          }
          foundAtLeastOneCacheFile=true;
          CacheParser::read(file, dir, categoryToInfos_);          
        }
      }
    }
    if(not foundAtLeastOneCacheFile) {
      auto ex = cms::Exception("PluginManagerNoCacheFile")<<"No cache files named '"<<standard::cachefileName()<<"' were found in the directories \n";
      for( auto const& seen : alreadySeen) {
        ex <<" '"<<seen<<"'\n";
      }
      throw ex;
    }
    //Since this should not be called until after 'main' has started, we can set the value
    loadingLibraryNamed_()="<loaded by another plugin system>";
}
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 71 of file PluginManager.h.

References categoryToInfos_.

Referenced by PrintLoadingPlugins::askedToLoad(), edm::RootAutoLibraryLoader::loadAll(), and edm::service::LoadAllDictionaries::LoadAllDictionaries().

                                                     {
        return categoryToInfos_;
      }
PluginManager & PluginManager::configure ( const Config iConfig) [static]

Definition at line 291 of file PluginManager.cc.

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

Referenced by AutoLibraryLoader::enable(), StorageFactory::getMaker(), HcalO2OManager::HcalO2OManager(), evf::iDie::initFramework(), cond::Utilities::initializePluginManager(), HPDNoiseLibraryReader::initializeServices(), main(), edm::ProblemTracker::ProblemTracker(), and cond::topinit().

{
  PluginManager*& s = singleton();
  if( 0 != s ){
    throw cms::Exception("PluginManagerReconfigured");
  }
  
  Config realConfig = iConfig;
  if (realConfig.searchPath().empty() ) {
    throw cms::Exception("PluginManagerEmptySearchPath");
  }
  s = new PluginManager (realConfig);
  return *s;
}
PluginManager * PluginManager::get ( void  ) [static]

Definition at line 281 of file PluginManager.cc.

References Exception, and singleton().

Referenced by PrintLoadingPlugins::askedToLoad(), edmplugin::PluginFactoryBase::checkProperLoadable(), FWEveViewManager::FWEveViewManager(), PluginManager(), and PrintLoadingPlugins::PrintLoadingPlugins().

{
  PluginManager* manager = singleton();
  if(0==manager) {
    throw cms::Exception("PluginManagerNotConfigured")<<"PluginManager::get() was called before PluginManager::configure.";
  }
  return manager;
}
bool PluginManager::isAvailable ( ) [static]
const SharedLibrary & PluginManager::load ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 227 of file PluginManager.cc.

References askedToLoadCategoryWithPlugin_, goingToLoad_, justLoaded_, loadableFor(), loadables_, loadingLibraryNamed_(), AlCaHLTBitMon_ParallelJobs::p, getHLTPrescaleColumns::path, and alignCSCRings::s.

{
  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
  const boost::filesystem::path& p = loadableFor(iCategory,iPlugin);
  
  //have we already loaded this?
  std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded = 
    loadables_.find(p);
  if(itLoaded == loadables_.end()) {
    //try to make one
    goingToLoad_(p);
    Sentry s(loadingLibraryNamed_(), p.string());
    //boost::filesystem::path native(p.string());
    boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
    loadables_[p]=ptr;
    justLoaded_(*ptr);
    return *ptr;
  }
  return *(itLoaded->second);
}
const boost::filesystem::path & PluginManager::loadableFor ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 143 of file PluginManager.cc.

References loadableFor_().

Referenced by load().

{
  bool throwIfFail = true;
  return loadableFor_(iCategory, iPlugin,throwIfFail);
}
const boost::filesystem::path & PluginManager::loadableFor_ ( const std::string &  iCategory,
const std::string &  iPlugin,
bool &  ioThrowIfFailElseSucceedStatus 
) [private]

Definition at line 151 of file PluginManager.cc.

References categoryToInfos_, Exception, i, edmplugin::PluginInfo::name_, and getHLTPrescaleColumns::path.

Referenced by loadableFor(), and tryToLoad().

{
  const bool throwIfFail = ioThrowIfFailElseSucceedStatus;
  ioThrowIfFailElseSucceedStatus = true;
  CategoryToInfos::iterator itFound = categoryToInfos_.find(iCategory);
  if(itFound == categoryToInfos_.end()) {
    if(throwIfFail) {
      throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin<<
      "' because the category '"<<iCategory<<"' has no known plugins";
    } else {
      ioThrowIfFailElseSucceedStatus = false;
      static boost::filesystem::path s_path;
      return s_path;
    }
  }
  
  PluginInfo i;
  i.name_ = iPlugin;
  typedef std::vector<PluginInfo>::iterator PIItr;
  std::pair<PIItr,PIItr> range = std::equal_range(itFound->second.begin(),
                                                  itFound->second.end(),
                                                  i,
                                                  PICompare() );
  
  if(range.first == range.second) {
    if(throwIfFail) {
      throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin
      <<"' in category '"<<iCategory<<"'. Please check spelling of name.";
    } else {
      ioThrowIfFailElseSucceedStatus = false;
      static boost::filesystem::path s_path;
      return s_path;
    }
  }
  
  if(range.second - range.first > 1 ) {
    //see if the come from the same directory
    if(range.first->loadable_.branch_path() == (range.first+1)->loadable_.branch_path()) {
      //std::cout<<range.first->name_ <<" " <<(range.first+1)->name_<<std::endl;
      throw cms::Exception("MultiplePlugins")<<"The plugin '"<<iPlugin<<"' is found in multiple files \n"
      " '"<<range.first->loadable_.leaf()<<"'\n '"
      <<(range.first+1)->loadable_.leaf()<<"'\n"
      "in directory '"<<range.first->loadable_.branch_path().string()<<"'.\n"
      "The code must be changed so the plugin only appears in one plugin file. "
      "You will need to remove the macro which registers the plugin so it only appears in"
      " one of these files.\n"
      "  If none of these files register such a plugin, "
      "then the problem originates in a library to which all these files link.\n"
      "The plugin registration must be removed from that library since plugins are not allowed in regular libraries.";
    }
  }
  
  return range.first->loadable_;
}
static const std::string& edmplugin::PluginManager::loadingFile ( ) [inline, static]

file name of the shared object being loaded

Definition at line 81 of file PluginManager.h.

References loadingLibraryNamed_().

Referenced by edmplugin::PluginFactoryBase::newPlugin(), and edmplugin::PluginFactoryBase::registerPMaker().

                                            { 
        return loadingLibraryNamed_();}
std::string & PluginManager::loadingLibraryNamed_ ( ) [static, private]
void PluginManager::newFactory ( const PluginFactoryBase ) [private]

Definition at line 127 of file PluginManager.cc.

Referenced by PluginManager().

{
}
const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager ) [private]
PluginManager *& PluginManager::singleton ( ) [static, private]

Definition at line 321 of file PluginManager.cc.

Referenced by configure(), get(), and isAvailable().

{
  static PluginManager* s_singleton=0;
  return s_singleton;
}
const std::string & PluginManager::staticallyLinkedLoadingFileName ( ) [static]

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

Definition at line 308 of file PluginManager.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by edmplugin::PluginFactoryBase::checkProperLoadable(), and loadingLibraryNamed_().

{
  static std::string s_name("static");
  return s_name;
}
const SharedLibrary * PluginManager::tryToLoad ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 250 of file PluginManager.cc.

References askedToLoadCategoryWithPlugin_, goingToLoad_, justLoaded_, loadableFor_(), loadables_, loadingLibraryNamed_(), AlCaHLTBitMon_ParallelJobs::p, getHLTPrescaleColumns::path, and alignCSCRings::s.

{
  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
  bool ioThrowIfFailElseSucceedStatus = false;
  const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus);
  
  if( not ioThrowIfFailElseSucceedStatus ) {
    return 0;
  }
  
  //have we already loaded this?
  std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded = 
    loadables_.find(p);
  if(itLoaded == loadables_.end()) {
    //try to make one
    goingToLoad_(p);
    Sentry s(loadingLibraryNamed_(), p.string());
    //boost::filesystem::path native(p.string());
    boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
    loadables_[p]=ptr;
    justLoaded_(*ptr);
    return ptr.get();
  }
  return (itLoaded->second).get();
}

Friends And Related Function Documentation

friend class DummyFriend [friend]

Definition at line 39 of file PluginManager.h.


Member Data Documentation

Definition at line 96 of file PluginManager.h.

Referenced by load(), PrintLoadingPlugins::PrintLoadingPlugins(), and tryToLoad().

Definition at line 114 of file PluginManager.h.

Referenced by categoryToInfos(), loadableFor_(), and PluginManager().

edm::signalslot::Signal<void(const boost::filesystem::path&)> edmplugin::PluginManager::goingToLoad_

Definition at line 94 of file PluginManager.h.

Referenced by load(), PrintLoadingPlugins::PrintLoadingPlugins(), and tryToLoad().

Definition at line 95 of file PluginManager.h.

Referenced by load(), and tryToLoad().

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

Definition at line 112 of file PluginManager.h.

Referenced by load(), and tryToLoad().

Definition at line 111 of file PluginManager.h.

Referenced by PluginManager().