Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:58:58

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     bool implDoPrePrefetchSelection(StreamID, EventPrincipal const&, ModuleCallingContext const*) override;
0096     bool implDoBeginProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) override;
0097     bool implDoAccessInputProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) override;
0098     bool implDoEndProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) override;
0099     bool implDoBegin(RunTransitionInfo const&, ModuleCallingContext const*) override;
0100     bool implDoStreamBegin(StreamID, RunTransitionInfo const&, ModuleCallingContext const*) override;
0101     bool implDoStreamEnd(StreamID, RunTransitionInfo const&, ModuleCallingContext const*) override;
0102     bool implDoEnd(RunTransitionInfo const&, ModuleCallingContext const*) override;
0103     bool implDoBegin(LumiTransitionInfo const&, ModuleCallingContext const*) override;
0104     bool implDoStreamBegin(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*) override;
0105     bool implDoStreamEnd(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*) override;
0106     bool implDoEnd(LumiTransitionInfo const&, ModuleCallingContext const*) override;
0107     void implBeginJob() override;
0108     void implEndJob() override;
0109     void implBeginStream(StreamID) override;
0110     void implEndStream(StreamID) override;
0111     void implRespondToOpenInputFile(FileBlock const& fb) override;
0112     void implRespondToCloseInputFile(FileBlock const& fb) override;
0113     void implRespondToCloseOutputFile() override;
0114     void implRegisterThinnedAssociations(ProductRegistry const&, ThinnedAssociationsHelper&) override;
0115     std::string workerType() const override;
0116     TaskQueueAdaptor serializeRunModule() override;
0117 
0118     void modulesWhoseProductsAreConsumed(
0119         std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0120         std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0121         ProductRegistry const& preg,
0122         std::map<std::string, ModuleDescription const*> const& labelsToDesc) const override {
0123       module_->modulesWhoseProductsAreConsumed(
0124           modules, modulesInPreviousProcesses, preg, labelsToDesc, module_->moduleDescription().processName());
0125     }
0126 
0127     void convertCurrentProcessAlias(std::string const& processName) override {
0128       module_->convertCurrentProcessAlias(processName);
0129     }
0130 
0131     std::vector<ConsumesInfo> consumesInfo() const override { return module_->consumesInfo(); }
0132 
0133     void itemsToGet(BranchType branchType, std::vector<ProductResolverIndexAndSkipBit>& indexes) const override {
0134       module_->itemsToGet(branchType, indexes);
0135     }
0136 
0137     void itemsMayGet(BranchType branchType, std::vector<ProductResolverIndexAndSkipBit>& indexes) const override {
0138       module_->itemsMayGet(branchType, indexes);
0139     }
0140 
0141     std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const final {
0142       return module_->itemsToGetFrom(iType);
0143     }
0144 
0145     std::vector<ESProxyIndex> const& esItemsToGetFrom(Transition iTransition) const override {
0146       return module_->esGetTokenIndicesVector(iTransition);
0147     }
0148     std::vector<ESRecordIndex> const& esRecordsToGetFrom(Transition iTransition) const override {
0149       return module_->esGetTokenRecordIndicesVector(iTransition);
0150     }
0151 
0152     std::vector<ProductResolverIndex> const& itemsShouldPutInEvent() const override;
0153 
0154     void preActionBeforeRunEventAsync(WaitingTaskHolder iTask,
0155                                       ModuleCallingContext const& iModuleCallingContext,
0156                                       Principal const& iPrincipal) const override {
0157       module_->preActionBeforeRunEventAsync(iTask, iModuleCallingContext, iPrincipal);
0158     }
0159 
0160     bool hasAcquire() const override { return module_->hasAcquire(); }
0161 
0162     bool hasAccumulator() const override { return module_->hasAccumulator(); }
0163 
0164     edm::propagate_const<std::shared_ptr<T>> module_;
0165   };
0166 
0167 }  // namespace edm
0168 
0169 #endif