Limit of AddFriend for a TTree

I am using AddFriend function to extend new branches to a existing TTree in a TFile.
However, I found that if 4 friend trees have been added (in total 4+1 trees in the TFile), and we try to add the 5th friend tree to it, the 5th one will cause segmentation violation when we access the content of the 5th friend tree.

This is how I add friend tree:

  TFile* file=new TFile("in.root","UPDATE");
  TTree* old_tree=(TTree*)file->Get("h1");

  TTree* t=new TTree("h2","h2");
  TBranch* b_m =t->Branch("m",&m,"m");

  for(unsigned int i=0;i<old_tree->GetEntries();i++)
    m = i;


The code worked until the 5th friend tree is added.
Is there any limit on the number of friend trees to a TTree?
Besides, is there any way to extend a new branch to an existing TTree in an existing TFile?
I know that we can use CopyTree to make a TFile, and make new branch to the copied tree during the process. But I hope to do so by updating the TFile without making a new one.
Thank you in advance.

ROOT Version: 5.34/38
Platform: SL7
Compiler: g++

Hi @ytlai

There is no hard limit. Is the crash still there with ROOT v6.26.02?


I checked with root v6, and the problem seems gone. I will check more on similar cases. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.