CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
void reset()
Resets access to the resource so that added tasks will wait.
assert(be >=bs)
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
void add(tbb::task_group *, WaitingTask *)
Adds task to the waiting list.
void prefetchAsyncImpl(WaitingTaskHolder iTask, const EventSetupRecordImpl &iRecord, const DataKey &iKey, EventSetupImpl const *iEventSetupImpl, edm::ServiceToken const &iToken, edm::ESParentContext const &iParent) override
tbb::task_group * group() const noexcept
virtual const DataT * make(const RecordT &, const DataKey &)=0
EventSetupRecordKey const & key() const