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::pathloadableFor (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

sigc::signal< void, const
std::string &, const
std::string & > 
askedToLoadCategoryWithPlugin_
 
sigc::signal< void, const
boost::filesystem::path & > 
goingToLoad_
 
sigc::signal< void, const
SharedLibrary & > 
justLoaded_
 

Private Member Functions

const boost::filesystem::pathloadableFor_ (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 98 of file PluginManager.cc.

99 {
100 }
PluginManager::PluginManager ( const Config iConfig)
private

Definition at line 44 of file PluginManager.cc.

References edmplugin::PluginFactoryManager::begin(), edmplugin::standard::cachefileName(), categoryToInfos_, dir, edmplugin::PluginFactoryManager::end(), edm::hlt::Exception, mergeVDriftHistosByStation::file, edmplugin::PluginFactoryManager::get(), i, loadingLibraryNamed_(), newFactory(), edmplugin::PluginFactoryManager::newFactory_, 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  std::set<std::string> alreadySeen;
64  for(SearchPath::const_iterator itPath=searchPath_.begin(), itEnd = searchPath_.end();
65  itPath != itEnd;
66  ++itPath) {
67  //take care of the case where the same path is passed in multiple times
68  if (alreadySeen.find(*itPath) != alreadySeen.end() ) {
69  continue;
70  }
71  alreadySeen.insert(*itPath);
73  if( exists( dir) ) {
74  if(not is_directory(dir) ) {
75  throw cms::Exception("PluginManagerBadPath") <<"The path '"<<dir.native_file_string()<<"' for the PluginManager is not a directory";
76  }
77  boost::filesystem::path cacheFile = dir/kCacheFile;
78 
79  if(exists(cacheFile) ) {
80  std::ifstream file(cacheFile.native_file_string().c_str());
81  if(not file) {
82  throw cms::Exception("PluginMangerCacheProblem")<<"Unable to open the cache file '"<<cacheFile.native_file_string()
83  <<"'. Please check permissions on file";
84  }
86  }
87  }
88  }
89  //Since this should not be called until after 'main' has started, we can set the value
90  loadingLibraryNamed_()="<loaded by another plugin system>";
91 }
CategoryToInfos categoryToInfos_
int i
Definition: DBlmapReader.cc:9
const boost::filesystem::path & cachefileName()
Definition: standard.cc:48
int path() const
Definition: HLTadd.h:3
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 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 282 of file PluginManager.cc.

References edm::hlt::Exception, PluginManager(), asciidump::s, edmplugin::PluginManager::Config::searchPath(), and singleton().

Referenced by AutoLibraryLoader::enable(), StorageFactory::getMaker(), HcalO2OManager::HcalO2OManager(), cond::Utilities::initializePluginManager(), HPDNoiseLibraryReader::initializeServices(), main(), edm::ProblemTracker::ProblemTracker(), and cond::topinit().

283 {
284  PluginManager*& s = singleton();
285  if( 0 != s ){
286  throw cms::Exception("PluginManagerReconfigured");
287  }
288 
289  Config realConfig = iConfig;
290  if (realConfig.searchPath().empty() ) {
291  throw cms::Exception("PluginManagerEmptySearchPath");
292  }
293  s = new PluginManager (realConfig);
294  return *s;
295 }
static PluginManager *& singleton()
string s
Definition: asciidump.py:422
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 218 of file PluginManager.cc.

References askedToLoadCategoryWithPlugin_, goingToLoad_, justLoaded_, loadableFor(), loadables_, loadingLibraryNamed_(), L1TEmulatorMonitor_cff::p, path(), and asciidump::s.

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

220 {
221  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
222  const boost::filesystem::path& p = loadableFor(iCategory,iPlugin);
223 
224  //have we already loaded this?
225  std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded =
226  loadables_.find(p);
227  if(itLoaded == loadables_.end()) {
228  //try to make one
229  goingToLoad_(p);
230  Sentry s(loadingLibraryNamed_(), p.native_file_string());
231  //boost::filesystem::path native(p.native_file_string());
232  boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
233  loadables_[p]=ptr;
234  justLoaded_(*ptr);
235  return *ptr;
236  }
237  return *(itLoaded->second);
238 }
std::map< boost::filesystem::path, boost::shared_ptr< SharedLibrary > > loadables_
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
sigc::signal< void, const boost::filesystem::path & > goingToLoad_
Definition: PluginManager.h:94
sigc::signal< void, const std::string &, const std::string & > askedToLoadCategoryWithPlugin_
Definition: PluginManager.h:96
int path() const
Definition: HLTadd.h:3
string s
Definition: asciidump.py:422
static std::string & loadingLibraryNamed_()
sigc::signal< void, const SharedLibrary & > justLoaded_
Definition: PluginManager.h:95
const boost::filesystem::path & PluginManager::loadableFor ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 134 of file PluginManager.cc.

References loadableFor_().

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

136 {
137  bool throwIfFail = true;
138  return loadableFor_(iCategory, iPlugin,throwIfFail);
139 }
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 142 of file PluginManager.cc.

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

Referenced by loadableFor(), and tryToLoad().

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

References staticallyLinkedLoadingFileName().

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

307 {
308  static std::string s_name(staticallyLinkedLoadingFileName());
309  return s_name;
310 }
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 118 of file PluginManager.cc.

Referenced by PluginManager().

119 {
120 }
const PluginManager& edmplugin::PluginManager::operator= ( const PluginManager )
private
PluginManager *& PluginManager::singleton ( )
staticprivate

Definition at line 312 of file PluginManager.cc.

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

313 {
314  static PluginManager* s_singleton;
315  return s_singleton;
316 }
const std::string & PluginManager::staticallyLinkedLoadingFileName ( )
static

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

Definition at line 299 of file PluginManager.cc.

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

300 {
301  static std::string s_name("static");
302  return s_name;
303 }
const SharedLibrary * PluginManager::tryToLoad ( const std::string &  iCategory,
const std::string &  iPlugin 
)

Definition at line 241 of file PluginManager.cc.

References askedToLoadCategoryWithPlugin_, goingToLoad_, justLoaded_, loadableFor_(), loadables_, loadingLibraryNamed_(), L1TEmulatorMonitor_cff::p, path(), and asciidump::s.

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

243 {
244  askedToLoadCategoryWithPlugin_(iCategory,iPlugin);
245  bool ioThrowIfFailElseSucceedStatus = false;
246  const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus);
247 
248  if( not ioThrowIfFailElseSucceedStatus ) {
249  return 0;
250  }
251 
252  //have we already loaded this?
253  std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded =
254  loadables_.find(p);
255  if(itLoaded == loadables_.end()) {
256  //try to make one
257  goingToLoad_(p);
258  Sentry s(loadingLibraryNamed_(), p.native_file_string());
259  //boost::filesystem::path native(p.native_file_string());
260  boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) );
261  loadables_[p]=ptr;
262  justLoaded_(*ptr);
263  return ptr.get();
264  }
265  return (itLoaded->second).get();
266 }
std::map< boost::filesystem::path, boost::shared_ptr< SharedLibrary > > loadables_
sigc::signal< void, const boost::filesystem::path & > goingToLoad_
Definition: PluginManager.h:94
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
sigc::signal< void, const std::string &, const std::string & > askedToLoadCategoryWithPlugin_
Definition: PluginManager.h:96
int path() const
Definition: HLTadd.h:3
string s
Definition: asciidump.py:422
static std::string & loadingLibraryNamed_()
sigc::signal< void, const SharedLibrary & > justLoaded_
Definition: PluginManager.h:95

Friends And Related Function Documentation

friend class DummyFriend
friend

Definition at line 39 of file PluginManager.h.

Member Data Documentation

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

sigc::signal<void,const boost::filesystem::path&> edmplugin::PluginManager::goingToLoad_

Definition at line 94 of file PluginManager.h.

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

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