Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FWCore_Framework_stream_ProducingModuleAdaptorBase_h
0002 #define FWCore_Framework_stream_ProducingModuleAdaptorBase_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     ProducingModuleAdaptorBase
0007 //
0008 /**\class edm::stream::ProducingModuleAdaptorBase ProducingModuleAdaptorBase.h "FWCore/Framework/interface/stream/ProducingModuleAdaptorBase.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Fri, 02 Aug 2013 18:09:15 GMT
0019 //
0020 
0021 // system include files
0022 #include <array>
0023 #include <map>
0024 #include <string>
0025 #include <vector>
0026 #include <unordered_map>
0027 
0028 // user include files
0029 #include "DataFormats/Provenance/interface/BranchType.h"
0030 #include "FWCore/Utilities/interface/ProductResolverIndex.h"
0031 #include "FWCore/Common/interface/FWCoreCommonFwd.h"
0032 #include "FWCore/Framework/interface/Frameworkfwd.h"
0033 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0035 #include "FWCore/Utilities/interface/StreamID.h"
0036 #include "FWCore/Utilities/interface/RunIndex.h"
0037 #include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
0038 #include "FWCore/Utilities/interface/ESIndices.h"
0039 #include "FWCore/Framework/interface/Event.h"
0040 #include "FWCore/Framework/interface/ProcessBlock.h"
0041 #include "FWCore/Framework/interface/Run.h"
0042 #include "FWCore/Framework/interface/LuminosityBlock.h"
0043 #include "FWCore/ServiceRegistry/interface/ConsumesInfo.h"
0044 
0045 // forward declarations
0046 
0047 namespace edm {
0048   class Event;
0049   class ModuleCallingContext;
0050   class ModuleProcessName;
0051   class ProductResolverIndexHelper;
0052   class EDConsumerBase;
0053   class PreallocationConfiguration;
0054   class ProductResolverIndexAndSkipBit;
0055   class ThinnedAssociationsHelper;
0056 
0057   namespace maker {
0058     template <typename T>
0059     class ModuleHolderT;
0060   }
0061 
0062   namespace eventsetup {
0063     class ESRecordsToProxyIndices;
0064   }
0065 
0066   namespace stream {
0067     template <typename T>
0068     class ProducingModuleAdaptorBase {
0069     public:
0070       template <typename U>
0071       friend class edm::WorkerT;
0072       template <typename U>
0073       friend class edm::maker::ModuleHolderT;
0074 
0075       ProducingModuleAdaptorBase();
0076       ProducingModuleAdaptorBase(const ProducingModuleAdaptorBase&) = delete;                   // stop default
0077       const ProducingModuleAdaptorBase& operator=(const ProducingModuleAdaptorBase&) = delete;  // stop default
0078       virtual ~ProducingModuleAdaptorBase();
0079 
0080       // ---------- const member functions ---------------------
0081 
0082       // ---------- static member functions --------------------
0083 
0084       // ---------- member functions ---------------------------
0085       const ModuleDescription& moduleDescription() const { return moduleDescription_; }
0086 
0087       virtual bool wantsProcessBlocks() const = 0;
0088       virtual bool wantsInputProcessBlocks() const = 0;
0089       virtual bool wantsGlobalRuns() const = 0;
0090       virtual bool wantsGlobalLuminosityBlocks() const = 0;
0091       virtual bool hasAcquire() const = 0;
0092       virtual bool hasAccumulator() const = 0;
0093       bool wantsStreamRuns() const { return true; }
0094       bool wantsStreamLuminosityBlocks() const { return true; }
0095 
0096       void registerProductsAndCallbacks(ProducingModuleAdaptorBase const*, ProductRegistry* reg);
0097 
0098       void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
0099       void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
0100       std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType) const;
0101 
0102       std::vector<ESProxyIndex> const& esGetTokenIndicesVector(edm::Transition iTrans) const;
0103       std::vector<ESRecordIndex> const& esGetTokenRecordIndicesVector(edm::Transition iTrans) const;
0104 
0105       void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&, bool iPrefetchMayGet);
0106       void updateLookup(eventsetup::ESRecordsToProxyIndices const&);
0107       virtual void selectInputProcessBlocks(ProductRegistry const&, ProcessBlockHelperBase const&) = 0;
0108 
0109       void modulesWhoseProductsAreConsumed(std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0110                                            std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0111                                            ProductRegistry const& preg,
0112                                            std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0113                                            std::string const& processName) const;
0114 
0115       void convertCurrentProcessAlias(std::string const& processName);
0116 
0117       std::vector<ConsumesInfo> consumesInfo() const;
0118 
0119       using ModuleToResolverIndicies =
0120           std::unordered_multimap<std::string, std::tuple<edm::TypeID const*, const char*, edm::ProductResolverIndex>>;
0121 
0122       void resolvePutIndicies(BranchType iBranchType,
0123                               ModuleToResolverIndicies const& iIndicies,
0124                               std::string const& moduleLabel);
0125 
0126       std::vector<edm::ProductResolverIndex> const& indiciesForPutProducts(BranchType iBranchType) const;
0127 
0128     protected:
0129       template <typename F>
0130       void createStreamModules(F iFunc) {
0131         unsigned int iStreamModule = 0;
0132         for (auto& m : m_streamModules) {
0133           m = iFunc(iStreamModule);
0134           m->setModuleDescriptionPtr(&moduleDescription_);
0135           ++iStreamModule;
0136         }
0137       }
0138 
0139       void commit(ProcessBlock& iProcessBlock) {
0140         iProcessBlock.commit_(m_streamModules[0]->indiciesForPutProducts(InProcess));
0141       }
0142       void commit(Run& iRun) { iRun.commit_(m_streamModules[0]->indiciesForPutProducts(InRun)); }
0143       void commit(LuminosityBlock& iLumi) { iLumi.commit_(m_streamModules[0]->indiciesForPutProducts(InLumi)); }
0144       template <typename I>
0145       void commit(Event& iEvent, I* iID) {
0146         iEvent.commit_(m_streamModules[0]->indiciesForPutProducts(InEvent), iID);
0147       }
0148 
0149       const EDConsumerBase* consumer() { return m_streamModules[0]; }
0150 
0151       const ProducerBase* producer() { return m_streamModules[0]; }
0152 
0153       void deleteModulesEarly();
0154 
0155     private:
0156       void doPreallocate(PreallocationConfiguration const&);
0157       virtual void preallocLumis(unsigned int) {}
0158       virtual void setupStreamModules() = 0;
0159       virtual void doBeginJob() = 0;
0160       virtual void doEndJob() = 0;
0161 
0162       void doBeginStream(StreamID);
0163       void doEndStream(StreamID);
0164       void doStreamBeginRun(StreamID, RunTransitionInfo const&, ModuleCallingContext const*);
0165       virtual void setupRun(T*, RunIndex) = 0;
0166       void doStreamEndRun(StreamID, RunTransitionInfo const&, ModuleCallingContext const*);
0167       virtual void streamEndRunSummary(T*, edm::Run const&, edm::EventSetup const&) = 0;
0168 
0169       void doStreamBeginLuminosityBlock(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*);
0170       virtual void setupLuminosityBlock(T*, LuminosityBlockIndex) = 0;
0171       void doStreamEndLuminosityBlock(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*);
0172       virtual void streamEndLuminosityBlockSummary(T*, edm::LuminosityBlock const&, edm::EventSetup const&) = 0;
0173 
0174       virtual void doBeginProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) = 0;
0175       virtual void doAccessInputProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) = 0;
0176       virtual void doEndProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*) = 0;
0177       virtual void doBeginRun(RunTransitionInfo const&, ModuleCallingContext const*) = 0;
0178       virtual void doEndRun(RunTransitionInfo const&, ModuleCallingContext const*) = 0;
0179       virtual void doBeginLuminosityBlock(LumiTransitionInfo const&, ModuleCallingContext const*) = 0;
0180       virtual void doEndLuminosityBlock(LumiTransitionInfo const&, ModuleCallingContext const*) = 0;
0181 
0182       void doRespondToOpenInputFile(FileBlock const&) {}
0183       void doRespondToCloseInputFile(FileBlock const&) {}
0184       virtual void doRespondToCloseOutputFile() = 0;
0185       void doRegisterThinnedAssociations(ProductRegistry const&, ThinnedAssociationsHelper&);
0186 
0187       // ---------- member data --------------------------------
0188       void setModuleDescription(ModuleDescription const& md) { moduleDescription_ = md; }
0189       ModuleDescription moduleDescription_;
0190 
0191     protected:
0192       std::vector<T*> m_streamModules;
0193     };
0194   }  // namespace stream
0195 }  // namespace edm
0196 
0197 #endif