CMS 3D CMS Logo

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

Static Private Member Functions

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

Private Attributes

CategoryToInfos categoryToInfos_
 
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasherloadables_
 
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 124 of file PluginManager.cc.

124 {}
PluginManager::PluginManager ( const Config iConfig)
private

Definition at line 59 of file PluginManager.cc.

References edmplugin::PluginFactoryManager::begin(), edmplugin::standard::cachefileName(), categoryToInfos_, dir, MillePedeFileConverter_cfg::e, edmplugin::PluginFactoryManager::end(), Exception, edmplugin::PluginFactoryManager::get(), mps_fire::i, loadingLibraryNamed_(), edmplugin::PluginManager::Config::mustHaveCache(), newFactory(), edmplugin::PluginFactoryManager::newFactory_, callgraph::path, edmplugin::standard::poisonedCachefileName(), edmplugin::readCacheFile(), searchPath_, and postprocess-scan-build::seen.

Referenced by configure().

59  : searchPath_(iConfig.searchPath()) {
60  using std::placeholders::_1;
62  // This is the filename of a file which contains plugins which exist in the
63  // base release and which should exists in the local area, otherwise they
64  // were removed and we want to catch their usage.
65  const boost::filesystem::path& kPoisonedCacheFile(standard::poisonedCachefileName());
66  //NOTE: This may not be needed :/
68  pfm->newFactory_.connect(std::bind(std::mem_fn(&PluginManager::newFactory), this, _1));
69 
70  // When building a single big executable the plugins are already registered in the
71  // PluginFactoryManager, we therefore only need to populate the categoryToInfos_ map
72  // with the relevant information.
73  for (PluginFactoryManager::const_iterator i = pfm->begin(), e = pfm->end(); i != e; ++i) {
74  categoryToInfos_[(*i)->category()] = (*i)->available();
75  }
76 
77  //read in the files
78  //Since we are looping in the 'precidence' order then the lists in categoryToInfos_ will also be
79  // in that order
80  bool foundAtLeastOneCacheFile = false;
81  std::set<std::string> alreadySeen;
82  for (SearchPath::const_iterator itPath = searchPath_.begin(), itEnd = searchPath_.end(); itPath != itEnd;
83  ++itPath) {
84  //take care of the case where the same path is passed in multiple times
85  if (alreadySeen.find(*itPath) != alreadySeen.end()) {
86  continue;
87  }
88  alreadySeen.insert(*itPath);
90  if (exists(dir)) {
91  if (not is_directory(dir)) {
92  throw cms::Exception("PluginManagerBadPath")
93  << "The path '" << dir.string() << "' for the PluginManager is not a directory";
94  }
95  boost::filesystem::path cacheFile = dir / kCacheFile;
96 
97  if (readCacheFile(cacheFile, dir, categoryToInfos_)) {
98  foundAtLeastOneCacheFile = true;
99  }
100 
101  // We do not check for return code since we do not want to consider a
102  // poison cache file as a valid cache file having been found.
103  boost::filesystem::path poisonedCacheFile = dir / kPoisonedCacheFile;
104  readCacheFile(poisonedCacheFile, dir / "poisoned", categoryToInfos_);
105  }
106  }
107  if (not foundAtLeastOneCacheFile and iConfig.mustHaveCache()) {
108  auto ex = cms::Exception("PluginManagerNoCacheFile")
109  << "No cache files named '" << standard::cachefileName() << "' were found in the directories \n";
110  for (auto const& seen : alreadySeen) {
111  ex << " '" << seen << "'\n";
112  }
113  throw ex;
114  }
115  //Since this should not be called until after 'main' has started, we can set the value
116  loadingLibraryNamed_() = "<loaded by another plugin system>";
117  }
CategoryToInfos categoryToInfos_
const boost::filesystem::path & cachefileName()
Definition: standard.cc:47
const boost::filesystem::path & poisonedCachefileName()
Definition: standard.cc:52
static bool readCacheFile(const boost::filesystem::path &cacheFile, const boost::filesystem::path &dir, PluginManager::CategoryToInfos &categoryToInfos)
dbl *** dir
Definition: mlp_gen.cc:35
static std::string & loadingLibraryNamed_()
std::vector< const PluginFactoryBase * >::const_iterator const_iterator
void newFactory(const PluginFactoryBase *)
static PluginFactoryManager * get()
edmplugin::PluginManager::PluginManager ( const PluginManager )
privatedelete

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 83 of file PluginManager.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 306 of file PluginManager.cc.

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

Referenced by FWLiteEnabler::enable(), StorageFactory::getMaker(), main(), edm::ProblemTracker::ProblemTracker(), cond::Utilities::run(), and edm::PluginDescription< T >::writeCfi_().

306  {
307  PluginManager*& s = singleton();
308  if (nullptr != s) {
309  throw cms::Exception("PluginManagerReconfigured");
310  }
311 
312  const Config& realConfig = iConfig;
313  if (realConfig.searchPath().empty()) {
314  throw cms::Exception("PluginManagerEmptySearchPath");
315  }
316  s = new PluginManager(realConfig);
317  return *s;
318  }
static PluginManager *& singleton()
Definition: Config.py:1
PluginManager(const Config &)
PluginManager * PluginManager::get ( )
static
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, callgraph::path, pluginLoadMutex(), and alignCSCRings::s.

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

227  {
228  askedToLoadCategoryWithPlugin_(iCategory, iPlugin);
229  const boost::filesystem::path& p = loadableFor(iCategory, iPlugin);
230 
231  //have we already loaded this?
232  auto itLoaded = loadables_.find(p);
233  if (itLoaded == loadables_.end()) {
234  //Need to make sure we only have on SharedLibrary loading at a time
235  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
236  //Another thread may have gotten this while we were waiting on the mutex
237  itLoaded = loadables_.find(p);
238  if (itLoaded == loadables_.end()) {
239  //try to make one
240  goingToLoad_(p);
241  Sentry s(loadingLibraryNamed_(), p.string());
242  //boost::filesystem::path native(p.string());
243  std::shared_ptr<SharedLibrary> ptr;
244  {
245  //TEMPORARY: to avoid possible deadlocks from ROOT, we must
246  // take the lock ourselves
247  R__LOCKGUARD2(gInterpreterMutex);
248  ptr.reset(new SharedLibrary(p));
249  }
250  loadables_[p] = ptr;
251  justLoaded_(*ptr);
252  return *ptr;
253  }
254  }
255  return *(itLoaded->second);
256  }
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
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 151 of file PluginManager.cc.

References loadableFor_().

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

151  {
152  bool throwIfFail = true;
153  return loadableFor_(iCategory, iPlugin, throwIfFail);
154  }
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 156 of file PluginManager.cc.

References categoryToInfos_, Exception, mps_fire::i, edmplugin::PluginInfo::name_, oldPath_, callgraph::path, path_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by loadableFor(), and tryToLoad().

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

file name of the shared object being loaded

Definition at line 90 of file PluginManager.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 325 of file PluginManager.cc.

References CMS_THREAD_SAFE, staticallyLinkedLoadingFileName(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 141 of file PluginManager.cc.

References edmplugin::PluginInfo::name_.

Referenced by PluginManager().

141 {}
const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager )
privatedelete
std::recursive_mutex& edmplugin::PluginManager::pluginLoadMutex ( )
inlineprivate

Definition at line 115 of file PluginManager.h.

References callgraph::path, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by load(), and tryToLoad().

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

Definition at line 332 of file PluginManager.cc.

References CMS_THREAD_SAFE.

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

332  {
333  CMS_THREAD_SAFE static PluginManager* s_singleton = nullptr;
334  return s_singleton;
335  }
#define CMS_THREAD_SAFE
const std::string & PluginManager::staticallyLinkedLoadingFileName ( )
static

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

Definition at line 320 of file PluginManager.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 258 of file PluginManager.cc.

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

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

258  {
259  askedToLoadCategoryWithPlugin_(iCategory, iPlugin);
260  bool ioThrowIfFailElseSucceedStatus = false;
261  const boost::filesystem::path& p = loadableFor_(iCategory, iPlugin, ioThrowIfFailElseSucceedStatus);
262 
263  if (not ioThrowIfFailElseSucceedStatus) {
264  return nullptr;
265  }
266 
267  //have we already loaded this?
268  auto itLoaded = loadables_.find(p);
269  if (itLoaded == loadables_.end()) {
270  //Need to make sure we only have on SharedLibrary loading at a time
271  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
272  //Another thread may have gotten this while we were waiting on the mutex
273  itLoaded = loadables_.find(p);
274  if (itLoaded == loadables_.end()) {
275  //try to make one
276  goingToLoad_(p);
277  Sentry s(loadingLibraryNamed_(), p.string());
278  //boost::filesystem::path native(p.string());
279  std::shared_ptr<SharedLibrary> ptr;
280  {
281  //TEMPORARY: to avoid possible deadlocks from ROOT, we must
282  // take the lock ourselves
283  R__LOCKGUARD(gInterpreterMutex);
284  ptr.reset(new SharedLibrary(p));
285  }
286  loadables_[p] = ptr;
287  justLoaded_(*ptr);
288  return ptr.get();
289  }
290  }
291  return (itLoaded->second).get();
292  }
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
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 49 of file PluginManager.h.

Member Data Documentation

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

Definition at line 103 of file PluginManager.h.

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

CategoryToInfos edmplugin::PluginManager::categoryToInfos_
private

Definition at line 125 of file PluginManager.h.

Referenced by loadableFor_(), and PluginManager().

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

Definition at line 101 of file PluginManager.h.

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

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

Definition at line 102 of file PluginManager.h.

Referenced by load(), and tryToLoad().

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

Definition at line 123 of file PluginManager.h.

Referenced by load(), and tryToLoad().

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

Definition at line 126 of file PluginManager.h.

SearchPath edmplugin::PluginManager::searchPath_
private

Definition at line 121 of file PluginManager.h.

Referenced by PluginManager().