Skip to content

Commit

Permalink
[ntuple] test I/O rule with multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Feb 1, 2025
1 parent ce9785f commit aac01e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tree/ntuple/v7/test/CustomStruct.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ struct StructWithIORules : StructWithIORulesBase {
StructWithIORules(float _a, char _c[4]) : StructWithIORulesBase{_a, 0.0f}, s{{_c[0], _c[1], _c[2], _c[3]}, {}} {}
};

struct CoordinatesWithIORules {
float fX;
float fY;
float fR; //!
float fPhi; //!
};

struct Cyclic {
std::vector<Cyclic> fMember;
};
Expand Down
6 changes: 6 additions & 0 deletions tree/ntuple/v7/test/CustomStructLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
#pragma read sourceClass = "StructWithIORules" source = "" checksum = "[1]" targetClass = "StructWithIORules" target = \
"checksumB" code = "{ checksumB = 0.0; }"

#pragma link C++ options = version(3) class CoordinatesWithIORules + ;

#pragma read sourceClass = "CoordinatesWithIORules" source = "float fX; float fY" version = "[3]" targetClass = \
"CoordinatesWithIORules" target = "fPhi,fR" include = "cmath" code = \
"{ fR = sqrt(onfile.fX * onfile.fX + onfile.fY * onfile.fY); fPhi = atan2(onfile.fY, onfile.fX); }"

#pragma link C++ class Cyclic + ;
#pragma link C++ class CyclicCollectionProxy + ;
#pragma link C++ class Unsupported + ;
Expand Down
9 changes: 9 additions & 0 deletions tree/ntuple/v7/test/rfield_class.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ TEST(RNTuple, TClassReadRules)
{
auto model = RNTupleModel::Create();
auto ptrClass = model->MakeField<StructWithIORules>("class");
auto ptrCoord = model->MakeField<CoordinatesWithIORules>("coord");
ptrCoord->fX = 1.0;
ptrCoord->fY = 1.0;
auto writer = RNTupleWriter::Recreate(std::move(model), "f", fileGuard.GetPath());
for (int i = 0; i < 5; i++) {
*ptrClass = StructWithIORules{/*a=*/static_cast<float>(i), /*chars=*/c};
Expand Down Expand Up @@ -271,4 +274,10 @@ TEST(RNTuple, TClassReadRules)
// The following member is not touched by a rule due to a checksum mismatch
EXPECT_FLOAT_EQ(137.0, viewKlass(i).checksumB);
}

auto viewCoord = reader->GetView<CoordinatesWithIORules>("coord");
EXPECT_FLOAT_EQ(1.0, viewCoord(0).fX);
EXPECT_FLOAT_EQ(1.0, viewCoord(0).fY);
EXPECT_FLOAT_EQ(sqrt(2), viewCoord(0).fR);
EXPECT_FLOAT_EQ(M_PI / 4., viewCoord(0).fPhi);
}

0 comments on commit aac01e8

Please sign in to comment.