File indexing completed on 2024-04-06 12:12:01
0001 #ifndef FWCore_Framework_DependentRecordImplementation_h
0002 #define FWCore_Framework_DependentRecordImplementation_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <sstream>
0023 #include <type_traits>
0024
0025
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
0034
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036
0037
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
0047
0048
0049 template <class DepRecordT>
0050 const DepRecordT getRecord() const {
0051
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
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
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
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
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
0117
0118
0119
0120 private:
0121
0122 };
0123
0124 }
0125 }
0126
0127 #endif