Hi Jiri,
The Tree does not write itself to a file. It is your responsability
to write the Tree header. There are applications that write the Tree header
in a different file than the Tree baskets.
What you request is already in place via TTree::AutoSave.
See the example below:
Rene Brun
void wtree() {
TFile *hfile = new TFile("file1.root","recreate");
TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
TFile *hfile2 = new TFile("file2.root","recreate");
Float_t px, py, pz;
for (Int_t i = 0; i < 25000; i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
Float_t random = gRandom->Rndm();
ntuple->Fill(px,py,pz,random,i);
}
ntuple->AutoSave(); //tree header written to file1
ntuple->Write(); //tree header also written to file2
delete hfile;
delete hfile2;
}
Jiri Chudoba wrote:
>
> Hello,
>
> the TTree knows its (ROOT) directory, where it was created (fDirectory),
> but when it is written, it writes itself to gDirectory. Is there any
> reason for that? Could it be changed that the default directory for
> writing would be to fDirectory?
>
> The workarround is simple:
>
> TDirectory *cwd = gDirectory;
> treeD->GetDirectory()->cd();
> treeD->Write(fTreeD->GetName(),option);
> cwd->cd();
>
> but it could be directly in the root code.
>
> Cheers,
> Jiri.
>
> PS: root 3.02.07, linux RedHat 6.1
>
> *************************************************************************
> * E-mail address: Jiri.Chudoba@cern.ch *
> * WWW Homepage : http://delphiwww.troja.mff.cuni.cz/chudoba/ *
> * Telephone : +41 22 76 72288 *
> * Fax : +41 22 76 79480 *
> *************************************************************************
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:46 MET