← Back to Pull requests

[tree] Use the counter of the same object for variable-size arrays #24183

Closed
unknown closed this pull request without merging on Nov 19, 2026 22:59 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 21:42 UTC
Author

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 called fN, and b.fX ends up using a.fN as its counter.

Two bugs share one cause, looking the counter up by its short name. Each commit fixes one of them:

1. [tree], write side: when the sub-branches are created, TBranchElement::Init finds the counter with fTree->GetBranch("fN"), which returns the first fN in the tree. The wrong link (fBranchCount and the leaf's fLeafCount) is then stored in the file.
2. [treeplayer], TTreeReaderArray: even when the stored link is correct, TTreeReaderArray takes only the counter's short name ("fN") and looks it up again, so it still finds a.fN. This bug stays hidden until commit 1 is applied. With commit 1 alone, Draw("b.fX") is correct but TTreeReaderArray still 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 in ReadLeavesMakeClass all use it.

  • TTreeReaderArray.cxx: TArrayParameterSizeReader gets 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 in TDynamicArrayReader moves into SetSizeReader() so both constructors share it.

  • New gtest testTBranchElementBranchCount (tree/tree/test/TBranchElementBranchCount.cxx, dictionary BranchCountStruct.h):

  • - unprefixed basic-type array, array of objects, and an array inside an embedded split member (b.fV.fX): checks the stored counter (branch and leaf), TTreeReaderArray size and values, and Draw;
    - controls that pass with and without the fix: prefixed names, a single object; and counted arrays inside TClonesArray / std::vector, whose counters must stay the collection branch.

    The Unprefixed tests fail on master. With only the first commit, they fail on the TTreeReaderArray checks.

    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 to b.fN after opening an old file reads 0 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:

  • tested changes locally

  • updated the docs (if necessary)
  • This PR fixes #24146

    Diff: 367 lines (+275 / -92) across 4 files Reviewer: pcanal Review duration: 4396m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 367 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.353
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #24183"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.7% (MEDIUM) · Higher = larger blast radius
    42.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%