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
22 
23 //
24 // constants, enums and typedefs
25 //
26 namespace edm {
27  namespace eventsetup {
28  static std::recursive_mutex s_esGlobalMutex;
29 //
30 // static data member definitions
31 //
32 static
35 {
36  static ComponentDescription s_desc;
37  return &s_desc;
38 }
39 //
40 // constructors and destructor
41 //
43  cache_(nullptr),
44  cacheIsValid_(false),
45  nonTransientAccessRequested_(false),
46  description_(dummyDescription())
47 {
48 }
49 
50 // DataProxy::DataProxy(const DataProxy& rhs)
51 // {
52 // // do actual copying here;
53 // }
54 
56 {
57 }
58 
59 //
60 // assignment operators
61 //
62 // const DataProxy& DataProxy::operator=(const DataProxy& rhs)
63 // {
64 // //An exception safe implementation is
65 // DataProxy temp(rhs);
66 // swap(rhs);
67 //
68 // return *this;
69 // }
70 
71 //
72 // member functions
73 //
75  cacheIsValid_.store(false, std::memory_order_release);
76  nonTransientAccessRequested_.store(false, std::memory_order_release);
77  cache_ = nullptr;
78 }
79 
80 void
82  if (!nonTransientAccessRequested_.load(std::memory_order_acquire)) {
85  }
86 }
87 
88 void
91 }
92 //
93 // const member functions
94 //
95 namespace {
96  void throwMakeException(const EventSetupRecord& iRecord,
97  const DataKey& iKey) {
98  throw MakeDataException(iRecord.key(),iKey);
99  }
100 
101  class ESSignalSentry {
102  public:
103  ESSignalSentry(const EventSetupRecord& iRecord,
104  const DataKey& iKey,
105  ComponentDescription const* componentDescription,
106  ActivityRegistry* activityRegistry) :
107  eventSetupRecord_(iRecord),
108  dataKey_(iKey),
109  componentDescription_(componentDescription),
110  calledPostLock_(false),
111  activityRegistry_(activityRegistry) {
112 
114  }
115  void sendPostLockSignal() {
116  calledPostLock_ = true;
117  activityRegistry_->postLockEventSetupGetSignal_(componentDescription_, eventSetupRecord_.key(), dataKey_);
118  }
119  ~ESSignalSentry() noexcept(false) {
120  if (!calledPostLock_) {
121  activityRegistry_->postLockEventSetupGetSignal_(componentDescription_, eventSetupRecord_.key(), dataKey_);
122  }
123  activityRegistry_->postEventSetupGetSignal_(componentDescription_, eventSetupRecord_.key(), dataKey_);
124  }
125  private:
128  ComponentDescription const* componentDescription_;
131  };
132 }
133 
134 const void*
135 DataProxy::get(const EventSetupRecord& iRecord, const DataKey& iKey, bool iTransiently, ActivityRegistry* activityRegistry) const
136 {
137  if(!cacheIsValid()) {
138  ESSignalSentry signalSentry(iRecord, iKey, providerDescription(), activityRegistry);
139  std::lock_guard<std::recursive_mutex> guard(s_esGlobalMutex);
140  signalSentry.sendPostLockSignal();
141  if(!cacheIsValid()) {
142  cache_ = const_cast<DataProxy*>(this)->getImpl(iRecord, iKey);
143  cacheIsValid_.store(true,std::memory_order_release);
144  }
145  }
146  //We need to set the AccessType for each request so this can't be called in the if block above.
147  //This also must be before the cache_ check since we want to setCacheIsValid before a possible
148  // exception throw. If we don't, 'getImpl' will be called again on a second request for the data.
149  if(!iTransiently) {
150  nonTransientAccessRequested_.store(true, std::memory_order_release);
151  }
152 
153  if(nullptr == cache_) {
154  throwMakeException(iRecord, iKey);
155  }
156  return cache_;
157 }
158 
159 void DataProxy::doGet(const EventSetupRecord& iRecord, const DataKey& iKey, bool iTransiently, ActivityRegistry* activityRegistry) const {
160  get(iRecord, iKey, iTransiently, activityRegistry);
161 }
162 
163 
164 //
165 // static member functions
166 //
167  }
168 }
bool cacheIsValid() const
Definition: DataProxy.h:44
virtual EventSetupRecordKey key() const =0
ComponentDescription const * componentDescription_
Definition: DataProxy.cc:128
void doGet(EventSetupRecord const &iRecord, DataKey const &iKey, bool iTransiently, ActivityRegistry *) const
Definition: DataProxy.cc:159
virtual void invalidateTransientCache()
Definition: DataProxy.cc:89
#define noexcept
EventSetupRecord const & eventSetupRecord_
Definition: DataProxy.cc:126
ActivityRegistry * activityRegistry_
Definition: DataProxy.cc:130
DataKey const & dataKey_
Definition: DataProxy.cc:127
std::atomic< bool > nonTransientAccessRequested_
Definition: DataProxy.h:96
#define nullptr
PreLockEventSetupGet preLockEventSetupGetSignal_
signal is emitted before lock taken in EventSetup DataProxy::get function
bool calledPostLock_
Definition: DataProxy.cc:129
std::atomic< bool > cacheIsValid_
Definition: DataProxy.h:95
ComponentDescription const * providerDescription() const
returns the description of the DataProxyProvider which owns this Proxy
Definition: DataProxy.h:50
HLT enums.
static std::recursive_mutex s_esGlobalMutex
Definition: DataProxy.cc:28
void const * get(EventSetupRecord const &, DataKey const &iKey, bool iTransiently, ActivityRegistry *) const
Definition: DataProxy.cc:135
static const ComponentDescription * dummyDescription()
Definition: DataProxy.cc:34
virtual void invalidateCache()=0
virtual void const * getImpl(EventSetupRecord const &, DataKey const &iKey)=0