Repository navigation
[tree] Use the counter of the same object for variable-size arrays - #24183
Merged
Merged
Conversation
Member
|
Please review https://github.com/root-project/root/blob/master/CONTRIBUTING.md. Thanks. |
pcanal
requested changes
Nov 18, 2026
pcanal
left a comment
Member
There was a problem hiding this comment.
Please update the commit log to indicate the AI agent/model used in producing the commit.
pcanal
reviewed
Nov 18, 2026
pcanal
reviewed
Nov 18, 2026
kr1xh
force-pushed
the
fix/ttree-branchcount-sibling
branch
from
November 18, 2026 19:53
d3e4811 to
fba00bd
Compare
Test Results 22 files 22 suites 3d 10h 3m 42s ⏱️ Results for commit 6d3c27c. ♻️ This comment has been updated with latest results. |
When two objects of the same class are stored in top-level branches
whose names have no trailing dot, their sub-branches get identical
names, e.g. "fN" and "fX" under both "a" and "b". The counter of a
variable-size array member (`Double_t *fX; //[fN]`) was found with
TTree::GetBranch("fN"), which returns the first match in the tree. So
b.fX used a.fN as its counter, and that link was stored in the file.
Look up the counter among the sub-branches of the array's parent
first, and only fall back to the tree-wide search if it is not there.
This covers basic-type arrays, arrays of objects and the MakeClass
recovery path in ReadLeavesMakeClass.
Files written before this change store the wrong counter and are still
read incorrectly; this is not addressed here.
Assisted-by: claude-code:claude-opus-5-5
pcanal
reviewed
Nov 19, 2026
For a variable-size array member of a split object, TTreeReaderArray
took only the short name of the counter branch ("fN") and looked it up
again in the tree. With two objects of the same class in top-level
branches without a trailing dot, that lookup returns the first "fN" in
the tree, so b.fX was read with a.fN's size even when the file stores
the right counter.
Pass the counter branch itself to the size reader and read the size
through the counter's full name ("b.fN").
Fixes root-project#24146
Assisted-by: claude-code:claude-opus-5-5
kr1xh
force-pushed
the
fix/ttree-branchcount-sibling
branch
from
November 19, 2026 14:23
fba00bd to
6d3c27c
Compare
Member
|
/backport to 6.40, 6.42 |
|
Preparing to backport PR #24183 to branches 6.40 and 6.42 requested by pcanal |
|
This PR has been backported to |
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI DESCRIPTION BELOW
This Pull request:
Fixes counted arrays (
Double_t *fX; //[fN]) in split objects that read the wrong number of elements when two objects of the same class are stored in top-level branches without a trailing dot. In that layout both objects have a sub-branch calledfN, andb.fXends up usinga.fNas its counter.Two bugs share one cause, looking the counter up by its short name. Each commit fixes one of them:
[tree], write side: when the sub-branches are created,TBranchElement::Initfinds the counter withfTree->GetBranch("fN"), which returns the firstfNin the tree. The wrong link (fBranchCountand the leaf'sfLeafCount) is then stored in the file.[treeplayer],TTreeReaderArray: even when the stored link is correct,TTreeReaderArraytakes only the counter's short name ("fN") and looks it up again, so it still findsa.fN. This bug stays hidden until commit 1 is applied. With commit 1 alone,Draw("b.fX")is correct butTTreeReaderArraystill reads 0 elements.Changes or fixes:
TBranchElement.cxx: a new helper,FindBranchCount(), looks for the counter among the sub-branches of the array's parent and falls back to the tree-wide search only if it isn't there. Basic-type arrays (TStreamerBasicPointer), arrays of objects (TStreamerLoop) and the MakeClass recovery path inReadLeavesMakeClassall use it.TTreeReaderArray.cxx:TArrayParameterSizeReadergets a constructor that takes the counter branch itself and creates the size reader from the counter's full name (b.fN,b.fV.fN). The size-reader setup inTDynamicArrayReadermoves intoSetSizeReader()so both constructors share it.New gtest
testTBranchElementBranchCount(tree/tree/test/TBranchElementBranchCount.cxx, dictionaryBranchCountStruct.h):b.fV.fX): checks the stored counter (branch and leaf),TTreeReaderArraysize and values, andDraw;TClonesArray/std::vector, whose counters must stay the collection branch.The
Unprefixed*tests fail on master. With only the first commit, they fail on theTTreeReaderArraychecks.Not in this PR: files written before this change still store the wrong counter, so they are still read incorrectly. The data on disk is complete pointing
b.fX's counter back tob.fNafter opening an old file reads0 1 2, so the file could be repaired when it is read. The options are discussed in #24146, and I'd do the repair as a follow-up once we agree on an approach.I can split the two commits into two PRs if you prefer.
Used Claude Opus 5.5, at High Effort
Checklist:
This PR fixes #24146