Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FWCore_Framework_DependentRecordImplementation_h
0002 #define FWCore_Framework_DependentRecordImplementation_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     DependentRecordImplementation
0007 //
0008 /**\class DependentRecordImplementation DependentRecordImplementation.h FWCore/Framework/interface/DependentRecordImplementation.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Author:      Chris Jones
0018 // Created:     Fri Apr 29 10:03:54 EDT 2005
0019 //
0020 
0021 // system include files
0022 #include <sstream>
0023 #include <type_traits>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/EventSetupRecordImplementation.h"
0027 #include "FWCore/Framework/interface/EventSetupImpl.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/Framework/interface/NoRecordException.h"
0030 #include "FWCore/Framework/interface/DependentRecordTag.h"
0031 #include "FWCore/Utilities/interface/mplVector.h"
0032 
0033 //This is here only because too many modules depend no
0034 // getting this header from this file (before EventSetupImpl)
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 
0037 // forward declarations
0038 namespace edm {
0039   namespace eventsetup {
0040 
0041     template <class RecordT, class ListT>
0042     class DependentRecordImplementation : public EventSetupRecordImplementation<RecordT>, public DependentRecordTag {
0043     public:
0044       DependentRecordImplementation() {}
0045       using list_type = ListT;
0046       //virtual ~DependentRecordImplementation();
0047 
0048       // ---------- const member functions ---------------------
0049       template <class DepRecordT>
0050       const DepRecordT getRecord() const {
0051         //Make sure that DepRecordT is a type in ListT
0052         static_assert(
0053             (list_type::template contains<DepRecordT>()),
0054             "Trying to get a Record from another Record where the second Record is not dependent on the first Record.");
0055         try {
0056           EventSetup const eventSetupT{
0057               this->eventSetup(), this->transitionID(), this->getTokenIndices(), *this->esParentContext()};
0058           return eventSetupT.get<DepRecordT>();
0059         } catch (cms::Exception& e) {
0060           std::ostringstream sstrm;
0061           sstrm << "While getting dependent Record from Record " << this->key().type().name();
0062           e.addContext(sstrm.str());
0063           throw;
0064         }
0065       }
0066 
0067       template <class DepRecordT>
0068       std::optional<DepRecordT> tryToGetRecord() const {
0069         //Make sure that DepRecordT is a type in ListT
0070         static_assert(
0071             (list_type::template contains<DepRecordT>()),
0072             "Trying to get a Record from another Record where the second Record is not dependent on the first Record.");
0073         EventSetup const eventSetupT{
0074             this->eventSetup(), this->transitionID(), this->getTokenIndices(), *this->esParentContext()};
0075         return eventSetupT.tryToGet<DepRecordT>();
0076       }
0077 
0078       using EventSetupRecordImplementation<RecordT>::getHandle;
0079 
0080       template <typename ProductT, typename DepRecordT>
0081       ESHandle<ProductT> getHandle(ESGetToken<ProductT, DepRecordT> const& iToken) const {
0082         //Make sure that DepRecordT is a type in ListT
0083         static_assert((list_type::template contains<DepRecordT>()),
0084                       "Trying to get a product with an ESGetToken specifying a Record from another Record where the "
0085                       "second Record is not dependent on the first Record.");
0086         return getRecord<DepRecordT>().getHandle(iToken);
0087       }
0088 
0089       using EventSetupRecordImplementation<RecordT>::getTransientHandle;
0090 
0091       template <typename ProductT, typename DepRecordT>
0092       ESTransientHandle<ProductT> getTransientHandle(ESGetToken<ProductT, DepRecordT> const& iToken) const {
0093         //Make sure that DepRecordT is a type in ListT
0094         static_assert((list_type::template contains<DepRecordT>()),
0095                       "Trying to get a product with an ESGetToken specifying a Record from another Record where the "
0096                       "second Record is not dependent on the first Record.");
0097         return getRecord<DepRecordT>().getTransientHandle(iToken);
0098       }
0099 
0100       using EventSetupRecordImplementation<RecordT>::get;
0101 
0102       template <typename ProductT, typename DepRecordT>
0103       ProductT const& get(ESGetToken<ProductT, DepRecordT> const& iToken) const {
0104         //Make sure that DepRecordT is a type in ListT
0105         static_assert((list_type::template contains<DepRecordT>()),
0106                       "Trying to get a product with an ESGetToken specifying a Record from another Record where the "
0107                       "second Record is not dependent on the first Record.");
0108         return getRecord<DepRecordT>().get(iToken);
0109       }
0110 
0111       template <typename ProductT, typename DepRecordT>
0112       ProductT const& get(ESGetToken<ProductT, DepRecordT>& iToken) const {
0113         return get(const_cast<ESGetToken<ProductT, DepRecordT> const&>(iToken));
0114       }
0115 
0116       // ---------- static member functions --------------------
0117 
0118       // ---------- member functions ---------------------------
0119 
0120     private:
0121       // ---------- member data --------------------------------
0122     };
0123 
0124   }  // namespace eventsetup
0125 }  // namespace edm
0126 
0127 #endif