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 &)
 
 PluginManager (const Config &)
 
 PluginManager (const PluginManager &)
 

Static Private Member Functions

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

Private Attributes

CategoryToInfos categoryToInfos_
 
std::map
< boost::filesystem::path,
boost::shared_ptr
< SharedLibrary > > 
loadables_
 
SearchPath searchPath_
 

Friends

class DummyFriend
 

Detailed Description

Definition at line 37 of file PluginManager.h.

Member Typedef Documentation

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

Definition at line 43 of file PluginManager.h.

Definition at line 42 of file PluginManager.h.

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

Definition at line 41 of file PluginManager.h.

Constructor & Destructor Documentation

PluginManager::~PluginManager ( )

Definition at line 107 of file PluginManager.cc.

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

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

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

References categoryToInfos_.

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

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

Definition at line 291 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(), evf::iDie::initFramework(), cond::Utilities::initializePluginManager(), HPDNoiseLibraryReader::initializeServices(), main(), edm::ProblemTracker::ProblemTracker(), and cond::topinit().

292 {
293  PluginManager*& s = singleton();
294  if( 0 != s ){
295  throw cms::Exception("PluginManagerReconfigured");
296  }
297 
298  Config realConfig = iConfig;
299  if (realConfig.searchPath().empty() ) {
300  throw cms::Exception("PluginManagerEmptySearchPath");
301  }
302  s = new PluginManager (realConfig);
303  return *s;
304 }
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 227 of file PluginManager.cc.

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

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

229 {
230  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
231  const boost::filesystem::path& p = loadableFor(iCategory,iPlugin);
232 
233  //have we already loaded this?
234  std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded =
235  loadables_.find(p);
236  if(itLoaded == loadables_.end()) {
237  //try to make one
238  goingToLoad_(p);
239  Sentry s(loadingLibraryNamed_(), p.string());
240  //boost::filesystem::path native(p.string());
241  boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
242  loadables_[p]=ptr;
243  justLoaded_(*ptr);
244  return *ptr;
245  }
246  return *(itLoaded->second);
247 }
std::map< boost::filesystem::path, boost::shared_ptr< SharedLibrary > > loadables_
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
Definition: PluginManager.h:95
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
Definition: PluginManager.h:96
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Definition: PluginManager.h:94
static std::string & loadingLibraryNamed_()
const boost::filesystem::path & PluginManager::loadableFor ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 143 of file PluginManager.cc.

References loadableFor_().

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

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

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

Referenced by loadableFor(), and tryToLoad().

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

References loadingLibraryNamed_().

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

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

Definition at line 315 of file PluginManager.cc.

References staticallyLinkedLoadingFileName(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

316 {
318  return s_name;
319 }
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 127 of file PluginManager.cc.

Referenced by PluginManager().

128 {
129 }
const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager )
private
PluginManager *& PluginManager::singleton ( )
staticprivate

Definition at line 321 of file PluginManager.cc.

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

322 {
323  static PluginManager* s_singleton=0;
324  return s_singleton;
325 }
const std::string & PluginManager::staticallyLinkedLoadingFileName ( )
static

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

Definition at line 308 of file PluginManager.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

309 {
310  static std::string s_name("static");
311  return s_name;
312 }
const SharedLibrary * PluginManager::tryToLoad ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 250 of file PluginManager.cc.

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

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

252 {
253  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
254  bool ioThrowIfFailElseSucceedStatus = false;
255  const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus);
256 
257  if( not ioThrowIfFailElseSucceedStatus ) {
258  return 0;
259  }
260 
261  //have we already loaded this?
262  std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded =
263  loadables_.find(p);
264  if(itLoaded == loadables_.end()) {
265  //try to make one
266  goingToLoad_(p);
267  Sentry s(loadingLibraryNamed_(), p.string());
268  //boost::filesystem::path native(p.string());
269  boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
270  loadables_[p]=ptr;
271  justLoaded_(*ptr);
272  return ptr.get();
273  }
274  return (itLoaded->second).get();
275 }
std::map< boost::filesystem::path, boost::shared_ptr< SharedLibrary > > loadables_
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
Definition: PluginManager.h:95
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
Definition: PluginManager.h:96
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Definition: PluginManager.h:94
static std::string & loadingLibraryNamed_()

Friends And Related Function Documentation

friend class DummyFriend
friend

Definition at line 39 of file PluginManager.h.

Member Data Documentation

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

Definition at line 96 of file PluginManager.h.

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

CategoryToInfos edmplugin::PluginManager::categoryToInfos_
private

Definition at line 114 of file PluginManager.h.

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

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

Definition at line 94 of file PluginManager.h.

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

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

Definition at line 95 of file PluginManager.h.

Referenced by load(), and tryToLoad().

std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> > edmplugin::PluginManager::loadables_
private

Definition at line 112 of file PluginManager.h.

Referenced by load(), and tryToLoad().

SearchPath edmplugin::PluginManager::searchPath_
private

Definition at line 111 of file PluginManager.h.

Referenced by PluginManager().