CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 const 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()) {
106  throw edm::Exception(errors::LogicError) << "DataProxy::get called without first doing prefetch.\nThis should "
107  "not be able to happen.\nPlease contact framework developers";
108  }
109  return getAfterPrefetch(iRecord, iKey, iTransiently);
110  }
111 
112  } // namespace eventsetup
113 } // namespace edm
void const * get(EventSetupRecordImpl const &, DataKey const &, bool iTransiently, ActivityRegistry const *, EventSetupImpl const *, ESParentContext const &) const
Definition: DataProxy.cc:99
virtual void invalidateTransientCache()
Definition: DataProxy.cc:59
#define LIKELY(x)
Definition: Likely.h:20
std::atomic< bool > nonTransientAccessRequested_
Definition: DataProxy.h:151
std::atomic< bool > cacheIsValid_
Definition: DataProxy.h:118
void prefetchAsync(WaitingTaskHolder, EventSetupRecordImpl const &, DataKey const &, EventSetupImpl const *, ServiceToken const &, ESParentContext const &) const
Definition: DataProxy.cc:68
bool cacheIsValid() const
Definition: DataProxy.h:50
EventSetupRecordKey const & key() const
void const * getAfterPrefetch(const EventSetupRecordImpl &iRecord, const DataKey &iKey, bool iTransiently) const
Definition: DataProxy.cc:77
HLT enums.
virtual void prefetchAsyncImpl(WaitingTaskHolder, EventSetupRecordImpl const &, DataKey const &iKey, EventSetupImpl const *, ServiceToken const &, ESParentContext const &)=0
#define UNLIKELY(x)
Definition: Likely.h:21
static const ComponentDescription * dummyDescription()
Definition: DataProxy.cc:33
virtual void invalidateCache()=0
virtual void const * getAfterPrefetchImpl() const =0