Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-11 03:34:10

0001 #ifndef FWCore_Framework_limited_EDProducerBase_h
0002 #define FWCore_Framework_limited_EDProducerBase_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     EDProducerBase
0007 //
0008 /**\class EDProducerBase EDProducerBase.h "EDProducerBase.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Thu, 18 Jul 2013 11:51:14 GMT
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/ProducerBase.h"
0026 #include "FWCore/Framework/interface/EDConsumerBase.h"
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0030 #include "FWCore/Concurrency/interface/LimitedTaskQueue.h"
0031 #include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
0032 
0033 // forward declarations
0034 
0035 namespace edm {
0036   class ModuleCallingContext;
0037   class PreallocationConfiguration;
0038   class StreamID;
0039   class GlobalSchedule;
0040   class ActivityRegistry;
0041   class ThinnedAssociationsHelper;
0042   class EventForTransformer;
0043   class ServiceWeakToken;
0044 
0045   namespace maker {
0046     template <typename T>
0047     class ModuleHolderT;
0048   }
0049 
0050   namespace limited {
0051 
0052     class EDProducerBase : public ProducerBase, public EDConsumerBase {
0053     public:
0054       template <typename T>
0055       friend class edm::maker::ModuleHolderT;
0056       template <typename T>
0057       friend class edm::WorkerT;
0058       typedef EDProducerBase ModuleType;
0059 
0060       friend class edm::GlobalSchedule;
0061 
0062       EDProducerBase(ParameterSet const& pset);
0063       ~EDProducerBase() override;
0064 
0065       static void fillDescriptions(ConfigurationDescriptions& descriptions);
0066       static void prevalidate(ConfigurationDescriptions& descriptions);
0067       static const std::string& baseType();
0068 
0069       // Warning: the returned moduleDescription will be invalid during construction
0070       ModuleDescription const& moduleDescription() const { return moduleDescription_; }
0071 
0072       virtual bool wantsProcessBlocks() const noexcept = 0;
0073       virtual bool wantsInputProcessBlocks() const noexcept = 0;
0074       virtual bool wantsGlobalRuns() const noexcept = 0;
0075       virtual bool wantsGlobalLuminosityBlocks() const noexcept = 0;
0076       virtual bool wantsStreamRuns() const noexcept = 0;
0077       virtual bool wantsStreamLuminosityBlocks() const noexcept = 0;
0078 
0079       unsigned int concurrencyLimit() const { return queue_.concurrencyLimit(); }
0080 
0081       LimitedTaskQueue& queue() { return queue_; }
0082 
0083     private:
0084       bool doEvent(EventTransitionInfo const&, ActivityRegistry*, ModuleCallingContext const*);
0085       void doTransformAsync(WaitingTaskHolder iTask,
0086                             size_t iTransformIndex,
0087                             EventPrincipal const& iEvent,
0088                             ActivityRegistry*,
0089                             ModuleCallingContext,
0090                             ServiceWeakToken const&) noexcept;
0091       void doPreallocate(PreallocationConfiguration const&);
0092       void doBeginJob();
0093       void doEndJob();
0094 
0095       void doBeginStream(StreamID id);
0096       void doEndStream(StreamID id);
0097       void doStreamBeginRun(StreamID, RunTransitionInfo const&, ModuleCallingContext const*);
0098       void doStreamEndRun(StreamID, RunTransitionInfo const&, ModuleCallingContext const*);
0099       void doStreamBeginLuminosityBlock(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*);
0100       void doStreamEndLuminosityBlock(StreamID, LumiTransitionInfo const&, ModuleCallingContext const*);
0101 
0102       void doBeginProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*);
0103       void doAccessInputProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*);
0104       void doEndProcessBlock(ProcessBlockPrincipal const&, ModuleCallingContext const*);
0105       void doBeginRun(RunTransitionInfo const&, ModuleCallingContext const*);
0106       void doEndRun(RunTransitionInfo const&, ModuleCallingContext const*);
0107       void doBeginLuminosityBlock(LumiTransitionInfo const&, ModuleCallingContext const*);
0108       void doEndLuminosityBlock(LumiTransitionInfo const&, ModuleCallingContext const*);
0109 
0110       //For now, the following are just dummy implemenations with no ability for users to override
0111       void doRespondToOpenInputFile(FileBlock const&) {}
0112       void doRespondToCloseInputFile(FileBlock const&) {}
0113       void doRespondToCloseOutputFile() { clearInputProcessBlockCaches(); }
0114       void doRegisterThinnedAssociations(ProductRegistry const&, ThinnedAssociationsHelper&) {}
0115 
0116       void registerProductsAndCallbacks(EDProducerBase* module, ProductRegistry* reg) {
0117         registerProducts(module, reg, moduleDescription_);
0118       }
0119       std::string workerType() const { return "WorkerT<EDProducer>"; }
0120 
0121       virtual void produce(StreamID, Event&, EventSetup const&) const = 0;
0122       //For now this is a placeholder
0123       /*virtual*/ void preActionBeforeRunEventAsync(WaitingTaskHolder iTask,
0124                                                     ModuleCallingContext const& iModuleCallingContext,
0125                                                     Principal const& iPrincipal) const noexcept {}
0126 
0127       virtual void beginJob() {}
0128       virtual void endJob() {}
0129 
0130       virtual void preallocStreams(unsigned int);
0131       virtual void preallocRuns(unsigned int);
0132       virtual void preallocRunsSummary(unsigned int);
0133       virtual void preallocLumis(unsigned int);
0134       virtual void preallocLumisSummary(unsigned int);
0135       virtual void preallocate(PreallocationConfiguration const&);
0136       virtual void doBeginStream_(StreamID id);
0137       virtual void doEndStream_(StreamID id);
0138       virtual void doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c);
0139       virtual void doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c);
0140       virtual void doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c);
0141       virtual void doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c);
0142       virtual void doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c);
0143       virtual void doStreamEndLuminosityBlockSummary_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c);
0144 
0145       virtual void doBeginProcessBlock_(ProcessBlock const&);
0146       virtual void doAccessInputProcessBlock_(ProcessBlock const&);
0147       virtual void doEndProcessBlock_(ProcessBlock const&);
0148       virtual void doBeginRun_(Run const& rp, EventSetup const& c);
0149       virtual void doBeginRunSummary_(Run const& rp, EventSetup const& c);
0150       virtual void doEndRunSummary_(Run const& rp, EventSetup const& c);
0151       virtual void doEndRun_(Run const& rp, EventSetup const& c);
0152       virtual void doBeginLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c);
0153       virtual void doBeginLuminosityBlockSummary_(LuminosityBlock const& rp, EventSetup const& c);
0154       virtual void doEndLuminosityBlockSummary_(LuminosityBlock const& lb, EventSetup const& c);
0155       virtual void doEndLuminosityBlock_(LuminosityBlock const& lb, EventSetup const& c);
0156 
0157       virtual void doBeginProcessBlockProduce_(ProcessBlock&);
0158       virtual void doEndProcessBlockProduce_(ProcessBlock&);
0159       virtual void doBeginRunProduce_(Run& rp, EventSetup const& c);
0160       virtual void doEndRunProduce_(Run& rp, EventSetup const& c);
0161       virtual void doBeginLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c);
0162       virtual void doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c);
0163 
0164       virtual size_t transformIndex_(edm::BranchDescription const& iBranch) const noexcept;
0165       virtual ProductResolverIndex transformPrefetch_(std::size_t iIndex) const noexcept;
0166       virtual void transformAsync_(WaitingTaskHolder iTask,
0167                                    std::size_t iIndex,
0168                                    edm::EventForTransformer& iEvent,
0169                                    edm::ActivityRegistry* iAct,
0170                                    ServiceWeakToken const& iToken) const noexcept;
0171 
0172       virtual void clearInputProcessBlockCaches();
0173       virtual bool hasAccumulator() const noexcept { return false; }
0174 
0175       bool hasAcquire() const noexcept { return false; }
0176 
0177       void setModuleDescription(ModuleDescription const& md) { moduleDescription_ = md; }
0178       ModuleDescription moduleDescription_;
0179       std::unique_ptr<std::vector<BranchID>[]> previousParentages_;
0180       std::unique_ptr<ParentageID[]> previousParentageIds_;
0181       LimitedTaskQueue queue_;
0182     };
0183 
0184   }  // namespace limited
0185 }  // namespace edm
0186 
0187 #endif