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
24 
26 namespace edm {
27  namespace eventsetup {
28 
30  static ComponentDescription s_desc;
31  return &s_desc;
32  }
33 
35  : description_(dummyDescription()),
36  cache_(nullptr),
37  cacheIsValid_(false),
38  nonTransientAccessRequested_(false) {}
39 
41 
43  nonTransientAccessRequested_.store(false, std::memory_order_release);
44  cache_ = nullptr;
45  cacheIsValid_.store(false, std::memory_order_release);
46  }
47 
49  if (!nonTransientAccessRequested_.load(std::memory_order_acquire)) {
52  }
53  }
54 
56 
57  namespace {
58  void throwMakeException(const EventSetupRecordImpl& iRecord, const DataKey& iKey) {
59  throw MakeDataException(iRecord.key(), iKey);
60  }
61 
62  } // namespace
63 
65  EventSetupRecordImpl const& iRecord,
66  DataKey const& iKey,
67  EventSetupImpl const* iEventSetupImpl,
68  ServiceToken const& iToken) const {
69  const_cast<DataProxy*>(this)->prefetchAsyncImpl(iTask, iRecord, iKey, iEventSetupImpl, iToken);
70  }
71 
73  const DataKey& iKey,
74  bool iTransiently) const {
75  //We need to set the AccessType for each request so this can't be called in an earlier function in the stack.
76  //This also must be before the cache_ check since we want to setCacheIsValid before a possible
77  // exception throw. If we don't, 'getImpl' will be called again on a second request for the data.
78 
79  if LIKELY (!iTransiently) {
80  nonTransientAccessRequested_.store(true, std::memory_order_release);
81  }
82 
83  if UNLIKELY (!cacheIsValid()) {
85  cacheIsValid_.store(true, std::memory_order_release);
86  }
87 
88  if UNLIKELY (nullptr == cache_) {
89  throwMakeException(iRecord, iKey);
90  }
91  return cache_;
92  }
93 
94  const void* DataProxy::get(const EventSetupRecordImpl& iRecord,
95  const DataKey& iKey,
96  bool iTransiently,
97  ActivityRegistry const* activityRegistry,
98  EventSetupImpl const* iEventSetupImpl) const {
99  if (!cacheIsValid()) {
100  auto waitTask = edm::make_empty_waiting_task();
101  waitTask->set_ref_count(2);
102  auto waitTaskPtr = waitTask.get();
104  edm::esTaskArena().execute([this, waitTaskPtr, &iRecord, &iKey, iEventSetupImpl, token]() {
105  prefetchAsync(waitTaskPtr, iRecord, iKey, iEventSetupImpl, token);
106  waitTaskPtr->decrement_ref_count();
107  waitTaskPtr->wait_for_all();
108  });
110  cacheIsValid_.store(true, std::memory_order_release);
111  if (waitTask->exceptionPtr()) {
112  std::rethrow_exception(*waitTask->exceptionPtr());
113  }
114  }
115  return getAfterPrefetch(iRecord, iKey, iTransiently);
116  }
117 
118  } // namespace eventsetup
119 } // namespace edm
edm::eventsetup::DataProxy::prefetchAsync
void prefetchAsync(WaitingTask *, EventSetupRecordImpl const &, DataKey const &, EventSetupImpl const *, ServiceToken const &) const
Definition: DataProxy.cc:64
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:72
edm::eventsetup::DataProxy::cacheIsValid_
std::atomic< bool > cacheIsValid_
Definition: DataProxy.h:111
edm::EventSetupImpl
Definition: EventSetupImpl.h:48
edm
HLT enums.
Definition: AlignableModifier.h:19
ComponentDescription.h
edm::eventsetup::DataProxy::clearCacheIsValid
void clearCacheIsValid()
Definition: DataProxy.cc:42
MakeDataException.h
edm::eventsetup::dummyDescription
static const ComponentDescription * dummyDescription()
Definition: DataProxy.cc:29
edm::eventsetup::DataProxy::getAfterPrefetchImpl
virtual void const * getAfterPrefetchImpl() const =0
edm::eventsetup::DataKey
Definition: DataKey.h:29
edm::esTaskArena
tbb::task_arena & esTaskArena()
Definition: esTaskArenas.cc:8
DataProxy.h
edm::eventsetup::DataProxy::get
void const * get(EventSetupRecordImpl const &, DataKey const &, bool iTransiently, ActivityRegistry const *, EventSetupImpl const *) const
Definition: DataProxy.cc:94
EventSetupRecord.h
edm::eventsetup::DataProxy::invalidateTransientCache
virtual void invalidateTransientCache()
Definition: DataProxy.cc:55
ActivityRegistry.h
edm::ServiceToken
Definition: ServiceToken.h:40
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::eventsetup::DataProxy::invalidateCache
virtual void invalidateCache()=0
edm::ActivityRegistry
Definition: ActivityRegistry.h:133
edm::eventsetup::DataProxy::cache_
void const * cache_
Definition: DataProxy.h:110
edm::eventsetup::ComponentDescription
Definition: ComponentDescription.h:30
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:76
edm::eventsetup::EventSetupRecordImpl::key
EventSetupRecordKey const & key() const
Definition: EventSetupRecordImpl.h:102
edm::eventsetup::DataProxy::resetIfTransient
void resetIfTransient()
Definition: DataProxy.cc:48
edm::ServiceRegistry::presentToken
ServiceToken presentToken() const
Definition: ServiceRegistry.cc:63
edm::eventsetup::DataProxy::cacheIsValid
bool cacheIsValid() const
Definition: DataProxy.h:49
edm::eventsetup::DataProxy::~DataProxy
virtual ~DataProxy()
Definition: DataProxy.cc:40
edm::eventsetup::DataProxy::DataProxy
DataProxy()
Definition: DataProxy.cc:34
edm::ServiceRegistry::instance
static ServiceRegistry & instance()
Definition: ServiceRegistry.cc:90
edm::make_empty_waiting_task
std::unique_ptr< edm::EmptyWaitingTask, waitingtask::TaskDestroyer > make_empty_waiting_task()
Create an EmptyWaitingTask which will properly be destroyed.
Definition: WaitingTaskList.h:96
edm::WaitingTask
Definition: WaitingTask.h:36
esTaskArenas.h
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
edm::eventsetup::DataProxy::nonTransientAccessRequested_
std::atomic< bool > nonTransientAccessRequested_
Definition: DataProxy.h:144
edm::eventsetup::MakeDataException
Definition: MakeDataException.h:45
WaitingTaskList.h
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318