RE: [ROOT] closing TTree files

From: Philippe Canal (pcanal@fnal.gov)
Date: Fri Jul 18 2003 - 18:46:39 MEST


Hi John,

> (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...)

Well it is to delete the TFile object they are associate with.

> 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.

"Branches" do not live by themselves, they can only be part of a TTree.
Since it is only the branch you used, I am suspecting that this 'stray'
TTree is actually one you have created as a duplication of the existing
TTree but have not filled.  For more information, I would need to look
at the control flow at least containing all the instance of creating
TFile, TChain and TTree objects (include call to CloneTree, etc.).

Cheers,
Philippe.


-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Dr. John Krane
Sent: Friday, July 18, 2003 8:33 AM
To: Philippe Canal
Cc: roottalk@pcroot.cern.ch
Subject: Re: [ROOT] closing TTree files


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