CMS 3D CMS Logo

Callback.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Callback_h
2 #define FWCore_Framework_Callback_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : Callback
7 //
16 //
17 // Author: Chris Jones
18 // Created: Sun Apr 17 14:30:24 EDT 2005
19 //
20 
21 // system include files
22 #include <vector>
23 #include <type_traits>
24 // user include files
28 
29 namespace edm {
30  namespace eventsetup {
31 
32  // The default decorator that does nothing
33  template <typename TRecord>
35  void pre(const TRecord&) {}
36  void post(const TRecord&) {}
37  };
38 
39  template <typename T, //producer's type
40  typename TReturn, //return type of the producer's method
41  typename TRecord, //the record passed in as an argument
42  typename TDecorator //allows customization using pre/post calls
43  = CallbackSimpleDecorator<TRecord> >
44  class Callback {
45  public:
46  using method_type = TReturn (T ::*)(const TRecord&);
47 
48  Callback(T* iProd, method_type iMethod, unsigned int iID, const TDecorator& iDec = TDecorator())
49  : proxyData_{},
50  producer_(iProd),
51  method_(iMethod),
52  id_(iID),
54  decorator_(iDec) {}
55 
57 
58  Callback(const Callback&) = delete;
59  const Callback& operator=(const Callback&) = delete;
60 
61  void operator()(const TRecord& iRecord) {
63  producer_->updateFromMayConsumes(id_, iRecord);
64  decorator_.pre(iRecord);
67  decorator_.post(iRecord);
68  }
69  }
70 
71  template <class DataT>
72  void holdOntoPointer(DataT* iData) {
74  }
75 
76  void storeReturnedValues(TReturn iReturn) {
78  setData<typename type::head_type, typename type::tail_type>(iReturn);
79  }
80 
81  template <class RemainingContainerT, class DataT, class ProductsT>
82  void setData(ProductsT& iProducts) {
83  DataT* temp = reinterpret_cast<DataT*>(proxyData_[produce::find_index<TReturn, DataT>::value]);
84  if (nullptr != temp) {
85  moveFromTo(iProducts, *temp);
86  }
87  if constexpr (not std::is_same_v<produce::Null, RemainingContainerT>) {
88  setData<typename RemainingContainerT::head_type, typename RemainingContainerT::tail_type>(iProducts);
89  }
90  }
92 
93  unsigned int transitionID() const { return id_; }
94  ESProxyIndex const* getTokenIndices() const { return producer_->getTokenIndices(id_); }
95 
96  private:
100  // This transition id identifies which setWhatProduced call this Callback is associated with
101  unsigned int id_;
103  TDecorator decorator_;
104  };
105  } // namespace eventsetup
106 } // namespace edm
107 
108 #endif
edm::eventsetup::Callback::operator=
const Callback & operator=(const Callback &)=delete
edm::eventsetup::CallbackSimpleDecorator::pre
void pre(const TRecord &)
Definition: Callback.h:35
edm::eventsetup::produce::product_traits::type
T type
Definition: produce_helpers.h:58
edm::eventsetup::Callback::storeReturnedValues
void storeReturnedValues(TReturn iReturn)
Definition: Callback.h:76
edm::eventsetup::Callback::producer_
edm::propagate_const< T * > producer_
Definition: Callback.h:98
edm::eventsetup::Callback::newRecordComing
void newRecordComing()
Definition: Callback.h:91
propagate_const.h
edm::eventsetup::Callback::holdOntoPointer
void holdOntoPointer(DataT *iData)
Definition: Callback.h:72
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::eventsetup::Callback::method_type
TReturn(T ::*)(const TRecord &) method_type
Definition: Callback.h:46
edm::eventsetup::CallbackSimpleDecorator::post
void post(const TRecord &)
Definition: Callback.h:36
edm::eventsetup::CallbackSimpleDecorator
Definition: Callback.h:34
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
ESIndices.h
edm::eventsetup::Callback::transitionID
unsigned int transitionID() const
Definition: Callback.h:93
edm::eventsetup::Callback
Definition: Callback.h:44
edm::eventsetup::Callback::id_
unsigned int id_
Definition: Callback.h:101
edm::ESProxyIndex
Definition: ESIndices.h:29
edm::eventsetup::Callback::decorator_
TDecorator decorator_
Definition: Callback.h:103
edm::propagate_const::get
element_type const * get() const
Definition: propagate_const.h:64
edm::propagate_const< T * >
edm::eventsetup::Callback::proxyData_
std::array< void *, produce::size< TReturn >::value > proxyData_
Definition: Callback.h:97
edm::eventsetup::Callback::Callback
Callback(T *iProd, method_type iMethod, unsigned int iID, const TDecorator &iDec=TDecorator())
Definition: Callback.h:48
edm::eventsetup::Callback::getTokenIndices
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:94
edm::eventsetup::Callback::operator()
void operator()(const TRecord &iRecord)
Definition: Callback.h:61
edm::eventsetup::Callback::setData
void setData(ProductsT &iProducts)
Definition: Callback.h:82
edm::eventsetup::produce::find_index
Definition: produce_helpers.h:117
produce_helpers.h
type
type
Definition: HCALResponse.h:21
T
long double T
Definition: Basic3DVectorLD.h:48
edm::eventsetup::Callback::wasCalledForThisRecord_
bool wasCalledForThisRecord_
Definition: Callback.h:102
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::eventsetup::Callback::method_
method_type method_
Definition: Callback.h:99
edm::eventsetup::Callback::clone
Callback * clone()
Definition: Callback.h:56
edm::eventsetup::moveFromTo
void moveFromTo(FromT &iFrom, ToT &iTo)
Definition: produce_helpers.h:33