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 
40 namespace edm {
41 namespace soa {
42 
43  template <typename... Args>
44  class ColumnFillers {
45  using Layout = std::tuple<Args...>;
47 
48  template<int I, typename ELEMENT, typename RET>
49  auto callFiller(ELEMENT&& iEl, RET*, std::true_type) -> decltype(std::get<I>(m_fillers).m_f(iEl)) {
50  return std::get<I>(m_fillers).m_f(iEl);
51  }
52 
53  template<int I, typename ELEMENT, typename RET>
54  RET callFiller(ELEMENT&& iEl, RET*, std::false_type) {
55  return RET{};
56  }
57 
58  template<int I, typename ELEMENT, typename COLUMN>
59  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::true_type, std::true_type) {
60  using Pair = typename std::tuple_element<I,Layout>::type;
61  using COL = typename Pair::Column_type;
63  return callFiller<I>(iEl,
64  static_cast<typename COLUMN::type*>(nullptr),
65  std::conditional_t<std::is_same<COL,COLUMN>::value,
66  std::true_type, std::false_type>{});
67  }
68  return tryValue<I+1>(iEl, static_cast<COLUMN*>(nullptr),
69  std::conditional_t<I+1 == sizeof...(Args),
70  std::false_type, std::true_type>{},
72  std::false_type, std::true_type>{});
73  }
74 
75  template<int I, typename ELEMENT, typename COLUMN>
76  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::false_type, std::true_type) {
77  return value_for_column(iEl,static_cast<COLUMN*>(nullptr));
78  }
79  template<int I, typename ELEMENT, typename COLUMN>
80  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::true_type, std::false_type) {
81  return typename COLUMN::type{};
82  }
83  template<int I, typename ELEMENT, typename COLUMN>
84  typename COLUMN::type tryValue(ELEMENT&& iEl, COLUMN*, std::false_type, std::false_type) {
85  return typename COLUMN::type{};
86  }
87 
88  public:
89  ColumnFillers(Args... iArgs): m_fillers(std::forward<Args>(iArgs)...) {}
90 
91  template<typename ELEMENT, typename COLUMN>
92  typename COLUMN::type value(ELEMENT&& iEl, COLUMN*) {
93  return tryValue<0>(iEl, static_cast<COLUMN*>(nullptr), std::true_type{},std::true_type{});
94  }
95  };
96 
97  template<typename... Args>
98  ColumnFillers<Args...> column_fillers(Args... iArgs) {
99  return ColumnFillers<Args...>(std::forward<Args>(iArgs)...);
100  }
101 
102 }
103 }
104 
105 
106 #endif
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::true_type, std::false_type)
Definition: ColumnFillers.h:80
type
Definition: HCALResponse.h:21
RET callFiller(ELEMENT &&iEl, RET *, std::false_type)
Definition: ColumnFillers.h:54
COLUMN::type value(ELEMENT &&iEl, COLUMN *)
Definition: ColumnFillers.h:92
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::false_type, std::true_type)
Definition: ColumnFillers.h:76
ColumnFillers(Args...iArgs)
Definition: ColumnFillers.h:89
ColumnFillers< Args... > column_fillers(Args...iArgs)
Definition: ColumnFillers.h:98
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:49
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::false_type, std::false_type)
Definition: ColumnFillers.h:84
HLT enums.
COLUMN::type tryValue(ELEMENT &&iEl, COLUMN *, std::true_type, std::true_type)
Definition: ColumnFillers.h:59
std::tuple< Args... > Layout
Definition: ColumnFillers.h:45