RE: [ROOT] Writing a root file...

From: Philippe Canal (pcanal@fnal.gov)
Date: Sun Jul 20 2003 - 03:30:53 MEST


Hi,

The TTree (and THx and TEventList) object are attached at the time 
of their creation to the current ROOT directory.  "Attached" means 
here that they will be written to that current directory each time 
it's Write method is called.  In the case of the TTree it also 
means that Fill will eventually save the data in the directory.

Note that TFile inherits from TDirectory and is, for the purpose
of this discussion the same thing as it own top directory.

When a TFile object is constructed is becomes the current directory.
The current directory can also be change by call TDirectory::cd on
the directory you want.

> In otherwords, is it INPUT.root or UTPUT.root ?

So it depends from the control flow of your program.  Usually, you
would created the TFile object your want to write to just before
creating the TTree and TH1x objects (but you could also use cd).

Cheers,
Philippe

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of zaldy
Sent: Saturday, July 19, 2003 4:13 PM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Writing a root file...



Dear ROOT Users,


In using the methods tree_ptr->Write() and file_ptr->Write(), how does the 
TTree object communicates with the TFile object?

For instance in writing a root file, I noticed the ff. steps from the 
tutorial(filename: tree*.C) or manual (Users Man. 3.05, pp.212-214):

	1. a declaration of the form
              TFile * firstFILEinput = new TFile("INPUT.root",MODE);
              TTree * myTree= new TTree("T","Oak Tree");
            
        2. Creating branches;
              myTree->Branch(.......arguments.......);
              .......

        3. Filling the branches with data;
              branchName = data_one;
              ............. 
              myTree->Fill();

        4. actual writing;
              myTree->Write();  
              (sometimes: fileOUT->Write(); ) 
 
Now what about if one has to create another TFile object

  TFile * anotherFileOUTPUT = new TFile("OUTPUT.root",MODE), 

how will the TTree select which TFile's to direct? 
(Or, how intelligent this tree is to choose w/c from the two files to 
write?)

I did not see an explicit 
declaration on the part of TTree that it has to write to a specific file. 
So far in the manual, we are told that it is for writing or reading 
through its MODE.

In otherwords, is it INPUT.root or UTPUT.root ?
Are we assured that it will not overwrite, for instance, the file
"INPUT.root" with mode=>READ?

My apology for the many questions.

Thanks.

-- 

--------------------------------------------------------
                   Zaldy A. Nawang 
                   PS Users Room 2
                   Yon Gokan, 
                   E362, Neutrino Group, 
                   IPNS, KEK, 
                   Japan 
                    
                   e-mail: zaldy@neutrino.kek.jp
                   Tel. No. : (81) 029864 - 5387
--------------------------------------------------------



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET