CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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
21 
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_ = 0;
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 
102 
103 const void*
104 DataProxy::get(const EventSetupRecord& iRecord, const DataKey& iKey, bool iTransiently) const
105 {
106  if(!cacheIsValid()) {
107  std::lock_guard<std::recursive_mutex> guard(s_esGlobalMutex);
108  if(!cacheIsValid()) {
109  cache_ = const_cast<DataProxy*>(this)->getImpl(iRecord, iKey);
110  cacheIsValid_.store(true,std::memory_order_release);
111  }
112  }
113  //We need to set the AccessType for each request so this can't be called in the if block above.
114  //This also must be before the cache_ check since we want to setCacheIsValid before a possible
115  // exception throw. If we don't, 'getImpl' will be called again on a second request for the data.
116  if(!iTransiently) {
117  nonTransientAccessRequested_.store(true, std::memory_order_release);
118  }
119 
120  if(0 == cache_) {
121  throwMakeException(iRecord, iKey);
122  }
123  return cache_;
124 }
125 
126 void DataProxy::doGet(const EventSetupRecord& iRecord, const DataKey& iKey, bool iTransiently) const {
127  get(iRecord, iKey, iTransiently);
128 }
129 
130 
131 //
132 // static member functions
133 //
134  }
135 }
bool cacheIsValid() const
Definition: DataProxy.h:41
virtual EventSetupRecordKey key() const =0
virtual void invalidateTransientCache()
Definition: DataProxy.cc:89
std::atomic< bool > nonTransientAccessRequested_
Definition: DataProxy.h:93
#define nullptr
std::atomic< bool > cacheIsValid_
Definition: DataProxy.h:92
void const * get(EventSetupRecord const &, DataKey const &iKey, bool iTransiently) const
Definition: DataProxy.cc:104
void doGet(EventSetupRecord const &iRecord, DataKey const &iKey, bool iTransiently) const
Definition: DataProxy.cc:126
static std::recursive_mutex s_esGlobalMutex
Definition: DataProxy.cc:28
volatile std::atomic< bool > shutdown_flag false
static const ComponentDescription * dummyDescription()
Definition: DataProxy.cc:34
virtual void invalidateCache()=0
virtual void const * getImpl(EventSetupRecord const &, DataKey const &iKey)=0