Re: Write histogram to a specific file

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Jan 26 2000 - 23:30:09 MET


Hi Stefan,
It seems that you hit s scope problem. You give only some lines
of your code. My guess is that you create the histogram
in a function different than the one where you write.
When you exit the scope of the function, objects in the stack
are automatically deleted.
You should create your histogram object with new instead.

Rene Brun

On Wed, 26 Jan 2000, Stefan Stonjek wrote:

> On Wed, 26 Jan 2000, Rene Brun wrote:
> 
> > > It is no problem to read the allready existig histos in this program. They
> > > are already filled in the same program and the "print" command clearly
> > > indicated that the new histogram contains usefull date. But these data
> > > does not end up in the file.
> > > 
> > > Here is the code in question. It is just an excerpt from a much longer
> > > program with many subroutines.
> > > 
> > >   TH1F *pt_gcc_sig_etamlt18 = (TH1F*)hfile->Get("pt_gcc_sig_etamlt18");
> > >   TH1F *pt_wcc_sig_etamlt18 = (TH1F*)hfile->Get("pt_wcc_sig_etamlt18");
> > >   hfile->cd();
> > >   TH1F pt_sig_etamlt18 = ( *pt_gcc_sig_etamlt18 - *pt_wcc_sig_etamlt18);
> > >   pt_sig_etamlt18.SetName("pt_sig_etamlt18");
> > >   pt_sig_etamlt18.SetDirectory(hfile);
> > >   pt_sig_etamlt18.Print("all");
> > > 
> > > Mayby it is just a stupid mistake but I hope someone is able to help me.
> 
> > You must write back the modified and new objects to the file.
> > The file mmust be opened in update mode.
> > To write back the modified/new objects, two possibilities
> >  1- write each of them individually to the file, eg
> > pt_sig_teamlt18.Write();
> >  2 -write all objects to the file with file->Write();
> > 
> > In your case, option 2 is probably the best.
> 
> Hello Rene,
> 
> at the end of my program I write all histos at once. The first two
> histograms do end up in the file, the one generated here does not. All the
> histograms which I book in the begining of the program, just after
> generating the output file exist in the file. Those booked somewhere in
> the program does not. 
> 
> Tschuess
> 	Stefan
> 
> 
> *********      Stefan  Stonjek     *********
> *****            DESY / ZEUS           *****
> *****      Stefan.Stonjek@desy.de      *****
> *********  Tel.: +49-40-8998-3159  *********
> 



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET