Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPL Analysis: reduce usage of selected_pack #12678

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 52 additions & 18 deletions Framework/Core/include/Framework/ASoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ struct Binding {
void accessingInvalidIndexFor(const char* getter);
void dereferenceWithWrongType();

template <typename... C>
auto createFieldsFromColumns(framework::pack<C...>)
{
return std::vector<std::shared_ptr<arrow::Field>>{C::asArrowField()...};
}

using SelectionVector = std::vector<int64_t>;

template <typename, typename = void>
Expand Down Expand Up @@ -574,6 +568,19 @@ struct is_index<Ref<Args...>, Ref> : std::true_type {
template <typename T>
using is_index_t = is_index<T, Index>;

template <typename... C>
auto createFieldsFromColumns(framework::pack<C...>)
{
std::vector<std::shared_ptr<arrow::Field>> result;
([&]() {
if constexpr (soa::is_persistent_v<C>) {
result.push_back(C::asArrowField());
}
}(),
...);
return result;
}

struct IndexPolicyBase {
/// Position inside the current table
int64_t mRowIndex = 0;
Expand Down Expand Up @@ -775,6 +782,30 @@ struct FilteredIndexPolicy : IndexPolicyBase {
template <typename... C>
class Table;

template <typename... Cs>
constexpr auto select_persistent(framework::pack<Cs...>)
{
return framework::selected_pack<is_persistent_t, Cs...>{};
}

template <typename... Cs>
constexpr auto select_external_index(framework::pack<Cs...>)
{
return framework::selected_pack<is_external_index_t, Cs...>{};
}

template <typename... Cs>
constexpr auto select_internal_index(framework::pack<Cs...>)
{
return framework::selected_pack<is_self_index_t, Cs...>{};
}

template <typename... Cs>
constexpr auto select_dynamic(framework::pack<Cs...>)
{
return framework::selected_pack<is_dynamic_t, Cs...>{};
}

/// Similar to a pair but not a pair, to avoid
/// exposing the second type everywhere.
template <typename C>
Expand All @@ -789,7 +820,6 @@ struct RowViewCore : public IP, C... {
using policy_t = IP;
using table_t = o2::soa::Table<C...>;
using all_columns = framework::pack<C...>;
using persistent_columns_t = framework::selected_pack<is_persistent_t, C...>;
using dynamic_columns_t = framework::selected_pack<is_dynamic_t, C...>;
using index_columns_t = framework::selected_pack<is_index_t, C...>;
constexpr inline static bool has_index_v = framework::pack_size(index_columns_t{}) > 0;
Expand All @@ -800,7 +830,7 @@ struct RowViewCore : public IP, C... {
: IP{policy},
C(columnData[framework::has_type_at_v<C>(all_columns{})])...
{
bindIterators(persistent_columns_t{});
bindIterators(all_columns{});
bindAllDynamicColumns(dynamic_columns_t{});
// In case we have an index column might need to constrain the actual
// number of rows in the view to the range provided by the index.
Expand All @@ -816,23 +846,23 @@ struct RowViewCore : public IP, C... {
: IP{static_cast<IP const&>(other)},
C(static_cast<C const&>(other))...
{
bindIterators(persistent_columns_t{});
bindIterators(all_columns{});
bindAllDynamicColumns(dynamic_columns_t{});
}

RowViewCore(RowViewCore&& other) noexcept
{
IP::operator=(static_cast<IP&&>(other));
(void(static_cast<C&>(*this) = static_cast<C&&>(other)), ...);
bindIterators(persistent_columns_t{});
bindIterators(all_columns{});
bindAllDynamicColumns(dynamic_columns_t{});
}

RowViewCore& operator=(RowViewCore const& other)
{
IP::operator=(static_cast<IP const&>(other));
(void(static_cast<C&>(*this) = static_cast<C const&>(other)), ...);
bindIterators(persistent_columns_t{});
bindIterators(all_columns{});
bindAllDynamicColumns(dynamic_columns_t{});
return *this;
}
Expand Down Expand Up @@ -972,7 +1002,12 @@ struct RowViewCore : public IP, C... {
auto bindIterators(framework::pack<PC...>)
{
using namespace o2::soa;
(void(PC::mColumnIterator.mCurrentPos = &this->mRowIndex), ...);
([&]() {
if constexpr (soa::is_persistent_v<PC>) {
PC::mColumnIterator.mCurrentPos = &this->mRowIndex;
}
}(),
...);
}

template <typename... DC>
Expand Down Expand Up @@ -1069,7 +1104,7 @@ static auto hasColumnForKey(framework::pack<C...>, std::string const& key)
template <typename T>
static std::pair<bool, std::string> hasKey(std::string const& key)
{
return {hasColumnForKey(typename T::persistent_columns_t{}, key), getLabelFromType<T>()};
return {hasColumnForKey(typename T::columns{}, key), getLabelFromType<T>()};
}

template <typename... C>
Expand Down Expand Up @@ -1369,6 +1404,9 @@ auto select(T const& t, framework::expressions::Filter const& f)

arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label);

template <typename... Cs>
using select_persistent_t = decltype(select_persistent(framework::pack<Cs...>{}));

/// A Table class which observes an arrow::Table and provides
/// It is templated on a set of Column / DynamicColumn types.
template <typename... C>
Expand All @@ -1379,7 +1417,6 @@ class Table
using table_t = Table<C...>;
using columns = framework::pack<C...>;
using column_types = framework::pack<typename C::type...>;
using persistent_columns_t = framework::selected_pack<is_persistent_t, C...>;
using external_index_columns_t = framework::selected_pack<is_external_index_t, C...>;
using internal_index_columns_t = framework::selected_pack<is_self_index_t, C...>;

Expand Down Expand Up @@ -1538,7 +1575,7 @@ class Table
{
if constexpr (framework::has_type_conditional_v<is_binding_compatible, Key, external_index_columns_t>) {
using IC = framework::pack_element_t<framework::has_type_at_conditional<is_binding_compatible, Key>(external_index_columns_t{}), external_index_columns_t>;
return mColumnChunks[framework::has_type_at<IC>(persistent_columns_t{})];
return mColumnChunks[framework::has_type_at<IC>(select_persistent(columns{}))];
} else if constexpr (std::is_same_v<table_t, Key>) {
return nullptr;
} else {
Expand Down Expand Up @@ -2691,7 +2728,6 @@ struct Join : JoinBase<Ts...> {

using self_t = Join<Ts...>;
using table_t = base;
using persistent_columns_t = typename table_t::persistent_columns_t;
using iterator = typename table_t::template RowView<Join<Ts...>, Ts...>;
using const_iterator = iterator;
using unfiltered_iterator = iterator;
Expand Down Expand Up @@ -2801,7 +2837,6 @@ struct Concat : ConcatBase<T1, T2> {
using left_t = T1;
using right_t = T2;
using table_t = ConcatBase<T1, T2>;
using persistent_columns_t = typename table_t::persistent_columns_t;

using iterator = typename table_t::template RowView<Concat<T1, T2>, T1, T2>;
using filtered_iterator = typename table_t::template RowViewFiltered<Concat<T1, T2>, T1, T2>;
Expand All @@ -2826,7 +2861,6 @@ class FilteredBase : public T
using self_t = FilteredBase<T>;
using originals = originals_pack_t<T>;
using table_t = typename T::table_t;
using persistent_columns_t = typename T::persistent_columns_t;
using external_index_columns_t = typename T::external_index_columns_t;

template <typename P, typename... Os>
Expand Down
2 changes: 1 addition & 1 deletion Framework/Core/include/Framework/ASoAHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
selectedRows = table.getSelectedRows(); // vector<int64_t>
}

auto persistentColumns = typename BP<Cs...>::persistent_columns_t{};
auto persistentColumns = o2::soa::select_persistent(framework::pack<Cs...>{});
constexpr auto persistentColumnsCount = pack_size(persistentColumns);
auto arrowColumns = o2::soa::row_helpers::getArrowColumns(arrowTable, persistentColumns);
auto chunksCount = arrowColumns[0]->num_chunks();
Expand Down
17 changes: 3 additions & 14 deletions Framework/Core/include/Framework/AnalysisHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ struct OutputForTable {
/// means of the WritingCursor helper class, from which produces actually
/// derives.
template <typename T>
struct Produces : WritingCursor<typename soa::PackToTable<typename T::table_t::persistent_columns_t>::table> {
struct Produces : WritingCursor<typename soa::PackToTable<decltype(o2::soa::select_persistent(typename T::table_t::columns{}))>::table> {
};

template <template <typename...> class T, typename... C>
struct Produces<T<C...>> : WritingCursor<typename soa::PackToTable<typename T<C...>::table_t::persistent_columns_t>::table> {
struct Produces<T<C...>> : WritingCursor<typename soa::PackToTable<decltype(o2::soa::select_persistent(typename T<C...>::table_t::columns{}))>::table> {
};

/// Helper template for table transformations
Expand Down Expand Up @@ -233,7 +233,7 @@ template <typename T, typename Key>
inline std::shared_ptr<arrow::ChunkedArray> getIndexToKey(arrow::Table* table)
{
using IC = framework::pack_element_t<framework::has_type_at_conditional<soa::is_binding_compatible, Key>(typename T::external_index_columns_t{}), typename T::external_index_columns_t>;
return table->column(framework::has_type_at<IC>(typename T::persistent_columns_t{}));
return table->column(framework::has_type_at<IC>(o2::soa::select_persistent(typename T::columns{})));
}

template <typename C>
Expand Down Expand Up @@ -310,17 +310,6 @@ struct IndexBuilder {
{self.template result<C1>(), std::static_pointer_cast<typename Reduction<Key, Cs>::type>(columnBuilders[framework::has_type_at_v<Cs>(framework::pack<Cs...>{})])->template result<Cs>()...},
{self.field(), std::static_pointer_cast<typename Reduction<Key, Cs>::type>(columnBuilders[framework::has_type_at_v<Cs>(framework::pack<Cs...>{})])->field()...});
}

template <typename IDX, typename Key, typename T1, typename... T>
static auto makeIndex(Key const& key, std::tuple<T1, T...>&& tables)
{
auto t = IDX{indexBuilder(o2::aod::MetadataTrait<IDX>::metadata::tableLabel(),
typename o2::aod::MetadataTrait<IDX>::metadata::index_pack_t{},
key,
std::make_tuple(std::decay_t<T1>{{std::get<T1>(tables)}}, std::decay_t<T>{{std::get<T>(tables)}}...))};
t.bindExternalIndices(&key, &std::get<T1>(tables), &std::get<T>(tables)...);
return t;
}
};

/// This helper struct allows you to declare index tables to be created in a task
Expand Down
4 changes: 2 additions & 2 deletions Framework/Core/include/Framework/AnalysisTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ struct AnalysisDataProcessorBuilder {
using dT = std::decay_t<T>;
if constexpr (is_enumeration_v<dT> == false) {
if constexpr (soa::is_soa_filtered_v<dT>) {
auto fields = createFieldsFromColumns(typename dT::table_t::persistent_columns_t{});
auto fields = createFieldsFromColumns(typename dT::table_t::columns{});
eInfos.emplace_back(ai, hash, dT::hashes(), std::make_shared<arrow::Schema>(fields));
} else if constexpr (soa::is_soa_iterator_v<dT>) {
auto fields = createFieldsFromColumns(typename dT::parent_t::persistent_columns_t{});
auto fields = createFieldsFromColumns(typename dT::parent_t::columns{});
if constexpr (std::is_same_v<typename dT::policy_t, soa::FilteredIndexPolicy>) {
eInfos.emplace_back(ai, hash, dT::parent_t::hashes(), std::make_shared<arrow::Schema>(fields));
}
Expand Down
8 changes: 0 additions & 8 deletions Framework/Core/include/Framework/BinningPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include "Framework/HistogramSpec.h" // only for VARIABLE_WIDTH
#include "Framework/Pack.h"
#include "Framework/ArrowTypes.h"
#include <optional>

namespace o2::framework
{
Expand Down Expand Up @@ -268,8 +266,6 @@ struct FlexibleBinningPolicy<std::tuple<Ls...>, Ts...> : BinningPolicyBase<sizeo
return BinningPolicyBase<sizeof...(Ts)>::template getBin<T2s...>(data);
}

using persistent_columns_t = framework::selected_pack<o2::soa::is_persistent_t, Ts...>;

private:
std::tuple<Ls...> mBinningFunctions;
};
Expand All @@ -296,8 +292,6 @@ struct ColumnBinningPolicy : BinningPolicyBase<sizeof...(Ts)> {
{
return BinningPolicyBase<sizeof...(Ts)>::template getBin<typename Ts::type...>(data);
}

using persistent_columns_t = framework::selected_pack<o2::soa::is_persistent_t, Ts...>;
};

template <typename C>
Expand All @@ -321,8 +315,6 @@ struct NoBinningPolicy {
{
return std::get<0>(data);
}

using persistent_columns_t = framework::selected_pack<o2::soa::is_persistent_t, C>;
};

} // namespace o2::framework
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ struct RootTableBuilderHelpers {
template <typename T>
static void convertASoA(TableBuilder& builder, TTreeReader& reader)
{
return convertASoAColumns(builder, reader, typename T::persistent_columns_t{});
return convertASoAColumns(builder, reader, o2::soa::select_persistent(typename T::columns{}));
}
};

Expand Down
4 changes: 2 additions & 2 deletions Framework/Core/include/Framework/TableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,15 @@ class TableBuilder
{
return [this]<typename... Cs>(pack<Cs...>) {
return this->template persist<typename Cs::type...>({Cs::columnLabel()...});
}(typename T::table_t::persistent_columns_t{});
}(o2::soa::select_persistent(typename T::table_t::columns{}));
}

template <typename T, typename E>
auto cursor()
{
return [this]<typename... Cs>(pack<Cs...>) {
return this->template persist<E>({Cs::columnLabel()...});
}(typename T::table_t::persistent_columns_t{});
}(o2::soa::select_persistent(typename T::table_t::columns{}));
}

template <typename... ARGS, size_t NCOLUMNS = sizeof...(ARGS)>
Expand Down
2 changes: 1 addition & 1 deletion Framework/Core/test/test_ASoA.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ TEST_CASE("TestDereference")

TEST_CASE("TestSchemaCreation")
{
auto schema = std::make_shared<arrow::Schema>(createFieldsFromColumns(o2::aod::Points::persistent_columns_t{}));
auto schema = std::make_shared<arrow::Schema>(createFieldsFromColumns(o2::aod::Points::columns{}));
REQUIRE(schema->num_fields() == 2);
REQUIRE(schema->field(0)->name() == "fX");
REQUIRE(schema->field(1)->name() == "fY");
Expand Down
2 changes: 1 addition & 1 deletion Framework/Core/test/test_Expressions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ TEST_CASE("TestGandivaTreeCreation")
REQUIRE(gandiva_expression2->ToString() == "if (bool less_than_or_equal_to(float absf((float) fSigned1Pt), (const float) 1.17549e-38 raw(7fffe1))) { (const float) 8.50709e+37 raw(7e80001f) } else { float absf(float divide((const float) 1 raw(3f800000), (float) fSigned1Pt)) }");

auto projector_b = createProjector(schema2, ptespecs, resfield2);
auto fields = o2::soa::createFieldsFromColumns(o2::aod::Tracks::persistent_columns_t{});
auto fields = o2::soa::createFieldsFromColumns(o2::aod::Tracks::columns{});
auto schema_p = std::make_shared<arrow::Schema>(fields);
auto projector_alt = o2::framework::expressions::createProjectors(o2::framework::pack<o2::aod::track::Pt>{}, fields, schema_p);

Expand Down
12 changes: 6 additions & 6 deletions Framework/Core/test/test_IndexBuilder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ DECLARE_SOA_INDEX_COLUMN(Flag, flag);
DECLARE_SOA_INDEX_COLUMN(Category, category);
} // namespace indices

DECLARE_SOA_TABLE(IDXs, "TST", "Index", Index<>, indices::PointId, indices::DistanceId, indices::FlagId, indices::CategoryId);
DECLARE_SOA_TABLE(IDX2s, "TST", "Index2", Index<>, indices::DistanceId, indices::PointId, indices::FlagId, indices::CategoryId);
DECLARE_SOA_TABLE(IDXs, "TST", "Index", indices::PointId, indices::DistanceId, indices::FlagId, indices::CategoryId);
DECLARE_SOA_TABLE(IDX2s, "TST", "Index2", indices::DistanceId, indices::PointId, indices::FlagId, indices::CategoryId);

TEST_CASE("TestIndexBuilder")
{
Expand Down Expand Up @@ -99,7 +99,7 @@ TEST_CASE("TestIndexBuilder")
auto t4 = b4.finalize();
Categorys st4{t4};

auto t5 = IndexBuilder<Exclusive>::indexBuilder<Points>("test1a", {t1, t2, t3, t4}, typename IDXs::persistent_columns_t{}, o2::framework::pack<Points, Distances, Flags, Categorys>{});
auto t5 = IndexBuilder<Exclusive>::indexBuilder<Points>("test1a", {t1, t2, t3, t4}, typename IDXs::columns{}, o2::framework::pack<Points, Distances, Flags, Categorys>{});
REQUIRE(t5->num_rows() == 4);
IDXs idxt{t5};
idxt.bindExternalIndices(&st1, &st2, &st3, &st4);
Expand All @@ -109,7 +109,7 @@ TEST_CASE("TestIndexBuilder")
REQUIRE(row.category().pointId() == row.pointId());
}

auto t6 = IndexBuilder<Sparse>::indexBuilder<Points>("test3", {t2, t1, t3, t4}, typename IDX2s::persistent_columns_t{}, o2::framework::pack<Distances, Points, Flags, Categorys>{});
auto t6 = IndexBuilder<Sparse>::indexBuilder<Points>("test3", {t2, t1, t3, t4}, typename IDX2s::columns{}, o2::framework::pack<Distances, Points, Flags, Categorys>{});
REQUIRE(t6->num_rows() == st2.size());
IDXs idxs{t6};
std::array<int, 7> fs{0, 1, 2, -1, -1, 4, -1};
Expand Down Expand Up @@ -146,7 +146,7 @@ DECLARE_SOA_SLICE_INDEX_COLUMN(BinnedPoint, binsSlice);
DECLARE_SOA_ARRAY_INDEX_COLUMN(ColoredPoint, colorsList);
} // namespace indices

DECLARE_SOA_TABLE(IDX3s, "TST", "Index3", Index<>, indices::PointId, indices::BinnedPointIdSlice, indices::ColoredPointIds);
DECLARE_SOA_TABLE(IDX3s, "TST", "Index3", indices::PointId, indices::BinnedPointIdSlice, indices::ColoredPointIds);

TEST_CASE("AdvancedIndexTables")
{
Expand Down Expand Up @@ -204,7 +204,7 @@ TEST_CASE("AdvancedIndexTables")
{14, 34},
{8, 31, 42, 46, 58}}};

auto t3 = IndexBuilder<Sparse>::indexBuilder<Points>("test4", {t1, t2, tc}, typename IDX3s::persistent_columns_t{}, o2::framework::pack<Points, BinnedPoints, ColoredPoints>{});
auto t3 = IndexBuilder<Sparse>::indexBuilder<Points>("test4", {t1, t2, tc}, typename IDX3s::columns{}, o2::framework::pack<Points, BinnedPoints, ColoredPoints>{});
REQUIRE(t3->num_rows() == st1.size());
IDX3s idxs{t3};
idxs.bindExternalIndices(&st1, &st2, &st3);
Expand Down
Loading