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