Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-04 22:45:04

0001 #include "FWCore/Framework/interface/GlobalSchedule.h"
0002 #include "FWCore/Framework/interface/maker/WorkerMaker.h"
0003 #include "FWCore/Framework/src/TriggerResultInserter.h"
0004 #include "FWCore/Framework/src/PathStatusInserter.h"
0005 #include "FWCore/Framework/src/EndPathStatusInserter.h"
0006 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0007 
0008 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0009 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/Registry.h"
0012 #include "FWCore/Utilities/interface/Algorithms.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 
0015 #include <algorithm>
0016 #include <cassert>
0017 #include <cstdlib>
0018 #include <functional>
0019 #include <map>
0020 
0021 namespace edm {
0022   GlobalSchedule::GlobalSchedule(
0023       std::shared_ptr<TriggerResultInserter> inserter,
0024       std::vector<edm::propagate_const<std::shared_ptr<PathStatusInserter>>>& pathStatusInserters,
0025       std::vector<edm::propagate_const<std::shared_ptr<EndPathStatusInserter>>>& endPathStatusInserters,
0026       std::shared_ptr<ModuleRegistry> modReg,
0027       std::vector<std::string> const& iModulesToUse,
0028       ParameterSet& proc_pset,
0029       ProductRegistry& pregistry,
0030       PreallocationConfiguration const& prealloc,
0031       ExceptionToActionTable const& actions,
0032       std::shared_ptr<ActivityRegistry> areg,
0033       std::shared_ptr<ProcessConfiguration const> processConfiguration,
0034       ProcessContext const* processContext)
0035       : actReg_(areg), processContext_(processContext) {
0036     workerManagers_.reserve(prealloc.numberOfLuminosityBlocks());
0037     for (unsigned int i = 0; i < prealloc.numberOfLuminosityBlocks(); ++i) {
0038       workerManagers_.emplace_back(modReg, areg, actions);
0039     }
0040     for (auto const& moduleLabel : iModulesToUse) {
0041       bool isTracked;
0042       ParameterSet* modpset = proc_pset.getPSetForUpdate(moduleLabel, isTracked);
0043       if (modpset != nullptr) {  // It will be null for PathStatusInserters, it should
0044                                  // be impossible to be null for anything else
0045         assert(isTracked);
0046 
0047         //side effect keeps this module around
0048         for (auto& wm : workerManagers_) {
0049           wm.addToAllWorkers(wm.getWorker(*modpset, pregistry, &prealloc, processConfiguration, moduleLabel));
0050         }
0051       }
0052     }
0053     if (inserter) {
0054       inserter->doPreallocate(prealloc);
0055       for (auto& wm : workerManagers_) {
0056         auto results_inserter = WorkerPtr(new edm::WorkerT<TriggerResultInserter::ModuleType>(
0057             inserter, inserter->moduleDescription(), &actions));  // propagate_const<T> has no reset() function
0058         results_inserter->setActivityRegistry(actReg_);
0059         wm.addToAllWorkers(results_inserter.get());
0060         extraWorkers_.emplace_back(std::move(results_inserter));
0061       }
0062     }
0063 
0064     for (auto& pathStatusInserter : pathStatusInserters) {
0065       std::shared_ptr<PathStatusInserter> inserterPtr = get_underlying(pathStatusInserter);
0066       inserterPtr->doPreallocate(prealloc);
0067 
0068       for (auto& wm : workerManagers_) {
0069         WorkerPtr workerPtr(
0070             new edm::WorkerT<PathStatusInserter::ModuleType>(inserterPtr, inserterPtr->moduleDescription(), &actions));
0071         workerPtr->setActivityRegistry(actReg_);
0072         wm.addToAllWorkers(workerPtr.get());
0073         extraWorkers_.emplace_back(std::move(workerPtr));
0074       }
0075     }
0076 
0077     for (auto& endPathStatusInserter : endPathStatusInserters) {
0078       std::shared_ptr<EndPathStatusInserter> inserterPtr = get_underlying(endPathStatusInserter);
0079       inserterPtr->doPreallocate(prealloc);
0080       for (auto& wm : workerManagers_) {
0081         WorkerPtr workerPtr(new edm::WorkerT<EndPathStatusInserter::ModuleType>(
0082             inserterPtr, inserterPtr->moduleDescription(), &actions));
0083         workerPtr->setActivityRegistry(actReg_);
0084         wm.addToAllWorkers(workerPtr.get());
0085         extraWorkers_.emplace_back(std::move(workerPtr));
0086       }
0087     }
0088 
0089   }  // GlobalSchedule::GlobalSchedule
0090 
0091   void GlobalSchedule::endJob(ExceptionCollector& collector) { workerManagers_[0].endJob(collector); }
0092 
0093   void GlobalSchedule::beginJob(ProductRegistry const& iRegistry,
0094                                 eventsetup::ESRecordsToProxyIndices const& iESIndices,
0095                                 ProcessBlockHelperBase const& processBlockHelperBase) {
0096     workerManagers_[0].beginJob(iRegistry, iESIndices, processBlockHelperBase);
0097   }
0098 
0099   void GlobalSchedule::replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel) {
0100     Worker* found = nullptr;
0101     for (auto& wm : workerManagers_) {
0102       for (auto const& worker : wm.allWorkers()) {
0103         if (worker->description()->moduleLabel() == iLabel) {
0104           found = worker;
0105           break;
0106         }
0107       }
0108       if (nullptr == found) {
0109         return;
0110       }
0111 
0112       iMod->replaceModuleFor(found);
0113       found->beginJob();
0114     }
0115   }
0116 
0117   void GlobalSchedule::deleteModule(std::string const& iLabel) {
0118     for (auto& wm : workerManagers_) {
0119       wm.deleteModuleIfExists(iLabel);
0120     }
0121   }
0122 
0123   std::vector<ModuleDescription const*> GlobalSchedule::getAllModuleDescriptions() const {
0124     std::vector<ModuleDescription const*> result;
0125     result.reserve(allWorkers().size());
0126 
0127     for (auto const& worker : allWorkers()) {
0128       ModuleDescription const* p = worker->description();
0129       result.push_back(p);
0130     }
0131     return result;
0132   }
0133 }  // namespace edm