Skip to content

[treeplayer] Fix Alt$(array) to iterate correctly when used standalone#22599

Open
guitargeek wants to merge 1 commit into
root-project:masterfrom
guitargeek:issue-6378
Open

[treeplayer] Fix Alt$(array) to iterate correctly when used standalone#22599
guitargeek wants to merge 1 commit into
root-project:masterfrom
guitargeek:issue-6378

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

A standalone Alt$ on a variable-length array, e.g.

t.Scan("Alt$(x,-1)");

only ever evaluated the first element of each entry instead of looping over the whole array. The combined form x:Alt$(x,-1) worked because the sibling formula x drove the iteration, which made the bug easy to miss.

Root cause: TTreeFormula::ResetDimensions() never accounted for the kAlternate/kAlternateString actions when computing fMultiplicity. By design, Alt$ hides its primary operand from the TTreeFormulaManager so that, in expressions like arr1+Alt$(arr2,0), arr1 drives the loop and the alternate pads the entries where arr2 is too short. But when Alt$ is the only source of multiplicity there is no sibling to drive the loop, so the formula collapsed to a single instance.

Fix: in ResetDimensions(), after the main operand loop, if the formula has no other multiplicity (fMultiplicity == 0) scan for kAlternate/ kAlternateString operands and register their primary with the manager when that primary is itself a genuine array.

Adds two regression tests: AltDollarVariableArray (standalone Alt$ now loops; Alt$(x[2],-1) keeps its fall-back behaviour) and AltDollarPadsShorterArray (the documented arr1+Alt$(arr2,0) padding still iterates over the longer array).

Closes #6378.

🤖 Done with the help of Claude Code (Claude Opus 4.8)

A standalone Alt$ on a variable-length array, e.g.

```c++
t.Scan("Alt$(x,-1)");
```

only ever evaluated the first element of each entry instead of looping
over the whole array. The combined form `x:Alt$(x,-1)` worked because
the sibling formula `x` drove the iteration, which made the bug easy to
miss.

Root cause: `TTreeFormula::ResetDimensions()` never accounted for the
`kAlternate`/`kAlternateString` actions when computing `fMultiplicity`.
By design, `Alt$` hides its primary operand from the TTreeFormulaManager
so that, in expressions like `arr1+Alt$(arr2,0)`, `arr1` drives the loop
and the alternate pads the entries where `arr2` is too short. But when
`Alt$` is the *only* source of multiplicity there is no sibling to drive
the loop, so the formula collapsed to a single instance.

Fix: in `ResetDimensions()`, after the main operand loop, if the formula
has no other multiplicity (`fMultiplicity == 0`) scan for `kAlternate`/
`kAlternateString` operands and register their primary with the manager
when that primary is itself a genuine array.

Adds two regression tests: **AltDollarVariableArray** (standalone `Alt$`
now loops; `Alt$(x[2],-1)` keeps its fall-back behaviour) and
**AltDollarPadsShorterArray** (the documented `arr1+Alt$(arr2,0)`
padding still iterates over the longer array).

Closes root-project#6378.

🤖 Done with the help of [Claude Code](https://claude.com/claude-code) (Claude Opus 4.8)
@guitargeek guitargeek self-assigned this Jun 13, 2026
@guitargeek guitargeek requested a review from pcanal as a code owner June 13, 2026 07:23
@guitargeek guitargeek added the bug label Jun 13, 2026
@guitargeek guitargeek requested a review from jblomer as a code owner June 13, 2026 07:23
@guitargeek guitargeek changed the title [treeplayer] Fix Alt$(array) to iterate correctly when used standalone [treeplayer] Fix Alt$(array) to iterate correctly when used standalone Jun 13, 2026
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

Test Results

    21 files      21 suites   3d 7h 40m 3s ⏱️
 3 861 tests  3 861 ✅ 0 💤 0 ❌
73 685 runs  73 685 ✅ 0 💤 0 ❌

Results for commit 40c7101.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTreeFormula Alt$ gives (silently) wrong result when used by itself.

1 participant