diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 592864528244c..bf290611e7201 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -471,6 +471,12 @@ struct unwrap> { using type = T; }; +template +struct unwrap { + using type = T[N]; + using base_type = T; +}; + template <> struct unwrap { using type = char; @@ -560,25 +566,32 @@ class ColumnIterator : ChunkingPolicy mLast = mCurrent + array->length() + (mFirstIndex >> SCALE_FACTOR); } - decltype(auto) operator*() const + auto operator*() const requires std::same_as> { checkSkipChunk(); return (*(mCurrent - (mOffset >> SCALE_FACTOR) + ((*mCurrentPos + mOffset) >> SCALE_FACTOR)) & (1 << ((*mCurrentPos + mOffset) & 0x7))) != 0; } - decltype(auto) operator*() const - requires((!std::same_as>) && std::same_as, arrow::ListArray>) + auto operator*() const + requires((!std::same_as>) && std::same_as, arrow::ListArray> && !std::same_as, arrow::FixedSizeListArray>) { checkSkipChunk(); auto list = std::static_pointer_cast(mColumn->chunk(mCurrentChunk)); auto offset = list->value_offset(*mCurrentPos - mFirstIndex); auto length = list->value_length(*mCurrentPos - mFirstIndex); - return gsl::span{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)}; + return std::span{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)}; + } + + auto operator*() const + requires((!std::same_as>) && !std::same_as, arrow::ListArray> && std::same_as, arrow::FixedSizeListArray>) + { + checkSkipChunk(); + return std::span{reinterpret_cast::base_type*>(mCurrent + (*mCurrentPos >> SCALE_FACTOR)), arrow_array_for::width}; } - decltype(auto) operator*() const - requires((!std::same_as>) && !std::same_as, arrow::ListArray>) + auto operator*() const + requires((!std::same_as>) && !std::same_as, arrow::ListArray> && !std::same_as, arrow::FixedSizeListArray>) { checkSkipChunk(); return *(mCurrent + (*mCurrentPos >> SCALE_FACTOR)); @@ -840,7 +853,7 @@ struct FilteredIndexPolicy : IndexPolicyBase { // which happens below which will properly setup the first index // by remapping the filtered index 0 to whatever unfiltered index // it belongs to. - FilteredIndexPolicy(gsl::span selection, int64_t rows, uint64_t offset = 0) + FilteredIndexPolicy(std::span selection, int64_t rows, uint64_t offset = 0) : IndexPolicyBase{-1, offset}, mSelectedRows(selection), mMaxSelection(selection.size()), @@ -849,7 +862,7 @@ struct FilteredIndexPolicy : IndexPolicyBase { this->setCursor(0); } - void resetSelection(gsl::span selection) + void resetSelection(std::span selection) { mSelectedRows = selection; mMaxSelection = selection.size(); @@ -933,7 +946,7 @@ struct FilteredIndexPolicy : IndexPolicyBase { { this->mRowIndex = O2_BUILTIN_LIKELY(mSelectionRow < mMaxSelection) ? mSelectedRows[mSelectionRow] : -1; } - gsl::span mSelectedRows; + std::span mSelectedRows; int64_t mSelectionRow = 0; int64_t mMaxSelection = 0; int64_t nRows = 0; @@ -1417,7 +1430,7 @@ struct PreslicePolicyGeneral : public PreslicePolicyBase { void updateSliceInfo(SliceInfoUnsortedPtr&& si); SliceInfoUnsortedPtr sliceInfo; - gsl::span getSliceFor(int value) const; + std::span getSliceFor(int value) const; }; template @@ -1442,7 +1455,7 @@ struct PresliceBase : public Policy { return Policy::getSliceFor(value, input, offset); } - gsl::span getSliceFor(int value) const + std::span getSliceFor(int value) const { if constexpr (OPT) { if (Policy::isMissing()) { @@ -1520,7 +1533,7 @@ auto doSliceBy(T const* table, o2::framework::PresliceBase const } template -auto doSliceByHelper(T const* table, gsl::span const& selection) +auto doSliceByHelper(T const* table, std::span const& selection) { auto t = soa::Filtered({table->asArrowTable()}, selection); table->copyIndexBindings(t); @@ -1531,7 +1544,7 @@ auto doSliceByHelper(T const* table, gsl::span const& selection) template requires(!soa::is_filtered_table) -auto doSliceByHelper(T const* table, gsl::span const& selection) +auto doSliceByHelper(T const* table, std::span const& selection) { auto t = soa::Filtered({table->asArrowTable()}, selection); table->copyIndexBindings(t); @@ -1552,7 +1565,7 @@ auto doSliceBy(T const* table, o2::framework::PresliceBase const return doSliceByHelper(table, selection); } -SelectionVector sliceSelection(gsl::span const& mSelectedRows, int64_t nrows, uint64_t offset); +SelectionVector sliceSelection(std::span const& mSelectedRows, int64_t nrows, uint64_t offset); template auto prepareFilteredSlice(T const* table, std::shared_ptr slice, uint64_t offset) @@ -1982,7 +1995,7 @@ class Table return RowViewSentinel{mEnd}; } - filtered_iterator filtered_begin(gsl::span selection) + filtered_iterator filtered_begin(std::span selection) { // Note that the FilteredIndexPolicy will never outlive the selection which // is held by the table, so we are safe passing the bare pointer. If it does it @@ -2561,12 +2574,12 @@ consteval auto getIndexTargets() _Name_##Ids(_Name_##Ids const& other) = default; \ _Name_##Ids& operator=(_Name_##Ids const& other) = default; \ \ - gsl::span inline getIds() const \ + std::span inline getIds() const \ { \ return _Getter_##Ids(); \ } \ \ - gsl::span _Getter_##Ids() const \ + std::span _Getter_##Ids() const \ { \ return *mColumnIterator; \ } \ @@ -2918,12 +2931,12 @@ consteval auto getIndexTargets() _Name_##Ids() = default; \ _Name_##Ids(_Name_##Ids const& other) = default; \ _Name_##Ids& operator=(_Name_##Ids const& other) = default; \ - gsl::span inline getIds() const \ + std::span inline getIds() const \ { \ return _Getter_##Ids(); \ } \ \ - gsl::span _Getter_##Ids() const \ + std::span _Getter_##Ids() const \ { \ return *mColumnIterator; \ } \ @@ -3373,7 +3386,7 @@ class FilteredBase : public T mSelectedRowsCache{std::move(selection)}, mCached{true} { - mSelectedRows = gsl::span{mSelectedRowsCache}; + mSelectedRows = std::span{mSelectedRowsCache}; if (this->tableSize() != 0) { mFilteredBegin = table_t::filtered_begin(mSelectedRows); } @@ -3381,7 +3394,7 @@ class FilteredBase : public T mFilteredBegin.bindInternalIndices(this); } - FilteredBase(std::vector>&& tables, gsl::span const& selection, uint64_t offset = 0) + FilteredBase(std::vector>&& tables, std::span const& selection, uint64_t offset = 0) : T{std::move(tables), offset}, mSelectedRows{selection} { @@ -3460,12 +3473,12 @@ class FilteredBase : public T static inline auto getSpan(gandiva::Selection const& sel) { if (sel == nullptr) { - return gsl::span{}; + return std::span{}; } auto array = std::static_pointer_cast(sel->ToArray()); auto start = array->raw_values(); auto stop = start + array->length(); - return gsl::span{start, stop}; + return std::span{start, stop}; } /// Bind the columns which refer to other tables @@ -3564,7 +3577,7 @@ class FilteredBase : public T resetRanges(); } - void sumWithSelection(gsl::span const& selection) + void sumWithSelection(std::span const& selection) { mCached = true; SelectionVector rowsUnion; @@ -3574,7 +3587,7 @@ class FilteredBase : public T resetRanges(); } - void intersectWithSelection(gsl::span const& selection) + void intersectWithSelection(std::span const& selection) { mCached = true; SelectionVector intersection; @@ -3593,7 +3606,7 @@ class FilteredBase : public T void resetRanges() { if (mCached) { - mSelectedRows = gsl::span{mSelectedRowsCache}; + mSelectedRows = std::span{mSelectedRowsCache}; } mFilteredEnd.reset(new RowViewSentinel{static_cast(mSelectedRows.size())}); if (tableSize() == 0) { @@ -3603,7 +3616,7 @@ class FilteredBase : public T } } - gsl::span mSelectedRows; + std::span mSelectedRows; SelectionVector mSelectedRowsCache; bool mCached = false; iterator mFilteredBegin; @@ -3639,7 +3652,7 @@ class Filtered : public FilteredBase Filtered(std::vector>&& tables, SelectionVector&& selection, uint64_t offset = 0) : FilteredBase(std::move(tables), std::forward(selection), offset) {} - Filtered(std::vector>&& tables, gsl::span const& selection, uint64_t offset = 0) + Filtered(std::vector>&& tables, std::span const& selection, uint64_t offset = 0) : FilteredBase(std::move(tables), selection, offset) {} Filtered operator+(SelectionVector const& selection) @@ -3649,7 +3662,7 @@ class Filtered : public FilteredBase return copy; } - Filtered operator+(gsl::span const& selection) + Filtered operator+(std::span const& selection) { Filtered copy(*this); copy.sumWithSelection(selection); @@ -3667,7 +3680,7 @@ class Filtered : public FilteredBase return *this; } - Filtered operator+=(gsl::span const& selection) + Filtered operator+=(std::span const& selection) { this->sumWithSelection(selection); return *this; @@ -3685,7 +3698,7 @@ class Filtered : public FilteredBase return copy; } - Filtered operator*(gsl::span const& selection) + Filtered operator*(std::span const& selection) { Filtered copy(*this); copy.intersectWithSelection(selection); @@ -3703,7 +3716,7 @@ class Filtered : public FilteredBase return *this; } - Filtered operator*=(gsl::span const& selection) + Filtered operator*=(std::span const& selection) { this->intersectWithSelection(selection); return *this; @@ -3811,7 +3824,7 @@ class Filtered> : public FilteredBase } } - Filtered(std::vector>&& tables, gsl::span const& selection, uint64_t offset = 0) + Filtered(std::vector>&& tables, std::span const& selection, uint64_t offset = 0) : FilteredBase(std::move(extractTablesFromFiltered(tables)), selection, offset) { for (auto& table : tables) { @@ -3826,7 +3839,7 @@ class Filtered> : public FilteredBase return copy; } - Filtered> operator+(gsl::span const& selection) + Filtered> operator+(std::span const& selection) { Filtered> copy(*this); copy.sumWithSelection(selection); @@ -3844,7 +3857,7 @@ class Filtered> : public FilteredBase return *this; } - Filtered> operator+=(gsl::span const& selection) + Filtered> operator+=(std::span const& selection) { this->sumWithSelection(selection); return *this; @@ -3862,7 +3875,7 @@ class Filtered> : public FilteredBase return copy; } - Filtered> operator*(gsl::span const& selection) + Filtered> operator*(std::span const& selection) { Filtered> copy(*this); copy.intersectionWithSelection(selection); @@ -3880,7 +3893,7 @@ class Filtered> : public FilteredBase return *this; } - Filtered> operator*=(gsl::span const& selection) + Filtered> operator*=(std::span const& selection) { this->intersectWithSelection(selection); return *this; @@ -3989,7 +4002,7 @@ struct SmallGroupsBase : public Filtered { SmallGroupsBase(std::vector>&& tables, SelectionVector&& selection, uint64_t offset = 0) : Filtered(std::move(tables), std::forward(selection), offset) {} - SmallGroupsBase(std::vector>&& tables, gsl::span const& selection, uint64_t offset = 0) + SmallGroupsBase(std::vector>&& tables, std::span const& selection, uint64_t offset = 0) : Filtered(std::move(tables), selection, offset) {} }; diff --git a/Framework/Core/include/Framework/AnalysisHelpers.h b/Framework/Core/include/Framework/AnalysisHelpers.h index 95be6c7e407b3..b2f48d01a0a46 100644 --- a/Framework/Core/include/Framework/AnalysisHelpers.h +++ b/Framework/Core/include/Framework/AnalysisHelpers.h @@ -119,6 +119,9 @@ class TableConsumer; template concept is_producable = soa::has_metadata> || soa::has_metadata>; +template +concept is_enumerated_iterator = requires(T t) { t.globalIndex(); }; + template struct WritingCursor { public: @@ -126,9 +129,9 @@ struct WritingCursor { using cursor_t = decltype(std::declval().cursor()); template - void operator()(Ts... args) + void operator()(Ts&&... args) + requires(sizeof...(Ts) == framework::pack_size(typename persistent_table_t::persistent_columns_t{})) { - static_assert(sizeof...(Ts) == framework::pack_size(typename persistent_table_t::persistent_columns_t{}), "Argument number mismatch"); ++mCount; cursor(0, extract(args)...); } @@ -167,15 +170,15 @@ struct WritingCursor { decltype(FFL(std::declval())) cursor; private: - template - requires requires { &A::globalIndex; } - static decltype(auto) extract(A const& arg) + template + static inline decltype(auto) extract(A const& arg) { return arg.globalIndex(); } template - static decltype(auto) extract(A const& arg) + requires(!is_enumerated_iterator) + static inline decltype(auto) extract(A&& arg) { return arg; } diff --git a/Framework/Core/include/Framework/ArrowTableSlicingCache.h b/Framework/Core/include/Framework/ArrowTableSlicingCache.h index 292a67023fc5e..5bbb2ba279143 100644 --- a/Framework/Core/include/Framework/ArrowTableSlicingCache.h +++ b/Framework/Core/include/Framework/ArrowTableSlicingCache.h @@ -21,17 +21,17 @@ namespace o2::framework using ListVector = std::vector>; struct SliceInfoPtr { - gsl::span values; - gsl::span counts; + std::span values; + std::span counts; std::pair getSliceFor(int value) const; }; struct SliceInfoUnsortedPtr { - gsl::span values; + std::span values; ListVector const* groups; - gsl::span getSliceFor(int value) const; + std::span getSliceFor(int value) const; }; struct Entry { diff --git a/Framework/Core/include/Framework/ArrowTypes.h b/Framework/Core/include/Framework/ArrowTypes.h index 69946b6f35a50..0d974dab91042 100644 --- a/Framework/Core/include/Framework/ArrowTypes.h +++ b/Framework/Core/include/Framework/ArrowTypes.h @@ -64,26 +64,31 @@ struct arrow_array_for { }; template struct arrow_array_for { + static constexpr size_t width = N; using type = arrow::FixedSizeListArray; using value_type = float; }; template struct arrow_array_for { + static constexpr size_t width = N; using type = arrow::FixedSizeListArray; using value_type = int; }; template struct arrow_array_for { + static constexpr size_t width = N; using type = arrow::FixedSizeListArray; using value_type = short; }; template struct arrow_array_for { + static constexpr size_t width = N; using type = arrow::FixedSizeListArray; using value_type = double; }; template struct arrow_array_for { + static constexpr size_t width = N; using type = arrow::FixedSizeListArray; using value_type = int8_t; }; diff --git a/Framework/Core/include/Framework/GroupSlicer.h b/Framework/Core/include/Framework/GroupSlicer.h index b8436314b057e..00af0a8fc7da5 100644 --- a/Framework/Core/include/Framework/GroupSlicer.h +++ b/Framework/Core/include/Framework/GroupSlicer.h @@ -266,9 +266,9 @@ struct GroupSlicer { std::tuple* mAt; typename grouping_t::iterator mGroupingElement; uint64_t position = 0; - gsl::span groupSelection; - std::array const*, sizeof...(A)> selections; - std::array::iterator, sizeof...(A)> starts; + std::span groupSelection; + std::array const*, sizeof...(A)> selections; + std::array::iterator, sizeof...(A)> starts; std::array sliceInfos; std::array sliceInfosUnsorted; diff --git a/Framework/Core/include/Framework/TableBuilder.h b/Framework/Core/include/Framework/TableBuilder.h index eb56791acfd3c..0368c8c0b3e6e 100644 --- a/Framework/Core/include/Framework/TableBuilder.h +++ b/Framework/Core/include/Framework/TableBuilder.h @@ -157,7 +157,7 @@ struct BuilderUtils { /// Appender for the vector case. template - static arrow::Status append(HolderType& holder, std::vector const& data) + static arrow::Status append(HolderType& holder, std::span data) { using ArrowType = typename detail::ConversionTraits::ArrowType; using ValueBuilderType = typename arrow::TypeTraits::BuilderType; @@ -170,7 +170,7 @@ struct BuilderUtils { } template - static void unsafeAppend(HolderType& holder, std::vector const& value) + static void unsafeAppend(HolderType& holder, std::span value) { auto status = append(holder, value); if (!status.ok()) { @@ -276,7 +276,7 @@ struct BuilderMaker { template struct BuilderMaker> { - using FillType = std::pair; + using FillType = std::pair const&; using STLValueType = typename ITERATOR::value_type; using ArrowType = arrow::ListType; using ValueType = typename detail::ConversionTraits::ArrowType; @@ -361,7 +361,7 @@ struct BuilderMaker> { template struct BuilderMaker> { - using FillType = std::vector; + using FillType = std::span; using BuilderType = arrow::ListBuilder; using ArrowType = arrow::ListType; using ElementType = typename detail::ConversionTraits::ArrowType; @@ -647,7 +647,7 @@ class TableBuilder { auto persister = persistTuple(framework::pack{}, columnNames); // Callback used to fill the builders - return [persister = persister](unsigned int slot, typename BuilderMaker::FillType const& arg, typename BuilderMaker::FillType... args) -> void { + return [persister = persister](unsigned int slot, typename BuilderMaker::FillType arg, typename BuilderMaker::FillType... args) -> void { persister(slot, std::forward_as_tuple(arg, args...)); }; } diff --git a/Framework/Core/src/ASoA.cxx b/Framework/Core/src/ASoA.cxx index 3a681ee931a2b..7b5cdf72191cf 100644 --- a/Framework/Core/src/ASoA.cxx +++ b/Framework/Core/src/ASoA.cxx @@ -50,7 +50,7 @@ SelectionVector selectionToVector(gandiva::Selection const& sel) return rows; } -SelectionVector sliceSelection(gsl::span const& mSelectedRows, int64_t nrows, uint64_t offset) +SelectionVector sliceSelection(std::span const& mSelectedRows, int64_t nrows, uint64_t offset) { auto start = offset; auto end = start + nrows; @@ -217,7 +217,7 @@ std::shared_ptr PreslicePolicySorted::getSliceFor(int value, std:: return output; } -gsl::span PreslicePolicyGeneral::getSliceFor(int value) const +std::span PreslicePolicyGeneral::getSliceFor(int value) const { return this->sliceInfo.getSliceFor(value); } diff --git a/Framework/Core/src/ArrowTableSlicingCache.cxx b/Framework/Core/src/ArrowTableSlicingCache.cxx index e001e293c4733..5ed7066d198c9 100644 --- a/Framework/Core/src/ArrowTableSlicingCache.cxx +++ b/Framework/Core/src/ArrowTableSlicingCache.cxx @@ -56,7 +56,7 @@ std::pair SliceInfoPtr::getSliceFor(int value) const return {offset, 0}; } -gsl::span SliceInfoUnsortedPtr::getSliceFor(int value) const +std::span SliceInfoUnsortedPtr::getSliceFor(int value) const { if (values.empty()) { return {}; diff --git a/Framework/Core/test/test_ASoA.cxx b/Framework/Core/test/test_ASoA.cxx index 80519aebc9ee7..346821e21ab6a 100644 --- a/Framework/Core/test/test_ASoA.cxx +++ b/Framework/Core/test/test_ASoA.cxx @@ -1150,8 +1150,8 @@ TEST_CASE("TestListColumns") for (auto& row : tbl) { auto f = row.l1(); auto i = row.l2(); - auto constexpr bf = std::same_as>; - auto constexpr bi = std::same_as>; + auto constexpr bf = std::same_as>; + auto constexpr bi = std::same_as>; REQUIRE(bf); REQUIRE(bi); REQUIRE(f.size() == s); @@ -1332,7 +1332,7 @@ DECLARE_SOA_COLUMN(One, one, int); DECLARE_SOA_COLUMN(Two, two, float); DECLARE_SOA_COLUMN(Three, three, double); DECLARE_SOA_COLUMN(Four, four, int[2]); -DECLARE_SOA_DYNAMIC_COLUMN(Five, five, [](const int in[2]) -> float { return (float)in[0] / (float)in[1]; }); +DECLARE_SOA_DYNAMIC_COLUMN(Five, five, [](std::span in) -> float { return (float)in[0] / (float)in[1]; }); } // namespace table DECLARE_SOA_TABLE(MixTest, "AOD", "MIXTST",