Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:04

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 
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/PrincipalGetAdapter.h"
0023 #include "FWCore/Utilities/interface/TypeID.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 #include "FWCore/Utilities/interface/propagate_const.h"
0026 
0027 #include <memory>
0028 #include <string>
0029 #include <typeinfo>
0030 #include <vector>
0031 
0032 class testEventGetRefBeforePut;
0033 
0034 namespace edmtest {
0035   class TestOutputModule;
0036 }
0037 
0038 namespace edm {
0039 
0040   class BranchDescription;
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 
0068     void getAllProvenance(std::vector<Provenance const*>& provenances) const;
0069 
0070     void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
0071 
0072     virtual ProcessHistory const& processHistory() const;
0073 
0074     size_t size() const;
0075 
0076   protected:
0077     Principal const& principal() const;
0078 
0079   private:
0080     friend class edmtest::TestOutputModule;  // For testing
0081     ModuleCallingContext const* moduleCallingContext() const { return moduleCallingContext_; }
0082 
0083     PrincipalGetAdapter provRecorder_;
0084 
0085     ModuleCallingContext const* moduleCallingContext_;
0086   };
0087 
0088   template <typename PROD>
0089   bool OccurrenceForOutput::getByToken(EDGetToken token, Handle<PROD>& result) const {
0090     if (!provRecorder_.checkIfComplete<PROD>()) {
0091       principal_get_adapter_detail::throwOnPrematureRead("RunOrLumi", TypeID(typeid(PROD)), token);
0092     }
0093     BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
0094     result = convert_handle<PROD>(std::move(bh));  // throws on conversion error
0095     if (result.failedToGet()) {
0096       return false;
0097     }
0098     return true;
0099   }
0100 
0101   template <typename PROD>
0102   bool OccurrenceForOutput::getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const {
0103     if (!provRecorder_.checkIfComplete<PROD>()) {
0104       principal_get_adapter_detail::throwOnPrematureRead("RunOrLumi", TypeID(typeid(PROD)), token);
0105     }
0106     BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
0107     result = convert_handle<PROD>(std::move(bh));  // throws on conversion error
0108     if (result.failedToGet()) {
0109       return false;
0110     }
0111     return true;
0112   }
0113 
0114   template <typename PROD>
0115   Handle<PROD> OccurrenceForOutput::getHandle(EDGetTokenT<PROD> token) const {
0116     if (!provRecorder_.checkIfComplete<PROD>()) {
0117       principal_get_adapter_detail::throwOnPrematureRead("RunOrLumi", TypeID(typeid(PROD)), token);
0118     }
0119     BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
0120     return convert_handle<PROD>(std::move(bh));  // throws on conversion error
0121   }
0122 
0123 }  // namespace edm
0124 #endif