[tree] Fix interaction between GetEntries and GetListOfFriends #17822
+91
−6
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.
Fixes #17820
Full analysis of the issue follows:
TChain::GetEntries calls TChain::LoadTree(TTree::kMaxEntries - 1)
Internally, this will set fReadEntry == -2, due to how LoadTree works and the fact it's trying to read beyond the last entry in the chain
This has an effect here
root/tree/tree/src/TChain.cxx
Lines 1675 to 1679 in f33985d
t
is the current friend being traversed in the list of friends of the chain. We callt->LoadTree(TTree::kMaxEntries - 1)
.Inside the call to LoadTree on the friend, we reach this line
root/tree/tree/src/TChain.cxx
Line 1484 in f33985d
Back to the LoadTree of the main chain, these lines
root/tree/tree/src/TChain.cxx
Lines 1681 to 1684 in f33985d
friend->GetTree()
will return nullptr so the connection won't happen.This commit fixes the issue by always calling LoadTreeFriend on the friend, which will anyway call LoadTree eventually but with the index value and does not incur in the wrong mechanics.