Skip to content

Commit 42c447b

Browse files
committed
[df] Add regression test for #19104
1 parent c0b165b commit 42c447b

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

tree/dataframe/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ endif()
6969

7070
ROOT_ADD_GTEST(dataframe_display dataframe_display.cxx LIBRARIES ROOTDataFrame)
7171
ROOT_ADD_GTEST(dataframe_ranges dataframe_ranges.cxx LIBRARIES ROOTDataFrame)
72-
ROOT_ADD_GTEST(dataframe_leaves dataframe_leaves.cxx LIBRARIES ROOTDataFrame)
72+
ROOT_ADD_GTEST(dataframe_leaves dataframe_leaves.cxx LIBRARIES ROOTDataFrame Physics)
7373
ROOT_ADD_GTEST(dataframe_resptr dataframe_resptr.cxx LIBRARIES ROOTDataFrame)
7474
ROOT_ADD_GTEST(dataframe_take dataframe_take.cxx LIBRARIES ROOTDataFrame)
7575
ROOT_ADD_GTEST(dataframe_entrylist dataframe_entrylist.cxx LIBRARIES ROOTDataFrame)

tree/dataframe/test/dataframe_leaves.cxx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,23 @@
33
#include "TTree.h"
44
#include "gtest/gtest.h"
55

6+
#include <memory>
7+
#include <TClonesArray.h>
8+
#include <TLorentzVector.h>
9+
#include <ROOT/RVec.hxx>
10+
#include <ROOT/TestSupport.hxx>
611

712
using namespace ROOT::VecOps;
813

14+
template <typename T0, typename T1>
15+
void expect_vec_float_eq(const T0 &v1, const T1 &v2)
16+
{
17+
ASSERT_EQ(v1.size(), v2.size()) << "Vectors 'v1' and 'v2' are of unequal length";
18+
for (std::size_t i = 0ull; i < v1.size(); ++i) {
19+
EXPECT_FLOAT_EQ(v1[i], v2[i]) << "Vectors 'v1' and 'v2' differ at index " << i;
20+
}
21+
}
22+
923
struct BrVal {
1024
Float_t a;
1125
Int_t i;
@@ -72,3 +86,42 @@ TEST(RDFLeaves, OneLeafWithDotNameClass)
7286
EXPECT_EQ(*res, 40);
7387
}
7488

89+
TEST(RDFLeaves, LeafFromTClonesArray)
90+
{
91+
// Regression test for https://github.com/root-project/root/issues/19104
92+
ROOT::TestSupport::CheckDiagsRAII diagRAII;
93+
diagRAII.requiredDiag(kWarning, "TTree::Bronch",
94+
"Using split mode on a class: TLorentzVector with a custom Streamer");
95+
diagRAII.requiredDiag(
96+
kWarning, "RTreeColumnReader::Get",
97+
"Branch ca.fE hangs from a non-split branch. A copy is being performed in order to properly read the content.");
98+
constexpr static auto fName{"leaffromtclonesarray.root"};
99+
struct Dataset {
100+
Dataset()
101+
{
102+
auto f = std::make_unique<TFile>(fName, "recreate");
103+
auto t = std::make_unique<TTree>("t", "t");
104+
auto ca = std::make_unique<TClonesArray>("TLorentzVector");
105+
auto branchData = ca.get();
106+
auto &caRef = *ca;
107+
t->Branch("ca", &branchData);
108+
for (Int_t ev = 0; ev < 1; ev++) {
109+
caRef.Clear();
110+
for (int i = 1; i < 3; i++) {
111+
new (caRef[i - 1]) TLorentzVector(0, 0, 0, i * 42.42);
112+
}
113+
t->Fill();
114+
}
115+
f->Write();
116+
}
117+
118+
~Dataset() { std::remove(fName); }
119+
} _;
120+
121+
std::vector expected{42.42, 84.84};
122+
123+
ROOT::RDataFrame df("t", fName);
124+
auto resultptr = df.Take<ROOT::RVecD>("ca.fE");
125+
ASSERT_EQ(resultptr->size(), 1);
126+
expect_vec_float_eq(expected, resultptr->at(0));
127+
}

0 commit comments

Comments
 (0)