Skip to content

Commit

Permalink
DPL Analysis: add a static constexpr function to check if a Join cont…
Browse files Browse the repository at this point in the history
…ains certain component (#10578)
  • Loading branch information
aalkin authored Jan 18, 2023
1 parent 31b07fa commit 6411869
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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>());
}

0 comments on commit 6411869

Please sign in to comment.