Skip to content

Commit e3fd03a

Browse files
committed
improve partition handling; update test
1 parent 591e23b commit e3fd03a

File tree

2 files changed

+87
-6
lines changed

2 files changed

+87
-6
lines changed

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,28 @@ struct Service {
805805
}
806806
};
807807

808-
template <typename T>
808+
template <soa::soaFilteredTable T>
809809
auto getTableFromFilter(const T& table, soa::SelectionVector&& selection)
810810
{
811-
if constexpr (soa::is_soa_filtered_v<std::decay_t<T>>) {
812-
return std::make_unique<o2::soa::Filtered<T>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
813-
} else {
814-
return std::make_unique<o2::soa::Filtered<T>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
815-
}
811+
return std::make_unique<o2::soa::Filtered<T>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
812+
}
813+
814+
template <soa::soaTable T> requires (!soa::soaFilteredTable<T>)
815+
auto getTableFromFilter(const T& table, soa::SelectionVector&& selection)
816+
{
817+
return std::make_unique<o2::soa::Filtered<T>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
818+
}
819+
820+
template <soa::ngFilteredTable T>
821+
auto getTableFromFilter(const T& table, soa::SelectionVector&& selection)
822+
{
823+
return std::make_unique<o2::soa::FilteredNG<T>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
824+
}
825+
826+
template <soa::ngTable T> requires (!soa::ngFilteredTable<T>)
827+
auto getTableFromFilter(const T& table, soa::SelectionVector&& selection)
828+
{
829+
return std::make_unique<o2::soa::FilteredNG<T>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
816830
}
817831

818832
void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter);

Framework/Core/test/test_AnalysisTask.cxx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using namespace o2::framework;
2121

2222
namespace o2::aod
2323
{
24+
O2HASH("TestA/0");
2425
namespace test
2526
{
2627
DECLARE_SOA_COLUMN(X, x, float);
@@ -404,3 +405,69 @@ TEST_CASE("TestPartitionIteration")
404405
}
405406
REQUIRE(i == 1);
406407
}
408+
409+
TEST_CASE("TestPartitionIterationNG")
410+
{
411+
TableBuilder builderA;
412+
auto rowWriterA = builderA.persist<float, float>({"fX", "fY"});
413+
rowWriterA(0, 0.0f, 8.0f);
414+
rowWriterA(0, 1.0f, 9.0f);
415+
rowWriterA(0, 2.0f, 10.0f);
416+
rowWriterA(0, 3.0f, 11.0f);
417+
rowWriterA(0, 4.0f, 12.0f);
418+
rowWriterA(0, 5.0f, 13.0f);
419+
rowWriterA(0, 6.0f, 14.0f);
420+
rowWriterA(0, 7.0f, 15.0f);
421+
auto tableA = builderA.finalize();
422+
REQUIRE(tableA->num_rows() == 8);
423+
424+
using TestA = soa::InPlaceTableNG<"TestA/0"_h, o2::soa::Index<>, aod::test::X, aod::test::Y>;
425+
using FilteredTest = o2::soa::FilteredNG<TestA>;
426+
using PartitionTest = PartitionNG<TestA>;
427+
using PartitionFilteredTest = PartitionNG<o2::soa::FilteredNG<TestA>>;
428+
using PartitionNestedFilteredTest = PartitionNG<o2::soa::FilteredNG<o2::soa::FilteredNG<TestA>>>;
429+
using namespace o2::framework;
430+
431+
TestA testA{tableA};
432+
433+
PartitionTest p1 = aod::test::x < 4.0f;
434+
p1.bindTable(testA);
435+
REQUIRE(4 == p1.size());
436+
REQUIRE(p1.begin() != p1.end());
437+
auto i = 0;
438+
for (auto& p : p1) {
439+
REQUIRE(i == p.x());
440+
REQUIRE(i + 8 == p.y());
441+
REQUIRE(i == p.index());
442+
i++;
443+
}
444+
REQUIRE(i == 4);
445+
446+
expressions::Filter f1 = aod::test::x < 4.0f;
447+
auto selection = expressions::createSelection(testA.asArrowTable(), f1);
448+
FilteredTest filtered{{testA.asArrowTable()}, o2::soa::selectionToVector(selection)};
449+
PartitionFilteredTest p2 = aod::test::y > 9.0f;
450+
p2.bindTable(filtered);
451+
452+
REQUIRE(2 == p2.size());
453+
i = 0;
454+
for (auto& p : p2) {
455+
REQUIRE(i + 2 == p.x());
456+
REQUIRE(i + 10 == p.y());
457+
REQUIRE(i + 2 == p.index());
458+
i++;
459+
}
460+
REQUIRE(i == 2);
461+
462+
PartitionNestedFilteredTest p3 = aod::test::x < 3.0f;
463+
p3.bindTable(*(p2.mFiltered));
464+
REQUIRE(1 == p3.size());
465+
i = 0;
466+
for (auto& p : p3) {
467+
REQUIRE(i + 2 == p.x());
468+
REQUIRE(i + 10 == p.y());
469+
REQUIRE(i + 2 == p.index());
470+
i++;
471+
}
472+
REQUIRE(i == 1);
473+
}

0 commit comments

Comments
 (0)