Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:33:06

0001 // -*- C++ -*-
0002 //
0003 // Package:     Services
0004 // Class  :     PrintLoadingPlugins
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Thu Dec 13 15:00:49 EST 2007
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
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;                   // stop default
0036   const PrintLoadingPlugins& operator=(const PrintLoadingPlugins&) = delete;  // stop default
0037 
0038   virtual ~PrintLoadingPlugins();
0039 
0040   void goingToLoad(const std::filesystem::path&);
0041 
0042   void askedToLoad(const std::string&, const std::string&);
0043 
0044   // ---------- const member functions ---------------------
0045 
0046   // ---------- static member functions --------------------
0047   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048 
0049   // ---------- member functions ---------------------------
0050 
0051 private:
0052   // ---------- member data --------------------------------
0053 };
0054 
0055 //
0056 // constants, enums and typedefs
0057 //
0058 
0059 //
0060 // static data member definitions
0061 //
0062 
0063 //
0064 // constructors and destructor
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 // PrintLoadingPlugins::PrintLoadingPlugins(const PrintLoadingPlugins& rhs)
0079 // {
0080 //    // do actual copying here;
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 // assignment operators
0093 //
0094 // const PrintLoadingPlugins& PrintLoadingPlugins::operator=(const PrintLoadingPlugins& rhs)
0095 // {
0096 //   //An exception safe implementation is
0097 //   PrintLoadingPlugins temp(rhs);
0098 //   swap(rhs);
0099 //
0100 //   return *this;
0101 // }
0102 
0103 //
0104 // member functions
0105 //
0106 
0107 namespace {
0108   struct PICompare {
0109     bool operator()(const PluginInfo& iLHS, const PluginInfo& iRHS) const { return iLHS.name_ < iRHS.name_; }
0110   };
0111 }  // namespace
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 // const member functions
0150 //
0151 
0152 //
0153 // static member functions
0154 //
0155 
0156 typedef edm::serviceregistry::NoArgsMaker<PrintLoadingPlugins> PrintLoadingPluginsMaker;
0157 DEFINE_FWK_SERVICE_MAKER(PrintLoadingPlugins, PrintLoadingPluginsMaker);