File indexing completed on 2025-06-29 22:58:05
0001 #include "FWCore/Framework/interface/WorkerManager.h"
0002 #include "UnscheduledConfigurator.h"
0003
0004 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0005 #include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
0006 #include "FWCore/Framework/interface/maker/Worker.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/Algorithms.h"
0009 #include "FWCore/Utilities/interface/ConvertException.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "FWCore/Utilities/interface/ExceptionCollector.h"
0012 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0013
0014 #include <exception>
0015 #include <functional>
0016
0017 static const std::string kFilterType("EDFilter");
0018 static const std::string kProducerType("EDProducer");
0019
0020 namespace edm {
0021
0022 WorkerManager::WorkerManager(std::shared_ptr<ModuleRegistry> modReg,
0023 std::shared_ptr<ActivityRegistry> areg,
0024 ExceptionToActionTable const& actions)
0025 : workerReg_(areg, modReg),
0026 actionTable_(&actions),
0027 allWorkers_(),
0028 unscheduled_(*areg),
0029 lastSetupEventPrincipal_(nullptr) {}
0030
0031 void WorkerManager::deleteModuleIfExists(std::string const& moduleLabel) {
0032 auto worker = workerReg_.get(moduleLabel);
0033 if (worker != nullptr) {
0034 auto eraseBeg = std::remove(allWorkers_.begin(), allWorkers_.end(), worker);
0035 allWorkers_.erase(eraseBeg, allWorkers_.end());
0036 unscheduled_.removeWorker(worker);
0037 workerReg_.deleteModule(moduleLabel);
0038 }
0039 }
0040
0041 Worker* WorkerManager::getWorker(ParameterSet& pset,
0042 SignallingProductRegistryFiller& preg,
0043 PreallocationConfiguration const* prealloc,
0044 std::shared_ptr<ProcessConfiguration const> processConfiguration,
0045 std::string const& label,
0046 bool addToAll) {
0047 WorkerParams params(&pset, preg, prealloc, processConfiguration, *actionTable_);
0048 auto worker = workerReg_.getWorker(params, label);
0049 if (nullptr != worker and addToAll) {
0050 addToAllWorkers(worker);
0051 }
0052 return worker;
0053 }
0054
0055 Worker* WorkerManager::getWorkerForExistingModule(std::string const& label) {
0056 auto worker = workerReg_.getWorkerFromExistingModule(label, actionTable_);
0057 if (nullptr != worker) {
0058 addToAllWorkers(worker);
0059 }
0060 return worker;
0061 }
0062
0063 void WorkerManager::addToUnscheduledWorkers(ParameterSet& pset,
0064 SignallingProductRegistryFiller& preg,
0065 PreallocationConfiguration const* prealloc,
0066 std::shared_ptr<ProcessConfiguration const> processConfiguration,
0067 std::string label,
0068 std::set<std::string>& unscheduledLabels,
0069 std::vector<std::string>& shouldBeUsedLabels) {
0070
0071
0072
0073 auto modType = pset.getParameter<std::string>("@module_edm_type");
0074 if (modType == kProducerType || modType == kFilterType) {
0075 Worker* newWorker = getWorker(pset, preg, prealloc, processConfiguration, label);
0076 assert(newWorker->moduleType() == Worker::kProducer || newWorker->moduleType() == Worker::kFilter);
0077 unscheduledLabels.insert(label);
0078 unscheduled_.addWorker(newWorker);
0079
0080 addToAllWorkers(newWorker);
0081 } else {
0082 shouldBeUsedLabels.push_back(label);
0083 }
0084 }
0085
0086 void WorkerManager::resetAll() { for_all(allWorkers_, std::bind(&Worker::reset, std::placeholders::_1)); }
0087
0088 void WorkerManager::addToAllWorkers(Worker* w) {
0089 if (!search_all(allWorkers_, w)) {
0090 allWorkers_.push_back(w);
0091 }
0092 }
0093
0094 void WorkerManager::setupResolvers(Principal& ep) {
0095 this->resetAll();
0096 if (&ep != lastSetupEventPrincipal_) {
0097 UnscheduledConfigurator config(allWorkers_.begin(), allWorkers_.end(), &(unscheduled_.auxiliary()));
0098 ep.setupUnscheduled(config);
0099 lastSetupEventPrincipal_ = &ep;
0100 }
0101 }
0102
0103 void WorkerManager::setupOnDemandSystem(EventTransitionInfo const& info) {
0104 unscheduled_.setEventTransitionInfo(info);
0105 }
0106
0107 }