Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-14 23:36:15

0001 #ifndef FWCore_Framework_OccurrenceForOutput_h
0002 #define FWCore_Framework_OccurrenceForOutput_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:     Framework
0007 // Class  :     OccurrenceForOutput
0008 //
0009 /**\class edm::OccurrenceForOutput
0010 
0011 */
0012 /*----------------------------------------------------------------------
0013 ----------------------------------------------------------------------*/
0014 
0015 #include "DataFormats/Common/interface/BasicHandle.h"
0016 #include "DataFormats/Common/interface/ConvertHandle.h"
0017 #include "DataFormats/Common/interface/Handle.h"
0018 #include "DataFormats/Common/interface/Wrapper.h"
0019 #include "DataFormats/Provenance/interface/BranchListIndex.h"
0020 #include "DataFormats/Provenance/interface/ProductDescriptionFwd.h"
0021 
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/PrincipalGetAdapter.h"
0024 #include "FWCore/Utilities/interface/TypeID.h"
0025 #include "FWCore/Utilities/interface/EDGetToken.h"
0026 #include "FWCore/Utilities/interface/propagate_const.h"
0027 
0028 #include <memory>
0029 #include <string>
0030 #include <typeinfo>
0031 #include <vector>
0032 
0033 class testEventGetRefBeforePut;
0034 
0035 namespace edmtest {
0036   class TestOutputModule;
0037 }
0038 
0039 namespace edm {
0040 
0041   class ModuleCallingContext;
0042   class Principal;
0043   class EDConsumerBase;
0044 
0045   class OccurrenceForOutput {
0046   public:
0047     OccurrenceForOutput(Principal const& ep, ModuleDescription const& md, ModuleCallingContext const*, bool isAtEnd);
0048     virtual ~OccurrenceForOutput();
0049 
0050     //Used in conjunction with EDGetToken
0051     void setConsumer(EDConsumerBase const* iConsumer);
0052 
0053     ProcessHistoryID const& processHistoryID() const;
0054 
0055     BasicHandle getByToken(EDGetToken token, TypeID const& typeID) const;
0056 
0057     template <typename PROD>
0058     bool getByToken(EDGetToken token, Handle<PROD>& result) const;
0059 
0060     template <typename PROD>
0061     bool getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const;
0062 
0063     template <typename PROD>
0064     Handle<PROD> getHandle(EDGetTokenT<PROD> token) const;
0065 
0066     Provenance getProvenance(BranchID const& theID) const;
0067     StableProvenance const& getStableProvenance(BranchID const& ithID) const;
0068 
0069     void getAllProvenance(std::vector<Provenance const*>& provenances) const;
0070 
0071     void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
0072 
0073     std::vector<ProductDescription const*> productDescriptions() const;
0074     ProductRegistry const& productRegistry() const;
0075 
0076     virtual ProcessHistory const& processHistory() const;
0077 
0078     size_t size() const;
0079 
0080   protected:
0081     Principal const& principal() const;
0082 
0083   private:
0084     friend class edmtest::TestOutputModule;  // For testing
0085     ModuleCallingContext const* moduleCallingContext() const { return moduleCallingContext_; }
0086 
0087     PrincipalGetAdapter provRecorder_;
0088 
0089     ModuleCallingContext const* moduleCallingContext_;
0090   };
0091 
0092   template <typename PROD>
0093   bool OccurrenceForOutput::getByToken(EDGetToken token, Handle<PROD>& result) const {
0094     if (!provRecorder_.checkIfComplete<PROD>()) {
0095       principal_get_adapter_detail::throwOnPrematureRead("RunOrLumi", TypeID(typeid(PROD)), token);
0096     }
0097     BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
0098     result = convert_handle<PROD>(std::move(bh));  // throws on conversion error
0099     if (result.failedToGet()) {
0100       return false;
0101     }
0102     return true;
0103   }
0104 
0105   template <typename PROD>
0106   bool OccurrenceForOutput::getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const {
0107     if (!provRecorder_.checkIfComplete<PROD>()) {
0108       principal_get_adapter_detail::throwOnPrematureRead("RunOrLumi", TypeID(typeid(PROD)), token);
0109     }
0110     BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
0111     result = convert_handle<PROD>(std::move(bh));  // throws on conversion error
0112     if (result.failedToGet()) {
0113       return false;
0114     }
0115     return true;
0116   }
0117 
0118   template <typename PROD>
0119   Handle<PROD> OccurrenceForOutput::getHandle(EDGetTokenT<PROD> token) const {
0120     if (!provRecorder_.checkIfComplete<PROD>()) {
0121       principal_get_adapter_detail::throwOnPrematureRead("RunOrLumi", TypeID(typeid(PROD)), token);
0122     }
0123     BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
0124     return convert_handle<PROD>(std::move(bh));  // throws on conversion error
0125   }
0126 
0127 }  // namespace edm
0128 #endif