Ed, SetDirectory is not sufficient to move an object from one directory to another if the object is a class like a TTree, because one part of the object only is in memory. It does not move what is on disk. There is a special function to copy a Tree. Modify your code in the following way: TFile *file1 = new TFile("hsimple.root"); TFile *file2 = new TFile("new.root","RECREATE"); TNtuple *pNtup = (TNtuple *)file1->Get("ntuple"); TNtuple *n = pNtup->CloneTree(); n->Write(); Rene Brun Ed Oltman wrote: > > Hi, > I am having trouble writing an TNtuple object that lives in one directory > to a new file. For example, > using the hsimple.root file made by the hsimple.c macro in tutorials: > > TFile *file1 = new TFile("hsimple.root"); > TFile *file2 = new TFile("new.root","RECREATE"); > TNtuple *pNtup = (TNtuple *)file1->Get("ntuple"); > pNtup->SetDirectory(file2); > file2->Write(); > > I get the following error (5 times) on file2->Write() > > Error in <TBranch::Write>: File hsimple.root is not writeable > > Why is that? > > meanwhile, > > file2->ls() > > shows > > TFile** new.root > TFile* new.root > OBJ: TNtuple ntuple Demo ntuple : 0 > KEY: TNtuple ntuple;1 Demo ntuples > > When I start a new root session and type > > TFile *file = new TFile("new.root"); > file->ls() > > It shows: > > TFile** new.root > TFile* new.root > KEY: TNtuple ntuple;1 Demo ntuples > > however, when I try to do something (e.g. ntuple->Draw("px") > > I get a huge number of following: > > Error in <TFile::ReadBiuffer>: error reading all requested bytes from file > new.root, got 0 of 29594 > > What am I doing wrong??? I am using version 3.02/07 on Windows 2000. > > Thanks! > > Ed Oltman
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET