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_, DeadROC_duringRun::dir, MillePedeFileConverter_cfg::e, edmplugin::PluginFactoryManager::end(), Exception, edmplugin::PluginFactoryManager::get(), mps_fire::i, loadingLibraryNamed_(), edmplugin::PluginManager::Config::mustHaveCache(), newFactory(), edmplugin::PluginFactoryManager::newFactory_, castor_dqm_sourceclient_file_cfg::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)
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(), main(), and edm::PluginDescription< T >::printNestedContent_().

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

Definition at line 316 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_().

316  {
317  PluginManager*& s = singleton();
318  if (nullptr != s) {
319  throw cms::Exception("PluginManagerReconfigured");
320  }
321 
322  const Config& realConfig = iConfig;
323  if (realConfig.searchPath().empty()) {
324  throw cms::Exception("PluginManagerEmptySearchPath");
325  }
326  s = new PluginManager(realConfig);
327  return *s;
328  }
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 cms::Exception::addContext(), askedToLoadCategoryWithPlugin_, MillePedeFileConverter_cfg::e, goingToLoad_, justLoaded_, loadableFor(), loadables_, loadingLibraryNamed_(), AlCaHLTBitMon_ParallelJobs::p, castor_dqm_sourceclient_file_cfg::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  try {
249  ptr = std::make_shared<SharedLibrary>(p);
250  } catch (cms::Exception& e) {
251  e.addContext("While attempting to load plugin " + iPlugin);
252  throw;
253  }
254  }
255  loadables_[p] = ptr;
256  justLoaded_(*ptr);
257  return *ptr;
258  }
259  }
260  return *(itLoaded->second);
261  }
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_
void addContext(std::string const &context)
Definition: Exception.cc:165
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_, castor_dqm_sourceclient_file_cfg::path, path_, FastTimerService_cff::range, 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 335 of file PluginManager.cc.

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

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

335  {
336  //NOTE: pluginLoadMutex() indirectly guards this since this value
337  // is only accessible via the Sentry call which us guarded by the mutex
339  return s_name;
340  }
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 castor_dqm_sourceclient_file_cfg::path, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by load(), and tryToLoad().

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

Definition at line 342 of file PluginManager.cc.

References CMS_THREAD_SAFE.

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

342  {
343  CMS_THREAD_SAFE static PluginManager* s_singleton = nullptr;
344  return s_singleton;
345  }
#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 330 of file PluginManager.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 263 of file PluginManager.cc.

References cms::Exception::addContext(), askedToLoadCategoryWithPlugin_, MillePedeFileConverter_cfg::e, goingToLoad_, justLoaded_, loadableFor_(), loadables_, loadingLibraryNamed_(), AlCaHLTBitMon_ParallelJobs::p, castor_dqm_sourceclient_file_cfg::path, pluginLoadMutex(), and alignCSCRings::s.

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

263  {
264  askedToLoadCategoryWithPlugin_(iCategory, iPlugin);
265  bool ioThrowIfFailElseSucceedStatus = false;
266  const boost::filesystem::path& p = loadableFor_(iCategory, iPlugin, ioThrowIfFailElseSucceedStatus);
267 
268  if (not ioThrowIfFailElseSucceedStatus) {
269  return nullptr;
270  }
271 
272  //have we already loaded this?
273  auto itLoaded = loadables_.find(p);
274  if (itLoaded == loadables_.end()) {
275  //Need to make sure we only have on SharedLibrary loading at a time
276  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
277  //Another thread may have gotten this while we were waiting on the mutex
278  itLoaded = loadables_.find(p);
279  if (itLoaded == loadables_.end()) {
280  //try to make one
281  goingToLoad_(p);
282  Sentry s(loadingLibraryNamed_(), p.string());
283  //boost::filesystem::path native(p.string());
284  std::shared_ptr<SharedLibrary> ptr;
285  {
286  //TEMPORARY: to avoid possible deadlocks from ROOT, we must
287  // take the lock ourselves
288  R__LOCKGUARD(gInterpreterMutex);
289  try {
290  ptr = std::make_shared<SharedLibrary>(p);
291  } catch (cms::Exception& e) {
292  e.addContext("While attempting to load plugin " + iPlugin);
293  throw;
294  }
295  }
296  loadables_[p] = ptr;
297  justLoaded_(*ptr);
298  return ptr.get();
299  }
300  }
301  return (itLoaded->second).get();
302  }
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_
void addContext(std::string const &context)
Definition: Exception.cc:165
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().