File indexing completed on 2023-03-17 11:02:17
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/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
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
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
0063
0064
0065 auto md = modItr->second->moduleDescription();
0066 iPre(modItr->second->moduleDescription());
0067 bool postCalled = false;
0068
0069 CMS_SA_ALLOW try {
0070 labelToModule_.erase(modItr);
0071
0072 postCalled = true;
0073 iPost(md);
0074 } catch (...) {
0075 if (not postCalled) {
0076
0077 CMS_SA_ALLOW try { iPost(md); } catch (...) {
0078 }
0079 }
0080 throw;
0081 }
0082 }
0083 }