CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WorkerRegistry.cc
Go to the documentation of this file.
1 
8 #include <memory>
15 
16 namespace edm {
17 
18  WorkerRegistry::WorkerRegistry(std::shared_ptr<ActivityRegistry> areg)
19  : modRegistry_(new ModuleRegistry), m_workerMap(), actReg_(areg) {}
20 
21  WorkerRegistry::WorkerRegistry(std::shared_ptr<ActivityRegistry> areg, std::shared_ptr<ModuleRegistry> modReg)
22  : modRegistry_(modReg), m_workerMap(), actReg_(areg) {}
23 
25 
26  void WorkerRegistry::clear() { m_workerMap.clear(); }
27 
29  WorkerMap::iterator workerIt = m_workerMap.find(moduleLabel);
30 
31  // if the worker is not there, make it
32  if (workerIt == m_workerMap.end()) {
34  auto modulePtr = modRegistry_->getModule(
35  mmp, moduleLabel, actReg_->preModuleConstructionSignal_, actReg_->postModuleConstructionSignal_);
36  auto workerPtr = modulePtr->makeWorker(p.actions_);
37 
38  workerPtr->setActivityRegistry(actReg_);
39 
40  // Transfer ownership of worker to the registry
41  m_workerMap[moduleLabel] =
42  std::shared_ptr<Worker>(workerPtr.release()); // propagate_const<T> has no reset() function
43  return m_workerMap[moduleLabel].get();
44  }
45  return (workerIt->second.get());
46  }
47 
48  Worker const* WorkerRegistry::get(std::string const& moduleLabel) const {
49  WorkerMap::const_iterator workerIt = m_workerMap.find(moduleLabel);
50  if (workerIt != m_workerMap.end()) {
51  return workerIt->second;
52  }
53  return nullptr;
54  }
55 
56  void WorkerRegistry::deleteModule(std::string const& moduleLabel) {
57  WorkerMap::iterator workerIt = m_workerMap.find(moduleLabel);
58  if (workerIt == m_workerMap.end()) {
59  throw cms::Exception("LogicError")
60  << "WorkerRegistry::deleteModule() Trying to delete the module of a Worker with label " << moduleLabel
61  << " but no such Worker exists in the WorkerRegistry. Please contact framework developers.";
62  }
63  workerIt->second->clearModule();
64  }
65 
66 } // namespace edm
PreallocationConfiguration const * preallocate_
Definition: WorkerParams.h:38
ParameterSet * pset_
Definition: WorkerParams.h:36
std::shared_ptr< ActivityRegistry > actReg_
WorkerRegistry(std::shared_ptr< ActivityRegistry > areg)
ExceptionToActionTable const * actions_
Definition: WorkerParams.h:40
void deleteModule(std::string const &moduleLabel)
Deletes the module of the Worker, but the Worker continues to exist.
WorkerMap m_workerMap
internal map of registered workers (owned).
ProductRegistry * reg_
Definition: WorkerParams.h:37
areg
Definition: Schedule.cc:687
edm::propagate_const< std::shared_ptr< ModuleRegistry > > modRegistry_
Worker const * get(std::string const &moduleLabel) const
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: WorkerParams.h:39
Worker * getWorker(WorkerParams const &p, std::string const &moduleLabel)
Retrieve the particular instance of the worker.