File indexing completed on 2024-04-06 12:12:03
0001 #ifndef FWCore_Framework_EventSetupRecord_h
0002 #define FWCore_Framework_EventSetupRecord_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #include "FWCore/Framework/interface/FunctorESHandleExceptionFactory.h"
0043 #include "FWCore/Framework/interface/DataKey.h"
0044 #include "FWCore/Framework/interface/NoProductResolverException.h"
0045 #include "FWCore/Framework/interface/ValidityInterval.h"
0046 #include "FWCore/Framework/interface/EventSetupRecordImpl.h"
0047 #include "FWCore/Utilities/interface/ESGetToken.h"
0048 #include "FWCore/Utilities/interface/ESGetTokenGeneric.h"
0049 #include "FWCore/Utilities/interface/ESIndices.h"
0050 #include "FWCore/Utilities/interface/Likely.h"
0051
0052
0053 #include <exception>
0054 #include <memory>
0055 #include <utility>
0056 #include <vector>
0057 #include <cassert>
0058 #include <limits>
0059
0060
0061 namespace cms {
0062 class Exception;
0063 }
0064
0065 class testEventsetup;
0066 class testEventsetupRecord;
0067
0068 namespace edm {
0069 class ESHandleExceptionFactory;
0070 class ESParentContext;
0071 class EventSetupImpl;
0072
0073 namespace eventsetup {
0074 struct ComponentDescription;
0075 class EventSetupRecordKey;
0076
0077 class EventSetupRecord {
0078 public:
0079 EventSetupRecord();
0080 EventSetupRecord(EventSetupRecord&&) = default;
0081 EventSetupRecord& operator=(EventSetupRecord&&) = default;
0082
0083 EventSetupRecord(EventSetupRecord const&) = default;
0084 EventSetupRecord& operator=(EventSetupRecord const&) = default;
0085 virtual ~EventSetupRecord();
0086
0087
0088 ValidityInterval validityInterval() const { return impl_->validityInterval(); }
0089
0090 void setImpl(EventSetupRecordImpl const* iImpl,
0091 unsigned int transitionID,
0092 ESResolverIndex const* getTokenIndices,
0093 EventSetupImpl const* iEventSetupImpl,
0094 ESParentContext const* iContext) {
0095 impl_ = iImpl;
0096 transitionID_ = transitionID;
0097 getTokenIndices_ = getTokenIndices;
0098 eventSetupImpl_ = iEventSetupImpl;
0099 context_ = iContext;
0100 }
0101
0102
0103 bool doGet(ESGetTokenGeneric const&, bool aGetTransiently = false) const;
0104
0105
0106
0107
0108 bool wasGotten(DataKey const& aKey) const;
0109
0110
0111
0112
0113
0114 ComponentDescription const* providerDescription(DataKey const& aKey) const;
0115
0116 virtual EventSetupRecordKey key() const = 0;
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 unsigned long long cacheIdentifier() const { return impl_->cacheIdentifier(); }
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 unsigned int iovIndex() const { return impl_->iovIndex(); }
0140
0141
0142 void fillRegisteredDataKeys(std::vector<DataKey>& oToFill) const { impl_->fillRegisteredDataKeys(oToFill); }
0143
0144
0145 static constexpr bool allowConcurrentIOVs_ = true;
0146
0147 friend class ::testEventsetup;
0148 friend class ::testEventsetupRecord;
0149
0150 protected:
0151 template <template <typename> typename H, typename T, typename R>
0152 H<T> getHandleImpl(ESGetToken<T, R> const& iToken) const {
0153 if UNLIKELY (not iToken.isInitialized()) {
0154 std::rethrow_exception(makeUninitializedTokenException(this->key(), DataKey::makeTypeTag<T>()));
0155 }
0156 if UNLIKELY (iToken.transitionID() != transitionID()) {
0157 throwWrongTransitionID();
0158 }
0159 assert(getTokenIndices_);
0160
0161 if UNLIKELY (not iToken.hasValidIndex()) {
0162 return invalidTokenHandle<H>(iToken);
0163 }
0164
0165 auto resolverIndex = getTokenIndices_[iToken.index().value()];
0166 if UNLIKELY (resolverIndex.value() == std::numeric_limits<int>::max()) {
0167 return noResolverHandle<H>(iToken);
0168 }
0169
0170 T const* value = nullptr;
0171 ComponentDescription const* desc = nullptr;
0172 std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
0173
0174 impl_->getImplementation(value, resolverIndex, H<T>::transientAccessOnly, desc, whyFailedFactory);
0175
0176 if UNLIKELY (not value) {
0177 return H<T>(std::move(whyFailedFactory));
0178 }
0179 return H<T>(value, desc);
0180 }
0181
0182 EventSetupImpl const& eventSetup() const noexcept { return *eventSetupImpl_; }
0183
0184 ESResolverIndex const* getTokenIndices() const noexcept { return getTokenIndices_; }
0185
0186 ESParentContext const* esParentContext() const noexcept { return context_; }
0187
0188 void addTraceInfoToCmsException(cms::Exception& iException,
0189 char const* iName,
0190 ComponentDescription const*,
0191 DataKey const&) const;
0192
0193 EventSetupRecordImpl const* impl() const { return impl_; }
0194
0195 unsigned int transitionID() const { return transitionID_; }
0196
0197 private:
0198 template <template <typename> typename H, typename T, typename R>
0199 H<T> invalidTokenHandle(ESGetToken<T, R> const& iToken) const {
0200 auto const key = this->key();
0201 return H<T>{makeESHandleExceptionFactory([key, transitionID = iToken.transitionID()] {
0202 return makeInvalidTokenException(key, DataKey::makeTypeTag<T>(), transitionID);
0203 })};
0204 }
0205
0206 template <template <typename> typename H, typename T, typename R>
0207 H<T> noResolverHandle(ESGetToken<T, R> const& iToken) const {
0208 auto const key = this->key();
0209 auto name = iToken.name();
0210 return H<T>{makeESHandleExceptionFactory([key, name] {
0211 NoProductResolverException<T> ex(key, DataKey{DataKey::makeTypeTag<T>(), name});
0212 return std::make_exception_ptr(ex);
0213 })};
0214 }
0215
0216 static std::exception_ptr makeUninitializedTokenException(EventSetupRecordKey const&, TypeTag const&);
0217 static std::exception_ptr makeInvalidTokenException(EventSetupRecordKey const&, TypeTag const&, unsigned int);
0218 void throwWrongTransitionID() const;
0219
0220
0221 EventSetupRecordImpl const* impl_ = nullptr;
0222 EventSetupImpl const* eventSetupImpl_ = nullptr;
0223 ESResolverIndex const* getTokenIndices_ = nullptr;
0224 ESParentContext const* context_ = nullptr;
0225 unsigned int transitionID_ = std::numeric_limits<unsigned int>::max();
0226 };
0227
0228 class EventSetupRecordGeneric : public EventSetupRecord {
0229 public:
0230 EventSetupRecordGeneric(EventSetupRecordImpl const* iImpl,
0231 unsigned int iTransitionID,
0232 ESResolverIndex const* getTokenIndices,
0233 EventSetupImpl const* eventSetupImpl,
0234 ESParentContext const* context) {
0235 setImpl(iImpl, iTransitionID, getTokenIndices, eventSetupImpl, context);
0236 }
0237
0238 EventSetupRecordKey key() const final { return impl()->key(); }
0239 };
0240 }
0241 }
0242 #endif