CMS 3D CMS Logo

DataProxy.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : DataProxy
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Author: Chris Jones
10 // Created: Thu Mar 31 12:49:19 EST 2005
11 //
12 
13 // system include files
14 #include <mutex>
15 
16 // user include files
18 
29 
30 namespace edm {
31  namespace eventsetup {
32 
34  static ComponentDescription s_desc;
35  return &s_desc;
36  }
37 
39  : description_(dummyDescription()),
40  cache_(nullptr),
41  cacheIsValid_(false),
42  nonTransientAccessRequested_(false) {}
43 
45 
47  nonTransientAccessRequested_.store(false, std::memory_order_release);
48  cache_ = nullptr;
49  cacheIsValid_.store(false, std::memory_order_release);
50  }
51 
53  if (!nonTransientAccessRequested_.load(std::memory_order_acquire)) {
56  }
57  }
58 
60 
61  namespace {
62  void throwMakeException(const EventSetupRecordImpl& iRecord, const DataKey& iKey) {
63  throw MakeDataException(iRecord.key(), iKey);
64  }
65 
66  } // namespace
67 
69  EventSetupRecordImpl const& iRecord,
70  DataKey const& iKey,
71  EventSetupImpl const* iEventSetupImpl,
72  ServiceToken const& iToken,
73  ESParentContext const& iParent) const {
74  const_cast<DataProxy*>(this)->prefetchAsyncImpl(iTask, iRecord, iKey, iEventSetupImpl, iToken, iParent);
75  }
76 
78  const DataKey& iKey,
79  bool iTransiently) const {
80  //We need to set the AccessType for each request so this can't be called in an earlier function in the stack.
81  //This also must be before the cache_ check since we want to setCacheIsValid before a possible
82  // exception throw. If we don't, 'getImpl' will be called again on a second request for the data.
83 
84  if LIKELY (!iTransiently) {
85  nonTransientAccessRequested_.store(true, std::memory_order_release);
86  }
87 
88  if UNLIKELY (!cacheIsValid()) {
90  cacheIsValid_.store(true, std::memory_order_release);
91  }
92 
93  if UNLIKELY (nullptr == cache_) {
94  throwMakeException(iRecord, iKey);
95  }
96  return cache_;
97  }
98 
99  const void* DataProxy::get(const EventSetupRecordImpl& iRecord,
100  const DataKey& iKey,
101  bool iTransiently,
102  ActivityRegistry const* activityRegistry,
103  EventSetupImpl const* iEventSetupImpl,
104  ESParentContext const& iParent) const {
105  if (!cacheIsValid()) {
107  std::exception_ptr exceptPtr{};
108  iEventSetupImpl->taskArena()->execute([this, &exceptPtr, &iRecord, &iKey, iEventSetupImpl, token, iParent]() {
109  exceptPtr = syncWait([&, this](WaitingTaskHolder&& holder) {
110  prefetchAsync(std::move(holder), iRecord, iKey, iEventSetupImpl, token, iParent);
111  });
112  });
114  cacheIsValid_.store(true, std::memory_order_release);
115  if (exceptPtr) {
116  std::rethrow_exception(exceptPtr);
117  }
118  }
119  return getAfterPrefetch(iRecord, iKey, iTransiently);
120  }
121 
122  } // namespace eventsetup
123 } // namespace edm
ServiceRegistry.h
funct::false
false
Definition: Factorize.h:29
edm::eventsetup::DataProxy::getAfterPrefetch
void const * getAfterPrefetch(const EventSetupRecordImpl &iRecord, const DataKey &iKey, bool iTransiently) const
Definition: DataProxy.cc:77
edm::eventsetup::DataProxy::cacheIsValid_
std::atomic< bool > cacheIsValid_
Definition: DataProxy.h:118
edm::EventSetupImpl
Definition: EventSetupImpl.h:49
WaitingTaskHolder.h
edm
HLT enums.
Definition: AlignableModifier.h:19
ComponentDescription.h
EventSetupImpl.h
edm::eventsetup::DataProxy::clearCacheIsValid
void clearCacheIsValid()
Definition: DataProxy.cc:46
MakeDataException.h
edm::eventsetup::dummyDescription
static const ComponentDescription * dummyDescription()
Definition: DataProxy.cc:33
edm::eventsetup::DataProxy::getAfterPrefetchImpl
virtual void const * getAfterPrefetchImpl() const =0
edm::eventsetup::DataKey
Definition: DataKey.h:29
DataProxy.h
EventSetupRecord.h
edm::eventsetup::DataProxy::invalidateTransientCache
virtual void invalidateTransientCache()
Definition: DataProxy.cc:59
ActivityRegistry.h
edm::ServiceToken
Definition: ServiceToken.h:42
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::eventsetup::DataProxy::invalidateCache
virtual void invalidateCache()=0
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
edm::EventSetupImpl::taskArena
tbb::task_arena * taskArena() const
Definition: EventSetupImpl.h:74
edm::eventsetup::DataProxy::get
void const * get(EventSetupRecordImpl const &, DataKey const &, bool iTransiently, ActivityRegistry const *, EventSetupImpl const *, ESParentContext const &) const
Definition: DataProxy.cc:99
edm::eventsetup::DataProxy::cache_
void const * cache_
Definition: DataProxy.h:117
edm::eventsetup::ComponentDescription
Definition: ComponentDescription.h:30
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:77
include_first_syncWait.h
edm::eventsetup::DataProxy::prefetchAsync
void prefetchAsync(WaitingTaskHolder, EventSetupRecordImpl const &, DataKey const &, EventSetupImpl const *, ServiceToken const &, ESParentContext const &) const
Definition: DataProxy.cc:68
ESParentContext.h
edm::eventsetup::EventSetupRecordImpl::key
EventSetupRecordKey const & key() const
Definition: EventSetupRecordImpl.h:107
edm::eventsetup::DataProxy::resetIfTransient
void resetIfTransient()
Definition: DataProxy.cc:52
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:32
edm::ServiceRegistry::presentToken
ServiceToken presentToken() const
Definition: ServiceRegistry.cc:63
edm::eventsetup::DataProxy::cacheIsValid
bool cacheIsValid() const
Definition: DataProxy.h:50
edm::eventsetup::DataProxy::~DataProxy
virtual ~DataProxy()
Definition: DataProxy.cc:44
edm::eventsetup::DataProxy::DataProxy
DataProxy()
Definition: DataProxy.cc:38
edm::ESParentContext
Definition: ESParentContext.h:21
edm::ServiceRegistry::instance
static ServiceRegistry & instance()
Definition: ServiceRegistry.cc:90
eostools.move
def move(src, dest)
Definition: eostools.py:511
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
edm::eventsetup::DataProxy::nonTransientAccessRequested_
std::atomic< bool > nonTransientAccessRequested_
Definition: DataProxy.h:151
edm::eventsetup::MakeDataException
Definition: MakeDataException.h:45
WaitingTaskList.h
edm::syncWait
std::exception_ptr syncWait(F &&iFunc)
Definition: include_first_syncWait.h:17
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316