ROOT Version: Not Provided Platform: Not Provided Compiler: Not Provided
Hi. I think I have a problem with TTrees. I have a file with a tree. I read it. Then I must copy a subset of this tree to another tree and I deactivate the branches I don’t want to copy. And all is fine .
But then I must reactivate all branches of the first tree because I need them in the macro. With the following code I get a segmentation violation, but if I don’t try “reactivation” and I read the tree again from the file to have all branches active (i.e. the first “Get” to have the tree to clone it, the second to have the same tree to use it), I have no problem. So…is there a solution?
Thanks a lot
TFile *hfile=TFile::Open("simulazione.root", "READ");
hfile->ls();
TTree *treelec1 = (TTree*)hfile->Get("tree");
treelec1->SetBranchStatus("*", 0);
for (auto activeBranchName : {"vertext*", "accept"})
treelec1->SetBranchStatus(activeBranchName, 1);
TFile *hfilerec = TFile::Open("ricostruzione.root","RECREATE");
auto treerec =treelec1->CloneTree();
treelec1->SetBranchStatus("vertext*", 0);//even without this, same problem
treelec1->SetBranchStatus("accept", 0);//even without this, same problem
treelec1->SetBranchStatus("*", 1);
So after cloning treelec1, if you set the status of all branches to active and then do treelect1->GetEntry(0), that causes a segfault?
If that’s the case I think your approach of creating another tree object to avoid the issue might be the right one, unless @pcanal has another suggestion.
When I use valgrind I don’t get something like “segmentation violation”, when I use ROOT I get a crash when I run a simulation.
Maybe I have some ROOT problem. Compiler reports a warning even if it doesn’t crash (maybe I shouldn’t underestimate it)