CMS 3D CMS Logo

ModuleRegistry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Framework
4 // Class : edm::ModuleRegistry
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Fri, 23 Aug 2013 16:39:58 GMT
11 //
12 
13 // system include files
14 
15 // user include files
18 
19 namespace edm {
20  std::shared_ptr<maker::ModuleHolder> ModuleRegistry::getModule(
21  MakeModuleParams const& p,
22  std::string const& moduleLabel,
23  signalslot::Signal<void(ModuleDescription const&)>& iPre,
24  signalslot::Signal<void(ModuleDescription const&)>& iPost) {
25  auto modItr = labelToModule_.find(moduleLabel);
26  if (modItr == labelToModule_.end()) {
27  auto modPtr = Factory::get()->makeModule(p, iPre, iPost);
28 
29  // Transfer ownership of worker to the registry
30  labelToModule_[moduleLabel] = modPtr;
31  return modPtr;
32  }
33  return get_underlying_safe(modItr->second);
34  }
35 
37  edm::ParameterSet const& iPSet,
38  edm::PreallocationConfiguration const& iPrealloc) {
39  auto modItr = labelToModule_.find(iModuleLabel);
40  if (modItr == labelToModule_.end()) {
41  return nullptr;
42  }
43 
44  auto modPtr = Factory::get()->makeReplacementModule(iPSet);
45  modPtr->setModuleDescription(modItr->second->moduleDescription());
46  modPtr->preallocate(iPrealloc);
47 
48  // Transfer ownership of worker to the registry
49  modItr->second = modPtr;
50  return modItr->second.get();
51  }
52 
53  void ModuleRegistry::deleteModule(std::string const& iModuleLabel,
54  signalslot::Signal<void(ModuleDescription const&)>& iPre,
55  signalslot::Signal<void(ModuleDescription const&)>& iPost) {
56  auto modItr = labelToModule_.find(iModuleLabel);
57  if (modItr == labelToModule_.end()) {
58  throw cms::Exception("LogicError")
59  << "Trying to delete module " << iModuleLabel
60  << " but it does not exist in the ModuleRegistry. Please contact framework developers.";
61  }
62  // If iPost throws and exception, let it propagate
63  // If deletion throws an exception, capture it and call iPost before throwing an exception
64  // If iPost throws an exception, let it propagate
65  auto md = modItr->second->moduleDescription();
66  iPre(modItr->second->moduleDescription());
67  bool postCalled = false;
68  // exception is rethrown
69  CMS_SA_ALLOW try {
70  labelToModule_.erase(modItr);
71  // if exception then post will be called in the catch block
72  postCalled = true;
73  iPost(md);
74  } catch (...) {
75  if (not postCalled) {
76  // we're already handling exception, nothing we can do if iPost throws
77  CMS_SA_ALLOW try { iPost(md); } catch (...) {
78  }
79  }
80  throw;
81  }
82  }
83 } // namespace edm
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::MakeModuleParams
Definition: MakeModuleParams.h:21
edm::maker::ModuleHolder
Definition: ModuleHolder.h:37
edm::get_underlying_safe
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition: get_underlying_safe.h:41
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edm::Factory::makeReplacementModule
std::shared_ptr< maker::ModuleHolder > makeReplacementModule(const edm::ParameterSet &) const
Definition: Factory.cc:64
edm::ModuleDescription
Definition: ModuleDescription.h:21
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
edm::ModuleRegistry::labelToModule_
std::map< std::string, edm::propagate_const< std::shared_ptr< maker::ModuleHolder > > > labelToModule_
Definition: ModuleRegistry.h:64
edm::Factory::makeModule
std::shared_ptr< maker::ModuleHolder > makeModule(const MakeModuleParams &, signalslot::Signal< void(const ModuleDescription &)> &pre, signalslot::Signal< void(const ModuleDescription &)> &post) const
Definition: Factory.cc:55
edm::ModuleRegistry::deleteModule
void deleteModule(std::string const &iModuleLabel, signalslot::Signal< void(ModuleDescription const &)> &iPre, signalslot::Signal< void(ModuleDescription const &)> &iPost)
Definition: ModuleRegistry.cc:53
edm::PreallocationConfiguration
Definition: PreallocationConfiguration.h:27
ModuleRegistry.h
edm::ModuleRegistry::replaceModule
maker::ModuleHolder * replaceModule(std::string const &iModuleLabel, edm::ParameterSet const &iPSet, edm::PreallocationConfiguration const &)
Definition: ModuleRegistry.cc:36
edm::Factory::get
static Factory const * get()
Definition: Factory.cc:23
Exception
Definition: hltDiff.cc:245
edm::ModuleRegistry::getModule
std::shared_ptr< maker::ModuleHolder > getModule(MakeModuleParams const &p, std::string const &moduleLabel, signalslot::Signal< void(ModuleDescription const &)> &iPre, signalslot::Signal< void(ModuleDescription const &)> &iPost)
Definition: ModuleRegistry.cc:20
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
Factory.h
edm::signalslot::Signal
Definition: DelayedReader.h:26