Skip to content

Commit cacc984

Browse files
committed
add test for table extension
1 parent b92d987 commit cacc984

File tree

6 files changed

+107
-29
lines changed

6 files changed

+107
-29
lines changed

Framework/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ add_executable(o2-test-framework-core
236236
test/test_Services.cxx
237237
test/test_StringHelpers.cxx
238238
test/test_StaticFor.cxx
239+
test/test_TableSpawner.cxx
239240
test/test_TMessageSerializer.cxx
240241
test/test_TableBuilder.cxx
241242
test/test_TimeParallelPipelining.cxx

Framework/Core/include/Framework/ASoA.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,28 +3925,29 @@ consteval auto getIndexTargets()
39253925
O2HASH(_Label_); \
39263926
O2HASH(_Desc_ "/" #_Version_); \
39273927
template <typename O> \
3928-
using _Name_##ExtensionFrom = TableNG<Hash<_Label_ ""_h>, Hash<_Desc "/" #_Version_ ""_h>, O>; \
3929-
using _Name_##Extension = _Name_##ExtensionFrom<Hash<_Origin_ ""_h>>; \
3930-
template <> \
3931-
struct MetadataTraitNG<Hash<_Desc_ "/" #_Version_ ""_h>> { \
3932-
using metadata = _Name_##ExtensionMetadata; \
3933-
}; \
3928+
using _Name_##ExtensionFrom = TableNG<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3929+
using _Name_##Extension = _Name_##ExtensionFrom<o2::aod::Hash<_Origin_ ""_h>>; \
39343930
template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3935-
struct _Name_##ExtensionMetadata : TableMetadataNG<Hash<_Desc "/" #_Version_ ""_h>, __VA_ARGS__> { \
3931+
struct _Name_##ExtensionMetadataFrom : TableMetadataNG<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
39363932
using base_table_t = _OriginalTable_; \
39373933
using extension_table_t = _Name_##ExtensionFrom<O>; \
3938-
using expression_pack_t = framework::pack<__VA_ARGS>; \
3934+
using expression_pack_t = framework::pack<__VA_ARGS__>; \
39393935
static constexpr auto sources = _OriginalTable_::originals; \
39403936
}; \
3937+
using _Name_##ExtensionMetadata = _Name_##ExtensionMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3938+
template <> \
3939+
struct MetadataTraitNG<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3940+
using metadata = _Name_##ExtensionMetadata; \
3941+
}; \
39413942
template <typename O> \
39423943
using _Name_##From = o2::soa::JoinNGFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _OriginalTable_, _Name_##ExtensionFrom<O>>; \
3943-
using _Name_ = _Name_##From < o2::aod::Hash<_Origin_ ""_h>;
3944+
using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
39443945

39453946
#define DECLARE_SOA_EXTENDED_TABLE_NG(_Name_, _Table_, _Description_, ...) \
3946-
DECLARE_SOA_EXTENDED_TABLE_NG_FULL(_Name_, _Table_, "DYN", _Description_, __VA_ARGS__)
3947+
DECLARE_SOA_EXTENDED_TABLE_NG_FULL(_Name_, #_Name_, _Table_, "DYN", _Description_, 0, __VA_ARGS__)
39473948

39483949
#define DECLARE_SOA_EXTENDED_TABLE_NG_USER(_Name_, _Table_, _Description_, ...) \
3949-
DECLARE_SOA_EXTENDED_TABLE_NG_FULL(_Name_, _Table_, "AOD", _Description_, __VA_ARGS__)
3950+
DECLARE_SOA_EXTENDED_TABLE_NG_FULL(_Name_, #_Name_, _Table_, "AOD", _Description_, 0, __VA_ARGS__)
39503951

39513952
#define DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, _Origin_, _Description_, _Exclusive_, ...) \
39523953
template <o2::soa::OriginEnc ORIGIN = o2::soa::OriginEnc{_Origin_}> \

Framework/Core/include/Framework/AnalysisManagers.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,22 +455,22 @@ struct OutputManager<SpawnsNG<T>> {
455455
using metadata = o2::aod::MetadataTraitNG<o2::aod::Hash<T::ref.desc_hash>>::metadata;
456456
auto originalTable = soa::ArrowHelpers::joinTables(extractOriginals<metadata::sources>(pc));
457457
if (originalTable->schema()->fields().empty() == true) {
458-
using base_table_t = typename Spawns<T>::base_table_t::table_t;
458+
using base_table_t = typename SpawnsNG<T>::base_table_t::table_t;
459459
originalTable = makeEmptyTable<base_table_t>(o2::aod::Hash<metadata::extension_table_t::ref.label_hash>::str);
460460
}
461461

462-
what.extension = std::make_shared<typename Spawns<T>::extension_t>(o2::framework::spawner<o2::aod::Hash<metadata::extension_t::ref.desc_hash>>(originalTable, o2::aod::Hash<metadata::extension_table_t::ref.label_hash>::str));
462+
what.extension = std::make_shared<typename SpawnsNG<T>::extension_t>(o2::framework::spawner<o2::aod::Hash<metadata::extension_t::ref.desc_hash>>(originalTable, o2::aod::Hash<metadata::extension_table_t::ref.label_hash>::str));
463463
what.table = std::make_shared<typename T::table_t>(soa::ArrowHelpers::joinTables({what.extension->asArrowTable(), originalTable}));
464464
return true;
465465
}
466466

467-
static bool finalize(ProcessingContext& pc, Spawns<T>& what)
467+
static bool finalize(ProcessingContext& pc, SpawnsNG<T>& what)
468468
{
469469
pc.outputs().adopt(what.output(), what.asArrowTable());
470470
return true;
471471
}
472472

473-
static bool postRun(EndOfStreamContext&, Spawns<T>&)
473+
static bool postRun(EndOfStreamContext&, SpawnsNG<T>&)
474474
{
475475
return true;
476476
}

Framework/Core/include/Framework/TableBuilder.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -854,41 +854,43 @@ auto makeEmptyTable(const char* name, framework::pack<Cs...> p)
854854
return b.finalize();
855855
}
856856

857-
std::shared_ptr<arrow::Table> spawnerHelper(std::shared_ptr<arrow::Table>& fullTable, std::shared_ptr<arrow::Schema> newSchema, size_t nColumns,
857+
std::shared_ptr<arrow::Table> spawnerHelper(std::shared_ptr<arrow::Table> const& fullTable, std::shared_ptr<arrow::Schema> newSchema, size_t nColumns,
858858
expressions::Projector* projectors, std::vector<std::shared_ptr<arrow::Field>> const& fields, const char* name);
859859

860860
/// Expression-based column generator to materialize columns
861861
template <aod::aodHash D>
862862
auto spawner(std::vector<std::shared_ptr<arrow::Table>>&& tables, const char* name)
863863
{
864+
using expression_pack_t = typename o2::aod::MetadataTraitNG<D>::metadata::expression_pack_t;
864865
auto fullTable = soa::ArrowHelpers::joinTables(std::move(tables));
865866
if (fullTable->num_rows() == 0) {
866-
return makeEmptyTable(name, typename o2::aod::MetadataTraitNG<D>::expression_pack_t{});
867+
return makeEmptyTable(name, expression_pack_t{});
867868
}
868-
static auto fields = o2::soa::createFieldsFromColumns(typename o2::aod::MetadataTraitNG<D>::expression_pack_t{});
869+
static auto fields = o2::soa::createFieldsFromColumns(expression_pack_t{});
869870
static auto new_schema = std::make_shared<arrow::Schema>(fields);
870-
auto projectors = []<typename... C>() -> std::array<expressions::Projector, sizeof...(C)>
871+
auto projectors = []<typename... C>(framework::pack<C...>) -> std::array<expressions::Projector, sizeof...(C)>
871872
{
872873
return {{std::move(C::Projector())...}};
873-
}
874-
(typename o2::aod::MetadataTraitNG<D>::expression_pack_t{}); //;
875-
return spawnerHelper(fullTable, new_schema, framework::pack_size(typename o2::aod::MetadataTraitNG<D>::expression_pack_t{}), projectors.data(), fields, name);
874+
}(expression_pack_t{});
875+
876+
return spawnerHelper(fullTable, new_schema, framework::pack_size(expression_pack_t{}), projectors.data(), fields, name);
876877
}
877878

878879
template <aod::aodHash D>
879880
auto spawner(std::shared_ptr<arrow::Table> const& fullTable, const char* name)
880881
{
882+
using expression_pack_t = typename o2::aod::MetadataTraitNG<D>::metadata::expression_pack_t;
881883
if (fullTable->num_rows() == 0) {
882-
return makeEmptyTable(name, typename o2::aod::MetadataTraitNG<D>::expression_pack_t{});
884+
return makeEmptyTable(name,expression_pack_t{});
883885
}
884-
static auto fields = o2::soa::createFieldsFromColumns(typename o2::aod::MetadataTraitNG<D>::expression_pack_t{});
886+
static auto fields = o2::soa::createFieldsFromColumns(expression_pack_t{});
885887
static auto new_schema = std::make_shared<arrow::Schema>(fields);
886-
auto projectors = []<typename... C>() -> std::array<expressions::Projector, sizeof...(C)>
888+
auto projectors = []<typename... C>(framework::pack<C...>) -> std::array<expressions::Projector, sizeof...(C)>
887889
{
888890
return {{std::move(C::Projector())...}};
889-
}
890-
(typename o2::aod::MetadataTraitNG<D>::expression_pack_t{}); //;
891-
return spawnerHelper(fullTable, new_schema, framework::pack_size(typename o2::aod::MetadataTraitNG<D>::expression_pack_t{}), projectors.data(), fields, name);
891+
}(expression_pack_t{});
892+
893+
return spawnerHelper(fullTable, new_schema, framework::pack_size(expression_pack_t{}), projectors.data(), fields, name);
892894
}
893895

894896
template <soa::OriginEnc ORIGIN, typename... C>

Framework/Core/src/TableBuilder.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void TableBuilder::setLabel(const char* label)
8484
mSchema = mSchema->WithMetadata(std::make_shared<arrow::KeyValueMetadata>(std::vector{std::string{"label"}}, std::vector{std::string{label}}));
8585
}
8686

87-
std::shared_ptr<arrow::Table> spawnerHelper(std::shared_ptr<arrow::Table>& fullTable, std::shared_ptr<arrow::Schema> newSchema, size_t nColumns,
87+
std::shared_ptr<arrow::Table> spawnerHelper(std::shared_ptr<arrow::Table> const& fullTable, std::shared_ptr<arrow::Schema> newSchema, size_t nColumns,
8888
expressions::Projector* projectors, std::vector<std::shared_ptr<arrow::Field>> const& fields, const char* name)
8989
{
9090
auto mergedProjectors = framework::expressions::createProjectorHelper(nColumns, projectors, fullTable->schema(), fields);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#include <catch_amalgamated.hpp>
13+
#include "Framework/AnalysisHelpers.h"
14+
15+
#include <Framework/AnalysisDataModel.h>
16+
#include <Framework/TableBuilder.h>
17+
18+
using namespace o2::framework;
19+
using namespace o2::soa;
20+
using namespace o2::aod;
21+
22+
namespace o2::aod
23+
{
24+
namespace test
25+
{
26+
DECLARE_SOA_COLUMN(X, x, float);
27+
DECLARE_SOA_COLUMN(Y, y, float);
28+
DECLARE_SOA_COLUMN(Z, z, float);
29+
DECLARE_SOA_EXPRESSION_COLUMN(Rsq, rsq, float, test::x * test::x + test::y * test::y + test::z * test::z);
30+
DECLARE_SOA_EXPRESSION_COLUMN(Sin, sin, float, test::x / nsqrt (test::x * test::x + test::y * test::y));
31+
}
32+
33+
DECLARE_SOA_TABLE_NG(PointNGs, "AOD", "PTSNG", test::X, test::Y, test::Z);
34+
DECLARE_SOA_EXTENDED_TABLE_NG(ExPointNGs, PointNGs, "EXPTSNG", test::Rsq, test::Sin);
35+
}
36+
37+
TEST_CASE("TestTableSpawner")
38+
{
39+
TableBuilder b1;
40+
auto w1 = b1.cursor<PointNGs>();
41+
42+
for (auto i = 1; i < 10; ++i) {
43+
w1(0, i * 2., i * 3., i * 4.);
44+
}
45+
46+
auto t1 = b1.finalize();
47+
PointNGs st1{t1};
48+
49+
auto expoints_a = o2::soa::Extend<o2::aod::PointNGs, test::Rsq, test::Sin>(st1);
50+
auto extension = ExPointNGsExtension{o2::framework::spawner<o2::aod::Hash<"EXPTSNG/0"_h>>(t1, o2::aod::Hash<"ExPointNGs"_h>::str)};
51+
auto expoints = ExPointNGs{{t1, extension.asArrowTable()}, 0};
52+
53+
REQUIRE(expoints_a.size() == 9);
54+
REQUIRE(extension.size() == 9);
55+
REQUIRE(expoints.size() == 9);
56+
57+
auto rex = extension.begin();
58+
auto rexp = expoints.begin();
59+
auto rexp_a = expoints_a.begin();
60+
61+
for (auto i = 1; i < 10; ++i) {
62+
float rsq = i * i * 4 + i * i * 9 + i * i * 16;
63+
float sin = i * 2 / std::sqrt(i * i * 4 + i * i * 9);
64+
REQUIRE(rexp_a.rsq() == rsq);
65+
REQUIRE(rex.rsq() == rsq);
66+
REQUIRE(rexp.rsq() == rsq);
67+
REQUIRE(rexp_a.sin() == sin);
68+
REQUIRE(rex.sin() == sin);
69+
REQUIRE(rexp.sin() == sin);
70+
++rex;
71+
++rexp;
72+
++rexp_a;
73+
}
74+
}

0 commit comments

Comments
 (0)