File indexing completed on 2024-04-06 12:13:09
0001 #ifndef FWCore_SOA_TableView_h
0002 #define FWCore_SOA_TableView_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 #include <tuple>
0038 #include <array>
0039
0040
0041 #include "FWCore/SOA/interface/Table.h"
0042 #include "FWCore/SOA/interface/ColumnValues.h"
0043
0044
0045
0046 namespace edm {
0047 namespace soa {
0048 template <typename... Args>
0049 class TableView {
0050 public:
0051 using Layout = std::tuple<Args...>;
0052 static constexpr const size_t kNColumns = sizeof...(Args);
0053 using const_iterator = ConstTableItr<Args...>;
0054
0055 template <typename... OArgs>
0056 TableView(Table<OArgs...> const& iTable) : m_size(iTable.size()) {
0057 fillArray(iTable, std::make_index_sequence<sizeof...(Args)>{});
0058 }
0059 TableView(unsigned int iSize, std::array<void*, sizeof...(Args)>& iArray) : m_size(iSize), m_values(iArray) {}
0060
0061 TableView(unsigned int iSize, std::array<void const*, sizeof...(Args)>& iArray)
0062 : m_size(iSize), m_values(iArray) {}
0063
0064 unsigned int size() const { return m_size; }
0065
0066 template <typename U>
0067 typename U::type const& get(size_t iRow) const {
0068 return *(static_cast<typename U::type const*>(columnAddress<U>()) + iRow);
0069 }
0070
0071 template <typename U>
0072 ColumnValues<typename U::type> column() const {
0073 return ColumnValues<typename U::type>{static_cast<typename U::type const*>(columnAddress<U>()), m_size};
0074 }
0075
0076 const_iterator begin() const { return const_iterator{m_values}; }
0077 const_iterator end() const { return const_iterator{m_values, size()}; }
0078
0079 private:
0080 std::array<void const*, sizeof...(Args)> m_values;
0081 unsigned int m_size;
0082
0083 template <typename U>
0084 void const* columnAddress() const {
0085 return m_values[impl::GetIndex<0, U, Layout>::index];
0086 }
0087
0088 template <typename T, size_t... I>
0089 void fillArray(T const& iTable, std::index_sequence<I...>) {
0090 ((m_values[I] = iTable.columnAddressWorkaround(
0091 static_cast<typename std::tuple_element<I, Layout>::type const*>(nullptr))),
0092 ...);
0093 }
0094 };
0095
0096 template <typename T>
0097 struct ViewFromTable;
0098
0099 template <typename... T>
0100 struct ViewFromTable<Table<T...>> {
0101 using type = TableView<T...>;
0102 };
0103 template <typename T>
0104 using ViewFromTable_t = typename ViewFromTable<T>::type;
0105
0106 }
0107 }
0108
0109 #endif