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 110 of file PluginManager.cc.

111 {
112 }
PluginManager::PluginManager ( const Config iConfig)
private

Definition at line 47 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_, cmsHarvester::path, edmplugin::CacheParser::read(), and searchPath_.

Referenced by configure().

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

318 {
319  PluginManager*& s = singleton();
320  if( 0 != s ){
321  throw cms::Exception("PluginManagerReconfigured");
322  }
323 
324  Config realConfig = iConfig;
325  if (realConfig.searchPath().empty() ) {
326  throw cms::Exception("PluginManagerEmptySearchPath");
327  }
328  s = new PluginManager (realConfig);
329  return *s;
330 }
static PluginManager *& singleton()
PluginManager(const Config &)
PluginManager * PluginManager::get ( void  )
static
bool PluginManager::isAvailable ( )
static

Definition at line 356 of file PluginManager.cc.

References singleton().

Referenced by edmplugin::PluginFactoryBase::checkProperLoadable(), StorageFactory::getMaker(), edm::ProblemTracker::ProblemTracker(), and cond::topinit().

357 {
358  return 0 != singleton();
359 }
static PluginManager *& singleton()
const SharedLibrary & PluginManager::load ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 230 of file PluginManager.cc.

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

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

232 {
233  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
234  const boost::filesystem::path& p = loadableFor(iCategory,iPlugin);
235 
236  //have we already loaded this?
237  auto itLoaded = loadables_.find(p);
238  if(itLoaded == loadables_.end()) {
239  //Need to make sure we only have on SharedLibrary loading at a time
240  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
241  //Another thread may have gotten this while we were waiting on the mutex
242  itLoaded = loadables_.find(p);
243  if(itLoaded == loadables_.end()){
244  //try to make one
245  goingToLoad_(p);
246  Sentry s(loadingLibraryNamed_(), p.string());
247  //boost::filesystem::path native(p.string());
248  boost::shared_ptr<SharedLibrary> ptr;
249  {
250  //TEMPORARY: to avoid possible deadlocks from ROOT, we must
251  // take the lock ourselves
252  R__LOCKGUARD2(gCINTMutex);
253  ptr.reset( new SharedLibrary(p) );
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)
tuple path
else: Piece not in the list, fine.
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 146 of file PluginManager.cc.

References loadableFor_().

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

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

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

Referenced by loadableFor(), and tryToLoad().

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

References staticallyLinkedLoadingFileName(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

342 {
343  //NOTE: pluginLoadMutex() indirectly guards this since this value
344  // is only accessible via the Sentry call which us guarded by the mutex
345  [[cms::thread_safe]] static std::string s_name(staticallyLinkedLoadingFileName());
346  return s_name;
347 }
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 130 of file PluginManager.cc.

Referenced by PluginManager().

131 {
132 }
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 349 of file PluginManager.cc.

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

350 {
351  [[cms::thread_safe]] static PluginManager* s_singleton=0;
352  return s_singleton;
353 }
const std::string & PluginManager::staticallyLinkedLoadingFileName ( )
static

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

Definition at line 334 of file PluginManager.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 264 of file PluginManager.cc.

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

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

266 {
267  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
268  bool ioThrowIfFailElseSucceedStatus = false;
269  const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus);
270 
271  if( not ioThrowIfFailElseSucceedStatus ) {
272  return 0;
273  }
274 
275 
276  //have we already loaded this?
277  auto itLoaded = loadables_.find(p);
278  if(itLoaded == loadables_.end()) {
279  //Need to make sure we only have on SharedLibrary loading at a time
280  std::lock_guard<std::recursive_mutex> guard(pluginLoadMutex());
281  //Another thread may have gotten this while we were waiting on the mutex
282  itLoaded = loadables_.find(p);
283  if(itLoaded == loadables_.end()){
284  //try to make one
285  goingToLoad_(p);
286  Sentry s(loadingLibraryNamed_(), p.string());
287  //boost::filesystem::path native(p.string());
288  boost::shared_ptr<SharedLibrary> ptr;
289  {
290  //TEMPORARY: to avoid possible deadlocks from ROOT, we must
291  // take the lock ourselves
292  R__LOCKGUARD(gCINTMutex);
293  ptr.reset( new SharedLibrary(p) );
294  }
295  loadables_[p]=ptr;
296  justLoaded_(*ptr);
297  return ptr.get();
298  }
299  }
300  return (itLoaded->second).get();
301 }
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
tuple path
else: Piece not in the list, fine.
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().