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
23 
24 namespace edm {
25  namespace eventsetup {
26 
28  static ComponentDescription s_desc;
29  return &s_desc;
30  }
31 
33  : description_(dummyDescription()),
34  cache_(nullptr),
35  cacheIsValid_(false),
36  nonTransientAccessRequested_(false) {}
37 
39 
41  cacheIsValid_.store(false, std::memory_order_release);
42  nonTransientAccessRequested_.store(false, std::memory_order_release);
43  cache_ = nullptr;
44  }
45 
47  if (!nonTransientAccessRequested_.load(std::memory_order_acquire)) {
50  }
51  }
52 
54 
55  namespace {
56  void throwMakeException(const EventSetupRecordImpl& iRecord, const DataKey& iKey) {
57  throw MakeDataException(iRecord.key(), iKey);
58  }
59 
60  class ESSignalSentry {
61  public:
62  ESSignalSentry(const EventSetupRecordImpl& iRecord,
63  const DataKey& iKey,
64  ComponentDescription const* componentDescription,
65  ActivityRegistry const* activityRegistry)
66  : eventSetupRecord_(iRecord),
67  dataKey_(iKey),
68  componentDescription_(componentDescription),
70  activityRegistry_(activityRegistry) {
72  }
73  void sendPostLockSignal() {
74  calledPostLock_ = true;
75  activityRegistry_->postLockEventSetupGetSignal_(componentDescription_, eventSetupRecord_.key(), dataKey_);
76  }
77  ~ESSignalSentry() noexcept(false) {
78  if (!calledPostLock_) {
79  activityRegistry_->postLockEventSetupGetSignal_(componentDescription_, eventSetupRecord_.key(), dataKey_);
80  }
81  activityRegistry_->postEventSetupGetSignal_(componentDescription_, eventSetupRecord_.key(), dataKey_);
82  }
83 
84  private:
85  EventSetupRecordImpl const& eventSetupRecord_;
86  DataKey const& dataKey_;
87  ComponentDescription const* componentDescription_;
90  };
91  } // namespace
92 
93  const void* DataProxy::get(const EventSetupRecordImpl& iRecord,
94  const DataKey& iKey,
95  bool iTransiently,
96  ActivityRegistry const* activityRegistry,
97  EventSetupImpl const* iEventSetupImpl) const {
98  if (!cacheIsValid()) {
99  ESSignalSentry signalSentry(iRecord, iKey, providerDescription(), activityRegistry);
100  std::lock_guard<std::recursive_mutex> guard(esGlobalMutex());
101  signalSentry.sendPostLockSignal();
102  if (!cacheIsValid()) {
103  cache_ = const_cast<DataProxy*>(this)->getImpl(iRecord, iKey, iEventSetupImpl);
104  cacheIsValid_.store(true, std::memory_order_release);
105  }
106  }
107 
108  //We need to set the AccessType for each request so this can't be called in the if block above.
109  //This also must be before the cache_ check since we want to setCacheIsValid before a possible
110  // exception throw. If we don't, 'getImpl' will be called again on a second request for the data.
111 
112  if (!iTransiently) {
113  nonTransientAccessRequested_.store(true, std::memory_order_release);
114  }
115 
116  if (nullptr == cache_) {
117  throwMakeException(iRecord, iKey);
118  }
119  return cache_;
120  }
121 
123  const DataKey& iKey,
124  bool iTransiently,
125  ActivityRegistry const* activityRegistry,
126  EventSetupImpl const* iEventSetupImpl) const {
127  get(iRecord, iKey, iTransiently, activityRegistry, iEventSetupImpl);
128  }
129 
130  } // namespace eventsetup
131 } // namespace edm
funct::false
false
Definition: Factorize.h:34
edm::eventsetup::DataProxy::cacheIsValid_
std::atomic< bool > cacheIsValid_
Definition: DataProxy.h:101
ActivityRegistry
DataKey
edm::EventSetupImpl
Definition: EventSetupImpl.h:44
edm
HLT enums.
Definition: AlignableModifier.h:19
ComponentDescription.h
edm::eventsetup::DataProxy::clearCacheIsValid
void clearCacheIsValid()
Definition: DataProxy.cc:40
MakeDataException.h
edm::eventsetup::dummyDescription
static const ComponentDescription * dummyDescription()
Definition: DataProxy.cc:27
edm::eventsetup::DataKey
Definition: DataKey.h:29
ESGlobalMutex.h
DataProxy.h
edm::eventsetup::DataProxy::get
void const * get(EventSetupRecordImpl const &, DataKey const &, bool iTransiently, ActivityRegistry const *, EventSetupImpl const *) const
Definition: DataProxy.cc:93
EventSetupRecord.h
edm::eventsetup::DataProxy::invalidateTransientCache
virtual void invalidateTransientCache()
Definition: DataProxy.cc:53
edm::eventsetup::DataProxy::doGet
void doGet(EventSetupRecordImpl const &, DataKey const &, bool iTransiently, ActivityRegistry const *, EventSetupImpl const *) const
Definition: DataProxy.cc:122
ActivityRegistry.h
calledPostLock_
bool calledPostLock_
Definition: DataProxy.cc:88
edm::eventsetup::DataProxy::invalidateCache
virtual void invalidateCache()=0
dataKey_
DataKey const & dataKey_
Definition: DataProxy.cc:86
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
edm::eventsetup::DataProxy::cache_
void const * cache_
Definition: DataProxy.h:100
edm::eventsetup::ComponentDescription
Definition: ComponentDescription.h:30
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:73
edm::esGlobalMutex
std::recursive_mutex & esGlobalMutex()
Definition: ESGlobalMutex.cc:7
edm::eventsetup::EventSetupRecordImpl::key
EventSetupRecordKey const & key() const
Definition: EventSetupRecordImpl.h:99
edm::eventsetup::DataProxy::resetIfTransient
void resetIfTransient()
Definition: DataProxy.cc:46
edm::eventsetup::DataProxy::cacheIsValid
bool cacheIsValid() const
Definition: DataProxy.h:46
edm::eventsetup::DataProxy::~DataProxy
virtual ~DataProxy()
Definition: DataProxy.cc:38
edm::eventsetup::DataProxy::DataProxy
DataProxy()
Definition: DataProxy.cc:32
edm::eventsetup::DataProxy::providerDescription
ComponentDescription const * providerDescription() const
returns the description of the DataProxyProvider which owns this Proxy
Definition: DataProxy.h:60
activityRegistry_
ActivityRegistry const * activityRegistry_
Definition: DataProxy.cc:89
edm::ActivityRegistry::preLockEventSetupGetSignal_
PreLockEventSetupGet preLockEventSetupGetSignal_
signal is emitted before lock taken in EventSetup DataProxy::get function
Definition: ActivityRegistry.h:968
edm::eventsetup::DataProxy::nonTransientAccessRequested_
std::atomic< bool > nonTransientAccessRequested_
Definition: DataProxy.h:134
edm::eventsetup::MakeDataException
Definition: MakeDataException.h:45
eventSetupRecord_
EventSetupRecordImpl const & eventSetupRecord_
Definition: DataProxy.cc:85
componentDescription_
ComponentDescription const * componentDescription_
Definition: DataProxy.cc:87