Re: [ROOT] passing a TH2D** & CINT problem

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Apr 15 2003 - 10:51:42 MEST


Hi Nicolas,

CINT does not support passing by reference a XXXX** argument.
You can do:

root [0] .L test.C
root [1] TH2D** pifs[3]
root [2] test(pifs,3)

with
//test.C
void test(TH2D** h,int n){
   //h=new TH2D*[n];
   char name[10];
   for (int i=0;i<n;i++){
     sprintf(name,"h%d",i);
     h[i] = new TH2D(name,"bla",128,0,128,128,0,128);
  }
}

Masa, I remember a similar question a few weeks ago. Do you have any plans to
support this?

Rene Brun

Nicolas Produit wrote:
> 
> Hi,
> 
> I have a code that work when compiled but not when interpreted,
> here is the relevant part:
> 
> in test.C:
> void test(TH2D** &h,int n){
>    h=new (TH2D*)[n];
>    for (int i=0;i<n;i++){
>      char name[10];
>      sprintf(name,"h%d",i);
>      h[i] = new TH2D(name,"bla",128,0,128,128,0,128);
>    }
> }
> isdcpc3:~/investigate 102> root
>    *******************************************
>    *                                         *
>    *        W E L C O M E  to  R O O T       *
>    *                                         *
>    *   Version   3.04/02      5 March 2003   *
>    *                                         *
>    *  You are welcome to visit our Web site  *
>    *          http://root.cern.ch            *
>    *                                         *
>    *******************************************
> 
> Compiled for linux with thread support.
> 
> CINT/ROOT C/C++ Interpreter version 5.15.68, Dec 12 2002
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .L test.C
> root [1] TH2D** pifs;
> root [2] test(pifs,3);
> Error: Symbol TH2D is not defined in current scope  FILE:test.C LINE:2
> Syntax Error: TH2D* FILE:test.C LINE:2
> Error: memory allocation for  (TH2D*) size=4 pinc=3
> FILE:/home/isdc/produit/investigate/./test.C LINE:2
> Warning: Automatic variable h allocated in global scope FILE:test.C LINE:2
> Error: Undeclared variable h FILE:test.C LINE:2
> *** Interpreter error recovered ***
> root [3]
> 
> Then I try:
> in test.C:
> void test(TH2D** &h,int n){
>    h=new TH2D*[n];
>    for (int i=0;i<n;i++){
>      char name[10];
>      sprintf(name,"h%d",i);
>      h[i] = new TH2D(name,"bla",128,0,128,128,0,128);
>    }
> }
> 
> isdcpc3:~/investigate 103> root
>    *******************************************
>    *                                         *
>    *        W E L C O M E  to  R O O T       *
>    *                                         *
>    *   Version   3.04/02      5 March 2003   *
>    *                                         *
>    *  You are welcome to visit our Web site  *
>    *          http://root.cern.ch            *
>    *                                         *
>    *******************************************
> 
> Compiled for linux with thread support.
> 
> CINT/ROOT C/C++ Interpreter version 5.15.68, Dec 12 2002
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .L test.C
> root [1] TH2D** pifs;
> root [2] test(pifs,3);
> Error: Symbol i is not defined in current scope  FILE:test.C LINE:3
> 
>   *** Break *** segmentation violation
>   Generating stack trace...
> 
>   *** Break *** keyboard interrupt FILE:test.C LINE:3
> 
>   *** Break *** keyboard interrupt
> Root >
> 
> an then I have to kill the terminal...
> 
> --
> Nicolas Produit
> INTEGRAL Science Data Center    Phone:  +41 22 950 91 40
> 16, Chemin d'Ecogia             Fax:    +41 22 950 91 33
> CH-1290 Versoix                 www:    http://isdc.unige.ch/



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