File indexing completed on 2021-02-24 09:53:02
0001 #ifndef FWCore_Framework_EventSetupRecordImpl_h
0002 #define FWCore_Framework_EventSetupRecordImpl_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 #include "FWCore/Framework/interface/FunctorESHandleExceptionFactory.h"
0039 #include "FWCore/Framework/interface/DataKey.h"
0040 #include "FWCore/Framework/interface/NoProxyException.h"
0041 #include "FWCore/Framework/interface/ValidityInterval.h"
0042 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0043 #include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
0044 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0045 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0046 #include "FWCore/Utilities/interface/propagate_const.h"
0047 #include "FWCore/Utilities/interface/ESInputTag.h"
0048 #include "FWCore/Utilities/interface/ESIndices.h"
0049
0050
0051 #include <exception>
0052 #include <map>
0053 #include <memory>
0054 #include <utility>
0055 #include <vector>
0056 #include <atomic>
0057 #include <cassert>
0058
0059
0060 namespace cms {
0061 class Exception;
0062 }
0063
0064 namespace edm {
0065
0066 class ActivityRegistry;
0067 class ESHandleExceptionFactory;
0068 class ESInputTag;
0069 class EventSetupImpl;
0070 class ServiceToken;
0071 class ESParentContext;
0072
0073 namespace eventsetup {
0074 struct ComponentDescription;
0075 class DataProxy;
0076
0077 class EventSetupRecordImpl {
0078 friend class EventSetupRecord;
0079
0080 public:
0081 EventSetupRecordImpl(const EventSetupRecordKey& iKey, ActivityRegistry const*, unsigned int iovIndex = 0);
0082 EventSetupRecordImpl(EventSetupRecordImpl const&) = delete;
0083 EventSetupRecordImpl const& operator=(EventSetupRecordImpl const&) = delete;
0084 EventSetupRecordImpl(EventSetupRecordImpl&&);
0085 EventSetupRecordImpl& operator=(EventSetupRecordImpl&&);
0086
0087 ValidityInterval validityInterval() const;
0088
0089
0090 void prefetchAsync(WaitingTaskHolder iTask,
0091 ESProxyIndex iProxyIndex,
0092 EventSetupImpl const*,
0093 ServiceToken const&,
0094 ESParentContext) const;
0095
0096
0097
0098
0099 bool wasGotten(DataKey const& aKey) const;
0100
0101
0102
0103
0104
0105 ComponentDescription const* providerDescription(DataKey const& aKey) const;
0106
0107 EventSetupRecordKey const& key() const { return key_; }
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 unsigned long long cacheIdentifier() const { return cacheIdentifier_; }
0120
0121 unsigned int iovIndex() const { return iovIndex_; }
0122
0123
0124 void fillRegisteredDataKeys(std::vector<DataKey>& oToFill) const;
0125
0126 std::vector<ComponentDescription const*> componentsForRegisteredDataKeys() const;
0127
0128
0129 bool add(DataKey const& iKey, DataProxy* iProxy);
0130 void clearProxies();
0131
0132
0133
0134
0135
0136
0137 void initializeForNewIOV(unsigned long long iCacheIdentifier, ValidityInterval const&, bool hasFinder);
0138
0139
0140
0141
0142
0143
0144 void setSafely(ValidityInterval const&) const;
0145
0146 void getESProducers(std::vector<ComponentDescription const*>& esproducers) const;
0147
0148 DataProxy const* find(DataKey const& aKey) const;
0149
0150 void validate(ComponentDescription const*, ESInputTag const&) const;
0151
0152 ActivityRegistry const* activityRegistry() const noexcept { return activityRegistry_; }
0153
0154 void addTraceInfoToCmsException(cms::Exception& iException,
0155 char const* iName,
0156 ComponentDescription const*,
0157 DataKey const&) const;
0158
0159 void invalidateProxies();
0160 void resetIfTransientInProxies();
0161
0162 private:
0163 void const* getFromProxy(DataKey const& iKey,
0164 ComponentDescription const*& iDesc,
0165 bool iTransientAccessOnly,
0166 ESParentContext const&,
0167 EventSetupImpl const* = nullptr) const;
0168
0169 void const* getFromProxy(ESProxyIndex iProxyIndex,
0170 bool iTransientAccessOnly,
0171 ComponentDescription const*& iDesc,
0172 DataKey const*& oGottenKey,
0173 ESParentContext const&,
0174 EventSetupImpl const* = nullptr) const;
0175
0176 void const* getFromProxyAfterPrefetch(ESProxyIndex iProxyIndex,
0177 bool iTransientAccessOnly,
0178 ComponentDescription const*& iDesc,
0179 DataKey const*& oGottenKey) const;
0180
0181 template <typename DataT>
0182 void getImplementation(DataT const*& iData,
0183 char const* iName,
0184 ComponentDescription const*& iDesc,
0185 bool iTransientAccessOnly,
0186 std::shared_ptr<ESHandleExceptionFactory>& whyFailedFactory,
0187 ESParentContext const& iParent,
0188 EventSetupImpl const* iEventSetupImpl) const {
0189 DataKey dataKey(DataKey::makeTypeTag<DataT>(), iName, DataKey::kDoNotCopyMemory);
0190
0191 void const* pValue = this->getFromProxy(dataKey, iDesc, iTransientAccessOnly, iParent, iEventSetupImpl);
0192 if (nullptr == pValue) {
0193 whyFailedFactory = makeESHandleExceptionFactory([=] {
0194 NoProxyException<DataT> ex(this->key(), dataKey);
0195 return std::make_exception_ptr(ex);
0196 });
0197 }
0198 iData = reinterpret_cast<DataT const*>(pValue);
0199 }
0200
0201 template <typename DataT>
0202 void getImplementation(DataT const*& iData,
0203 ESProxyIndex iProxyIndex,
0204 bool iTransientAccessOnly,
0205 ComponentDescription const*& oDesc,
0206 std::shared_ptr<ESHandleExceptionFactory>& whyFailedFactory,
0207 EventSetupImpl const* iEventSetupImpl) const {
0208 DataKey const* dataKey = nullptr;
0209 if (iProxyIndex.value() == std::numeric_limits<int>::max()) {
0210 whyFailedFactory = makeESHandleExceptionFactory([=] {
0211 NoProxyException<DataT> ex(this->key(), {});
0212 return std::make_exception_ptr(ex);
0213 });
0214 iData = nullptr;
0215 return;
0216 }
0217 assert(iProxyIndex.value() > -1 and
0218 iProxyIndex.value() < static_cast<ESProxyIndex::Value_t>(keysForProxies_.size()));
0219 void const* pValue = this->getFromProxyAfterPrefetch(iProxyIndex, iTransientAccessOnly, oDesc, dataKey);
0220 if (nullptr == pValue) {
0221 whyFailedFactory = makeESHandleExceptionFactory([=] {
0222 NoProxyException<DataT> ex(this->key(), *dataKey);
0223 return std::make_exception_ptr(ex);
0224 });
0225 }
0226 iData = reinterpret_cast<DataT const*>(pValue);
0227 }
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238 CMS_THREAD_SAFE mutable ValidityInterval validity_;
0239
0240 EventSetupRecordKey key_;
0241 std::vector<DataKey> keysForProxies_;
0242 std::vector<edm::propagate_const<DataProxy*>> proxies_;
0243 ActivityRegistry const* activityRegistry_;
0244 unsigned long long cacheIdentifier_;
0245 unsigned int iovIndex_;
0246 std::atomic<bool> isAvailable_;
0247 mutable std::atomic<bool> validityModificationUnderway_;
0248 };
0249 }
0250 }
0251 #endif