Re: seg violation in named macro

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Sep 08 1999 - 10:27:30 MEST


Hi Michael,
Remove the statement output.Close() from your macro.
Close delete all objects associated with the file, including
your TProfile object. This object will again be deleted when leaving 
the scope of the function.
The safe alternative is to always do
  TProfile *prof = new TProfile(...
instead.

Rene Brun


M. Sievers wrote:
> 
> Hello,
> 
> I have a problem when writing data from within a named macro and Closing
> the file at the end. I have the following macro:
> 
> int mytest(char* outfile="mytest.root")
> {
>   TFile output(outfile,"RECREATE");
>   TProfile prof("prof","prof",10,0,10);
>   prof.Fill((float)5,(float)3);
>   prof.Write();
>   output.Close();
>   return 0;
> }
> 
> executing it yields (on Linux 2.2.10, glibc):
> 
>  $ root -b -q mytest.C
>   *******************************************
>   *                                         *
>   *        W E L C O M E  to  R O O T       *
>   *                                         *
>   *   Version   2.22/09      13 July 1999   *
>   *                                         *
>   *  You are welcome to visit our Web site  *
>   *          http://root.cern.ch            *
>   *                                         *
>   *******************************************
> 
> CINT/ROOT C/C++ Interpreter version 5.14.8, Jul 4 1999
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0]
> Processing mytest.C...
> 
>  *** Break *** segmentation violation
> Root > Function mytest() busy flag cleared
> 
> If I leave out output.Close() it does not complain and the file seems to
> be written correctly.
> 
> Did I make a mistake, is it a known problem that is already fixed, can I
> just leave out the Close() and rely on the file always to be written
> correctly?
> 
> Puzzled,
> Michael
> 
> --------------------------------------------------------------------------
> Michael Sievers
> Michael.Sievers@desy.de
> --------------------------------------------------------------------------
> esa$ gcc -Wall -o ariane5 ariane5.c
> ariane5.c: 666: warning: long float implicitly truncated to unsigned type
> esa$ ariane5



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