CMS 3D CMS Logo

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, PMakersPlugins
 
typedef tbb::concurrent_vector< PluginMakerInfoPMakers
 

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 &)=delete
 
 PluginFactoryBase (const PluginFactoryBase &)=delete
 

Private Attributes

Plugins m_plugins
 

Detailed Description

Definition at line 37 of file PluginFactoryBase.h.

Member Typedef Documentation

◆ Plugins

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

Definition at line 63 of file PluginFactoryBase.h.

◆ PMakers

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

Definition at line 62 of file PluginFactoryBase.h.

Constructor & Destructor Documentation

◆ PluginFactoryBase() [1/2]

edmplugin::PluginFactoryBase::PluginFactoryBase ( )
inline

Definition at line 39 of file PluginFactoryBase.h.

39 {}

◆ ~PluginFactoryBase()

PluginFactoryBase::~PluginFactoryBase ( )
virtual

Definition at line 39 of file PluginFactoryBase.cc.

39 {}

◆ PluginFactoryBase() [2/2]

edmplugin::PluginFactoryBase::PluginFactoryBase ( const PluginFactoryBase )
privatedelete

Member Function Documentation

◆ available()

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 151 of file PluginFactoryBase.cc.

151  {
152  std::vector<PluginInfo> returnValue;
153  returnValue.reserve(m_plugins.size());
154  fillAvailable(returnValue);
155  return returnValue;
156  }

References fillAvailable(), and m_plugins.

◆ category()

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

◆ checkProperLoadable()

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

Definition at line 129 of file PluginFactoryBase.cc.

129  {
130  //should check to see if this is from the proper loadable if it
131  // was not statically linked
133  if (iLoadedFrom != PluginManager::get()->loadableFor(category(), iName).string()) {
134  throw cms::Exception("WrongPluginLoaded")
135  << "The plugin '" << iName << "' should have been loaded from\n '"
136  << PluginManager::get()->loadableFor(category(), iName).string()
137  << "'\n but instead it was already loaded from\n '" << iLoadedFrom
138  << "'\n because some other plugin was loaded from the latter loadables.\n"
139  "To work around the problem the plugin '"
140  << iName << "' should only be defined in one of these loadables.";
141  }
142  }
143  }

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

Referenced by findPMaker(), and tryToFindPMaker().

◆ fillAvailable()

void PluginFactoryBase::fillAvailable ( std::vector< PluginInfo > &  iReturn) const
protected

Definition at line 121 of file PluginFactoryBase.cc.

121  {
123  for (Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) {
124  info.name_ = it->first;
125  fillInfo(it->second, info, iReturn);
126  }
127  }

References fillInfo(), info(), and m_plugins.

Referenced by available().

◆ fillInfo()

void PluginFactoryBase::fillInfo ( const PMakers makers,
PluginInfo iInfo,
std::vector< PluginInfo > &  iReturn 
) const
protected

Definition at line 112 of file PluginFactoryBase.cc.

112  {
113  for (PMakers::const_iterator it = makers.begin(); it != makers.end(); ++it) {
114  while (nullptr == it->m_ptr.load(std::memory_order_acquire))
115  ;
116  iInfo.loadable_ = it->m_name;
117  iReturn.push_back(iInfo);
118  }
119  }

References edmplugin::PluginInfo::loadable_.

Referenced by fillAvailable().

◆ findPMaker()

void * PluginFactoryBase::findPMaker ( const std::string &  iName) const
protected

Definition at line 65 of file PluginFactoryBase.cc.

65  {
66  //do we already have it?
67  Plugins::const_iterator itFound = m_plugins.find(iName);
68  if (itFound == m_plugins.end()) {
69  std::string lib = PluginManager::get()->load(this->category(), iName).path().string();
70  itFound = m_plugins.find(iName);
71  if (itFound == m_plugins.end()) {
72  throw cms::Exception("PluginCacheError")
73  << "The plugin '" << iName << "' should have been in loadable\n '" << lib
74  << "'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh " << lib
75  << "'";
76  }
77  } else {
78  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
79  auto const& value = itFound->second.front();
80  while (value.m_ptr.load(std::memory_order_acquire) == nullptr) {
81  }
82  checkProperLoadable(iName, value.m_name);
83  }
84  return itFound->second.front().m_ptr.load(std::memory_order_acquire);
85  }

References category(), checkProperLoadable(), Exception, edmplugin::PluginManager::get(), mps_check::lib, edmplugin::PluginManager::load(), m_plugins, edmplugin::SharedLibrary::path(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ finishedConstruction()

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 56 of file PluginFactoryBase.cc.

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

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

◆ newPlugin()

void PluginFactoryBase::newPlugin ( const std::string &  iName)
protected

◆ operator=()

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

◆ registerPMaker()

void PluginFactoryBase::registerPMaker ( void *  iPMaker,
const std::string &  iName 
)
protected

Definition at line 145 of file PluginFactoryBase.cc.

145  {
146  assert(nullptr != iPMaker);
147  m_plugins[iName].push_back(PluginMakerInfo(iPMaker, PluginManager::loadingFile()));
148  newPlugin(iName);
149  }

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

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

◆ tryToFindPMaker()

void * PluginFactoryBase::tryToFindPMaker ( const std::string &  iName) const
protected

Definition at line 87 of file PluginFactoryBase.cc.

87  {
88  //do we already have it?
89  Plugins::const_iterator itFound = m_plugins.find(iName);
90  if (itFound == m_plugins.end()) {
91  const SharedLibrary* slib = PluginManager::get()->tryToLoad(this->category(), iName);
92  if (nullptr != slib) {
93  std::string lib = slib->path().string();
94  itFound = m_plugins.find(iName);
95  if (itFound == m_plugins.end()) {
96  throw cms::Exception("PluginCacheError")
97  << "The plugin '" << iName << "' should have been in loadable\n '" << lib
98  << "'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "
99  << lib << "'";
100  }
101  }
102  } else {
103  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
104  auto const& value = itFound->second.front();
105  while (value.m_ptr.load(std::memory_order_acquire) == nullptr) {
106  }
107  checkProperLoadable(iName, value.m_name);
108  }
109  return itFound != m_plugins.end() ? itFound->second.front().m_ptr.load(std::memory_order_acquire) : nullptr;
110  }

References category(), checkProperLoadable(), Exception, edmplugin::PluginManager::get(), mps_check::lib, m_plugins, edmplugin::SharedLibrary::path(), AlCaHLTBitMon_QueryRunRegistry::string, and edmplugin::PluginManager::tryToLoad().

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

Member Data Documentation

◆ m_plugins

Plugins edmplugin::PluginFactoryBase::m_plugins
private

◆ newPluginAdded_

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 75 of file PluginFactoryBase.h.

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

edmplugin::PluginFactoryBase::category
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
edmplugin::PluginManager::load
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:227
cms::cuda::assert
assert(be >=bs)
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
edmplugin::SharedLibrary::path
const boost::filesystem::path & path() const
Definition: SharedLibrary.h:36
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:307
edmplugin::PluginFactoryBase::checkProperLoadable
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
Definition: PluginFactoryBase.cc:129
edmplugin::PluginFactoryManager::addFactory
void addFactory(const PluginFactoryBase *)
Definition: PluginFactoryManager.cc:55
edmplugin::PluginManager::loadableFor
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:151
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edmplugin::PluginFactoryBase::newPluginAdded_
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
Definition: PluginFactoryBase.h:75
edmplugin::PluginFactoryBase::fillInfo
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:112
edmplugin::PluginFactoryBase::m_plugins
Plugins m_plugins
Definition: PluginFactoryBase.h:111
value
Definition: value.py:1
edmplugin::PluginFactoryBase::fillAvailable
void fillAvailable(std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:121
mps_check.lib
lib
Definition: mps_check.py:21
SharedLibrary
Exception
Definition: hltDiff.cc:246
edmplugin::PluginFactoryBase::newPlugin
void newPlugin(const std::string &iName)
Definition: PluginFactoryBase.cc:58
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
edmplugin::PluginManager::loadingFile
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:87
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:347
edmplugin::PluginFactoryManager::get
static PluginFactoryManager * get()
Definition: PluginFactoryManager.cc:70
edmplugin::PluginManager::tryToLoad
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:263