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

Member Typedef Documentation

◆ CategoryToInfos

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

Definition at line 51 of file PluginManager.h.

◆ Infos

Definition at line 50 of file PluginManager.h.

◆ SearchPath

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

Definition at line 49 of file PluginManager.h.

Constructor & Destructor Documentation

◆ ~PluginManager()

PluginManager::~PluginManager ( )

Definition at line 124 of file PluginManager.cc.

124 {}

◆ PluginManager() [1/2]

PluginManager::PluginManager ( const Config iConfig)
private

Definition at line 59 of file PluginManager.cc.

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  }

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().

◆ PluginManager() [2/2]

edmplugin::PluginManager::PluginManager ( const PluginManager )
privatedelete

Member Function Documentation

◆ categoryToInfos()

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

80 { return categoryToInfos_; }

References categoryToInfos_.

Referenced by PrintLoadingPlugins::askedToLoad(), FWDetailViewManager::findViewersFor(), FWEveViewManager::FWEveViewManager(), FWItemAccessorFactory::hasAccessor(), main(), and edm::PluginDescription< T >::printNestedContent_().

◆ configure()

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

Definition at line 316 of file PluginManager.cc.

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  }

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_().

◆ get()

PluginManager * PluginManager::get ( )
static

◆ isAvailable()

bool PluginManager::isAvailable ( )
static

◆ load()

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

Definition at line 227 of file PluginManager.cc.

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  }

References 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().

◆ loadableFor()

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

Definition at line 151 of file PluginManager.cc.

151  {
152  bool throwIfFail = true;
153  return loadableFor_(iCategory, iPlugin, throwIfFail);
154  }

References loadableFor_().

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

◆ loadableFor_()

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.

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  }

References categoryToInfos_, Exception, mps_fire::i, castor_dqm_sourceclient_file_cfg::path, and FastTimerService_cff::range.

Referenced by loadableFor(), and tryToLoad().

◆ loadingFile()

static const std::string& edmplugin::PluginManager::loadingFile ( )
inlinestatic

file name of the shared object being loaded

Definition at line 87 of file PluginManager.h.

87 { return loadingLibraryNamed_(); }

References loadingLibraryNamed_().

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

◆ loadingLibraryNamed_()

std::string & PluginManager::loadingLibraryNamed_ ( )
staticprivate

Definition at line 335 of file PluginManager.cc.

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  }

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

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

◆ newFactory()

void PluginManager::newFactory ( const PluginFactoryBase )
private

Definition at line 141 of file PluginManager.cc.

141 {}

Referenced by PluginManager().

◆ operator=()

const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager )
privatedelete

◆ pluginLoadMutex()

std::recursive_mutex& edmplugin::PluginManager::pluginLoadMutex ( )
inlineprivate

Definition at line 112 of file PluginManager.h.

112 { return pluginLoadMutex_; }

References pluginLoadMutex_.

Referenced by load(), and tryToLoad().

◆ singleton()

PluginManager *& PluginManager::singleton ( )
staticprivate

Definition at line 342 of file PluginManager.cc.

342  {
343  CMS_THREAD_SAFE static PluginManager* s_singleton = nullptr;
344  return s_singleton;
345  }

References CMS_THREAD_SAFE.

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

◆ staticallyLinkedLoadingFileName()

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.

330  {
331  static const std::string s_name("static");
332  return s_name;
333  }

References AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ tryToLoad()

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

Definition at line 263 of file PluginManager.cc.

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  }

References 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().

Friends And Related Function Documentation

◆ DummyFriend

friend class DummyFriend
friend

Definition at line 46 of file PluginManager.h.

Member Data Documentation

◆ askedToLoadCategoryWithPlugin_

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

Definition at line 100 of file PluginManager.h.

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

◆ categoryToInfos_

CategoryToInfos edmplugin::PluginManager::categoryToInfos_
private

Definition at line 122 of file PluginManager.h.

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

◆ goingToLoad_

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

Definition at line 98 of file PluginManager.h.

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

◆ justLoaded_

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

Definition at line 99 of file PluginManager.h.

Referenced by load(), and tryToLoad().

◆ loadables_

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

Definition at line 120 of file PluginManager.h.

Referenced by load(), and tryToLoad().

◆ pluginLoadMutex_

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

Definition at line 123 of file PluginManager.h.

Referenced by pluginLoadMutex().

◆ searchPath_

SearchPath edmplugin::PluginManager::searchPath_
private

Definition at line 118 of file PluginManager.h.

Referenced by PluginManager().

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
edmplugin::PluginManager::searchPath_
SearchPath searchPath_
Definition: PluginManager.h:118
mps_fire.i
i
Definition: mps_fire.py:355
edmplugin::standard::poisonedCachefileName
const boost::filesystem::path & poisonedCachefileName()
Definition: standard.cc:52
edmplugin::PluginManager::loadables_
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
Definition: PluginManager.h:120
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edmplugin::PluginManager::PluginManager
PluginManager(const Config &)
Definition: PluginManager.cc:59
edmplugin::PluginManager::pluginLoadMutex
std::recursive_mutex & pluginLoadMutex()
Definition: PluginManager.h:112
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edmplugin::PluginManager::loadableFor
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:151
PluginFactoryManager
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edmplugin::standard::cachefileName
const boost::filesystem::path & cachefileName()
Definition: standard.cc:47
edmplugin::PluginManager::singleton
static PluginManager *& singleton()
Definition: PluginManager.cc:342
edmplugin::PluginManager::pluginLoadMutex_
std::recursive_mutex pluginLoadMutex_
Definition: PluginManager.h:123
postprocess-scan-build.seen
seen
Definition: postprocess-scan-build.py:9
PluginManager
edmplugin::PluginManager::loadingLibraryNamed_
static std::string & loadingLibraryNamed_()
Definition: PluginManager.cc:335
edmplugin::PluginManager::newFactory
void newFactory(const PluginFactoryBase *)
Definition: PluginManager.cc:141
edmplugin::PluginManager::askedToLoadCategoryWithPlugin_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
Definition: PluginManager.h:100
Exception
Definition: hltDiff.cc:246
edmplugin::readCacheFile
static bool readCacheFile(const boost::filesystem::path &cacheFile, const boost::filesystem::path &dir, PluginManager::CategoryToInfos &categoryToInfos)
Definition: PluginManager.cc:42
edmplugin::PluginManager::categoryToInfos_
CategoryToInfos categoryToInfos_
Definition: PluginManager.h:122
edmplugin::PluginFactoryManager::const_iterator
std::vector< const PluginFactoryBase * >::const_iterator const_iterator
Definition: PluginFactoryManager.h:38
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
PluginInfo
edmplugin::PluginManager::staticallyLinkedLoadingFileName
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked
Definition: PluginManager.cc:330
Config
Definition: Config.py:1
edmplugin::PluginManager::goingToLoad_
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Definition: PluginManager.h:98
edmplugin::PluginManager::loadableFor_
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
Definition: PluginManager.cc:156
edmplugin::PluginFactoryManager::get
static PluginFactoryManager * get()
Definition: PluginFactoryManager.cc:70
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edmplugin::PluginManager::justLoaded_
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
Definition: PluginManager.h:99