Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002    \file
0003    Implementation of class WorkerRegistry
0004 
0005    \author Stefano ARGIRO
0006    \date 18 May 2005
0007 */
0008 #include <memory>
0009 #include "FWCore/Framework/interface/WorkerRegistry.h"
0010 #include "FWCore/Framework/interface/maker/Worker.h"
0011 #include "FWCore/Framework/interface/maker/ModuleHolder.h"
0012 #include "FWCore/Framework/interface/maker/MakeModuleParams.h"
0013 #include "FWCore/Framework/interface/ModuleRegistry.h"
0014 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0015 
0016 namespace edm {
0017 
0018   WorkerRegistry::WorkerRegistry(std::shared_ptr<ActivityRegistry> areg, ModuleTypeResolverMaker const* resolverMaker)
0019       : modRegistry_(std::make_shared<ModuleRegistry>(resolverMaker)), m_workerMap(), actReg_(areg) {}
0020 
0021   WorkerRegistry::WorkerRegistry(std::shared_ptr<ActivityRegistry> areg, std::shared_ptr<ModuleRegistry> modReg)
0022       : modRegistry_(modReg), m_workerMap(), actReg_(areg) {}
0023 
0024   WorkerRegistry::~WorkerRegistry() {}
0025 
0026   void WorkerRegistry::clear() { m_workerMap.clear(); }
0027 
0028   Worker* WorkerRegistry::getWorker(WorkerParams const& p, std::string const& moduleLabel) {
0029     WorkerMap::iterator workerIt = m_workerMap.find(moduleLabel);
0030 
0031     // if the worker is not there, make it
0032     if (workerIt == m_workerMap.end()) {
0033       MakeModuleParams mmp(p.pset_, *p.reg_, p.preallocate_, p.processConfiguration_);
0034       auto modulePtr = modRegistry_->getModule(
0035           mmp, moduleLabel, actReg_->preModuleConstructionSignal_, actReg_->postModuleConstructionSignal_);
0036       auto workerPtr = modulePtr->makeWorker(p.actions_);
0037 
0038       workerPtr->setActivityRegistry(actReg_);
0039 
0040       // Transfer ownership of worker to the registry
0041       m_workerMap[moduleLabel] =
0042           std::shared_ptr<Worker>(workerPtr.release());  // propagate_const<T> has no reset() function
0043       return m_workerMap[moduleLabel].get();
0044     }
0045     return (workerIt->second.get());
0046   }
0047 
0048   Worker const* WorkerRegistry::get(std::string const& moduleLabel) const {
0049     WorkerMap::const_iterator workerIt = m_workerMap.find(moduleLabel);
0050     if (workerIt != m_workerMap.end()) {
0051       return workerIt->second;
0052     }
0053     return nullptr;
0054   }
0055 
0056   void WorkerRegistry::deleteModule(std::string const& moduleLabel) {
0057     WorkerMap::iterator workerIt = m_workerMap.find(moduleLabel);
0058     if (workerIt == m_workerMap.end()) {
0059       throw cms::Exception("LogicError")
0060           << "WorkerRegistry::deleteModule() Trying to delete the module of a Worker with label " << moduleLabel
0061           << " but no such Worker exists in the WorkerRegistry. Please contact framework developers.";
0062     }
0063     workerIt->second->clearModule();
0064   }
0065 
0066 }  // namespace edm