File indexing completed on 2024-04-06 12:13:09
0001 #ifndef FWCore_SOA_RowView_h
0002 #define FWCore_SOA_RowView_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include <tuple>
0045 #include <array>
0046
0047
0048 #include "FWCore/SOA/interface/tablehelpers.h"
0049 #include "FWCore/SOA/interface/ColumnFillers.h"
0050
0051
0052
0053 namespace edm {
0054 namespace soa {
0055
0056 template <typename... Args>
0057 class RowView {
0058 using Layout = std::tuple<Args...>;
0059 std::array<void const*, sizeof...(Args)> m_values;
0060
0061 public:
0062 explicit RowView(std::array<void const*, sizeof...(Args)> const& iValues) : m_values{iValues} {}
0063
0064 template <typename U>
0065 typename U::type const& get() const {
0066 return *(static_cast<typename U::type const*>(columnAddress<U>()));
0067 }
0068
0069 template <typename U>
0070 void const* columnAddress() const {
0071 return m_values[impl::GetIndex<0, U, Layout>::index];
0072 }
0073 };
0074
0075 template <typename... Args>
0076 class MutableRowView {
0077 using Layout = std::tuple<Args...>;
0078 std::array<void*, sizeof...(Args)> m_values;
0079
0080 public:
0081 explicit MutableRowView(std::array<void*, sizeof...(Args)>& iValues) : m_values{iValues} {}
0082
0083 template <typename U>
0084 typename U::type& get() {
0085 return *(static_cast<typename U::type*>(columnAddress<U>()));
0086 }
0087 template <typename U>
0088 typename U::type const& get() const {
0089 return *(static_cast<typename U::type const*>(columnAddress<U>()));
0090 }
0091
0092 template <typename U>
0093 MutableRowView<Args...>& set(typename U::type const& iValue) {
0094 get<U>() = iValue;
0095 return *this;
0096 }
0097
0098 template <typename U>
0099 void* columnAddress() {
0100 return m_values[impl::GetIndex<0, U, Layout>::index];
0101 }
0102 template <typename U>
0103 void const* columnAddress() const {
0104 return m_values[impl::GetIndex<0, U, Layout>::index];
0105 }
0106
0107 template <typename O>
0108 void copyValuesFrom(O const& iObj) {
0109 copyValueFromImpl<0>(iObj);
0110 }
0111 template <typename O, typename... CArgs>
0112 void copyValuesFrom(O const& iObj, ColumnFillers<CArgs...> iFiller) {
0113 copyValuesUsingFiller<0>(iFiller, iObj, m_values);
0114 }
0115
0116 private:
0117 template <int I, typename O>
0118 void copyValueFromImpl(O const& iObj) {
0119 if constexpr (I < sizeof...(Args)) {
0120 using ColumnType = typename std::tuple_element<I, Layout>::type;
0121 using Type = typename ColumnType::type;
0122 auto ptr = static_cast<Type*>(m_values[I]);
0123 *ptr = value_for_column(iObj, static_cast<ColumnType*>(nullptr));
0124 copyValueFromImpl<I + 1>(iObj);
0125 }
0126 }
0127
0128 template <int I, typename E, typename F>
0129 static void copyValuesUsingFiller(F& iFiller, E const& iItem, std::array<void*, sizeof...(Args)>& oValues) {
0130 if constexpr (I < sizeof...(Args)) {
0131 using Layout = std::tuple<Args...>;
0132 using ColumnType = typename std::tuple_element<I, Layout>::type;
0133 using Type = typename ColumnType::type;
0134 Type* pElement = static_cast<Type*>(oValues[I]);
0135 *pElement = iFiller.value(iItem, static_cast<ColumnType*>(nullptr));
0136 copyValuesUsingFiller<I + 1>(iFiller, iItem, oValues);
0137 }
0138 }
0139 };
0140
0141 }
0142 }
0143
0144 #endif