File indexing completed on 2024-04-06 12:13:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
0017
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/PluginManager/interface/PluginManager.h"
0020 #include "FWCore/PluginManager/interface/PluginInfo.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023
0024 #include "FWCore/Utilities/interface/Signal.h"
0025
0026 #include <algorithm>
0027 #include <functional>
0028 #include <iostream>
0029 #include <string>
0030 #include <map>
0031
0032 class PrintLoadingPlugins {
0033 public:
0034 PrintLoadingPlugins();
0035 PrintLoadingPlugins(const PrintLoadingPlugins&) = delete;
0036 const PrintLoadingPlugins& operator=(const PrintLoadingPlugins&) = delete;
0037
0038 virtual ~PrintLoadingPlugins();
0039
0040 void goingToLoad(const std::filesystem::path&);
0041
0042 void askedToLoad(const std::string&, const std::string&);
0043
0044
0045
0046
0047 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048
0049
0050
0051 private:
0052
0053 };
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 using namespace edmplugin;
0067
0068 PrintLoadingPlugins::PrintLoadingPlugins() {
0069 using std::placeholders::_1;
0070 using std::placeholders::_2;
0071 PluginManager* pm = PluginManager::get();
0072
0073 pm->askedToLoadCategoryWithPlugin_.connect(std::bind(std::mem_fn(&PrintLoadingPlugins::askedToLoad), this, _1, _2));
0074
0075 pm->goingToLoad_.connect(std::bind(std::mem_fn(&PrintLoadingPlugins::goingToLoad), this, _1));
0076 }
0077
0078
0079
0080
0081
0082
0083 PrintLoadingPlugins::~PrintLoadingPlugins() {}
0084
0085 void PrintLoadingPlugins::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0086 edm::ParameterSetDescription desc;
0087 descriptions.add("PrintLoadingPlugins", desc);
0088 descriptions.setComment("This service logs each request to load a plugin.");
0089 }
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 namespace {
0108 struct PICompare {
0109 bool operator()(const PluginInfo& iLHS, const PluginInfo& iRHS) const { return iLHS.name_ < iRHS.name_; }
0110 };
0111 }
0112
0113 void PrintLoadingPlugins::askedToLoad(const std::string& iCategory, const std::string& iPlugin) {
0114 PluginManager* pm = PluginManager::get();
0115
0116 const PluginManager::CategoryToInfos& category = pm->categoryToInfos();
0117
0118 PluginManager::CategoryToInfos::const_iterator itFound = category.find(iCategory);
0119
0120 std::string libname("Not found");
0121
0122 if (itFound != category.end()) {
0123 PluginInfo i;
0124
0125 i.name_ = iPlugin;
0126
0127 typedef std::vector<PluginInfo>::const_iterator PIItr;
0128
0129 std::pair<PIItr, PIItr> range = std::equal_range(itFound->second.begin(), itFound->second.end(), i, PICompare());
0130
0131 if (range.second - range.first > 1) {
0132 const std::filesystem::path& loadable = range.first->loadable_;
0133
0134 libname = loadable.string();
0135 }
0136
0137 edm::LogAbsolute("GetPlugin") << "Getting> '" << iCategory << "' " << iPlugin << "\n from " << libname
0138 << std::endl;
0139 }
0140 }
0141
0142 void PrintLoadingPlugins::goingToLoad(const std::filesystem::path& Loadable_)
0143
0144 {
0145 edm::LogAbsolute("LoadLib") << "Loading> " << Loadable_.string() << std::endl;
0146 }
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156 typedef edm::serviceregistry::NoArgsMaker<PrintLoadingPlugins> PrintLoadingPluginsMaker;
0157 DEFINE_FWK_SERVICE_MAKER(PrintLoadingPlugins, PrintLoadingPluginsMaker);