Project
Loading...
Searching...
No Matches
test_IndexBuilder.cxx
Go to the documentation of this file.
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
14#include <catch_amalgamated.hpp>
15
16using namespace o2::framework;
17using namespace arrow;
18using namespace o2::soa;
19using namespace o2::aod;
20
21namespace o2::aod
22{
23O2ORIGIN("TST");
24namespace coords
25{
26DECLARE_SOA_COLUMN_FULL(X, x, float, "x");
27DECLARE_SOA_COLUMN_FULL(Y, y, float, "y");
28DECLARE_SOA_COLUMN_FULL(Z, z, float, "z");
29} // namespace coords
30DECLARE_SOA_TABLE(Points, "TST", "POINTS", Index<>, coords::X, coords::Y, coords::Z);
31
32namespace extra_1
33{
35DECLARE_SOA_COLUMN_FULL(D, d, float, "d");
36} // namespace extra_1
37DECLARE_SOA_TABLE(Distances, "TST", "DISTANCES", Index<>, extra_1::PointId, extra_1::D);
38
39namespace extra_2
40{
42DECLARE_SOA_COLUMN_FULL(IsTrue, istrue, bool, "istrue");
43} // namespace extra_2
44DECLARE_SOA_TABLE(Flags, "TST", "Flags", Index<>, extra_2::PointId, extra_2::IsTrue);
45
46namespace extra_3
47{
49DECLARE_SOA_COLUMN_FULL(Category, category, int32_t, "category");
50} // namespace extra_3
51DECLARE_SOA_TABLE(Categorys, "TST", "Categories", Index<>, extra_3::PointId, extra_3::Category);
52
53namespace test_indices
54{
58DECLARE_SOA_INDEX_COLUMN(Category, category);
59} // namespace test_indices
60
61DECLARE_SOA_INDEX_TABLE(IDXs, Points, "Index1", test_indices::PointId, test_indices::DistanceId, test_indices::FlagId, test_indices::CategoryId);
62DECLARE_SOA_INDEX_TABLE(IDX2s, Points, "Index2", test_indices::DistanceId, test_indices::PointId, test_indices::FlagId, test_indices::CategoryId);
63} // namespace o2::aod
64
65TEST_CASE("TestIndexBuilder")
66{
68 auto w1 = b1.cursor<Points>();
69 TableBuilder b2;
70 auto w2 = b2.cursor<Distances>();
71 TableBuilder b3;
72 auto w3 = b3.cursor<Flags>();
73 TableBuilder b4;
74 auto w4 = b4.cursor<Categorys>();
75
76 for (auto i = 0; i < 10; ++i) {
77 w1(0, i * 2., i * 3., i * 4.);
78 }
79
80 std::array<int, 7> d{0, 1, 2, 4, 7, 8, 9};
81 std::array<int, 5> f{0, 1, 2, 5, 8};
82 std::array<int, 7> c{0, 1, 2, 3, 5, 7, 8};
83
84 for (auto i : d) {
85 w2(0, i, i * 10.);
86 }
87
88 for (auto i : f) {
89 w3(0, i, static_cast<bool>(i % 2));
90 }
91
92 for (auto i : c) {
93 w4(0, i, i + 2);
94 }
95
96 auto t1 = b1.finalize();
97 Points st1{t1};
98 auto t2 = b2.finalize();
99 Distances st2{t2};
100 auto t3 = b3.finalize();
101 Flags st3{t3};
102 auto t4 = b4.finalize();
103 Categorys st4{t4};
104
105 using m1 = MetadataTrait<o2::aod::Hash<"Index1/0"_h>>::metadata;
106 auto t5 = IndexBuilder<Exclusive>::indexBuilder<Points, m1::sources.size(), m1::sources>("test1a", {t1, t2, t3, t4}, typename IDXs::persistent_columns_t{});
107 REQUIRE(t5->num_rows() == 4);
108 IDXs idxt{t5};
109 idxt.bindExternalIndices(&st1, &st2, &st3, &st4);
110 for (auto& row : idxt) {
111 REQUIRE(row.distance().pointId() == row.pointId());
112 REQUIRE(row.flag().pointId() == row.pointId());
113 REQUIRE(row.category().pointId() == row.pointId());
114 }
115
116 using m2 = MetadataTrait<o2::aod::Hash<"Index2/0"_h>>::metadata;
117 auto t6 = IndexBuilder<Sparse>::indexBuilder<Points, m2::sources.size(), m2::sources>("test3", {t2, t1, t3, t4}, typename IDX2s::persistent_columns_t{});
118 REQUIRE(t6->num_rows() == st2.size());
119 IDX2s idxs{t6};
120 std::array<int, 7> fs{0, 1, 2, -1, -1, 4, -1};
121 std::array<int, 7> cs{0, 1, 2, -1, 5, 6, -1};
122 idxs.bindExternalIndices(&st1, &st2, &st3, &st4);
123 auto i = 0;
124 for (auto const& row : idxs) {
125 REQUIRE(row.has_distance());
126 REQUIRE(row.has_point());
127 if (row.has_flag()) {
128 REQUIRE(row.flag().pointId() == row.pointId());
129 }
130 if (row.has_category()) {
131 REQUIRE(row.category().pointId() == row.pointId());
132 }
133 REQUIRE(row.flagId() == fs[i]);
134 REQUIRE(row.categoryId() == cs[i]);
135 ++i;
136 }
137}
138
139namespace o2::aod
140{
141namespace extra_4
142{
143DECLARE_SOA_COLUMN_FULL(Bin, bin, int, "bin");
144DECLARE_SOA_COLUMN_FULL(Color, color, int, "color");
145} // namespace extra_4
146
147DECLARE_SOA_TABLE(BinnedPoints, "TST", "BinnedPoints", Index<>, extra_4::Bin, test_indices::PointId);
148DECLARE_SOA_TABLE(ColoredPoints, "TST", "ColoredPoints", Index<>, extra_4::Color, test_indices::PointId);
149
150namespace test_indices
151{
152DECLARE_SOA_SLICE_INDEX_COLUMN(BinnedPoint, binsSlice);
153DECLARE_SOA_ARRAY_INDEX_COLUMN(ColoredPoint, colorsList);
154} // namespace test_indices
155
156DECLARE_SOA_INDEX_TABLE(IDX3s, Points, "Index3", test_indices::PointId, test_indices::BinnedPointIdSlice, test_indices::ColoredPointIds);
157} // namespace o2::aod
158
159TEST_CASE("AdvancedIndexTables")
160{
162 auto w1 = b1.cursor<Points>();
163 for (auto i = 0; i < 10; ++i) {
164 w1(0, i * 2., i * 3., i * 4.);
165 }
166 auto t1 = b1.finalize();
167 Points st1{t1};
168
169 TableBuilder b2;
170 auto w2 = b2.cursor<BinnedPoints>();
171 std::array<int, 3> skipPoints = {2, 6, 9};
172 std::array<int, 10> sizes = {5, 3, 0, 12, 4, 1, 0, 8, 2, 0};
173 auto count = 0;
174 for (auto i = 0; i < 10; ++i) {
175 if (i == skipPoints[count]) {
176 ++count;
177 continue;
178 }
179 for (auto j = 0; j < sizes[i]; ++j) {
180 w2(0, j + 1, i);
181 }
182 }
183 auto t2 = b2.finalize();
184 BinnedPoints st2{t2};
185
186 TableBuilder b3;
187 auto w3 = b3.cursor<ColoredPoints>();
188 std::array<int, 20> pointIds1 = {19, 2, 10, 5, 7, 17, 1, 3, 9, 12, 17, 6, 4, 13, 8, 5, 16, 15, 18, 0};
189 std::array<int, 20> pointIds2 = {3, 19, 2, 6, 4, 13, 11, 5, 7, 11, 1, 9, 12, 17, 8, 14, 16, 2, 18, 0};
190 std::array<int, 20> pointIds3 = {19, 2, 9, 15, 1, 3, 9, 12, 17, 18, 0, 10, 5, 7, 11, 6, 4, 13, 9, 14};
191 for (int i = 0; i < 20; ++i) {
192 w3(0, i, pointIds1[i]);
193 }
194 for (int i = 0; i < 20; ++i) {
195 w3(0, i + 20, pointIds2[i]);
196 }
197 for (int i = 0; i < 20; ++i) {
198 w3(0, i + 40, pointIds3[i]);
199 }
200 auto tc = b3.finalize();
201 ColoredPoints st3{tc};
202
203 std::array<int, 10> colorsizes = {3, 3, 4, 3, 3, 4, 3, 3, 2, 5};
204 std::array<std::vector<int>, 10> colorvalues = {{{19, 39, 50},
205 {6, 30, 44},
206 {1, 22, 37, 41},
207 {7, 20, 45},
208 {12, 24, 56},
209 {3, 15, 27, 52},
210 {11, 23, 55},
211 {4, 28, 53},
212 {14, 34},
213 {8, 31, 42, 46, 58}}};
214
215 using m3 = MetadataTrait<o2::aod::Hash<"Index3/0"_h>>::metadata;
216 auto t3 = IndexBuilder<Sparse>::indexBuilder<Points, m3::sources.size(), m3::sources>("test4", {t1, t2, tc}, typename IDX3s::persistent_columns_t{});
217 REQUIRE(t3->num_rows() == st1.size());
218 IDX3s idxs{t3};
219 idxs.bindExternalIndices(&st1, &st2, &st3);
220 count = 0;
221 for (auto const& row : idxs) {
222 REQUIRE(row.has_point());
223 if (row.has_binsSlice()) {
224 auto slice = row.binsSlice();
225 REQUIRE(slice.size() == sizes[count]);
226 for (auto const& bin : slice) {
227 REQUIRE(bin.pointId() == row.pointId());
228 }
229 }
230 auto colors = row.colorsList();
231 REQUIRE(colors.size() == (size_t)colorsizes[count]);
232 for (auto j = 0U; j < colors.size(); ++j) {
233 REQUIRE(colors[j].color() == colorvalues[count][j]);
234 }
235 ++count;
236 }
237}
#define DECLARE_SOA_ARRAY_INDEX_COLUMN(_Name_, _Getter_)
Definition ASoA.h:2655
#define O2ORIGIN(_Str_)
Pre-declare Hash specialization for an origin string.
Definition ASoA.h:279
#define DECLARE_SOA_SLICE_INDEX_COLUMN(_Name_, _Getter_)
Definition ASoA.h:2500
#define DECLARE_SOA_TABLE(_Name_, _Origin_, _Desc_,...)
Definition ASoA.h:3052
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
Definition ASoA.h:2285
#define DECLARE_SOA_INDEX_COLUMN(_Name_, _Getter_)
Definition ASoA.h:2737
#define DECLARE_SOA_INDEX_TABLE(_Name_, _Key_, _Description_,...)
Definition ASoA.h:3126
std::pair< double, double > Point
int32_t i
const GPUTPCGMMerger::trackCluster & b1
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
std::shared_ptr< arrow::Table > finalize()
GLint GLenum GLint x
Definition glcorearb.h:403
GLint GLsizei count
Definition glcorearb.h:399
GLuint color
Definition glcorearb.h:1272
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition glcorearb.h:2595
GLsizei const GLubyte GLsizei GLenum const void * coords
Definition glcorearb.h:5468
GLdouble f
Definition glcorearb.h:310
GLsizei GLsizei GLfloat distance
Definition glcorearb.h:5506
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
std::vector< int > row