CMS 3D CMS Logo

Callback.h
Go to the documentation of this file.
1 #ifndef Framework_Callback_h
2 #define 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 // forward declarations
30 namespace edm {
31  namespace eventsetup {
32 
33  //need a virtual distructor since owner of callback only knows
34  // about the base class. Other users of callback know the specific
35  // type
36  struct CallbackBase {
37  virtual ~CallbackBase() {}
38  };
39 
40  // The default decorator that does nothing
41  template <typename TRecord>
43  void pre(const TRecord&) {}
44  void post(const TRecord&) {}
45  };
46 
47  template <typename T, //producer's type
48  typename TReturn, //return type of the producer's method
49  typename TRecord, //the record passed in as an argument
50  typename TDecorator //allows customization using pre/post calls
52  class Callback : public CallbackBase {
53  public:
54  using method_type = TReturn (T ::*)(const TRecord&);
55 
56  Callback(T* iProd, method_type iMethod, unsigned int iID, const TDecorator& iDec = TDecorator())
57  : proxyData_{},
58  producer_(iProd),
59  method_(iMethod),
60  id_(iID),
61  wasCalledForThisRecord_(false),
62  decorator_(iDec) {}
63 
64  // ---------- const member functions ---------------------
65 
66  // ---------- static member functions --------------------
67 
68  // ---------- member functions ---------------------------
69 
70  void operator()(const TRecord& iRecord) {
71  if (!wasCalledForThisRecord_) {
72  decorator_.pre(iRecord);
73  storeReturnedValues((producer_->*method_)(iRecord));
74  wasCalledForThisRecord_ = true;
75  decorator_.post(iRecord);
76  }
77  }
78 
79  template <class DataT>
80  void holdOntoPointer(DataT* iData) {
82  }
83 
84  void storeReturnedValues(TReturn iReturn) {
85  //std::cout <<" storeReturnedValues "<< iReturn <<" " <<iReturn->value_ <<std::endl;
87  setData<typename type::head_type, typename type::tail_type>(iReturn);
88  }
89 
90  template <class RemainingContainerT, class DataT, class ProductsT>
91  void setData(ProductsT& iProducts) {
92  DataT* temp = reinterpret_cast<DataT*>(proxyData_[produce::find_index<TReturn, DataT>::value]);
93  if (nullptr != temp) {
94  moveFromTo(iProducts, *temp);
95  }
96  if constexpr (not std::is_same_v<produce::Null, RemainingContainerT>) {
97  setData<typename RemainingContainerT::head_type, typename RemainingContainerT::tail_type>(iProducts);
98  }
99  }
100  void newRecordComing() { wasCalledForThisRecord_ = false; }
101 
102  unsigned int transitionID() const { return id_; }
103  ESProxyIndex const* getTokenIndices() const { return producer_->getTokenIndices(id_); }
104 
105  private:
106  Callback(const Callback&) = delete; // stop default
107 
108  const Callback& operator=(const Callback&) = delete; // stop default
109 
113  unsigned int id_;
115  TDecorator decorator_;
116  };
117  } // namespace eventsetup
118 } // namespace edm
119 
120 #endif
void storeReturnedValues(TReturn iReturn)
Definition: Callback.h:84
type
Definition: HCALResponse.h:21
void holdOntoPointer(DataT *iData)
Definition: Callback.h:80
std::array< void *, produce::size< TReturn >::value > proxyData_
Definition: Callback.h:110
unsigned int transitionID() const
Definition: Callback.h:102
Callback(T *iProd, method_type iMethod, unsigned int iID, const TDecorator &iDec=TDecorator())
Definition: Callback.h:56
TReturn(T::*)(const TRecord &) method_type
Definition: Callback.h:54
void moveFromTo(FromT &iFrom, ToT &iTo)
void operator()(const TRecord &iRecord)
Definition: Callback.h:70
void setData(ProductsT &iProducts)
Definition: Callback.h:91
HLT enums.
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:103
edm::propagate_const< T * > producer_
Definition: Callback.h:111
long double T
#define constexpr