diff --git a/tree/treeplayer/src/TTreeReaderArray.cxx b/tree/treeplayer/src/TTreeReaderArray.cxx index ac99b7f3202a6..4cc5963cc5119 100644 --- a/tree/treeplayer/src/TTreeReaderArray.cxx +++ b/tree/treeplayer/src/TTreeReaderArray.cxx @@ -843,8 +843,8 @@ bool ROOT::Internal::TTreeReaderArrayBase::GetBranchAndLeaf(TBranch *&branch, TL return false; } - if (tempDict->IsA() == TDataType::Class() && - TDictionary::GetDictionary(((TDataType *)tempDict)->GetTypeName()) == fDict) { + if (tempDict->IsA() == TDataType::Class() && fDict->IsA() == TDataType::Class() && + ((TDataType *)tempDict)->GetType() == ((TDataType *)fDict)->GetType()) { // fLeafOffset = myLeaf->GetOffset() / 4; branchActualType = fDict; fLeaf = myLeaf; diff --git a/tree/treeplayer/test/leafs.cxx b/tree/treeplayer/test/leafs.cxx index e457dc7d4fb66..73a4834d418de 100644 --- a/tree/treeplayer/test/leafs.cxx +++ b/tree/treeplayer/test/leafs.cxx @@ -254,3 +254,31 @@ TEST(TTreeReaderLeafs, BranchAndLeafWithDifferentNames) EXPECT_EQ(*rvwithdot, 42); EXPECT_FALSE(r.Next()); } + +// Test for https://github.com/root-project/root/issues/9758 +// A TTreeReaderArray of a typedef'd fundamental type (e.g. ULong64_t) must be +// readable through the extended "branch.leaf" syntax, not only through the plain +// branch name. The leaf type name ("ULong64_t") and the reader's resolved type +// name ("unsigned long long") differ, so the leaf/reader match must compare the +// underlying data type, not the dictionary identity. +TEST(TTreeReaderLeafs, ArrayLeafTypedefWithDots) +{ + TTree t("t", "t"); + Int_t n = 3; + ULong64_t x[3] = {1, 2, 3}; + t.Branch("n", &n, "n/I"); + t.Branch("x", x, "x[n]/l"); + t.Fill(); + + TTreeReader r(&t); + TTreeReaderArray arr(r, "x"); + TTreeReaderArray arrWithDot(r, "x.x"); + ASSERT_TRUE(r.Next()); + ASSERT_EQ(arr.GetSize(), 3u); + ASSERT_EQ(arrWithDot.GetSize(), 3u); + for (std::size_t i = 0; i < arr.GetSize(); ++i) { + EXPECT_EQ(arr[i], x[i]); + EXPECT_EQ(arrWithDot[i], x[i]); + } + EXPECT_FALSE(r.Next()); +}