[treeplayer] Fix Alt$(array) to iterate correctly when used standalone#22599
Open
guitargeek wants to merge 1 commit into
Open
[treeplayer] Fix Alt$(array) to iterate correctly when used standalone#22599guitargeek wants to merge 1 commit into
Alt$(array) to iterate correctly when used standalone#22599guitargeek wants to merge 1 commit into
Conversation
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)
Alt$(array) to iterate correctly when used standalone
Test Results 21 files 21 suites 3d 7h 40m 3s ⏱️ Results for commit 40c7101. ♻️ This comment has been updated with latest results. |
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.
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 formulaxdrove the iteration, which made the bug easy to miss.Root cause:
TTreeFormula::ResetDimensions()never accounted for thekAlternate/kAlternateStringactions when computingfMultiplicity. By design,Alt$hides its primary operand from the TTreeFormulaManager so that, in expressions likearr1+Alt$(arr2,0),arr1drives the loop and the alternate pads the entries wherearr2is too short. But whenAlt$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 forkAlternate/kAlternateStringoperands 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 documentedarr1+Alt$(arr2,0)padding still iterates over the longer array).Closes #6378.
🤖 Done with the help of Claude Code (Claude Opus 4.8)