Re: [ROOT] closing TTree files

From: Dr. John Krane (jkrane@netzero.com)
Date: Fri Jul 18 2003 - 15:32:35 MEST


Hi Philippe,

The owner is a modified version of MakeClass, that is generic enough to 
read branches/variables from nearly-identical trees.  Although I at 
first tried to mimic the destructor with

delete fChain->GetCurrentFile();

as you suggest, this didn't work so I tried numerous other things with 
poor results.  You see, with the above solution, I still have what 
appears to be the old files in the TBrowser, but they are just the 
branches I actually used in the code, not the branches I didn't use. 
All branches are empty.

If the branches need to be "freed" one by one, shouldn't this be in the 
default destructor for MakeClass?  Yet it is not.  (I assumed, with all 
dangers of assuming, that there existed a well-known way of closing the 
file and associated objects that I just didn't know about...)

	- John

Philippe Canal wrote:
> Hi John,
> 
> It all depends on how you allocated the TFile containing the TTree.
> 
> A guess would be that you should replace
> 	fChain->Delete();
> by
> 	delete fChain;
> 
> You may also have to do:
> 	if (fChain) delete fChain->GetCurrentFile();
> 
> But both are wild guesses :) ... The bottom line is that you have to insure
> that the 'owner' of the file of the tree closes and delete its file.
> 
> Cheers,
> Philippe.
> 
> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Dr. John Krane
> Sent: Thursday, July 17, 2003 4:36 PM
> To: roottalk@pcroot.cern.ch
> Subject: [ROOT] closing TTree files
> 
> 
> Hi,
> 
> I want to open a Tree, loop over it creating histograms, close the histo
> file, close the Tree.  Without leaving Root, I want to repeat the entire
> process with a different Tree and make a separate histo file.
> 
> I have most of what I need I think, but I don't know how to close the
> Tree when I'm done with it.  I do:
> 
>     // Write histos to disk.  Close all files.
>     histofile->Write();
>     histofile->Close();
>     delete histofile;
> 
>     fChain->Delete();
> 
> And this works as I expect with the histofile but not with the Tree.  I
> get through my loop twice and then seg fault.  When I check the
> TBrowser, I see both the first and second trees in there, which would
> cause a seg fault in my code all right.  Can anybody tell me how to get
> rid of the first Tree?
> 
> 	- John
> 
> 
> 



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