Skip to content

Commit acf837f

Browse files
authored
DPL Analysis: Extend binning policy to accept lambdas (#9299)
* Improve tests for persistent and index columns * Remove leftover lines * Add default values for ci, ai, globalIndex to simplify user interface * Add index check * Binning policy changes minimized, backward compatible * Fully working version
1 parent 488ce41 commit acf837f

3 files changed

Lines changed: 164 additions & 60 deletions

File tree

Framework/Core/include/Framework/ASoA.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,32 +1512,41 @@ std::array<std::shared_ptr<arrow::Array>, sizeof...(Cs)> getChunks(arrow::Table*
15121512
return std::array<std::shared_ptr<arrow::Array>, sizeof...(Cs)>{o2::soa::getIndexFromLabel(table, Cs::columnLabel())->chunk(ci)...};
15131513
}
15141514

1515-
template <typename C>
1516-
typename C::type getSingleRowPersistentData(arrow::Table* table, uint64_t ci, uint64_t ai)
1515+
template <typename T, typename C>
1516+
typename C::type getSingleRowPersistentData(arrow::Table* table, T& rowIterator, uint64_t ci = -1, uint64_t ai = -1)
15171517
{
1518+
if (ci == -1 || ai == -1) {
1519+
auto colIterator = static_cast<C>(rowIterator).getIterator();
1520+
ci = colIterator.mCurrentChunk;
1521+
ai = *(colIterator.mCurrentPos) - colIterator.mFirstIndex;
1522+
}
15181523
return std::static_pointer_cast<o2::soa::arrow_array_for_t<typename C::type>>(o2::soa::getIndexFromLabel(table, C::columnLabel())->chunk(ci))->raw_values()[ai];
15191524
}
15201525

15211526
template <typename T, typename C>
1522-
typename C::type getSingleRowDynamicData(T& rowIterator, uint64_t globalIndex)
1527+
typename C::type getSingleRowDynamicData(T& rowIterator, uint64_t globalIndex = -1)
15231528
{
1524-
rowIterator.setCursor(globalIndex);
1529+
if (globalIndex != -1 && globalIndex != *std::get<0>(rowIterator.getIndices())) {
1530+
rowIterator.setCursor(globalIndex);
1531+
}
15251532
return rowIterator.template getDynamicColumn<C>();
15261533
}
15271534

15281535
template <typename T, typename C>
1529-
typename C::type getSingleRowIndexData(T& rowIterator, uint64_t globalIndex)
1536+
typename C::type getSingleRowIndexData(T& rowIterator, uint64_t globalIndex = -1)
15301537
{
1531-
rowIterator.setCursor(globalIndex);
1538+
if (globalIndex != -1 && globalIndex != *std::get<0>(rowIterator.getIndices())) {
1539+
rowIterator.setCursor(globalIndex);
1540+
}
15321541
return rowIterator.template getId<C>();
15331542
}
15341543

15351544
template <typename T, typename C>
1536-
typename C::type getSingleRowData(arrow::Table* table, T& rowIterator, uint64_t ci, uint64_t ai, uint64_t globalIndex)
1545+
typename C::type getSingleRowData(arrow::Table* table, T& rowIterator, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
15371546
{
15381547
using decayed = std::decay_t<C>;
15391548
if constexpr (decayed::persistent::value) {
1540-
return getSingleRowPersistentData<C>(table, ci, ai);
1549+
return getSingleRowPersistentData<T, C>(table, rowIterator, ci, ai);
15411550
} else if constexpr (o2::soa::is_dynamic_t<decayed>()) {
15421551
return getSingleRowDynamicData<T, C>(rowIterator, globalIndex);
15431552
} else if constexpr (o2::soa::is_index_t<decayed>::value) {
@@ -1548,7 +1557,7 @@ typename C::type getSingleRowData(arrow::Table* table, T& rowIterator, uint64_t
15481557
}
15491558

15501559
template <typename T, typename... Cs>
1551-
std::tuple<typename Cs::type...> getRowData(arrow::Table* table, T rowIterator, uint64_t ci, uint64_t ai, uint64_t globalIndex)
1560+
std::tuple<typename Cs::type...> getRowData(arrow::Table* table, T rowIterator, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
15521561
{
15531562
return std::make_tuple(getSingleRowData<T, Cs>(table, rowIterator, ci, ai, globalIndex)...);
15541563
}

Framework/Core/include/Framework/ASoAHelpers.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
125125
selInd = selectedRows[ind];
126126
}
127127

128-
auto rowData = o2::soa::row_helpers::getRowData<decltype(rowIterator), Cs...>(arrowTable, rowIterator, ci, ai, ind);
129-
130-
int val = binningPolicy.getBin(rowData);
128+
auto values = binningPolicy.getBinningValues(rowIterator, arrowTable, ci, ai, ind);
129+
auto val = binningPolicy.getBin(values);
131130
if (val != outsider) {
132131
groupedIndices.emplace_back(val, ind);
133132
}

0 commit comments

Comments
 (0)