14 #include <boost/filesystem/operations.hpp> 21 #include "TInterpreter.h" 22 #include "TVirtualMutex.h" 45 if (exists(cacheFile)) {
46 std::ifstream
file(cacheFile.string().c_str());
49 <<
"Unable to open the cache file '" << cacheFile.string() <<
"'. Please check permissions on file";
60 using std::placeholders::_1;
80 bool foundAtLeastOneCacheFile =
false;
81 std::set<std::string> alreadySeen;
85 if (alreadySeen.find(*itPath) != alreadySeen.end()) {
88 alreadySeen.insert(*itPath);
91 if (not is_directory(dir)) {
93 <<
"The path '" << dir.string() <<
"' for the PluginManager is not a directory";
98 foundAtLeastOneCacheFile =
true;
107 if (not foundAtLeastOneCacheFile and iConfig.
mustHaveCache()) {
110 for (
auto const&
seen : alreadySeen) {
111 ex <<
" '" <<
seen <<
"'\n";
152 bool throwIfFail =
true;
158 bool& ioThrowIfFailElseSucceedStatus) {
159 const bool throwIfFail = ioThrowIfFailElseSucceedStatus;
160 ioThrowIfFailElseSucceedStatus =
true;
164 throw cms::Exception(
"PluginNotFound") <<
"Unable to find plugin '" << iPlugin <<
"' because the category '" 165 << iCategory <<
"' has no known plugins";
167 ioThrowIfFailElseSucceedStatus =
false;
175 typedef std::vector<PluginInfo>::iterator PIItr;
176 std::pair<PIItr, PIItr> range = std::equal_range(itFound->second.begin(), itFound->second.end(),
i, PICompare());
178 if (range.first == range.second) {
180 throw cms::Exception(
"PluginNotFound") <<
"Unable to find plugin '" << iPlugin <<
"' in category '" << iCategory
181 <<
"'. Please check spelling of name.";
183 ioThrowIfFailElseSucceedStatus =
false;
189 if (range.second - range.first > 1) {
191 if (range.first->loadable_.branch_path() == (range.first + 1)->loadable_.branch_path()) {
194 <<
"The plugin '" << iPlugin
195 <<
"' is found in multiple files \n" 197 << range.first->loadable_.leaf() <<
"'\n '" << (range.first + 1)->loadable_.leaf()
200 << range.first->loadable_.branch_path().string()
202 "The code must be changed so the plugin only appears in one plugin file. " 203 "You will need to remove the macro which registers the plugin so it only appears in" 204 " one of these files.\n" 205 " If none of these files register such a plugin, " 206 "then the problem originates in a library to which all these files link.\n" 207 "The plugin registration must be removed from that library since plugins are not allowed in regular " 212 return range.first->loadable_;
243 std::shared_ptr<SharedLibrary> ptr;
247 R__LOCKGUARD2(gInterpreterMutex);
255 return *(itLoaded->second);
260 bool ioThrowIfFailElseSucceedStatus =
false;
263 if (not ioThrowIfFailElseSucceedStatus) {
279 std::shared_ptr<SharedLibrary> ptr;
283 R__LOCKGUARD(gInterpreterMutex);
291 return (itLoaded->second).get();
299 if (
nullptr == manager) {
301 <<
"PluginManager::get() was called before PluginManager::configure.";
312 const Config& realConfig = iConfig;
CategoryToInfos categoryToInfos_
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
const boost::filesystem::path & cachefileName()
static PluginManager & configure(const Config &)
const boost::filesystem::path & poisonedCachefileName()
static PluginManager *& singleton()
std::map< std::string, Infos > CategoryToInfos
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
const_iterator end() const
const_iterator begin() const
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked ...
static bool isAvailable()
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
static bool readCacheFile(const boost::filesystem::path &cacheFile, const boost::filesystem::path &dir, PluginManager::CategoryToInfos &categoryToInfos)
edm::signalslot::Signal< void(const PluginFactoryBase *)> newFactory_
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
bool mustHaveCache() const
std::recursive_mutex & pluginLoadMutex()
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Config & searchPath(const SearchPath &iPath)
static std::string & loadingLibraryNamed_()
static void read(std::istream &, const boost::filesystem::path &iDirectory, CategoryToInfos &oOut)
std::vector< const PluginFactoryBase * >::const_iterator const_iterator
void newFactory(const PluginFactoryBase *)
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
static PluginManager * get()
static PluginFactoryManager * get()
PluginManager(const Config &)