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  } else {
79  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
80  auto const& value = itFound->second.front();
81  while (value.m_ptr.load(std::memory_order_acquire) == nullptr) {
82  }
83  checkProperLoadable(iName, value.m_name);
84  }
85  return itFound->second.front().m_ptr.load(std::memory_order_acquire);
86  }
87 
88  void* PluginFactoryBase::tryToFindPMaker(const std::string& iName) const {
89  //do we already have it?
90  Plugins::const_iterator itFound = m_plugins.find(iName);
91  if (itFound == m_plugins.end()) {
92  const SharedLibrary* slib = PluginManager::get()->tryToLoad(this->category(), iName);
93  if (nullptr != slib) {
94  std::string lib = slib->path().string();
95  itFound = m_plugins.find(iName);
96  if (itFound == m_plugins.end()) {
97  throw cms::Exception("PluginCacheError")
98  << "The plugin '" << iName << "' should have been in loadable\n '" << lib
99  << "'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "
100  << lib << "'";
101  }
102  }
103  } else {
104  //The item in the container can still be under construction so wait until the m_ptr has been set since that is done last
105  auto const& value = itFound->second.front();
106  while (value.m_ptr.load(std::memory_order_acquire) == nullptr) {
107  }
108  checkProperLoadable(iName, value.m_name);
109  }
110  return itFound != m_plugins.end() ? itFound->second.front().m_ptr.load(std::memory_order_acquire) : nullptr;
111  }
112 
113  void PluginFactoryBase::fillInfo(const PMakers& makers, PluginInfo& iInfo, std::vector<PluginInfo>& iReturn) const {
114  for (PMakers::const_iterator it = makers.begin(); it != makers.end(); ++it) {
115  while (nullptr == it->m_ptr.load(std::memory_order_acquire))
116  ;
117  iInfo.loadable_ = it->m_name;
118  iReturn.push_back(iInfo);
119  }
120  }
121 
122  void PluginFactoryBase::fillAvailable(std::vector<PluginInfo>& iReturn) const {
124  for (Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) {
125  info.name_ = it->first;
126  fillInfo(it->second, info, iReturn);
127  }
128  }
129 
130  void PluginFactoryBase::checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const {
131  //should check to see if this is from the proper loadable if it
132  // was not statically linked
134  if (iLoadedFrom != PluginManager::get()->loadableFor(category(), iName).string()) {
135  throw cms::Exception("WrongPluginLoaded")
136  << "The plugin '" << iName << "' should have been loaded from\n '"
137  << PluginManager::get()->loadableFor(category(), iName).string()
138  << "'\n but instead it was already loaded from\n '" << iLoadedFrom
139  << "'\n because some other plugin was loaded from the latter loadables.\n"
140  "To work around the problem the plugin '"
141  << iName << "' should only be defined in one of these loadables.";
142  }
143  }
144  }
145 
146  void PluginFactoryBase::registerPMaker(void* iPMaker, const std::string& iName) {
147  assert(nullptr != iPMaker);
148  m_plugins[iName].push_back(PluginMakerInfo(iPMaker, PluginManager::loadingFile()));
149  newPlugin(iName);
150  }
151 
152  std::vector<PluginInfo> PluginFactoryBase::available() const {
153  std::vector<PluginInfo> returnValue;
154  returnValue.reserve(m_plugins.size());
155  fillAvailable(returnValue);
156  return returnValue;
157  }
158 
159  //
160  // const member functions
161  //
162 
163  //
164  // static member functions
165  //
166 } // 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::PluginFactoryBase::PMakers
tbb::concurrent_vector< PluginMakerInfo > PMakers
Definition: PluginFactoryBase.h:64
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::available
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
Definition: PluginFactoryBase.cc:152
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:130
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:113
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:122
mps_check.lib
lib
Definition: mps_check.py:21
PluginManager.h
Exception
Definition: hltDiff.cc:246
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:146
edmplugin::SharedLibrary
Definition: SharedLibrary.h:29
edmplugin::PluginFactoryBase::tryToFindPMaker
void * tryToFindPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:88
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