CMS 3D CMS Logo

DataProxyTemplate.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_DataProxyTemplate_h
2 #define FWCore_Framework_DataProxyTemplate_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : DataProxyTemplate
7 //
26 //
27 // Author: Chris Jones
28 // Created: Thu Mar 31 12:45:32 EST 2005
29 //
30 
31 // system include files
32 
33 // user include files
40 #include <cassert>
41 #include <limits>
42 #include <atomic>
43 
44 // forward declarations
45 
46 namespace edm {
47 
48  class EventSetupImpl;
49 
50  namespace eventsetup {
51 
52  template <class RecordT, class DataT>
53  class DataProxyTemplate : public DataProxy {
54  public:
55  typedef DataT value_type;
56  typedef RecordT record_type;
57 
59 
61  const EventSetupRecordImpl& iRecord,
62  const DataKey& iKey,
63  EventSetupImpl const* iEventSetupImpl,
64  edm::ServiceToken const& iToken,
65  edm::ESParentContext const& iParent) override {
66  assert(iRecord.key() == RecordT::keyForClass());
67  bool expected = false;
68  bool doPrefetch = prefetching_.compare_exchange_strong(expected, true);
69  taskList_.add(iTask);
70 
71  if (doPrefetch) {
72  iTask.group()->run([this, &iRecord, iKey, iEventSetupImpl, iToken, iParent]() {
73  try {
74  RecordT rec;
75  rec.setImpl(&iRecord, std::numeric_limits<unsigned int>::max(), nullptr, iEventSetupImpl, &iParent, true);
76  ServiceRegistry::Operate operate(iToken);
77  this->make(rec, iKey);
78  } catch (...) {
79  this->taskList_.doneWaiting(std::current_exception());
80  return;
81  }
82  this->taskList_.doneWaiting(std::exception_ptr{});
83  });
84  }
85  }
86 
87  protected:
88  void invalidateCache() override {
89  taskList_.reset();
90  prefetching_ = false;
91  }
92 
93  virtual const DataT* make(const RecordT&, const DataKey&) = 0;
94 
95  private:
97  std::atomic<bool> prefetching_{false};
98  };
99 
100  } // namespace eventsetup
101 } // namespace edm
102 #endif
edm::eventsetup::DataProxyTemplate::record_type
RecordT record_type
Definition: DataProxyTemplate.h:56
ServiceRegistry.h
edm::eventsetup::DataProxyTemplate::prefetching_
std::atomic< bool > prefetching_
Definition: DataProxyTemplate.h:97
edm::eventsetup::DataProxyTemplate::value_type
DataT value_type
Definition: DataProxyTemplate.h:55
edm::EventSetupImpl
Definition: EventSetupImpl.h:49
WaitingTaskHolder.h
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::cuda::assert
assert(be >=bs)
edm::eventsetup::DataKey
Definition: DataKey.h:29
DataProxy.h
EventSetupRecord.h
edm::WaitingTaskList::reset
void reset()
Resets access to the resource so that added tasks will wait.
Definition: WaitingTaskList.cc:53
edm::WaitingTaskList
Definition: WaitingTaskList.h:84
edm::eventsetup::DataProxyTemplate::invalidateCache
void invalidateCache() override
Definition: DataProxyTemplate.h:88
edm::ServiceToken
Definition: ServiceToken.h:42
edm::eventsetup::DataProxyTemplate::DataProxyTemplate
DataProxyTemplate()
Definition: DataProxyTemplate.h:58
edm::WaitingTaskList::doneWaiting
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
Definition: WaitingTaskList.cc:212
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:77
edm::eventsetup::DataProxyTemplate::prefetchAsyncImpl
void prefetchAsyncImpl(WaitingTaskHolder iTask, const EventSetupRecordImpl &iRecord, const DataKey &iKey, EventSetupImpl const *iEventSetupImpl, edm::ServiceToken const &iToken, edm::ESParentContext const &iParent) override
Definition: DataProxyTemplate.h:60
ESParentContext.h
edm::eventsetup::DataProxyTemplate::taskList_
WaitingTaskList taskList_
Definition: DataProxyTemplate.h:96
edm::eventsetup::EventSetupRecordImpl::key
EventSetupRecordKey const & key() const
Definition: EventSetupRecordImpl.h:107
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:32
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::ESParentContext
Definition: ESParentContext.h:21
edm::eventsetup::DataProxy
Definition: DataProxy.h:42
edm::eventsetup::DataProxyTemplate::make
virtual const DataT * make(const RecordT &, const DataKey &)=0
edm::WaitingTaskList::add
void add(tbb::task_group *, WaitingTask *)
Adds task to the waiting list.
Definition: WaitingTaskList.cc:125
WaitingTaskList.h
edm::eventsetup::DataProxyTemplate
Definition: DataProxyTemplate.h:53
edm::ServiceRegistry::Operate
Definition: ServiceRegistry.h:40
edm::WaitingTaskHolder::group
tbb::task_group * group() const noexcept
Definition: WaitingTaskHolder.h:77