Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-31 02:19:20

0001 #ifndef FWCore_Framework_WorkerT_h
0002 #define FWCore_Framework_WorkerT_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 WorkerT: Code common to all workers.
0007 
0008 ----------------------------------------------------------------------*/
0009 
0010 #include "FWCore/Common/interface/FWCoreCommonFwd.h"
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0013 #include "FWCore/Framework/interface/maker/Worker.h"
0014 #include "FWCore/Framework/interface/maker/WorkerParams.h"
0015 #include "FWCore/ServiceRegistry/interface/ConsumesInfo.h"
0016 #include "FWCore/Utilities/interface/propagate_const.h"
0017 
0018 #include <array>
0019 #include <map>
0020 #include <memory>
0021 #include <string>
0022 #include <vector>
0023 
0024 namespace edm {
0025 
0026   class ModuleCallingContext;
0027   class ModuleProcessName;
0028   class ProductResolverIndexAndSkipBit;
0029   class ThinnedAssociationsHelper;
0030 
0031   template <typename T>
0032   class WorkerT : public Worker {
0033   public:
0034     typedef T ModuleType;
0035     typedef WorkerT<T> WorkerType;
0036     WorkerT(std::shared_ptr<T>, ModuleDescription const&, ExceptionToActionTable const* actions);
0037 
0038     ~WorkerT() override;
0039 
0040     void setModule(std::shared_ptr<T> iModule) {
0041       module_ = iModule;
0042       resetModuleDescription(&(module_->moduleDescription()));
0043     }
0044 
0045     Types moduleType() const override;
0046     ConcurrencyTypes moduleConcurrencyType() const override;
0047 
0048     bool wantsProcessBlocks() const noexcept final;
0049     bool wantsInputProcessBlocks() const noexcept final;
0050     bool wantsGlobalRuns() const noexcept final;
0051     bool wantsGlobalLuminosityBlocks() const noexcept final;
0052     bool wantsStreamRuns() const noexcept final;
0053     bool wantsStreamLuminosityBlocks() const noexcept final;
0054 
0055     SerialTaskQueue* globalRunsQueue() final;
0056     SerialTaskQueue* globalLuminosityBlocksQueue() final;
0057 
0058     void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&) final;
0059     void updateLookup(eventsetup::ESRecordsToProductResolverIndices const&) final;
0060     void selectInputProcessBlocks(ProductRegistry const&, ProcessBlockHelperBase const&) final;
0061 
0062     void resolvePutIndicies(
0063         BranchType iBranchType,
0064         std::unordered_multimap<std::string, std::tuple<TypeID const*, const char*, edm::ProductResolverIndex>> const&
0065             iIndicies) final;
0066 
0067     template <typename D>
0068     void callWorkerBeginStream(D, StreamID);
0069     template <typename D>
0070     void callWorkerEndStream(D, StreamID);
0071     template <typename D>
0072     void callWorkerStreamBegin(D, StreamID, RunTransitionInfo const&, ModuleCallingContext const*);
0073     template <typename D>
0074     void callWorkerStreamEnd(D, StreamID, RunTransitionInfo const&, ModuleCallingContext const*);
0075     template <typename D>
0076     void callWorkerStreamBegin(D, StreamID, LumiTransitionInfo const&, ModuleCallingContext const*);
0077     template <typename D>
0078     void callWorkerStreamEnd(D, StreamID, LumiTransitionInfo const&, ModuleCallingContext const*);
0079 
0080   protected:
0081     T& module() { return *module_; }
0082     T const& module() const { return *module_; }
0083 
0084   private:
0085     void doClearModule() override { get_underlying_safe(module_).reset(); }
0086 
0087     bool implDo(EventTransitionInfo const&, ModuleCallingContext const*) override;
0088 
0089     void itemsToGetForSelection(std::vector<ProductResolverIndexAndSkipBit>&) const final;
0090     bool implNeedToRunSelection() const noexcept final;
0091 
0092     void implDoAcquire(EventTransitionInfo const&, ModuleCallingContext const*, WaitingTaskHolder&&) final;
0093 
0094     size_t transformIndex(edm::ProductDescription const&) const noexcept final;
0095     void implDoTransformAsync(WaitingTaskHolder,
0096                               size_t iTransformIndex,
0097                               EventPrincipal const&,
0098                               ParentContext const&,
0099                               ServiceWeakToken const&) noexcept final;
0100     ProductResolverIndex itemToGetForTransform(size_t iTransformIndex) const noexcept final;
0101 
0102     bool implDoPrePrefetchSelection(StreamID, EventPrincipal const&, ModuleCallingContext const*) override;
0103     bool implDoBeginProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) override;
0104     bool implDoAccessInputProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) override;
0105     bool implDoEndProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) override;
0106     bool implDoBegin(RunTransitionInfo const&, ModuleCallingContext const*) override;
0107     bool implDoStreamBegin(StreamID, RunTransitionInfo const&, ModuleCallingContext const*) override;
0108     bool implDoStreamEnd(StreamID, RunTransitionInfo const&, ModuleCallingContext const*) override;
0109     bool implDoEnd(RunTransitionInfo const&, ModuleCallingContext const*) override;
0110     bool implDoBegin(LumiTransitionInfo const&, ModuleCallingContext const*) override;
0111     bool implDoStreamBegin(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*) override;
0112     bool implDoStreamEnd(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*) override;
0113     bool implDoEnd(LumiTransitionInfo const&, ModuleCallingContext const*) override;
0114     void implBeginJob() override;
0115     void implEndJob() override;
0116     void implBeginStream(StreamID) override;
0117     void implEndStream(StreamID) override;
0118     void implRespondToOpenInputFile(FileBlock const& fb) override;
0119     void implRespondToCloseInputFile(FileBlock const& fb) override;
0120     void implRespondToCloseOutputFile() override;
0121     void implRegisterThinnedAssociations(ProductRegistry const&, ThinnedAssociationsHelper&) override;
0122     std::string workerType() const override;
0123     TaskQueueAdaptor serializeRunModule() override;
0124 
0125     void modulesWhoseProductsAreConsumed(
0126         std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0127         std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0128         ProductRegistry const& preg,
0129         std::map<std::string, ModuleDescription const*> const& labelsToDesc) const override {
0130       module_->modulesWhoseProductsAreConsumed(
0131           modules, modulesInPreviousProcesses, preg, labelsToDesc, module_->moduleDescription().processName());
0132     }
0133 
0134     void convertCurrentProcessAlias(std::string const& processName) override {
0135       module_->convertCurrentProcessAlias(processName);
0136     }
0137 
0138     std::vector<ConsumesInfo> consumesInfo() const override { return module_->consumesInfo(); }
0139 
0140     void itemsToGet(BranchType branchType, std::vector<ProductResolverIndexAndSkipBit>& indexes) const override {
0141       module_->itemsToGet(branchType, indexes);
0142     }
0143 
0144     void itemsMayGet(BranchType branchType, std::vector<ProductResolverIndexAndSkipBit>& indexes) const override {
0145       module_->itemsMayGet(branchType, indexes);
0146     }
0147 
0148     std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const final {
0149       return module_->itemsToGetFrom(iType);
0150     }
0151 
0152     std::vector<ESResolverIndex> const& esItemsToGetFrom(Transition iTransition) const override {
0153       return module_->esGetTokenIndicesVector(iTransition);
0154     }
0155     std::vector<ESRecordIndex> const& esRecordsToGetFrom(Transition iTransition) const override {
0156       return module_->esGetTokenRecordIndicesVector(iTransition);
0157     }
0158 
0159     void preActionBeforeRunEventAsync(WaitingTaskHolder iTask,
0160                                       ModuleCallingContext const& iModuleCallingContext,
0161                                       Principal const& iPrincipal) const noexcept override {
0162       module_->preActionBeforeRunEventAsync(iTask, iModuleCallingContext, iPrincipal);
0163     }
0164 
0165     bool hasAcquire() const noexcept override { return module_->hasAcquire(); }
0166 
0167     bool hasAccumulator() const noexcept override { return module_->hasAccumulator(); }
0168 
0169     edm::propagate_const<std::shared_ptr<T>> module_;
0170   };
0171 
0172 }  // namespace edm
0173 
0174 #endif