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 | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes
edmplugin::PluginFactoryBase Class Referenceabstract

#include <PluginFactoryBase.h>

Inheritance diagram for edmplugin::PluginFactoryBase:
edmplugin::PluginCapabilities edmplugin::PluginFactory< R *(Args...)>

Classes

struct  PluginMakerInfo
 

Public Types

typedef
tbb::concurrent_unordered_map
< std::string, PMakers
Plugins
 
typedef tbb::concurrent_vector
< PluginMakerInfo
PMakers
 

Public Member Functions

virtual std::vector< PluginInfoavailable () const
 return info about all plugins which are already available in the program More...
 
virtual const std::string & category () const =0
 returns the name of the category to which this plugin factory belongs More...
 
 PluginFactoryBase ()
 
virtual ~PluginFactoryBase ()
 

Public Attributes

edm::signalslot::Signal< void(const
std::string &, const
PluginInfo &)> 
newPluginAdded_
 signal containing plugin category, and plugin info for newly added plugin More...
 

Protected Member Functions

void fillAvailable (std::vector< PluginInfo > &iReturn) const
 
void fillInfo (const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
 
void * findPMaker (const std::string &iName) const
 
void finishedConstruction ()
 
void newPlugin (const std::string &iName)
 
void registerPMaker (void *iPMaker, const std::string &iName)
 
void * tryToFindPMaker (const std::string &iName) const
 

Private Member Functions

void checkProperLoadable (const std::string &iName, const std::string &iLoadedFrom) const
 
const PluginFactoryBaseoperator= (const PluginFactoryBase &)
 
 PluginFactoryBase (const PluginFactoryBase &)
 

Private Attributes

Plugins m_plugins
 

Detailed Description

Definition at line 36 of file PluginFactoryBase.h.

Member Typedef Documentation

typedef tbb::concurrent_unordered_map<std::string, PMakers > edmplugin::PluginFactoryBase::Plugins

Definition at line 68 of file PluginFactoryBase.h.

typedef tbb::concurrent_vector<PluginMakerInfo> edmplugin::PluginFactoryBase::PMakers

Definition at line 67 of file PluginFactoryBase.h.

Constructor & Destructor Documentation

edmplugin::PluginFactoryBase::PluginFactoryBase ( )
inline

Definition at line 40 of file PluginFactoryBase.h.

40 {}
PluginFactoryBase::~PluginFactoryBase ( )
virtual

Definition at line 40 of file PluginFactoryBase.cc.

41 {
42 }
edmplugin::PluginFactoryBase::PluginFactoryBase ( const PluginFactoryBase )
private

Member Function Documentation

std::vector< PluginInfo > PluginFactoryBase::available ( ) const
virtual

return info about all plugins which are already available in the program

Reimplemented in edmplugin::PluginCapabilities.

Definition at line 172 of file PluginFactoryBase.cc.

References fillAvailable(), and m_plugins.

172  {
173  std::vector<PluginInfo> returnValue;
174  returnValue.reserve(m_plugins.size());
175  fillAvailable(returnValue);
176  return returnValue;
177 }
void fillAvailable(std::vector< PluginInfo > &iReturn) const
virtual const std::string& edmplugin::PluginFactoryBase::category ( ) const
pure virtual

returns the name of the category to which this plugin factory belongs

Implemented in edmplugin::PluginFactory< R *(Args...)>, and edmplugin::PluginCapabilities.

Referenced by checkProperLoadable(), findPMaker(), newPlugin(), and tryToFindPMaker().

void PluginFactoryBase::checkProperLoadable ( const std::string &  iName,
const std::string &  iLoadedFrom 
) const
private

Definition at line 147 of file PluginFactoryBase.cc.

References category(), edm::hlt::Exception, edmplugin::PluginManager::get(), edmplugin::PluginManager::isAvailable(), edmplugin::PluginManager::loadableFor(), and edmplugin::PluginManager::staticallyLinkedLoadingFileName().

Referenced by findPMaker(), and tryToFindPMaker().

148 {
149  //should check to see if this is from the proper loadable if it
150  // was not statically linked
151  if (iLoadedFrom != PluginManager::staticallyLinkedLoadingFileName() &&
153  if( iLoadedFrom != PluginManager::get()->loadableFor(category(),iName).string() ) {
154  throw cms::Exception("WrongPluginLoaded")<<"The plugin '"<<iName<<"' should have been loaded from\n '"
155  <<PluginManager::get()->loadableFor(category(),iName).string()
156  <<"'\n but instead it was already loaded from\n '"
157  <<iLoadedFrom<<"'\n because some other plugin was loaded from the latter loadables.\n"
158  "To work around the problem the plugin '"<<iName<<"' should only be defined in one of these loadables.";
159  }
160  }
161 }
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked ...
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
static PluginManager * get()
void PluginFactoryBase::fillAvailable ( std::vector< PluginInfo > &  iReturn) const
protected

Definition at line 135 of file PluginFactoryBase.cc.

References fillInfo(), info(), m_plugins, and edmplugin::PluginInfo::name_.

Referenced by available().

135  {
137  for( Plugins::const_iterator it = m_plugins.begin();
138  it != m_plugins.end();
139  ++it) {
140  info.name_ = it->first;
141  fillInfo(it->second,
142  info, iReturn);
143  }
144 }
static const TGPicture * info(bool iBackgroundIsBlack)
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
void PluginFactoryBase::fillInfo ( const PMakers makers,
PluginInfo iInfo,
std::vector< PluginInfo > &  iReturn 
) const
protected

Definition at line 122 of file PluginFactoryBase.cc.

References edmplugin::PluginInfo::loadable_.

Referenced by fillAvailable().

124  {
125  for(PMakers::const_iterator it = makers.begin();
126  it != makers.end();
127  ++it) {
128  while (nullptr ==it->m_ptr.load(std::memory_order_acquire)) ;
129  iInfo.loadable_ = it->m_name;
130  iReturn.push_back(iInfo);
131  }
132 }
void * PluginFactoryBase::findPMaker ( const std::string &  iName) const
protected

Definition at line 76 of file PluginFactoryBase.cc.

References category(), checkProperLoadable(), edm::hlt::Exception, edmplugin::PluginManager::get(), edmplugin::PluginManager::load(), m_plugins, edmplugin::SharedLibrary::path(), AlCaHLTBitMon_QueryRunRegistry::string, and relativeConstraints::value.

Referenced by edmplugin::PluginFactory< R *(Args...)>::create().

77 {
78  //do we already have it?
79  Plugins::const_iterator itFound = m_plugins.find(iName);
80  if(itFound == m_plugins.end()) {
81  std::string lib = PluginManager::get()->load(this->category(),iName).path().string();
82  itFound = m_plugins.find(iName);
83  if(itFound == m_plugins.end()) {
84  throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
85  <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
86  }
87  } else {
88  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
89  auto const& value= itFound->second.front();
90  while(value.m_ptr.load(std::memory_order_acquire)==nullptr) {}
91  checkProperLoadable(iName,value.m_name);
92  }
93  return itFound->second.front().m_ptr.load(std::memory_order_acquire);
94 }
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
const boost::filesystem::path & path() const
Definition: SharedLibrary.h:38
static PluginManager * get()
void PluginFactoryBase::finishedConstruction ( )
protected

call this as the last line in the constructor of inheriting classes this is done so that the virtual table will be properly initialized when the routine is called

Definition at line 60 of file PluginFactoryBase.cc.

References edmplugin::PluginFactoryManager::addFactory(), and edmplugin::PluginFactoryManager::get().

Referenced by edmplugin::PluginCapabilities::PluginCapabilities().

61 {
63 }
void addFactory(const PluginFactoryBase *)
static PluginFactoryManager * get()
void PluginFactoryBase::newPlugin ( const std::string &  iName)
protected

Definition at line 66 of file PluginFactoryBase.cc.

References category(), info(), edmplugin::PluginInfo::loadable_, edmplugin::PluginManager::loadingFile(), edmplugin::PluginInfo::name_, newPluginAdded_, and getHLTPrescaleColumns::path.

Referenced by registerPMaker().

67 {
70  info.name_=iName;
71  newPluginAdded_(category(),info);
72 }
static const TGPicture * info(bool iBackgroundIsBlack)
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:92
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
const PluginFactoryBase& edmplugin::PluginFactoryBase::operator= ( const PluginFactoryBase )
private
void PluginFactoryBase::registerPMaker ( void *  iPMaker,
const std::string &  iName 
)
protected

Definition at line 165 of file PluginFactoryBase.cc.

References edmplugin::PluginManager::loadingFile(), m_plugins, and newPlugin().

Referenced by edmplugin::PluginFactory< R *(Args...)>::registerPMaker().

165  {
166  assert(0!= iPMaker);
167  m_plugins[iName].push_back(PluginMakerInfo(iPMaker,PluginManager::loadingFile()));
168  newPlugin(iName);
169 }
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:92
void newPlugin(const std::string &iName)
void * PluginFactoryBase::tryToFindPMaker ( const std::string &  iName) const
protected

Definition at line 98 of file PluginFactoryBase.cc.

References category(), checkProperLoadable(), edm::hlt::Exception, edmplugin::PluginManager::get(), m_plugins, edmplugin::SharedLibrary::path(), AlCaHLTBitMon_QueryRunRegistry::string, edmplugin::PluginManager::tryToLoad(), and relativeConstraints::value.

Referenced by edmplugin::PluginFactory< R *(Args...)>::tryToCreate().

99 {
100  //do we already have it?
101  Plugins::const_iterator itFound = m_plugins.find(iName);
102  if(itFound == m_plugins.end()) {
103  const SharedLibrary* slib = PluginManager::get()->tryToLoad(this->category(),iName);
104  if(0!=slib) {
105  std::string lib = slib->path().string();
106  itFound = m_plugins.find(iName);
107  if(itFound == m_plugins.end()) {
108  throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
109  <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
110  }
111  }
112  } else {
113  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
114  auto const& value= itFound->second.front();
115  while(value.m_ptr.load(std::memory_order_acquire)==nullptr) {}
116  checkProperLoadable(iName,value.m_name);
117  }
118  return itFound != m_plugins.end()? itFound->second.front().m_ptr.load(std::memory_order_acquire) : nullptr;
119 }
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
static PluginManager * get()

Member Data Documentation

Plugins edmplugin::PluginFactoryBase::m_plugins
private
edm::signalslot::Signal<void(const std::string&, const PluginInfo&)> edmplugin::PluginFactoryBase::newPluginAdded_
mutable

signal containing plugin category, and plugin info for newly added plugin

Definition at line 79 of file PluginFactoryBase.h.

Referenced by newPlugin(), and edmplugin::PluginCapabilities::tryToFind().