Re: [ROOT] Branch of TMatrixD

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jan 21 2003 - 16:46:06 MET


Hi Dan,

I do not see a problem with your setup. I run 3.04/02 or 3.05
See example below

Rene Brun


void bugw(){

  TFile *fout=new TFile("TreeMat.root","RECREATE");
  TTree *tree=new TTree("test_tree","test_tree");
  TMatrixD matrix(2,2);
  TMatrixD *pointer = &matrix;
  tree->Branch("matrix","TMatrixD",&pointer,64000,0);

  matrix(0,0)=1.;
  matrix(0,1)=2.;
  matrix(1,0)=3.;
  matrix(1,1)=4.;

  tree->Fill();
    
  fout->Write();
  delete fout;
}
void bugr() {
   TFile *f = new TFile("TreeMat.root");
   TTree *T = (TTree*)f->Get("test_tree");
   TMatrixD *matrix=0;
   T->SetBranchAddress("matrix",&matrix);
   T->GetEntry(0);
   matrix->Print();
   T->MakeClass("T");
   delete f;
}
void bug(){
   bugw();
   bugr();
   gROOT->ProcessLine(".L T.C");
   T t;
   t.GetEntry(0);
   t->matrix->Print();
}

Dan Krop wrote:
> 
> Hi,
>         I am having a problem creating a tree with a branch of TMatrixD.  Below is a
> short test program showing the problem I have.  It runs fine, but when I tree
> to MakeClass() out of the tree and loop over it, I get a seg fault.  I
> apologize if this is some trivial mistake that I am overlooking.  I am using
> version 3.03/05 on RH 7.3.
> 
>                                         Thanks in advance,
>                                                                 Dan
> 
> //----------------------------------------------------------------------------------
> void TreeMat(){
> 
>   TFile *fout=new TFile("TreeMat.root","RECREATE");
>   TTree *tree=new TTree("test_tree","test_tree");
>   TMatrixD matrix(2,2);
>   tree->Branch("matrix","TMatrixD",&matrix,64000,0);
> 
>   matrix(0,0)=1.;
>   matrix(0,1)=2.;
>   matrix(1,0)=3.;
>   matrix(1,1)=4.;
> 
>   tree->Fill();
> 
>   fout->Write();
>   fout->Close();
> }
> //--------------------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:08 MET