File indexing completed on 2023-01-15 23:49:39
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/NoProxyException.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 <map>
0055 #include <memory>
0056 #include <utility>
0057 #include <vector>
0058 #include <atomic>
0059 #include <cassert>
0060 #include <limits>
0061
0062
0063 namespace cms {
0064 class Exception;
0065 }
0066
0067 class testEventsetup;
0068 class testEventsetupRecord;
0069
0070 namespace edm {
0071 class ESHandleExceptionFactory;
0072 class ESInputTag;
0073 class EventSetupImpl;
0074
0075 namespace eventsetup {
0076 struct ComponentDescription;
0077 class DataProxy;
0078 class EventSetupRecordKey;
0079
0080 class EventSetupRecord {
0081 public:
0082 EventSetupRecord();
0083 EventSetupRecord(EventSetupRecord&&) = default;
0084 EventSetupRecord& operator=(EventSetupRecord&&) = default;
0085
0086 EventSetupRecord(EventSetupRecord const&) = default;
0087 EventSetupRecord& operator=(EventSetupRecord const&) = default;
0088 virtual ~EventSetupRecord();
0089
0090
0091 ValidityInterval validityInterval() const { return impl_->validityInterval(); }
0092
0093 void setImpl(EventSetupRecordImpl const* iImpl,
0094 unsigned int transitionID,
0095 ESProxyIndex const* getTokenIndices,
0096 EventSetupImpl const* iEventSetupImpl,
0097 ESParentContext const* iContext) {
0098 impl_ = iImpl;
0099 transitionID_ = transitionID;
0100 getTokenIndices_ = getTokenIndices;
0101 eventSetupImpl_ = iEventSetupImpl;
0102 context_ = iContext;
0103 }
0104
0105
0106 bool doGet(ESGetTokenGeneric const&, bool aGetTransiently = false) const;
0107
0108
0109
0110
0111 bool wasGotten(DataKey const& aKey) const;
0112
0113
0114
0115
0116
0117 ComponentDescription const* providerDescription(DataKey const& aKey) const;
0118
0119 virtual EventSetupRecordKey key() const = 0;
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 unsigned long long cacheIdentifier() const { return impl_->cacheIdentifier(); }
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 unsigned int iovIndex() const { return impl_->iovIndex(); }
0143
0144
0145 void fillRegisteredDataKeys(std::vector<DataKey>& oToFill) const { impl_->fillRegisteredDataKeys(oToFill); }
0146
0147
0148 static constexpr bool allowConcurrentIOVs_ = true;
0149
0150 friend class ::testEventsetup;
0151 friend class ::testEventsetupRecord;
0152
0153 protected:
0154 template <template <typename> typename H, typename T, typename R>
0155 H<T> getHandleImpl(ESGetToken<T, R> const& iToken) const {
0156 if UNLIKELY (not iToken.isInitialized()) {
0157 std::rethrow_exception(makeUninitializedTokenException(this->key(), DataKey::makeTypeTag<T>()));
0158 }
0159 if UNLIKELY (iToken.transitionID() != transitionID()) {
0160 throwWrongTransitionID();
0161 }
0162 assert(getTokenIndices_);
0163
0164 if UNLIKELY (not iToken.hasValidIndex()) {
0165 return invalidTokenHandle<H>(iToken);
0166 }
0167
0168 auto proxyIndex = getTokenIndices_[iToken.index().value()];
0169 if UNLIKELY (proxyIndex.value() == std::numeric_limits<int>::max()) {
0170 return noProxyHandle<H>(iToken);
0171 }
0172
0173 T const* value = nullptr;
0174 ComponentDescription const* desc = nullptr;
0175 std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
0176
0177 impl_->getImplementation(value, proxyIndex, H<T>::transientAccessOnly, desc, whyFailedFactory, eventSetupImpl_);
0178
0179 if UNLIKELY (not value) {
0180 return H<T>(std::move(whyFailedFactory));
0181 }
0182 return H<T>(value, desc);
0183 }
0184
0185 EventSetupImpl const& eventSetup() const noexcept { return *eventSetupImpl_; }
0186
0187 ESProxyIndex const* getTokenIndices() const noexcept { return getTokenIndices_; }
0188
0189 ESParentContext const* esParentContext() const noexcept { return context_; }
0190
0191 void validate(ComponentDescription const*, ESInputTag const&) const;
0192
0193 void addTraceInfoToCmsException(cms::Exception& iException,
0194 char const* iName,
0195 ComponentDescription const*,
0196 DataKey const&) const;
0197
0198 EventSetupRecordImpl const* impl() const { return impl_; }
0199
0200 unsigned int transitionID() const { return transitionID_; }
0201
0202 private:
0203 template <template <typename> typename H, typename T, typename R>
0204 H<T> invalidTokenHandle(ESGetToken<T, R> const& iToken) const {
0205 auto const key = this->key();
0206 return H<T>{makeESHandleExceptionFactory([key, transitionID = iToken.transitionID()] {
0207 return makeInvalidTokenException(key, DataKey::makeTypeTag<T>(), transitionID);
0208 })};
0209 }
0210
0211 template <template <typename> typename H, typename T, typename R>
0212 H<T> noProxyHandle(ESGetToken<T, R> const& iToken) const {
0213 auto const key = this->key();
0214 auto name = iToken.name();
0215 return H<T>{makeESHandleExceptionFactory([key, name] {
0216 NoProxyException<T> ex(key, DataKey{DataKey::makeTypeTag<T>(), name});
0217 return std::make_exception_ptr(ex);
0218 })};
0219 }
0220
0221 void const* getFromProxy(DataKey const& iKey,
0222 ComponentDescription const*& iDesc,
0223 bool iTransientAccessOnly) const;
0224
0225 static std::exception_ptr makeUninitializedTokenException(EventSetupRecordKey const&, TypeTag const&);
0226 static std::exception_ptr makeInvalidTokenException(EventSetupRecordKey const&, TypeTag const&, unsigned int);
0227 void throwWrongTransitionID() const;
0228
0229
0230 EventSetupRecordImpl const* impl_ = nullptr;
0231 EventSetupImpl const* eventSetupImpl_ = nullptr;
0232 ESProxyIndex const* getTokenIndices_ = nullptr;
0233 ESParentContext const* context_ = nullptr;
0234 unsigned int transitionID_ = std::numeric_limits<unsigned int>::max();
0235 };
0236
0237 class EventSetupRecordGeneric : public EventSetupRecord {
0238 public:
0239 EventSetupRecordGeneric(EventSetupRecordImpl const* iImpl,
0240 unsigned int iTransitionID,
0241 ESProxyIndex const* getTokenIndices,
0242 EventSetupImpl const* eventSetupImpl,
0243 ESParentContext const* context) {
0244 setImpl(iImpl, iTransitionID, getTokenIndices, eventSetupImpl, context);
0245 }
0246
0247 EventSetupRecordKey key() const final { return impl()->key(); }
0248 };
0249 }
0250 }
0251 #endif