Repository navigation
[treeplayer] Fix leak of the collection proxy in TBranchProxy #23797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jmcarcell
wants to merge
3
commits into
root-project:master
Choose a base branch
from
jmcarcell:branchproxy-collection-leak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Read a data member of a split collection of a class without a dictionary | ||
| // over a TChain, which re-runs TBranchProxy::Setup() when switching files. | ||
| int ChainNoDict() | ||
| { | ||
| auto c = TClass::GetClass("ChainNoDictHit"); | ||
| if (c && c->HasDictionary()) { | ||
| std::cerr << "Class ChainNoDictHit has a dictionary and it should not." << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| TChain chain("t"); | ||
| chain.Add("chainNoDict0.root"); | ||
| chain.Add("chainNoDict1.root"); | ||
| TTreeReader r(&chain); | ||
| TTreeReaderArray<double> x(r, "hits.fX"); | ||
| int nValues = 0; | ||
| while (r.Next()) { | ||
| const auto entry = r.GetCurrentEntry(); | ||
| const int file = entry / 10; | ||
| if (x.GetSize() != static_cast<std::size_t>(entry % 10)) { | ||
| std::cerr << "Wrong size " << x.GetSize() << " in entry " << entry << std::endl; | ||
| return 1; | ||
| } | ||
| for (std::size_t i = 0; i < x.GetSize(); ++i) { | ||
| const double expected = 100. * file + entry % 10 + 0.1 * i; | ||
| if (std::abs(x[i] - expected) > 1e-9) { | ||
| std::cerr << "Wrong value " << x[i] << " in entry " << entry << ", expected " << expected << std::endl; | ||
| return 1; | ||
| } | ||
| ++nValues; | ||
| } | ||
| } | ||
| if (nValues != 90) { | ||
| std::cerr << "Read " << nValues << " values, expected 90" << std::endl; | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #ifndef __CreateChainNoDictFiles__ | ||
| #define __CreateChainNoDictFiles__ | ||
|
|
||
| #include "TFile.h" | ||
| #include "TTree.h" | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| struct ChainNoDictHit { | ||
| double fX = 0; | ||
| int fId = 0; | ||
| }; | ||
|
|
||
| #ifdef __ROOTCLING__ | ||
| #pragma link C++ class ChainNoDictHit+; | ||
| #pragma link C++ class std::vector<ChainNoDictHit>+; | ||
| #endif | ||
|
|
||
| // Write two files with a split std::vector of a struct. They are read in | ||
| // ChainNoDict.C without this dictionary, so that the collection proxy is emulated. | ||
| int CreateChainNoDictFiles() | ||
| { | ||
| for (int file = 0; file < 2; ++file) { | ||
| auto f = std::make_unique<TFile>(("chainNoDict" + std::to_string(file) + ".root").c_str(), "RECREATE"); | ||
| auto t = std::make_unique<TTree>("t", "test tree"); | ||
| std::vector<ChainNoDictHit> hits; | ||
| t->Branch("hits", &hits, 32000, 99); | ||
| for (int entry = 0; entry < 10; ++entry) { | ||
| hits.clear(); | ||
| for (int i = 0; i < entry; ++i) | ||
| hits.push_back({100. * file + entry + 0.1 * i, i}); | ||
| t->Fill(); | ||
| } | ||
| t->Write(); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| #endif |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly a question for @pcanal , I wonder if with this syntax we run the risk of leaving artifacts in the test directory that the reading test might pick up and effectively still read a dictionary from? The
ChainNoDict.Ctest already has a good check at lines 5-6, but what's your opinion?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACLiC doesn't generate a rootmap here, only
CreateChainNoDictFiles_C.so,_C.dand_C_ACLiC_dict_rdict.pcm, so there is nothing that would trigger autoloading of the library when reading. I checked by runningChainNoDict()in the test directory with those files present: after reading both filesChainNoDictHitstill has no dictionary and the library isn't loaded.