Commit 6c75a77
committed
[tree] Fix interaction between GetEntries and GetListOfFriends
Fixes #17820
Full analysis of the issue follows:
1. TChain::GetEntries calls TChain::LoadTree(TTree::kMaxEntries - 1)
2. 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
3. This has an effect here https://github.com/root-project/root/blob/f33985dca2d6bc505e83498f7b4561ddd969be17/tree/tree/src/TChain.cxx#L1675-L1679
where `t` is the current friend being traversed in the list of friends of the *chain*.
We call `t->LoadTree(TTree::kMaxEntries - 1)`.
4. Inside the call to LoadTree on the friend, we reach this line
https://github.com/root-project/root/blob/f33985dca2d6bc505e83498f7b4561ddd969be17/tree/tree/src/TChain.cxx#L1484
where the fTree data member of the friend is invalidated.
5. Back to the LoadTree of the main chain, these lines
https://github.com/root-project/root/blob/f33985dca2d6bc505e83498f7b4561ddd969be17/tree/tree/src/TChain.cxx#L1681-L1684
would normally connect the fTree data member of the main chain to the current friend, so the list of friends
is properly populated. But due to 4., `friend->GetTree()` will return nullptr so the connection won't happen.
This commit changes the implementation of TChain::GetEntries, so that
after computing the total number of entries the cursor on the chain is
brought back to its previous entry, or at least 0 if it was in an
invalid state before. TChain::LoadTree is also modified so that if the
current tree is not connected to the list of friends, the connection is
refreshed.1 parent f33985d commit 6c75a77
File tree
3 files changed
+98
-0
lines changed- tree
- treeplayer/test
- tree/src
3 files changed
+98
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
985 | 985 | | |
986 | 986 | | |
987 | 987 | | |
| 988 | + | |
988 | 989 | | |
| 990 | + | |
989 | 991 | | |
990 | 992 | | |
991 | 993 | | |
| |||
1373 | 1375 | | |
1374 | 1376 | | |
1375 | 1377 | | |
| 1378 | + | |
1376 | 1379 | | |
1377 | 1380 | | |
1378 | 1381 | | |
1379 | 1382 | | |
1380 | 1383 | | |
1381 | 1384 | | |
1382 | 1385 | | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
1383 | 1393 | | |
1384 | 1394 | | |
1385 | 1395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
0 commit comments