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