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 oneapi::tbb::concurrent_unordered_map< std::string, PMakersPlugins
 
typedef oneapi::tbb::concurrent_vector< PluginMakerInfo, edm::zero_allocator< 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...
 
const PluginFactoryBaseoperator= (const PluginFactoryBase &)=delete
 
 PluginFactoryBase ()
 
 PluginFactoryBase (const PluginFactoryBase &)=delete
 
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
 

Private Attributes

Plugins m_plugins
 

Detailed Description

Definition at line 37 of file PluginFactoryBase.h.

Member Typedef Documentation

◆ Plugins

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

Definition at line 65 of file PluginFactoryBase.h.

◆ PMakers

Definition at line 64 of file PluginFactoryBase.h.

Constructor & Destructor Documentation

◆ PluginFactoryBase() [1/2]

edmplugin::PluginFactoryBase::PluginFactoryBase ( )
inline

Definition at line 39 of file PluginFactoryBase.h.

39 {}

◆ PluginFactoryBase() [2/2]

edmplugin::PluginFactoryBase::PluginFactoryBase ( const PluginFactoryBase )
delete

◆ ~PluginFactoryBase()

PluginFactoryBase::~PluginFactoryBase ( )
virtual

Definition at line 40 of file PluginFactoryBase.cc.

40 {}

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

References fillAvailable(), and m_plugins.

161  {
162  std::vector<PluginInfo> returnValue;
163  returnValue.reserve(m_plugins.size());
164  fillAvailable(returnValue);
165  return returnValue;
166  }
void fillAvailable(std::vector< PluginInfo > &iReturn) const

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

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

Referenced by findPMaker(), and tryToFindPMaker().

134  {
135  //should check to see if this is from the proper loadable if it
136  // was not statically linked
138  if (iLoadedFrom != PluginManager::get()->loadableFor(category(), iName).string()) {
139  throw cms::Exception("WrongPluginLoaded")
140  << "The plugin '" << iName << "' should have been loaded from\n '"
141  << PluginManager::get()->loadableFor(category(), iName).string()
142  << "'\n but instead it was already loaded from\n '" << iLoadedFrom
143  << "'\n because some other plugin was loaded from the latter loadables.\n"
144  "To work around the problem the plugin '"
145  << iName << "' should only be defined in one of these loadables.";
146  }
147  }
148  }
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
const std::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
static PluginManager * get()

◆ fillAvailable()

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

Definition at line 126 of file PluginFactoryBase.cc.

References fillInfo(), info(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, and m_plugins.

Referenced by available().

126  {
128  for (Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) {
129  info.name_ = it->first;
130  fillInfo(it->second, info, iReturn);
131  }
132  }
static const TGPicture * info(bool iBackgroundIsBlack)
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const

◆ fillInfo()

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

Definition at line 117 of file PluginFactoryBase.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, and edmplugin::PluginInfo::loadable_.

Referenced by fillAvailable().

117  {
118  for (PMakers::const_iterator it = makers.begin(); it != makers.end(); ++it) {
119  while (nullptr == it->m_ptr.load(std::memory_order_acquire))
120  ;
121  iInfo.loadable_ = it->m_name;
122  iReturn.push_back(iInfo);
123  }
124  }

◆ findPMaker()

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

Definition at line 66 of file PluginFactoryBase.cc.

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

66  {
67  //do we already have it?
68  Plugins::const_iterator itFound = m_plugins.find(iName);
69  if (itFound == m_plugins.end()) {
70  std::string lib = PluginManager::get()->load(this->category(), iName).path().string();
71  itFound = m_plugins.find(iName);
72  if (itFound == m_plugins.end()) {
73  throw cms::Exception("PluginCacheError")
74  << "The plugin '" << iName << "' should have been in loadable\n '" << lib
75  << "'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh " << lib
76  << "'";
77  }
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  } else {
83  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
84  auto const& value = itFound->second.front();
85  while (value.m_ptr.load(std::memory_order_acquire) == nullptr) {
86  }
87  checkProperLoadable(iName, value.m_name);
88  }
89  return itFound->second.front().m_ptr.load(std::memory_order_acquire);
90  }
Definition: value.py:1
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
const std::filesystem::path & path() const
Definition: SharedLibrary.h:38
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
static PluginManager * get()
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const

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

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

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

void addFactory(const PluginFactoryBase *)
static PluginFactoryManager * get()

◆ newPlugin()

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

Definition at line 59 of file PluginFactoryBase.cc.

References category(), info(), edmplugin::PluginManager::loadingFile(), newPluginAdded_, and castor_dqm_sourceclient_file_cfg::path.

Referenced by registerPMaker().

59  {
62  info.name_ = iName;
64  }
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:89
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs

◆ operator=()

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

◆ registerPMaker()

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

Definition at line 150 of file PluginFactoryBase.cc.

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

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

150  {
151  assert(nullptr != iPMaker);
152  PMakers newMakers;
153  newMakers.emplace_back(iPMaker, PluginManager::loadingFile());
154  if (not m_plugins.emplace(iName, std::move(newMakers)).second) {
155  //the item was already added
156  m_plugins[iName].push_back(PluginMakerInfo(iPMaker, PluginManager::loadingFile()));
157  }
158  newPlugin(iName);
159  }
assert(be >=bs)
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:89
def move(src, dest)
Definition: eostools.py:511
oneapi::tbb::concurrent_vector< PluginMakerInfo, edm::zero_allocator< PluginMakerInfo > > PMakers
void newPlugin(const std::string &iName)

◆ tryToFindPMaker()

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

Definition at line 92 of file PluginFactoryBase.cc.

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

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

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

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