CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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>

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 More...
 
static const std::string & staticallyLinkedLoadingFileName ()
 if the value returned from loadingFile matches this string then the file is statically linked More...
 

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 &)
 
std::recursive_mutex & pluginLoadMutex ()
 
 PluginManager (const Config &)
 
 PluginManager (const PluginManager &)
 

Static Private Member Functions

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

Private Attributes

CategoryToInfos categoryToInfos_
 
tbb::concurrent_unordered_map
< boost::filesystem::path,
boost::shared_ptr
< SharedLibrary >
, PluginManagerPathHasher
loadables_
 
std::recursive_mutex pluginLoadMutex_
 
SearchPath searchPath_
 

Friends

class DummyFriend
 

Detailed Description

Definition at line 48 of file PluginManager.h.

Member Typedef Documentation

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

Definition at line 54 of file PluginManager.h.

Definition at line 53 of file PluginManager.h.

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

Definition at line 52 of file PluginManager.h.

Constructor & Destructor Documentation

PluginManager::~PluginManager ( )

Definition at line 106 of file PluginManager.cc.

107 {
108 }
PluginManager::PluginManager ( const Config iConfig)
private

Definition at line 43 of file PluginManager.cc.

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

Referenced by configure().

43  :
44  searchPath_( iConfig.searchPath() )
45 {
47  //NOTE: This may not be needed :/
49  pfm->newFactory_.connect(boost::bind(boost::mem_fn(&PluginManager::newFactory),this,_1));
50 
51  // When building a single big executable the plugins are already registered in the
52  // PluginFactoryManager, we therefore only need to populate the categoryToInfos_ map
53  // with the relevant information.
54  for (PluginFactoryManager::const_iterator i = pfm->begin(), e = pfm->end(); i != e; ++i)
55  {
56  categoryToInfos_[(*i)->category()] = (*i)->available();
57  }
58 
59  //read in the files
60  //Since we are looping in the 'precidence' order then the lists in categoryToInfos_ will also be
61  // in that order
62  bool foundAtLeastOneCacheFile = false;
63  std::set<std::string> alreadySeen;
64  for(SearchPath::const_iterator itPath=searchPath_.begin(), itEnd = searchPath_.end();
65  itPath != itEnd;
66  ++itPath) {
67  //take care of the case where the same path is passed in multiple times
68  if (alreadySeen.find(*itPath) != alreadySeen.end() ) {
69  continue;
70  }
71  alreadySeen.insert(*itPath);
73  if( exists( dir) ) {
74  if(not is_directory(dir) ) {
75  throw cms::Exception("PluginManagerBadPath") <<"The path '"<<dir.string()<<"' for the PluginManager is not a directory";
76  }
77  boost::filesystem::path cacheFile = dir/kCacheFile;
78 
79  if(exists(cacheFile) ) {
80  std::ifstream file(cacheFile.string().c_str());
81  if(not file) {
82  throw cms::Exception("PluginMangerCacheProblem")<<"Unable to open the cache file '"<<cacheFile.string()
83  <<"'. Please check permissions on file";
84  }
85  foundAtLeastOneCacheFile=true;
87  }
88  }
89  }
90  if(not foundAtLeastOneCacheFile) {
91  auto ex = cms::Exception("PluginManagerNoCacheFile")<<"No cache files named '"<<standard::cachefileName()<<"' were found in the directories \n";
92  for( auto const& seen : alreadySeen) {
93  ex <<" '"<<seen<<"'\n";
94  }
95  throw ex;
96  }
97  //Since this should not be called until after 'main' has started, we can set the value
98  loadingLibraryNamed_()="<loaded by another plugin system>";
99 }
CategoryToInfos categoryToInfos_
int i
Definition: DBlmapReader.cc:9
const boost::filesystem::path & cachefileName()
Definition: standard.cc:47
dbl *** dir
Definition: mlp_gen.cc:35
static std::string & loadingLibraryNamed_()
static void read(std::istream &, const boost::filesystem::path &iDirectory, CategoryToInfos &oOut)
Definition: CacheParser.cc:125
std::vector< const PluginFactoryBase * >::const_iterator const_iterator
void newFactory(const PluginFactoryBase *)
static PluginFactoryManager * get()
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 82 of file PluginManager.h.

References categoryToInfos_.

Referenced by PrintLoadingPlugins::askedToLoad(), FWEveViewManager::FWEveViewManager(), FWItemAccessorFactory::hasAccessor(), edm::RootAutoLibraryLoader::loadAll(), edm::service::LoadAllDictionaries::LoadAllDictionaries(), and main().

82  {
83  return categoryToInfos_;
84  }
CategoryToInfos categoryToInfos_
PluginManager & PluginManager::configure ( const Config iConfig)
static

Definition at line 301 of file PluginManager.cc.

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

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

302 {
303  PluginManager*& s = singleton();
304  if( 0 != s ){
305  throw cms::Exception("PluginManagerReconfigured");
306  }
307 
308  Config realConfig = iConfig;
309  if (realConfig.searchPath().empty() ) {
310  throw cms::Exception("PluginManagerEmptySearchPath");
311  }
312  s = new PluginManager (realConfig);
313  return *s;
314 }
static PluginManager *& singleton()
PluginManager(const Config &)
PluginManager * PluginManager::get ( void  )
static
bool PluginManager::isAvailable ( )
static
const SharedLibrary & PluginManager::load ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 226 of file PluginManager.cc.

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

Referenced by edmplugin::PluginFactoryBase::findPMaker(), and edmplugin::PluginCapabilities::load().

228 {
229  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
230  const boost::filesystem::path& p = loadableFor(iCategory,iPlugin);
231 
232  //have we already loaded this?
233  auto itLoaded = loadables_.find(p);
234  if(itLoaded == loadables_.end()) {
235  //Need to make sure we only have on SharedLibrary loading at a time
236  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
237  //Another thread may have gotten this while we were waiting on the mutex
238  itLoaded = loadables_.find(p);
239  if(itLoaded == loadables_.end()){
240  //try to make one
241  goingToLoad_(p);
242  Sentry s(loadingLibraryNamed_(), p.string());
243  //boost::filesystem::path native(p.string());
244  boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
245  loadables_[p]=ptr;
246  justLoaded_(*ptr);
247  return *ptr;
248  }
249  }
250  return *(itLoaded->second);
251 }
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
tbb::concurrent_unordered_map< boost::filesystem::path, boost::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
std::recursive_mutex & pluginLoadMutex()
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
static std::string & loadingLibraryNamed_()
const boost::filesystem::path & PluginManager::loadableFor ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 142 of file PluginManager.cc.

References loadableFor_().

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

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

Definition at line 150 of file PluginManager.cc.

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

Referenced by loadableFor(), and tryToLoad().

153 {
154  const bool throwIfFail = ioThrowIfFailElseSucceedStatus;
155  ioThrowIfFailElseSucceedStatus = true;
156  CategoryToInfos::iterator itFound = categoryToInfos_.find(iCategory);
157  if(itFound == categoryToInfos_.end()) {
158  if(throwIfFail) {
159  throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin<<
160  "' because the category '"<<iCategory<<"' has no known plugins";
161  } else {
162  ioThrowIfFailElseSucceedStatus = false;
163  static boost::filesystem::path s_path;
164  return s_path;
165  }
166  }
167 
168  PluginInfo i;
169  i.name_ = iPlugin;
170  typedef std::vector<PluginInfo>::iterator PIItr;
171  std::pair<PIItr,PIItr> range = std::equal_range(itFound->second.begin(),
172  itFound->second.end(),
173  i,
174  PICompare() );
175 
176  if(range.first == range.second) {
177  if(throwIfFail) {
178  throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin
179  <<"' in category '"<<iCategory<<"'. Please check spelling of name.";
180  } else {
181  ioThrowIfFailElseSucceedStatus = false;
182  static boost::filesystem::path s_path;
183  return s_path;
184  }
185  }
186 
187  if(range.second - range.first > 1 ) {
188  //see if the come from the same directory
189  if(range.first->loadable_.branch_path() == (range.first+1)->loadable_.branch_path()) {
190  //std::cout<<range.first->name_ <<" " <<(range.first+1)->name_<<std::endl;
191  throw cms::Exception("MultiplePlugins")<<"The plugin '"<<iPlugin<<"' is found in multiple files \n"
192  " '"<<range.first->loadable_.leaf()<<"'\n '"
193  <<(range.first+1)->loadable_.leaf()<<"'\n"
194  "in directory '"<<range.first->loadable_.branch_path().string()<<"'.\n"
195  "The code must be changed so the plugin only appears in one plugin file. "
196  "You will need to remove the macro which registers the plugin so it only appears in"
197  " one of these files.\n"
198  " If none of these files register such a plugin, "
199  "then the problem originates in a library to which all these files link.\n"
200  "The plugin registration must be removed from that library since plugins are not allowed in regular libraries.";
201  }
202  }
203 
204  return range.first->loadable_;
205 }
CategoryToInfos categoryToInfos_
int i
Definition: DBlmapReader.cc:9
static const std::string& edmplugin::PluginManager::loadingFile ( )
inlinestatic

file name of the shared object being loaded

Definition at line 92 of file PluginManager.h.

References loadingLibraryNamed_().

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

92  {
93  return loadingLibraryNamed_();}
static std::string & loadingLibraryNamed_()
std::string & PluginManager::loadingLibraryNamed_ ( )
staticprivate

Definition at line 325 of file PluginManager.cc.

References staticallyLinkedLoadingFileName(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by load(), loadingFile(), PluginManager(), and tryToLoad().

326 {
327  //NOTE: pluginLoadMutex() indirectly guards this since this value
328  // is only accessible via the Sentry call which us guarded by the mutex
330  return s_name;
331 }
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked ...
void PluginManager::newFactory ( const PluginFactoryBase )
private

Definition at line 126 of file PluginManager.cc.

Referenced by PluginManager().

127 {
128 }
const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager )
private
std::recursive_mutex& edmplugin::PluginManager::pluginLoadMutex ( )
inlineprivate

Definition at line 118 of file PluginManager.h.

References pluginLoadMutex_.

Referenced by load(), and tryToLoad().

118 {return pluginLoadMutex_;}
std::recursive_mutex pluginLoadMutex_
PluginManager *& PluginManager::singleton ( )
staticprivate

Definition at line 333 of file PluginManager.cc.

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

334 {
335  static PluginManager* s_singleton=0;
336  return s_singleton;
337 }
const std::string & PluginManager::staticallyLinkedLoadingFileName ( )
static

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

Definition at line 318 of file PluginManager.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 254 of file PluginManager.cc.

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

Referenced by edmplugin::PluginFactoryBase::tryToFindPMaker(), and edmplugin::PluginCapabilities::tryToLoad().

256 {
257  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
258  bool ioThrowIfFailElseSucceedStatus = false;
259  const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus);
260 
261  if( not ioThrowIfFailElseSucceedStatus ) {
262  return 0;
263  }
264 
265 
266  //have we already loaded this?
267  auto itLoaded = loadables_.find(p);
268  if(itLoaded == loadables_.end()) {
269  //Need to make sure we only have on SharedLibrary loading at a time
270  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
271  //Another thread may have gotten this while we were waiting on the mutex
272  itLoaded = loadables_.find(p);
273  if(itLoaded == loadables_.end()){
274  //try to make one
275  goingToLoad_(p);
276  Sentry s(loadingLibraryNamed_(), p.string());
277  //boost::filesystem::path native(p.string());
278  boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
279  loadables_[p]=ptr;
280  justLoaded_(*ptr);
281  return ptr.get();
282  }
283  }
284  return (itLoaded->second).get();
285 }
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
tbb::concurrent_unordered_map< boost::filesystem::path, boost::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
std::recursive_mutex & pluginLoadMutex()
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
static std::string & loadingLibraryNamed_()

Friends And Related Function Documentation

friend class DummyFriend
friend

Definition at line 50 of file PluginManager.h.

Member Data Documentation

edm::signalslot::Signal<void(const std::string&,const std::string&)> edmplugin::PluginManager::askedToLoadCategoryWithPlugin_

Definition at line 107 of file PluginManager.h.

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

CategoryToInfos edmplugin::PluginManager::categoryToInfos_
private

Definition at line 127 of file PluginManager.h.

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

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

Definition at line 105 of file PluginManager.h.

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

edm::signalslot::Signal<void(const SharedLibrary&)> edmplugin::PluginManager::justLoaded_

Definition at line 106 of file PluginManager.h.

Referenced by load(), and tryToLoad().

tbb::concurrent_unordered_map<boost::filesystem::path, boost::shared_ptr<SharedLibrary>, PluginManagerPathHasher > edmplugin::PluginManager::loadables_
private

Definition at line 125 of file PluginManager.h.

Referenced by load(), and tryToLoad().

std::recursive_mutex edmplugin::PluginManager::pluginLoadMutex_
private

Definition at line 128 of file PluginManager.h.

Referenced by pluginLoadMutex().

SearchPath edmplugin::PluginManager::searchPath_
private

Definition at line 124 of file PluginManager.h.

Referenced by PluginManager().