Re: Add new branches

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Dec 02 1999 - 00:56:55 MET


Hi Patrice,
This is possible, but you must be careful !
You have to think where you want to write the new Tree header:
in the original file or file2 ?
Why don't you simply create a second Tree with the new branch(es)
in file2 ? There is no penalty in using multiple Trees in parallel.
Assuming that you understand the first problem above, the procedure
to add a branch to an existing tree in a different file is the following:
 Here I assume that you can update file1.
  TFile f1("fil1.root","update");
  TTree *T = (TTree*)f1.Get("T");
  TBranch *br = T->Branch("newbranch",.....
  br->SetFile("file2.root");
  Int_t nentries = Int_t(T->GetEntries());
  for (Int_t i=0;i<nentries;i++) {
      some calculations necessary to fill the object(s) to go into
      newbranch
      br->Fill();
  }
  f1.cd();
  T->Write();

In case you need the data in the old branch(es) to fill the new branch(es)
you have to set the usual branch addresses.

Rene Brun


On Mon, 29 Nov 1999, Patrice Lebrun wrote:

> I need your help !
> 
>  I have a tree (simple tree from ntuple) in a file (file1.root)
> and  I would like to add some branches to this tree in one
> other file (file2.root), Which is a procedure to do this ?
> 
> Thank you.
> 
> --
> Patrice Lebrun
> Institut de Physique Nucleaire de Lyon
> Phone: 04 72 44 84 43
> Fax: 04 72 43 14 52
> 
> 
> 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET