Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-18 04:13:16

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