1212#include < catch_amalgamated.hpp>
1313
1414#include " Framework/TableBuilder.h"
15- #include " Framework/RootTableBuilderHelpers.h"
1615#include " Framework/ASoA.h"
1716#include " Framework/PluginManager.h"
1817#include " ../src/ArrowDebugHelpers.h"
5049
5150using namespace o2 ::framework;
5251
53- TEST_CASE (" RootTree2Table" )
54- {
55- using namespace o2 ::framework;
56- // / Create a simple TTree
57- TTree t1 (" t1" , " a simple Tree with simple variables" );
58- Float_t xyz[3 ];
59- Int_t ij[2 ];
60- Float_t px, py, pz;
61- Double_t random;
62- Int_t ev;
63- t1.Branch (" px" , &px, " px/F" );
64- t1.Branch (" py" , &py, " py/F" );
65- t1.Branch (" pz" , &pz, " pz/F" );
66- t1.Branch (" random" , &random, " random/D" );
67- t1.Branch (" ev" , &ev, " ev/I" );
68- t1.Branch (" xyz" , xyz, " xyz[3]/F" );
69- t1.Branch (" ij" , ij, " ij[2]/I" );
70- // fill the tree
71- for (Int_t i = 0 ; i < 1000 ; i++) {
72- xyz[0 ] = 1 ;
73- xyz[1 ] = 2 ;
74- xyz[2 ] = 3 ;
75- gRandom ->Rannor (px, py);
76- pz = px * px + py * py;
77- xyz[2 ] = i + 1 ;
78- ij[0 ] = i;
79- ij[1 ] = i + 1 ;
80- random = gRandom ->Rndm ();
81- ev = i + 1 ;
82- t1.Fill ();
83- }
84-
85- // Create an arrow table from this.
86- TableBuilder builder;
87- TTreeReader reader (&t1);
88- auto && xyzReader = HolderMaker<float [3 ]>::make (reader, " xyz" );
89- auto && ijkReader = HolderMaker<int [2 ]>::make (reader, " ij" );
90- auto && pxReader = HolderMaker<float >::make (reader, " px" );
91- auto && pyReader = HolderMaker<float >::make (reader, " py" );
92- auto && pzReader = HolderMaker<float >::make (reader, " pz" );
93- auto && randomReader = HolderMaker<double >::make (reader, " random" );
94- auto && evReader = HolderMaker<int >::make (reader, " ev" );
95-
96- RootTableBuilderHelpers::convertTTree (builder, reader, std::move (xyzReader), std::move (ijkReader), std::move (pxReader), std::move (pyReader), std::move (pzReader), std::move (randomReader), std::move (evReader));
97- auto table = builder.finalize ();
98- REQUIRE (table->num_rows () == 1000 );
99- REQUIRE (table->num_columns () == 7 );
100- REQUIRE (table->schema ()->field (0 )->type ()->id () == arrow::fixed_size_list (arrow::float32 (), 3 )->id ());
101- REQUIRE (table->schema ()->field (1 )->type ()->id () == arrow::fixed_size_list (arrow::int32 (), 2 )->id ());
102- REQUIRE (table->schema ()->field (2 )->type ()->id () == arrow::float32 ()->id ());
103- REQUIRE (table->schema ()->field (3 )->type ()->id () == arrow::float32 ()->id ());
104- REQUIRE (table->schema ()->field (4 )->type ()->id () == arrow::float32 ()->id ());
105- REQUIRE (table->schema ()->field (5 )->type ()->id () == arrow::float64 ()->id ());
106- REQUIRE (table->schema ()->field (6 )->type ()->id () == arrow::int32 ()->id ());
107-
108- {
109- auto chunkToUse = table->column (0 )->chunk (0 );
110- chunkToUse = std::dynamic_pointer_cast<arrow::FixedSizeListArray>(chunkToUse)->values ();
111- auto array = std::static_pointer_cast<arrow::FloatArray>(chunkToUse);
112- // array of 3 floats, time 1000.
113- REQUIRE (array->length () == 3000 );
114- const float * c = reinterpret_cast <float const *>(array->values ()->data ());
115-
116- CHECK (c[0 ] == 1 );
117- CHECK (c[1 ] == 2 );
118- CHECK (c[2 ] == 1 );
119- }
120- {
121- auto chunkToUse = table->column (1 )->chunk (0 );
122- chunkToUse = std::dynamic_pointer_cast<arrow::FixedSizeListArray>(chunkToUse)->values ();
123- auto array = std::static_pointer_cast<arrow::Int32Array>(chunkToUse);
124- REQUIRE (array->length () == 2000 );
125-
126- const int * ptr = reinterpret_cast <int const *>(array->values ()->data ());
127- for (size_t i = 0 ; i < 1000 ; i++) {
128- CHECK (ptr[2 * i + 0 ] == i);
129- CHECK (ptr[2 * i + 1 ] == i + 1 );
130- }
131- }
132- }
133-
13452namespace o2 ::aod
13553{
13654namespace test
@@ -149,60 +67,6 @@ DECLARE_SOA_TABLE(Test, "AOD", "ETAPHI",
14967 test::Random, test::Ev);
15068} // namespace o2::aod
15169
152- TEST_CASE (" RootTree2TableViaASoA" )
153- {
154- using namespace o2 ::framework;
155- // / Create a simple TTree
156- TTree t2 (" t2" , " a simple Tree with simple variables" );
157- Float_t xyz[3 ];
158- Int_t ij[2 ];
159- Float_t px, py, pz;
160- Double_t random;
161- Int_t ev;
162- t2.Branch (" px" , &px, " px/F" );
163- t2.Branch (" py" , &py, " py/F" );
164- t2.Branch (" pz" , &pz, " pz/F" );
165- t2.Branch (" random" , &random, " random/D" );
166- t2.Branch (" ev" , &ev, " ev/I" );
167- t2.Branch (" xyz" , xyz, " xyz[3]/F" );
168- t2.Branch (" ij" , ij, " ij[2]/I" );
169- // fill the tree
170- for (Int_t i = 0 ; i < 1000 ; i++) {
171- gRandom ->Rannor (xyz[0 ], xyz[1 ]);
172- gRandom ->Rannor (px, py);
173- pz = px * px + py * py;
174- xyz[2 ] = i + 1 ;
175- ij[0 ] = i;
176- ij[1 ] = i + 1 ;
177- random = gRandom ->Rndm ();
178- ev = i + 1 ;
179- t2.Fill ();
180- }
181-
182- // Create an arrow table from this.
183- TableBuilder builder;
184- TTreeReader reader (&t2);
185- REQUIRE (t2.GetEntries () == 1000 );
186-
187- RootTableBuilderHelpers::convertASoA<o2::aod::Test>(builder, reader);
188- auto table = builder.finalize ();
189- REQUIRE (table->num_rows () == 1000 );
190- REQUIRE (table->num_columns () == 7 );
191- REQUIRE (table->column (0 )->type ()->id () == arrow::float32 ()->id ());
192- REQUIRE (table->column (1 )->type ()->id () == arrow::float32 ()->id ());
193- REQUIRE (table->column (2 )->type ()->id () == arrow::float32 ()->id ());
194- REQUIRE (table->column (3 )->type ()->id () == arrow::fixed_size_list (arrow::float32 (), 3 )->id ());
195- REQUIRE (table->column (4 )->type ()->id () == arrow::fixed_size_list (arrow::int32 (), 2 )->id ());
196- REQUIRE (table->column (5 )->type ()->id () == arrow::float64 ()->id ());
197- REQUIRE (table->column (6 )->type ()->id () == arrow::int32 ()->id ());
198-
199- o2::aod::Test testTable{table};
200- for (auto & row : testTable) {
201- REQUIRE (row.ij ()[0 ] == row.ij ()[1 ] - 1 );
202- REQUIRE (row.ij ()[1 ] == row.ev ());
203- }
204- }
205-
20670TEST_CASE (" RootTree2Fragment" )
20771{
20872 using namespace o2 ::framework;
0 commit comments