File indexing completed on 2025-06-29 22:58:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "FWCore/Framework/interface/ModuleRegistry.h"
0017 #include "FWCore/Framework/src/ModuleHolderFactory.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 = ModuleHolderFactory::get()->makeModule(p, typeResolverMaker_, iPre, iPost);
0028
0029 if (maxModuleID_ < modPtr->moduleDescription().id()) {
0030 maxModuleID_ = modPtr->moduleDescription().id();
0031 }
0032
0033 labelToModule_[moduleLabel] = modPtr;
0034 return modPtr;
0035 }
0036 return get_underlying_safe(modItr->second);
0037 }
0038
0039 std::shared_ptr<maker::ModuleHolder> ModuleRegistry::getExistingModule(std::string const& moduleLabel) {
0040 auto modItr = labelToModule_.find(moduleLabel);
0041 if (modItr == labelToModule_.end()) {
0042 return {};
0043 }
0044 return get_underlying_safe(modItr->second);
0045 }
0046
0047 maker::ModuleHolder* ModuleRegistry::replaceModule(std::string const& iModuleLabel,
0048 edm::ParameterSet const& iPSet,
0049 edm::PreallocationConfiguration const& iPrealloc) {
0050 auto modItr = labelToModule_.find(iModuleLabel);
0051 if (modItr == labelToModule_.end()) {
0052 return nullptr;
0053 }
0054
0055 auto modPtr = ModuleHolderFactory::get()->makeReplacementModule(iPSet);
0056 modPtr->finishModuleInitialization(modItr->second->moduleDescription(), iPrealloc, nullptr);
0057
0058 if (maxModuleID_ < modPtr->moduleDescription().id()) {
0059 maxModuleID_ = modPtr->moduleDescription().id();
0060 }
0061
0062
0063 modItr->second = modPtr;
0064 return modItr->second.get();
0065 }
0066
0067 void ModuleRegistry::deleteModule(std::string const& iModuleLabel,
0068 signalslot::Signal<void(ModuleDescription const&)>& iPre,
0069 signalslot::Signal<void(ModuleDescription const&)>& iPost) {
0070 auto modItr = labelToModule_.find(iModuleLabel);
0071 if (modItr == labelToModule_.end()) {
0072 throw cms::Exception("LogicError")
0073 << "Trying to delete module " << iModuleLabel
0074 << " but it does not exist in the ModuleRegistry. Please contact framework developers.";
0075 }
0076
0077
0078
0079 auto md = modItr->second->moduleDescription();
0080 iPre(modItr->second->moduleDescription());
0081 bool postCalled = false;
0082
0083 CMS_SA_ALLOW try {
0084 labelToModule_.erase(modItr);
0085
0086 postCalled = true;
0087 iPost(md);
0088 } catch (...) {
0089 if (not postCalled) {
0090
0091 CMS_SA_ALLOW try { iPost(md); } catch (...) {
0092 }
0093 }
0094 throw;
0095 }
0096 }
0097 }