Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:12

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     edm::ModuleRegistry
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri, 23 Aug 2013 16:39:58 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/ModuleRegistry.h"
0017 #include "FWCore/Framework/src/Factory.h"
0018 
0019 namespace edm {
0020   std::shared_ptr<maker::ModuleHolder> ModuleRegistry::getModule(
0021       MakeModuleParams const& p,
0022       std::string const& moduleLabel,
0023       signalslot::Signal<void(ModuleDescription const&)>& iPre,
0024       signalslot::Signal<void(ModuleDescription const&)>& iPost) {
0025     auto modItr = labelToModule_.find(moduleLabel);
0026     if (modItr == labelToModule_.end()) {
0027       auto modPtr = Factory::get()->makeModule(p, typeResolverMaker_, iPre, iPost);
0028 
0029       // Transfer ownership of worker to the registry
0030       labelToModule_[moduleLabel] = modPtr;
0031       return modPtr;
0032     }
0033     return get_underlying_safe(modItr->second);
0034   }
0035 
0036   maker::ModuleHolder* ModuleRegistry::replaceModule(std::string const& iModuleLabel,
0037                                                      edm::ParameterSet const& iPSet,
0038                                                      edm::PreallocationConfiguration const& iPrealloc) {
0039     auto modItr = labelToModule_.find(iModuleLabel);
0040     if (modItr == labelToModule_.end()) {
0041       return nullptr;
0042     }
0043 
0044     auto modPtr = Factory::get()->makeReplacementModule(iPSet);
0045     modPtr->setModuleDescription(modItr->second->moduleDescription());
0046     modPtr->preallocate(iPrealloc);
0047 
0048     // Transfer ownership of worker to the registry
0049     modItr->second = modPtr;
0050     return modItr->second.get();
0051   }
0052 
0053   void ModuleRegistry::deleteModule(std::string const& iModuleLabel,
0054                                     signalslot::Signal<void(ModuleDescription const&)>& iPre,
0055                                     signalslot::Signal<void(ModuleDescription const&)>& iPost) {
0056     auto modItr = labelToModule_.find(iModuleLabel);
0057     if (modItr == labelToModule_.end()) {
0058       throw cms::Exception("LogicError")
0059           << "Trying to delete module " << iModuleLabel
0060           << " but it does not exist in the ModuleRegistry. Please contact framework developers.";
0061     }
0062     // If iPost throws and exception, let it propagate
0063     // If deletion throws an exception, capture it and call iPost before throwing an exception
0064     // If iPost throws an exception, let it propagate
0065     auto md = modItr->second->moduleDescription();
0066     iPre(modItr->second->moduleDescription());
0067     bool postCalled = false;
0068     // exception is rethrown
0069     CMS_SA_ALLOW try {
0070       labelToModule_.erase(modItr);
0071       // if exception then post will be called in the catch block
0072       postCalled = true;
0073       iPost(md);
0074     } catch (...) {
0075       if (not postCalled) {
0076         // we're already handling exception, nothing we can do if iPost throws
0077         CMS_SA_ALLOW try { iPost(md); } catch (...) {
0078         }
0079       }
0080       throw;
0081     }
0082   }
0083 }  // namespace edm