Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-16 00:05:37

0001 
0002 #include "FWCore/Framework/src/Factory.h"
0003 #include "FWCore/Framework/interface/maker/MakerPluginFactory.h"
0004 #include "FWCore/Framework/interface/ModuleTypeResolverBase.h"
0005 #include "FWCore/Framework/interface/resolveMaker.h"
0006 #include "FWCore/Utilities/interface/DebugMacros.h"
0007 #include "FWCore/Utilities/interface/EDMException.h"
0008 #include "FWCore/Utilities/interface/Algorithms.h"
0009 
0010 #include <iostream>
0011 
0012 EDM_REGISTER_PLUGINFACTORY(edm::MakerPluginFactory, "CMS EDM Framework Module");
0013 namespace edm {
0014 
0015   static void cleanup(const Factory::MakerMap::value_type& v) { delete v.second.get(); }
0016 
0017   Factory const Factory::singleInstance_;
0018 
0019   Factory::~Factory() { for_all(makers_, cleanup); }
0020 
0021   Factory::Factory()
0022       : makers_()
0023 
0024   {}
0025 
0026   Factory const* Factory::get() { return &singleInstance_; }
0027 
0028   Maker* Factory::findMaker(const MakeModuleParams& p, ModuleTypeResolverBase const* resolver) const {
0029     std::string modtype = p.pset_->getParameter<std::string>("@module_type");
0030     FDEBUG(1) << "Factory: module_type = " << modtype << std::endl;
0031     MakerMap::iterator it = makers_.find(modtype);
0032 
0033     if (it == makers_.end()) {
0034       std::unique_ptr<Maker> wm = detail::resolveMaker<MakerPluginFactory>(modtype, resolver);
0035       FDEBUG(1) << "Factory:  created worker of type " << modtype << std::endl;
0036 
0037       std::pair<MakerMap::iterator, bool> ret = makers_.insert(std::pair<std::string, Maker*>(modtype, wm.get()));
0038 
0039       it = ret.first;
0040       wm.release();
0041     }
0042     return it->second;
0043   }
0044 
0045   std::shared_ptr<maker::ModuleHolder> Factory::makeModule(
0046       const MakeModuleParams& p,
0047       const ModuleTypeResolverBase* resolver,
0048       signalslot::Signal<void(const ModuleDescription&)>& pre,
0049       signalslot::Signal<void(const ModuleDescription&)>& post) const {
0050     auto maker = findMaker(p, resolver);
0051     auto mod(maker->makeModule(p, pre, post));
0052     return mod;
0053   }
0054 
0055   std::shared_ptr<maker::ModuleHolder> Factory::makeReplacementModule(const edm::ParameterSet& p) const {
0056     std::string modtype = p.getParameter<std::string>("@module_type");
0057     MakerMap::iterator it = makers_.find(modtype);
0058     if (it != makers_.end()) {
0059       return it->second->makeReplacementModule(p);
0060     }
0061     return std::shared_ptr<maker::ModuleHolder>{};
0062   }
0063 }  // namespace edm