Adding entries to a tree

Hi,

I’m trying to add entries to a tree:

{
gROOT->Reset();

TFile *oldfile = new TFile(“clasnt_049669_00.root”);
TTree oldtree = (TTree)oldfile->Get(“h10”);

TFile *newfile = new TFile(“out.root”,“update”);
TTree newtree = (TTree)newfile->Get(“h10”);

Int_t nentries = newtree->GetEntries();

cout << "nentries " << nentries <GetEntry(223);
newtree->Fill();

oldtree->Show(223);
newtree->Show(nentries);

oldtree->Delete();
newtree->Delete();

oldfile->Close();
newfile->Close();

delete newfile;
delete oldfile;

}

The GetEntry - Fill combination is how I initially created the “newtree”, but when I open the file with it and try to add new entries, it doesn’t seem to work. Could you, please, tell me what is wrong here.

Thank you.

Hi,

Because you did not turn of HTML in your post, your code has been mangled (in the most interesting part :slight_smile: ).

Completely guessing, I would have to bet that you are missing the part where you should be connecting new and old tree together: oldtree->CopyAddresses(newtree);
Also by doing:oldtree->Delete(); newtree->Delete(); unless you also did an explicit newfile->Write before those, then you prevent the writing of the file.

Cheers,
Philippe

Sorry about the mangling. Anyway, your guess was correct. It works now. Thank you.