Re: Pb with Trees

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Oct 20 1997 - 17:52:01 MEST


After one iteration with Laurent, his problem shown below was simply
due to the fact that he was not giving the name of the class
in the branch creation. I post the problem to this list as it can be
of general interest.
Instead of the statement:
  TBranch *b = tree->Branch("event","Event",&gEvent,64000,0);
he should have:
  TBranch *b = tree->Branch("event","RBEvent",&gEvent,64000,0);

It is always a good principle to test the value of the pointer
to the branch in return of tree->Branch and print an aerror message
in case this pointer is NULL.

Rene Brun


Laurent Aphecetche wrote:
> 
> Hi,
> 
> I'm trying to write objects (my objects) to a Root file, in 2 ways :
> 
> 1. Serialization ;
> 2. Using a Tree (one branch) ;
> 
> My program looks like :
> 
>   ...
>   TROOT   ROSEBUD("Rosebud","Rosebud : the TAPS analysis software
> package");
>   TFile   file("rosebud.root","RECREATE","Rosebud") ;
>   TTree*  tree = new TTree("EM","EM particles") ;
>   TBranch* b = tree->Branch("event","Event",&gEvent,64000,0) ;
>   char keyname[200] ;
> 
>   HLIMIT(PAWC_SIZE) ; // Init PAW
> 
>   SetGlobals() ;
> 
>   // Get the input ntuple
>   FIn = new File(1,argv[1]," ",0,"INPUT","ROSEIN",1024) ;
>   FIn->Open() ;
>   FIn->PutId(1000) ;
>   GetInputNtuple(*FIn,gInputNtuple,"Experiment") ;
>   cout << (*FIn) << endl ;
> 
>   for ( i = 1 ; i <= atoi(argv[2]) ; i++ )
>   {
>     gEvent = new RBEvent ;
> 
>     FillEvent(i,*FIn) ;
> 
> //  1. sprintf(keyname,"Event%d",i) ;
> //  1. gEvent->Write(keyname) ;
> 
> //  2. tree->Fill() ;
> 
>     delete gEvent ;
>   }
> 
>   file.Close() ;
> 
> The first method works fine.
> The second one gives me a Segmentation fault in TTree::GetCurrentFile.
> 
> Any clue ?
> 
> Thanks.
> 
> --
> APHECETCHE Laurent (mailto:aphecetche@ganil.fr)
> GANIL, B.P. 5027, 14076, Caen Cedex 5, France
> Vox: +33 (0)2 31 45 45 85 - Fax: +33 (0)2 31 45 46 65
> WWW: http://ganp03.in2p3.fr/nof/ & (perso.)
> http://www.mygale.org/~p0mp0n



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