CMS 3D CMS Logo

PluginFactoryBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PluginManager
4 // Class : PluginFactoryBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Apr 4 13:09:50 EDT 2007
11 //
12 
13 // system include files
14 #include <cassert>
15 
16 // user include files
21 
22 namespace edmplugin {
23  //
24  // constants, enums and typedefs
25  //
26 
27  //
28  // static data member definitions
29  //
30 
31  //
32  // constructors and destructor
33  //
34 
35  // PluginFactoryBase::PluginFactoryBase(const PluginFactoryBase& rhs)
36  // {
37  // // do actual copying here;
38  // }
39 
41 
42  //
43  // assignment operators
44  //
45  // const PluginFactoryBase& PluginFactoryBase::operator=(const PluginFactoryBase& rhs)
46  // {
47  // //An exception safe implementation is
48  // PluginFactoryBase temp(rhs);
49  // swap(rhs);
50  //
51  // return *this;
52  // }
53 
54  //
55  // member functions
56  //
58 
62  info.name_ = iName;
64  }
65 
66  void* PluginFactoryBase::findPMaker(const std::string& iName) const {
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  }
91 
92  void* PluginFactoryBase::tryToFindPMaker(const std::string& iName) const {
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  }
116 
117  void PluginFactoryBase::fillInfo(const PMakers& makers, PluginInfo& iInfo, std::vector<PluginInfo>& iReturn) const {
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  }
125 
126  void PluginFactoryBase::fillAvailable(std::vector<PluginInfo>& iReturn) const {
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  }
133 
134  void PluginFactoryBase::checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const {
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  }
149 
150  void PluginFactoryBase::registerPMaker(void* iPMaker, const std::string& iName) {
151  assert(nullptr != iPMaker);
152  m_plugins[iName].push_back(PluginMakerInfo(iPMaker, PluginManager::loadingFile()));
153  newPlugin(iName);
154  }
155 
156  std::vector<PluginInfo> PluginFactoryBase::available() const {
157  std::vector<PluginInfo> returnValue;
158  returnValue.reserve(m_plugins.size());
159  fillAvailable(returnValue);
160  return returnValue;
161  }
162 
163  //
164  // const member functions
165  //
166 
167  //
168  // static member functions
169  //
170 } // namespace edmplugin
edmplugin::PluginFactoryBase::category
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
edmplugin
Definition: AlignmentAlgorithmPluginFactory.cc:9
edmplugin::PluginManager::load
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:226
cms::cuda::assert
assert(be >=bs)
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
edmplugin::PluginFactoryBase::~PluginFactoryBase
virtual ~PluginFactoryBase()
Definition: PluginFactoryBase.cc:40
edmplugin::PluginFactoryBase::PMakers
tbb::concurrent_vector< PluginMakerInfo, tbb::zero_allocator< PluginMakerInfo > > PMakers
Definition: PluginFactoryBase.h:64
edmplugin::PluginFactoryBase::available
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
Definition: PluginFactoryBase.cc:156
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:306
PluginFactoryManager.h
edmplugin::PluginFactoryBase::checkProperLoadable
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
Definition: PluginFactoryBase.cc:134
edmplugin::PluginFactoryManager::addFactory
void addFactory(const PluginFactoryBase *)
Definition: PluginFactoryManager.cc:55
edmplugin::PluginFactoryBase::findPMaker
void * findPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:66
edmplugin::PluginInfo::loadable_
std::filesystem::path loadable_
Definition: PluginInfo.h:30
edmplugin::PluginManager::loadableFor
const std::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:150
edmplugin::SharedLibrary::path
const std::filesystem::path & path() const
Definition: SharedLibrary.h:38
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:77
edmplugin::PluginFactoryBase::fillInfo
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:117
edmplugin::PluginFactoryBase::m_plugins
Plugins m_plugins
Definition: PluginFactoryBase.h:109
value
Definition: value.py:1
PluginFactoryBase.h
edmplugin::PluginFactoryBase::fillAvailable
void fillAvailable(std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:126
mps_check.lib
lib
Definition: mps_check.py:21
PluginManager.h
Exception
Definition: hltDiff.cc:245
edmplugin::PluginFactoryBase::PluginMakerInfo
Definition: PluginFactoryBase.h:44
Exception.h
edmplugin::PluginFactoryBase::finishedConstruction
void finishedConstruction()
Definition: PluginFactoryBase.cc:57
edmplugin::PluginFactoryBase::newPlugin
void newPlugin(const std::string &iName)
Definition: PluginFactoryBase.cc:59
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
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:329
edmplugin::PluginFactoryBase::registerPMaker
void registerPMaker(void *iPMaker, const std::string &iName)
Definition: PluginFactoryBase.cc:150
edmplugin::SharedLibrary
Definition: SharedLibrary.h:29
edmplugin::PluginFactoryBase::tryToFindPMaker
void * tryToFindPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:92
edmplugin::PluginManager::loadingFile
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:89
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:346
edmplugin::PluginInfo
Definition: PluginInfo.h:28
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:262