CMS 3D CMS Logo

CallbackProxy.h
Go to the documentation of this file.
1 #ifndef Framework_CallbackProxy_h
2 #define Framework_CallbackProxy_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : CallbackProxy
7 //
17 //
18 // Author: Chris Jones
19 // Created: Fri Apr 8 11:50:21 CDT 2005
20 //
21 
22 // system include files
23 #include <cassert>
24 #include <memory>
25 
26 // user include files
29 
32 
33 // forward declarations
34 namespace edm::eventsetup {
35 
36  template <class CallbackT, class RecordT, class DataT>
37  class CallbackProxy : public DataProxy {
38  public:
41  using RecordType = RecordT;
42 
43  CallbackProxy(std::shared_ptr<CallbackT>& iCallback) : callback_{iCallback} {
44  //The callback fills the data directly. This is done so that the callback does not have to
45  // hold onto a temporary copy of the result of the callback since the callback is allowed
46  // to return multiple items where only one item is needed by this Proxy
47  iCallback->holdOntoPointer(&data_);
48  }
49 
50  ~CallbackProxy() override {
51  DataT* dummy(nullptr);
52  callback_->holdOntoPointer(dummy);
53  }
54 
55  const void* getImpl(const EventSetupRecordImpl& iRecord,
56  const DataKey&,
57  EventSetupImpl const* iEventSetupImpl) override {
58  assert(iRecord.key() == RecordT::keyForClass());
59  RecordType rec;
60  rec.setImpl(&iRecord, callback_->transitionID(), callback_->getTokenIndices(), iEventSetupImpl, true);
61  (*callback_)(rec);
63  }
64 
65  void invalidateCache() override {
66  data_ = DataT{};
67  callback_->newRecordComing();
68  }
69 
70  // Delete copy operations
71  CallbackProxy(const CallbackProxy&) = delete;
72  const CallbackProxy& operator=(const CallbackProxy&) = delete;
73 
74  private:
75  DataT data_{};
77  };
78 
79 } // namespace edm::eventsetup
80 
81 #endif
edm::eventsetup::produce::smart_pointer_traits
Definition: produce_helpers.h:88
propagate_const.h
edm::EventSetupImpl
Definition: EventSetupImpl.h:44
edm::eventsetup::CallbackProxy::data_
DataT data_
Definition: CallbackProxy.h:75
cms::cuda::assert
assert(be >=bs)
edm::eventsetup::DataKey
Definition: DataKey.h:29
edm::eventsetup::CallbackProxy::invalidateCache
void invalidateCache() override
Definition: CallbackProxy.h:65
DataProxy.h
EventSetupRecord.h
edm::propagate_const
Definition: propagate_const.h:32
edm::eventsetup::CallbackProxy::ValueType
typename smart_pointer_traits::type ValueType
Definition: CallbackProxy.h:40
edm::eventsetup::CallbackProxy::operator=
const CallbackProxy & operator=(const CallbackProxy &)=delete
edm::eventsetup::CallbackProxy::~CallbackProxy
~CallbackProxy() override
Definition: CallbackProxy.h:50
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:73
edm::eventsetup::CallbackProxy::CallbackProxy
CallbackProxy(std::shared_ptr< CallbackT > &iCallback)
Definition: CallbackProxy.h:43
edm::eventsetup::EventSetupRecordImpl::key
EventSetupRecordKey const & key() const
Definition: EventSetupRecordImpl.h:99
edm::eventsetup::produce::smart_pointer_traits::getPointer
static auto getPointer(T &iPtr) -> decltype(&*iPtr)
Definition: produce_helpers.h:90
edm::eventsetup::CallbackProxy::RecordType
RecordT RecordType
Definition: CallbackProxy.h:41
edm::eventsetup::DataProxy
Definition: DataProxy.h:38
produce_helpers.h
edm::eventsetup::CallbackProxy::getImpl
const void * getImpl(const EventSetupRecordImpl &iRecord, const DataKey &, EventSetupImpl const *iEventSetupImpl) override
Definition: CallbackProxy.h:55
edm::eventsetup::CallbackProxy
Definition: CallbackProxy.h:37
edm::eventsetup::produce::smart_pointer_traits::type
typename T::element_type type
Definition: produce_helpers.h:89
dummy
Definition: DummySelector.h:38
edm::eventsetup
Definition: ES_DDDetector.cc:16
edm::eventsetup::CallbackProxy::callback_
edm::propagate_const< std::shared_ptr< CallbackT > > callback_
Definition: CallbackProxy.h:76