Skip to content

Commit df10dd3

Browse files
authored
DPL Analysis: rework cursor logic keeping the gsl::span for VLAs (#14607)
1 parent 06c1b84 commit df10dd3

File tree

7 files changed

+59
-57
lines changed

7 files changed

+59
-57
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -561,21 +561,21 @@ class ColumnIterator : ChunkingPolicy
561561
mLast = mCurrent + array->length() + (mFirstIndex >> SCALE_FACTOR);
562562
}
563563

564-
decltype(auto) operator*() const
564+
auto operator*() const
565565
requires std::same_as<bool, std::decay_t<T>>
566566
{
567567
checkSkipChunk();
568568
return (*(mCurrent - (mOffset >> SCALE_FACTOR) + ((*mCurrentPos + mOffset) >> SCALE_FACTOR)) & (1 << ((*mCurrentPos + mOffset) & 0x7))) != 0;
569569
}
570570

571-
decltype(auto) operator*() const
571+
auto operator*() const
572572
requires((!std::same_as<bool, std::decay_t<T>>) && std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
573573
{
574574
checkSkipChunk();
575575
auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
576576
auto offset = list->value_offset(*mCurrentPos - mFirstIndex);
577577
auto length = list->value_length(*mCurrentPos - mFirstIndex);
578-
return gsl::span{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)};
578+
return gsl::span<unwrap_t<T> const>{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)};
579579
}
580580

581581
decltype(auto) operator*() const
@@ -851,7 +851,7 @@ struct FilteredIndexPolicy : IndexPolicyBase {
851851
// which happens below which will properly setup the first index
852852
// by remapping the filtered index 0 to whatever unfiltered index
853853
// it belongs to.
854-
FilteredIndexPolicy(gsl::span<int64_t const> selection, int64_t rows, uint64_t offset = 0)
854+
FilteredIndexPolicy(std::span<int64_t const> selection, int64_t rows, uint64_t offset = 0)
855855
: IndexPolicyBase{-1, offset},
856856
mSelectedRows(selection),
857857
mMaxSelection(selection.size()),
@@ -860,7 +860,7 @@ struct FilteredIndexPolicy : IndexPolicyBase {
860860
this->setCursor(0);
861861
}
862862

863-
void resetSelection(gsl::span<int64_t const> selection)
863+
void resetSelection(std::span<int64_t const> selection)
864864
{
865865
mSelectedRows = selection;
866866
mMaxSelection = selection.size();
@@ -944,7 +944,7 @@ struct FilteredIndexPolicy : IndexPolicyBase {
944944
{
945945
this->mRowIndex = O2_BUILTIN_LIKELY(mSelectionRow < mMaxSelection) ? mSelectedRows[mSelectionRow] : -1;
946946
}
947-
gsl::span<int64_t const> mSelectedRows;
947+
std::span<int64_t const> mSelectedRows;
948948
int64_t mSelectionRow = 0;
949949
int64_t mMaxSelection = 0;
950950
int64_t nRows = 0;
@@ -1428,7 +1428,7 @@ struct PreslicePolicyGeneral : public PreslicePolicyBase {
14281428
void updateSliceInfo(SliceInfoUnsortedPtr&& si);
14291429

14301430
SliceInfoUnsortedPtr sliceInfo;
1431-
gsl::span<const int64_t> getSliceFor(int value) const;
1431+
std::span<const int64_t> getSliceFor(int value) const;
14321432
};
14331433

14341434
template <typename T, typename Policy, bool OPT = false>
@@ -1453,7 +1453,7 @@ struct PresliceBase : public Policy {
14531453
return Policy::getSliceFor(value, input, offset);
14541454
}
14551455

1456-
gsl::span<const int64_t> getSliceFor(int value) const
1456+
std::span<const int64_t> getSliceFor(int value) const
14571457
{
14581458
if constexpr (OPT) {
14591459
if (Policy::isMissing()) {
@@ -1549,7 +1549,7 @@ auto doSliceBy(T const* table, o2::framework::PresliceBase<C, Policy, OPT> const
15491549
}
15501550

15511551
template <soa::is_filtered_table T>
1552-
auto doSliceByHelper(T const* table, gsl::span<const int64_t> const& selection)
1552+
auto doSliceByHelper(T const* table, std::span<const int64_t> const& selection)
15531553
{
15541554
auto t = soa::Filtered<typename T::base_t>({table->asArrowTable()}, selection);
15551555
table->copyIndexBindings(t);
@@ -1560,7 +1560,7 @@ auto doSliceByHelper(T const* table, gsl::span<const int64_t> const& selection)
15601560

15611561
template <soa::is_table T>
15621562
requires(!soa::is_filtered_table<T>)
1563-
auto doSliceByHelper(T const* table, gsl::span<const int64_t> const& selection)
1563+
auto doSliceByHelper(T const* table, std::span<const int64_t> const& selection)
15641564
{
15651565
auto t = soa::Filtered<T>({table->asArrowTable()}, selection);
15661566
table->copyIndexBindings(t);
@@ -1581,7 +1581,7 @@ auto doSliceBy(T const* table, o2::framework::PresliceBase<C, Policy, OPT> const
15811581
return doSliceByHelper(table, selection);
15821582
}
15831583

1584-
SelectionVector sliceSelection(gsl::span<int64_t const> const& mSelectedRows, int64_t nrows, uint64_t offset);
1584+
SelectionVector sliceSelection(std::span<int64_t const> const& mSelectedRows, int64_t nrows, uint64_t offset);
15851585

15861586
template <soa::is_filtered_table T>
15871587
auto prepareFilteredSlice(T const* table, std::shared_ptr<arrow::Table> slice, uint64_t offset)
@@ -2011,7 +2011,7 @@ class Table
20112011
return RowViewSentinel{mEnd};
20122012
}
20132013

2014-
filtered_iterator filtered_begin(gsl::span<int64_t const> selection)
2014+
filtered_iterator filtered_begin(std::span<int64_t const> selection)
20152015
{
20162016
// Note that the FilteredIndexPolicy will never outlive the selection which
20172017
// is held by the table, so we are safe passing the bare pointer. If it does it
@@ -3371,15 +3371,15 @@ class FilteredBase : public T
33713371
mSelectedRowsCache{std::move(selection)},
33723372
mCached{true}
33733373
{
3374-
mSelectedRows = gsl::span{mSelectedRowsCache};
3374+
mSelectedRows = std::span{mSelectedRowsCache};
33753375
if (this->tableSize() != 0) {
33763376
mFilteredBegin = table_t::filtered_begin(mSelectedRows);
33773377
}
33783378
resetRanges();
33793379
mFilteredBegin.bindInternalIndices(this);
33803380
}
33813381

3382-
FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, gsl::span<int64_t const> const& selection, uint64_t offset = 0)
3382+
FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
33833383
: T{std::move(tables), offset},
33843384
mSelectedRows{selection}
33853385
{
@@ -3458,12 +3458,12 @@ class FilteredBase : public T
34583458
static inline auto getSpan(gandiva::Selection const& sel)
34593459
{
34603460
if (sel == nullptr) {
3461-
return gsl::span<int64_t const>{};
3461+
return std::span<int64_t const>{};
34623462
}
34633463
auto array = std::static_pointer_cast<arrow::Int64Array>(sel->ToArray());
34643464
auto start = array->raw_values();
34653465
auto stop = start + array->length();
3466-
return gsl::span{start, stop};
3466+
return std::span{start, stop};
34673467
}
34683468

34693469
/// Bind the columns which refer to other tables
@@ -3562,7 +3562,7 @@ class FilteredBase : public T
35623562
resetRanges();
35633563
}
35643564

3565-
void sumWithSelection(gsl::span<int64_t const> const& selection)
3565+
void sumWithSelection(std::span<int64_t const> const& selection)
35663566
{
35673567
mCached = true;
35683568
SelectionVector rowsUnion;
@@ -3572,7 +3572,7 @@ class FilteredBase : public T
35723572
resetRanges();
35733573
}
35743574

3575-
void intersectWithSelection(gsl::span<int64_t const> const& selection)
3575+
void intersectWithSelection(std::span<int64_t const> const& selection)
35763576
{
35773577
mCached = true;
35783578
SelectionVector intersection;
@@ -3591,7 +3591,7 @@ class FilteredBase : public T
35913591
void resetRanges()
35923592
{
35933593
if (mCached) {
3594-
mSelectedRows = gsl::span{mSelectedRowsCache};
3594+
mSelectedRows = std::span{mSelectedRowsCache};
35953595
}
35963596
mFilteredEnd.reset(new RowViewSentinel{static_cast<int64_t>(mSelectedRows.size())});
35973597
if (tableSize() == 0) {
@@ -3601,7 +3601,7 @@ class FilteredBase : public T
36013601
}
36023602
}
36033603

3604-
gsl::span<int64_t const> mSelectedRows;
3604+
std::span<int64_t const> mSelectedRows;
36053605
SelectionVector mSelectedRowsCache;
36063606
bool mCached = false;
36073607
iterator mFilteredBegin;
@@ -3637,7 +3637,7 @@ class Filtered : public FilteredBase<T>
36373637
Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
36383638
: FilteredBase<T>(std::move(tables), std::forward<SelectionVector>(selection), offset) {}
36393639

3640-
Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, gsl::span<int64_t const> const& selection, uint64_t offset = 0)
3640+
Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
36413641
: FilteredBase<T>(std::move(tables), selection, offset) {}
36423642

36433643
Filtered<T> operator+(SelectionVector const& selection)
@@ -3647,7 +3647,7 @@ class Filtered : public FilteredBase<T>
36473647
return copy;
36483648
}
36493649

3650-
Filtered<T> operator+(gsl::span<int64_t const> const& selection)
3650+
Filtered<T> operator+(std::span<int64_t const> const& selection)
36513651
{
36523652
Filtered<T> copy(*this);
36533653
copy.sumWithSelection(selection);
@@ -3665,7 +3665,7 @@ class Filtered : public FilteredBase<T>
36653665
return *this;
36663666
}
36673667

3668-
Filtered<T> operator+=(gsl::span<int64_t const> const& selection)
3668+
Filtered<T> operator+=(std::span<int64_t const> const& selection)
36693669
{
36703670
this->sumWithSelection(selection);
36713671
return *this;
@@ -3683,7 +3683,7 @@ class Filtered : public FilteredBase<T>
36833683
return copy;
36843684
}
36853685

3686-
Filtered<T> operator*(gsl::span<int64_t const> const& selection)
3686+
Filtered<T> operator*(std::span<int64_t const> const& selection)
36873687
{
36883688
Filtered<T> copy(*this);
36893689
copy.intersectWithSelection(selection);
@@ -3701,7 +3701,7 @@ class Filtered : public FilteredBase<T>
37013701
return *this;
37023702
}
37033703

3704-
Filtered<T> operator*=(gsl::span<int64_t const> const& selection)
3704+
Filtered<T> operator*=(std::span<int64_t const> const& selection)
37053705
{
37063706
this->intersectWithSelection(selection);
37073707
return *this;
@@ -3809,7 +3809,7 @@ class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
38093809
}
38103810
}
38113811

3812-
Filtered(std::vector<Filtered<T>>&& tables, gsl::span<int64_t const> const& selection, uint64_t offset = 0)
3812+
Filtered(std::vector<Filtered<T>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
38133813
: FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), selection, offset)
38143814
{
38153815
for (auto& table : tables) {
@@ -3824,7 +3824,7 @@ class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
38243824
return copy;
38253825
}
38263826

3827-
Filtered<Filtered<T>> operator+(gsl::span<int64_t const> const& selection)
3827+
Filtered<Filtered<T>> operator+(std::span<int64_t const> const& selection)
38283828
{
38293829
Filtered<Filtered<T>> copy(*this);
38303830
copy.sumWithSelection(selection);
@@ -3842,7 +3842,7 @@ class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
38423842
return *this;
38433843
}
38443844

3845-
Filtered<Filtered<T>> operator+=(gsl::span<int64_t const> const& selection)
3845+
Filtered<Filtered<T>> operator+=(std::span<int64_t const> const& selection)
38463846
{
38473847
this->sumWithSelection(selection);
38483848
return *this;
@@ -3860,7 +3860,7 @@ class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
38603860
return copy;
38613861
}
38623862

3863-
Filtered<Filtered<T>> operator*(gsl::span<int64_t const> const& selection)
3863+
Filtered<Filtered<T>> operator*(std::span<int64_t const> const& selection)
38643864
{
38653865
Filtered<Filtered<T>> copy(*this);
38663866
copy.intersectionWithSelection(selection);
@@ -3878,7 +3878,7 @@ class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
38783878
return *this;
38793879
}
38803880

3881-
Filtered<Filtered<T>> operator*=(gsl::span<int64_t const> const& selection)
3881+
Filtered<Filtered<T>> operator*=(std::span<int64_t const> const& selection)
38823882
{
38833883
this->intersectWithSelection(selection);
38843884
return *this;
@@ -3987,7 +3987,7 @@ struct SmallGroupsBase : public Filtered<T> {
39873987
SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
39883988
: Filtered<T>(std::move(tables), std::forward<SelectionVector>(selection), offset) {}
39893989

3990-
SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, gsl::span<int64_t const> const& selection, uint64_t offset = 0)
3990+
SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
39913991
: Filtered<T>(std::move(tables), selection, offset) {}
39923992
};
39933993

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,19 @@ class TableConsumer;
119119
template <typename T>
120120
concept is_producable = soa::has_metadata<aod::MetadataTrait<T>> || soa::has_metadata<aod::MetadataTrait<typename T::parent_t>>;
121121

122+
template <typename T>
123+
concept is_enumerated_iterator = requires(T t) { t.globalIndex(); };
124+
122125
template <is_producable T>
123126
struct WritingCursor {
124127
public:
125128
using persistent_table_t = decltype([]() { if constexpr (soa::is_iterator<T>) { return typename T::parent_t{nullptr}; } else { return T{nullptr}; } }());
126129
using cursor_t = decltype(std::declval<TableBuilder>().cursor<persistent_table_t>());
127130

128131
template <typename... Ts>
129-
void operator()(Ts... args)
132+
void operator()(Ts&&... args)
133+
requires(sizeof...(Ts) == framework::pack_size(typename persistent_table_t::persistent_columns_t{}))
130134
{
131-
static_assert(sizeof...(Ts) == framework::pack_size(typename persistent_table_t::persistent_columns_t{}), "Argument number mismatch");
132135
++mCount;
133136
cursor(0, extract(args)...);
134137
}
@@ -167,15 +170,14 @@ struct WritingCursor {
167170
decltype(FFL(std::declval<cursor_t>())) cursor;
168171

169172
private:
170-
template <typename A>
171-
requires requires { &A::globalIndex; }
172-
static decltype(auto) extract(A const& arg)
173+
static decltype(auto) extract(is_enumerated_iterator auto const& arg)
173174
{
174175
return arg.globalIndex();
175176
}
176177

177178
template <typename A>
178-
static decltype(auto) extract(A const& arg)
179+
requires(!is_enumerated_iterator<A>)
180+
static decltype(auto) extract(A&& arg)
179181
{
180182
return arg;
181183
}

Framework/Core/include/Framework/ArrowTableSlicingCache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ struct SliceInfoPtr {
2828
};
2929

3030
struct SliceInfoUnsortedPtr {
31-
gsl::span<int const> values;
31+
std::span<int const> values;
3232
ListVector const* groups;
3333

34-
gsl::span<int64_t const> getSliceFor(int value) const;
34+
std::span<int64_t const> getSliceFor(int value) const;
3535
};
3636

3737
struct Entry {

Framework/Core/include/Framework/GroupSlicer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ struct GroupSlicer {
264264
std::tuple<A...>* mAt;
265265
typename grouping_t::iterator mGroupingElement;
266266
uint64_t position = 0;
267-
gsl::span<int64_t const> groupSelection;
268-
std::array<gsl::span<int64_t const> const*, sizeof...(A)> selections;
269-
std::array<gsl::span<int64_t const>::iterator, sizeof...(A)> starts;
267+
std::span<int64_t const> groupSelection;
268+
std::array<std::span<int64_t const> const*, sizeof...(A)> selections;
269+
std::array<std::span<int64_t const>::iterator, sizeof...(A)> starts;
270270

271271
std::array<SliceInfoPtr, sizeof...(A)> sliceInfos;
272272
std::array<SliceInfoUnsortedPtr, sizeof...(A)> sliceInfosUnsorted;

0 commit comments

Comments
 (0)