CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RowView.h
Go to the documentation of this file.
1 #ifndef FWCore_SOA_RowView_h
2 #define FWCore_SOA_RowView_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SOA
6 // Class : RowView
7 //
38 //
39 // Original Author: Chris Jones
40 // Created: Thu, 24 Aug 2017 16:49:17 GMT
41 //
42 
43 // system include files
44 #include <tuple>
45 #include <array>
46 
47 // user include files
50 
51 // forward declarations
52 
53 namespace edm {
54  namespace soa {
55 
56  template <typename... Args>
57  class RowView {
58  using Layout = std::tuple<Args...>;
59  std::array<void const*, sizeof...(Args)> m_values;
60 
61  public:
62  explicit RowView(std::array<void const*, sizeof...(Args)> const& iValues) : m_values{iValues} {}
63 
64  template <typename U>
65  typename U::type const& get() const {
66  return *(static_cast<typename U::type const*>(columnAddress<U>()));
67  }
68 
69  template <typename U>
70  void const* columnAddress() const {
72  }
73  };
74 
75  template <typename... Args>
77  using Layout = std::tuple<Args...>;
78  std::array<void*, sizeof...(Args)> m_values;
79 
80  public:
81  explicit MutableRowView(std::array<void*, sizeof...(Args)>& iValues) : m_values{iValues} {}
82 
83  template <typename U>
84  typename U::type& get() {
85  return *(static_cast<typename U::type*>(columnAddress<U>()));
86  }
87  template <typename U>
88  typename U::type const& get() const {
89  return *(static_cast<typename U::type const*>(columnAddress<U>()));
90  }
91 
92  template <typename U>
93  MutableRowView<Args...>& set(typename U::type const& iValue) {
94  get<U>() = iValue;
95  return *this;
96  }
97 
98  template <typename U>
99  void* columnAddress() {
101  }
102  template <typename U>
103  void const* columnAddress() const {
105  }
106 
107  template <typename O>
108  void copyValuesFrom(O const& iObj) {
109  copyValueFromImpl<0>(iObj);
110  }
111  template <typename O, typename... CArgs>
112  void copyValuesFrom(O const& iObj, ColumnFillers<CArgs...> iFiller) {
113  copyValuesUsingFiller<0>(iFiller, iObj, m_values);
114  }
115 
116  private:
117  template <int I, typename O>
118  void copyValueFromImpl(O const& iObj) {
119  if constexpr (I < sizeof...(Args)) {
120  using ColumnType = typename std::tuple_element<I, Layout>::type;
121  using Type = typename ColumnType::type;
122  auto ptr = static_cast<Type*>(m_values[I]);
123  *ptr = value_for_column(iObj, static_cast<ColumnType*>(nullptr));
124  copyValueFromImpl<I + 1>(iObj);
125  }
126  }
127 
128  template <int I, typename E, typename F>
129  static void copyValuesUsingFiller(F& iFiller, E const& iItem, std::array<void*, sizeof...(Args)>& oValues) {
130  if constexpr (I < sizeof...(Args)) {
131  using Layout = std::tuple<Args...>;
132  using ColumnType = typename std::tuple_element<I, Layout>::type;
133  using Type = typename ColumnType::type;
134  Type* pElement = static_cast<Type*>(oValues[I]);
135  *pElement = iFiller.value(iItem, static_cast<ColumnType*>(nullptr));
136  copyValuesUsingFiller<I + 1>(iFiller, iItem, oValues);
137  }
138  }
139  };
140 
141  } // namespace soa
142 } // namespace edm
143 
144 #endif
tuple array
Definition: mps_check.py:216
void copyValuesFrom(O const &iObj, ColumnFillers< CArgs...> iFiller)
Definition: RowView.h:112
MutableRowView< Args...> & set(typename U::type const &iValue)
Definition: RowView.h:93
void copyValuesFrom(O const &iObj)
Definition: RowView.h:108
MutableRowView(std::array< void *, sizeof...(Args)> &iValues)
Definition: RowView.h:81
std::array< void *, sizeof...(Args)> m_values
Definition: RowView.h:78
void const * columnAddress() const
Definition: RowView.h:103
std::tuple< Args...> Layout
Definition: RowView.h:58
void const * columnAddress() const
Definition: RowView.h:70
ZVertexSoA * soa
const std::complex< double > I
Definition: I.h:8
void * columnAddress()
Definition: RowView.h:99
std::array< void const *, sizeof...(Args)> m_values
Definition: RowView.h:59
RowView(std::array< void const *, sizeof...(Args)> const &iValues)
Definition: RowView.h:62
std::tuple< Args...> Layout
Definition: RowView.h:77
col::Eta::type value_for_column(Object const &x, col::Eta *)
void copyValueFromImpl(O const &iObj)
Definition: RowView.h:118
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
static void copyValuesUsingFiller(F &iFiller, E const &iItem, std::array< void *, sizeof...(Args)> &oValues)
Definition: RowView.h:129