Re: How to correctly add a branch to a saved TTree?

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Sat, 20 Jun 2009 21:59:30 -0500


Hi Pierre-Luc,

I do not see any problem with this code, nor can I reproduce any issue.

How does it fail in your case? Which version of ROOT are you using?

Cheers,
Philippe.

Pierre-Luc Drouin wrote:
> Hi,
>
> I am trying to add and fill a branch to an existing TTree and I get a
> segmentation violation error when the number of entries exceeds some
> value
>
> Here is some code to reproduce the problem:
> {
> Int_t nentries=500000;
> TFile *file=new TFile("file.root","recreate");
> TTree *tree=new TTree("tree","tree");
> Float_t val=0;
> tree->Branch("br1",&val,"br1/F");
>
> for(Int_t i=0; i<nentries; ++i) {
> val=i;
> tree->Fill();
> }
>
> file->Write();
> file->Close();
> delete file;
>
> file=new TFile("file.root","update");
> tree=(TTree*)file->Get("tree");
> TBranch *br=tree->Branch("br2",&val,"br2/F");
>
> for(Int_t i=0; i<nentries; ++i) {
> val=i;
> br->Fill();
> }
> tree->SetEntries(br->GetEntries());
>
> file->Write();
> file->Close();
> delete file;
>
> file=new TFile("file.root","read");
> tree=(TTree*)file->Get("tree");
> tree->Draw("br1");
> }
>
> The code above works correctly when nentries is 25000 but fails with
> 500000.
>
> How can I fix this problem?
>
> Thank you!
> Pierre-Luc Drouin
>
Received on Sun Jun 21 2009 - 04:59:35 CEST

This archive was generated by hypermail 2.2.0 : Sun Jun 21 2009 - 05:50:05 CEST