Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:46:59

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), numberOfConcurrentLumis_(prealloc.numberOfLuminosityBlocks()) {
0036     unsigned int nManagers = prealloc.numberOfLuminosityBlocks() + prealloc.numberOfRuns();
0037     workerManagers_.reserve(nManagers);
0038     for (unsigned int i = 0; i < nManagers; ++i) {
0039       workerManagers_.emplace_back(modReg, areg, actions);
0040     }
0041     for (auto const& moduleLabel : iModulesToUse) {
0042       bool isTracked;
0043       ParameterSet* modpset = proc_pset.getPSetForUpdate(moduleLabel, isTracked);
0044       if (modpset != nullptr) {  // It will be null for PathStatusInserters, it should
0045                                  // be impossible to be null for anything else
0046         assert(isTracked);
0047 
0048         //side effect keeps this module around
0049         for (auto& wm : workerManagers_) {
0050           wm.addToAllWorkers(wm.getWorker(*modpset, pregistry, &prealloc, processConfiguration, moduleLabel));
0051         }
0052       }
0053     }
0054     if (inserter) {
0055       inserter->doPreallocate(prealloc);
0056       for (auto& wm : workerManagers_) {
0057         auto results_inserter = WorkerPtr(new edm::WorkerT<TriggerResultInserter::ModuleType>(
0058             inserter, inserter->moduleDescription(), &actions));  // propagate_const<T> has no reset() function
0059         results_inserter->setActivityRegistry(actReg_);
0060         wm.addToAllWorkers(results_inserter.get());
0061         extraWorkers_.emplace_back(std::move(results_inserter));
0062       }
0063     }
0064 
0065     for (auto& pathStatusInserter : pathStatusInserters) {
0066       std::shared_ptr<PathStatusInserter> inserterPtr = get_underlying(pathStatusInserter);
0067       inserterPtr->doPreallocate(prealloc);
0068 
0069       for (auto& wm : workerManagers_) {
0070         WorkerPtr workerPtr(
0071             new edm::WorkerT<PathStatusInserter::ModuleType>(inserterPtr, inserterPtr->moduleDescription(), &actions));
0072         workerPtr->setActivityRegistry(actReg_);
0073         wm.addToAllWorkers(workerPtr.get());
0074         extraWorkers_.emplace_back(std::move(workerPtr));
0075       }
0076     }
0077 
0078     for (auto& endPathStatusInserter : endPathStatusInserters) {
0079       std::shared_ptr<EndPathStatusInserter> inserterPtr = get_underlying(endPathStatusInserter);
0080       inserterPtr->doPreallocate(prealloc);
0081       for (auto& wm : workerManagers_) {
0082         WorkerPtr workerPtr(new edm::WorkerT<EndPathStatusInserter::ModuleType>(
0083             inserterPtr, inserterPtr->moduleDescription(), &actions));
0084         workerPtr->setActivityRegistry(actReg_);
0085         wm.addToAllWorkers(workerPtr.get());
0086         extraWorkers_.emplace_back(std::move(workerPtr));
0087       }
0088     }
0089 
0090   }  // GlobalSchedule::GlobalSchedule
0091 
0092   void GlobalSchedule::endJob(ExceptionCollector& collector) { workerManagers_[0].endJob(collector); }
0093 
0094   void GlobalSchedule::beginJob(ProductRegistry const& iRegistry,
0095                                 eventsetup::ESRecordsToProductResolverIndices const& iESIndices,
0096                                 ProcessBlockHelperBase const& processBlockHelperBase) {
0097     workerManagers_[0].beginJob(iRegistry, iESIndices, processBlockHelperBase);
0098   }
0099 
0100   void GlobalSchedule::replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel) {
0101     Worker* found = nullptr;
0102     for (auto& wm : workerManagers_) {
0103       for (auto const& worker : wm.allWorkers()) {
0104         if (worker->description()->moduleLabel() == iLabel) {
0105           found = worker;
0106           break;
0107         }
0108       }
0109       if (nullptr == found) {
0110         return;
0111       }
0112 
0113       iMod->replaceModuleFor(found);
0114       found->beginJob();
0115     }
0116   }
0117 
0118   void GlobalSchedule::deleteModule(std::string const& iLabel) {
0119     for (auto& wm : workerManagers_) {
0120       wm.deleteModuleIfExists(iLabel);
0121     }
0122   }
0123 
0124   std::vector<ModuleDescription const*> GlobalSchedule::getAllModuleDescriptions() const {
0125     std::vector<ModuleDescription const*> result;
0126     result.reserve(allWorkers().size());
0127 
0128     for (auto const& worker : allWorkers()) {
0129       ModuleDescription const* p = worker->description();
0130       result.push_back(p);
0131     }
0132     return result;
0133   }
0134 }  // namespace edm