Hi, I'm using Root 2.22/10 under Windows NT. Given an existing TFile containing a TTree - I want to add new branches that will be written out to another (new) TFile. I saw a previous post from Dec. 2, 1999: >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 I have tried to do this - but I get 2 copies of the same TTree in my original TFile. I made no special attempt to update the TTree header as Rene suggests, so I'm under the assumption that this is my problem. How do I go about fixing this? Or...what I am truly interested in is having associated data (i.e. raw and analyzed) linked together. It seems that having all data under one TTree would clearly link such data together. Is there better way to go about this? Thanks, Heather ******************************************************************** Heather Maria Theresa Arrighi Goddard Space Flight Center T2 Room 51 phone (301) 286-8359 fax (301) 286-1629
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET