Re: [ROOT] TGraph and vector

From: Colin Bernet (bernet@hep.saclay.cea.fr)
Date: Tue Jan 08 2002 - 10:24:22 MET


Hi Michael, 

As root was not compiled with STL (why not, Rene ?), 
root classes don't know about it. I also think it would be pretty
useful to have TTree/Branch classes know about the vector container. 

Anyway, even if you don't know how many points you have in your file, or
how many points you want, you can reallocate memory for your arrays
manually : 

float *x = malloc(100);

//and if you read more than 100 points :
realloc(x,200);

// now you have 100 more slots in your array. but the previous data are
// sill there

that's basically what vector is doing : it allocates a given (can be
specified) amount of memory, and doubles it if you go over this limit. 
Doubling the allocated memory is more efficient, cause memory
allocation costs time. 
Keep track of the size of your array so you can reallocate afterwards
again if needed.  

Happy new year !

Colin

cbernet@cea.fr

> Dear Rooters!
> 
> I just remember vaguely that there was somethin behing root and not
> using the stl container classes, but do not remember anymore ..
> 
> At the moment I want to draw some TGraphErrors and read the data from
> file, number of points not necessarily known. Using a stl vector<>
> would be very convenient, but TGraph prefers to have double* or float*
> ....  Is there any elegant OO way to cope with this problem?
> 
> 
> Cheers
> Michael
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:37 MET