Re: MultiDim array as data member

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 17 Mar 2010 13:49:02 -0500


Hi Vito,

You can try:

Int_t fMyDim;
Float_t *fMyArray[4] ; //[fMyDim] my array with dimension fMyDim

fMyDim = dim;
for ( Int_t n = 0; n< 4; n++ ){

     fMyArray[n] = new Float[fMyDim];
}

You could also try a vector<vector<int> > (probably the easy to use), or you could try (possibly the most efficient)

Int_t fMyDim; // N times what you need. Float_t *fMyArray ; //[fMyDim] my array with dimension fMyDim

And in the constructor I can initializa this variable as:

....
fMyDim = dim;
fMyArray = new Float_t[fMyDim] ;
for ( Int_t n = 0; n< fMyDim; n++ ){

    fMyArray[n] = MyVal;
}

and use as :

for (int i = 0; i< 4; ++i) {

   for (int j = 0; j< fMyDim / 4; ++j) {

      fMyArray[ j*4 + i ];
   }
}

Cheers,
Philippe.

On 3/17/10 8:43 AM, Vito Di Benedetto wrote:
> Dear ROOT experts,
> I know that I can define an array as data member of a ROOT derived class
> with dynamic dimension in this way:
>
> Int_t fMyDim;
> Float_t *fMyArray ; //[fMyDim] my array with dimension fMyDim
>
>
> And in the constructor I can initializa this variable as:
>
> ....
> fMyDim = dim;
>
> fMyArray = new Float_t[fMyDim] ;
>
> for ( Int_t n = 0; n< fMyDim; n++ ){
>
> fMyArray[n] = MyVal;
>
> }
>
>
> If I have a bi-dimensional array
>
> fMy2DArray[n][fMyDim]
>
> where the first dimension is a known constant value, but I want to use a
> dynamic value for the second dimension.
>
> Can I using something similar to the 1-dim array as before?
>
>
> Cheers,
> Vito
>
>
Received on Wed Mar 17 2010 - 19:49:10 CET

This archive was generated by hypermail 2.2.0 : Thu Mar 18 2010 - 23:50:01 CET