Re: Saving histograms in a file AFTER book+fill

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Jun 25 1998 - 18:35:16 MEST


Alberto Baldisseri wrote:
> 
> Hi rooters,
> 
> I have a macro that build some histograms and I would like to save it on
> a file. The standard
> way suggested on the tutorial is to open the file before creating the
> histograms, in that way
> all the histograms are located in the current directory of the open
> file. But, I would like to
> save the histograms AFTER the book+fill.
> When I open the file after the histogram book+fill, the file becomes the
> current directory
> which is empty. There is a way to copy all the histograms to the file
> directory ? Or another
> solution ?
> 

This is a complement to Fons and Martin's answers.
The list of histograms in memory for a given file/directory is obtained
via file->GetList().
For example, assume you have histograms in a given directory dir1
and you want to save these histograms to e new file, do
  TFile *newfile = new TFile("newfile.root","recreate");
  dir1->GetList()->Write();

The second statement will write all objects (histograms, or any other
object that is part of this list into newfile.

By default, Root systematically adds TH1 and TTree objects to
the current directory in memory. You can add your own objects as well
with
   object->AppendDirectory();

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:34 MET