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