31 TFile f1(
"tree2table.root",
"RECREATE");
32 TTree
t1(
"t1",
"a simple Tree with simple variables");
33 Bool_t ok, ts[5] = {
false};
38 const Int_t nelem = 9;
39 Double_t ij[nelem] = {0};
41 memset(xyzw, 1, 96 * 4);
42 TString leaflist = Form(
"ij[%i]/D", nelem);
45 t1.Branch(
"ok", &ok,
"ok/O");
46 t1.Branch(
"px", &px,
"px/F");
47 t1.Branch(
"py", &py,
"py/F");
48 t1.Branch(
"pz", &pz,
"pz/F");
49 t1.Branch(
"random", &random,
"random/D");
50 t1.Branch(
"ev", &ev,
"ev/I");
51 t1.Branch(
"ij", ij, leaflist.Data());
52 t1.Branch(
"tests", ts,
"tests[5]/O");
53 t1.Branch(
"xyzw", xyzw,
"xyzw[96]/F");
54 t1.Branch(
"small", &
b,
"small/b");
58 for (
int i = 0;
i < ndp;
i++) {
63 gRandom->Rannor(px, py);
64 pz = px * px + py * py;
65 random = gRandom->Rndm();
68 for (Int_t jj = 0; jj < nelem; jj++) {
69 ij[jj] =
i + 100 * jj;
71 for (Int_t jj = 0; jj < 5; jj++) {
72 ts[jj] = (((
i + jj) % 2) == 0);
90 REQUIRE(table->Validate().ok() ==
true);
91 REQUIRE(table->num_rows() == ndp);
92 REQUIRE(table->num_columns() == ncols);
94 REQUIRE(table->column(0)->type()->id() == arrow::Type::BOOL);
95 REQUIRE(table->column(1)->type()->id() == arrow::Type::FLOAT);
96 REQUIRE(table->column(2)->type()->id() == arrow::Type::FLOAT);
97 REQUIRE(table->column(3)->type()->id() == arrow::Type::FLOAT);
98 REQUIRE(table->column(4)->type()->id() == arrow::Type::DOUBLE);
99 REQUIRE(table->column(5)->type()->id() == arrow::Type::INT32);
100 REQUIRE(table->column(6)->type()->id() == arrow::Type::FIXED_SIZE_LIST);
101 REQUIRE(table->column(7)->type()->id() == arrow::Type::FIXED_SIZE_LIST);
102 REQUIRE(table->column(8)->type()->id() == arrow::Type::FIXED_SIZE_LIST);
103 REQUIRE(table->column(9)->type()->id() == arrow::Type::UINT8);
105 REQUIRE(table->column(0)->type()->Equals(arrow::boolean()));
106 REQUIRE(table->column(1)->type()->Equals(arrow::float32()));
107 REQUIRE(table->column(2)->type()->Equals(arrow::float32()));
108 REQUIRE(table->column(3)->type()->Equals(arrow::float32()));
109 REQUIRE(table->column(4)->type()->Equals(arrow::float64()));
110 REQUIRE(table->column(5)->type()->Equals(arrow::int32()));
111 REQUIRE(table->column(6)->type()->Equals(arrow::fixed_size_list(arrow::float64(), nelem)));
112 REQUIRE(table->column(7)->type()->Equals(arrow::fixed_size_list(arrow::boolean(), 5)));
113 REQUIRE(table->column(8)->type()->Equals(arrow::fixed_size_list(arrow::float32(), 96)));
114 REQUIRE(table->column(9)->type()->Equals(arrow::uint8()));
118 auto chunks = table->column(0);
119 REQUIRE(!(chunks.get() ==
nullptr));
121 auto oks = std::dynamic_pointer_cast<arrow::BooleanArray>(chunks->chunk(0));
122 REQUIRE(!(oks.get() ==
nullptr));
124 for (
int ii = 0; ii < table->num_rows(); ii++) {
125 ntrueout += oks->Value(ii) ? 1 : 0;
127 REQUIRE(ntruein[0] == ntrueout);
130 chunks = table->column(7);
131 REQUIRE(!(chunks.get() ==
nullptr));
133 auto chunkToUse = std::static_pointer_cast<arrow::FixedSizeListArray>(chunks->chunk(0))->values();
134 REQUIRE(!(chunkToUse.get() ==
nullptr));
136 auto tests = std::dynamic_pointer_cast<arrow::BooleanArray>(chunkToUse);
138 for (
int ii = 0; ii < table->num_rows() * 5; ii++) {
139 ntrueout += tests->Value(ii) ? 1 : 0;
141 REQUIRE(ntruein[1] == ntrueout);
144 TFile* f2 = TFile::Open(
"table2tree.root",
"RECREATE");
149 auto br = (TBranch*)t2->GetBranch(
"ok");
150 REQUIRE(t2->GetEntries() == ndp);
151 REQUIRE(br->GetEntries() == ndp);
152 br = (TBranch*)t2->GetBranch(
"tests");
153 REQUIRE(br->GetEntries() == ndp);