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: add a static constexpr function to check if a Join contains certain component #10578

Merged
merged 3 commits into from
Jan 18, 2023
Merged
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
17 changes: 17 additions & 0 deletions Framework/Core/include/Framework/ASoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ std::tuple<typename Cs::type...> getRowData(arrow::Table* table, T rowIterator,

namespace o2::soa
{

template <typename... Ts>
struct Join : JoinBase<Ts...> {
Join(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0);
Expand Down Expand Up @@ -2317,6 +2318,22 @@ struct Join : JoinBase<Ts...> {
static_assert(o2::framework::always_static_assert_v<T1>, "Wrong Preslice<> entry used: incompatible type");
}
}

template <typename T>
static constexpr bool contains()
{
if constexpr (is_type_with_originals_v<T>) {
return contains(typename T::originals{});
} else {
return framework::has_type_v<T, originals>;
}
}

template <typename... TTs>
static constexpr bool contains(framework::pack<TTs...>)
{
return (contains<TTs>() || ...);
}
};

template <typename... Ts>
Expand Down
9 changes: 9 additions & 0 deletions Framework/Core/test/test_ASoA.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,16 @@ BOOST_AUTO_TEST_CASE(TestJoinedTables)
using TestZ = o2::soa::Table<test::Z>;
using Test = Join<TestX, TestY>;

BOOST_CHECK(Test::contains<TestX>());
BOOST_CHECK(Test::contains<TestY>());
BOOST_CHECK(!Test::contains<TestZ>());

Test tests{0, tableX, tableY};

BOOST_CHECK(tests.contains<TestX>());
BOOST_CHECK(tests.contains<TestY>());
BOOST_CHECK(!tests.contains<TestZ>());

for (auto& test : tests) {
BOOST_CHECK_EQUAL(7, test.x() + test.y());
}
Expand Down
8 changes: 6 additions & 2 deletions Framework/Core/test/test_AnalysisDataModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ DECLARE_SOA_TABLE(ZD, "AOD", "ZD", col::Z, col::D);
BOOST_AUTO_TEST_CASE(TestJoinedTables)
{
TableBuilder XYBuilder;
//FIXME: using full tracks, instead of stored because of unbound dynamic
// column (normalized phi)
// FIXME: using full tracks, instead of stored because of unbound dynamic
// column (normalized phi)
auto xyWriter = XYBuilder.cursor<XY>();
xyWriter(0, 0, 0);
auto tXY = XYBuilder.finalize();
Expand All @@ -60,4 +60,8 @@ BOOST_AUTO_TEST_CASE(TestJoinedTables)
auto tests2 = join(XY{tXY}, ZD{tZD});
static_assert(std::is_same_v<Test::table_t, decltype(tests2)>,
"Joined tables should have the same type, regardless how we construct them");

using FullTracks = o2::soa::Join<o2::aod::Tracks, o2::aod::TracksExtra, o2::aod::TracksCov>;
BOOST_CHECK(FullTracks::contains<o2::aod::Tracks>());
BOOST_CHECK(!FullTracks::contains<o2::aod::Collisions>());
}