CMS 3D CMS Logo

ColumnFillers.h
Go to the documentation of this file.
1 #ifndef FWCore_SOA_ColumnFillers_h
2 #define FWCore_SOA_ColumnFillers_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SOA
6 // Class : ColumnFillers
7 //
29 //
30 // Original Author: Chris Jones
31 // Created: Thu, 24 Aug 2017 22:22:42 GMT
32 //
33 
34 // system include files
35 
36 // user include files
37 
38 // forward declarations
39 #include <tuple>
40 
41 namespace edm {
42 namespace soa {
43 
44  template <typename... Args>
45  class ColumnFillers {
46  using Layout = std::tuple<Args...>;
48 
49  template<int I, typename ELEMENT, typename RET>
50  auto callFiller(ELEMENT&& iEl, RET*, std::true_type) -> decltype(std::get<I>(m_fillers).m_f(iEl)) {
51  return std::get<I>(m_fillers).m_f(iEl);
52  }
53 
54  template<int I, typename ELEMENT, typename RET>
55  RET callFiller(ELEMENT&& iEl, RET*, std::false_type) {
56  return RET{};
57  }
58 
59  template<int I, typename ELEMENT, typename COLUMN>
60  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::true_type, std::true_type) {
61  using Pair = typename std::tuple_element<I,Layout>::type;
62  using COL = typename Pair::Column_type;
64  return callFiller<I>(iEl,
65  static_cast<typename COLUMN::type*>(nullptr),
66  std::conditional_t<std::is_same<COL,COLUMN>::value,
67  std::true_type, std::false_type>{});
68  }
69  return tryValue<I+1>(iEl, static_cast<COLUMN*>(nullptr),
70  std::conditional_t<I+1 == sizeof...(Args),
71  std::false_type, std::true_type>{},
73  std::false_type, std::true_type>{});
74  }
75 
76  template<int I, typename ELEMENT, typename COLUMN>
77  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::false_type, std::true_type) {
78  return value_for_column(iEl,static_cast<COLUMN*>(nullptr));
79  }
80  template<int I, typename ELEMENT, typename COLUMN>
81  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::true_type, std::false_type) {
82  return typename COLUMN::type{};
83  }
84  template<int I, typename ELEMENT, typename COLUMN>
85  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::false_type, std::false_type) {
86  return typename COLUMN::type{};
87  }
88 
89  public:
90  ColumnFillers(Args... iArgs): m_fillers(std::forward<Args>(iArgs)...) {}
91 
92  template<typename ELEMENT, typename COLUMN>
93  typename COLUMN::type value(ELEMENT&& iEl, COLUMN*) {
94  return tryValue<0>(iEl, static_cast<COLUMN*>(nullptr), std::true_type{},std::true_type{});
95  }
96  };
97 
98  template<typename... Args>
99  ColumnFillers<Args...> column_fillers(Args... iArgs) {
100  return ColumnFillers<Args...>(std::forward<Args>(iArgs)...);
101  }
102 
103 }
104 }
105 
106 
107 #endif
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::true_type, std::false_type)
Definition: ColumnFillers.h:81
type
Definition: HCALResponse.h:21
RET callFiller(ELEMENT &&iEl, RET *, std::false_type)
Definition: ColumnFillers.h:55
COLUMN::type value(ELEMENT &&iEl, COLUMN *)
Definition: ColumnFillers.h:93
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::false_type, std::true_type)
Definition: ColumnFillers.h:77
ColumnFillers(Args...iArgs)
Definition: ColumnFillers.h:90
ColumnFillers< Args... > column_fillers(Args...iArgs)
Definition: ColumnFillers.h:99
const std::complex< double > I
Definition: I.h:8
auto callFiller(ELEMENT &&iEl, RET *, std::true_type) -> decltype(std::get< I >(m_fillers).m_f(iEl))
Definition: ColumnFillers.h:50
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::false_type, std::false_type)
Definition: ColumnFillers.h:85
HLT enums.
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::true_type, std::true_type)
Definition: ColumnFillers.h:60
std::tuple< Args... > Layout
Definition: ColumnFillers.h:46