Re: [ROOT] TGraph and vector

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jan 08 2002 - 16:30:10 MET


Hi Colin,

Colin Bernet wrote:
> 
> Hi Michael,
> 
> As root was not compiled with STL (why not, Rene ?),

What do you mean by "compiled with STL" ?

If your class includes STL collections, ROOT can process this class.
rootcint can generate the code for I/O for these classes.
Classes containing STL collections can also be put in ROOT Trees.

However, ROOT Trees with classes containing STL code need the original
library with the classes to read the objects.

We hope to implement one day the possibility to automatically split
a member like vector<MyClass> as we do today for a TClonesArray.

Concerning your statement with:
    float *x = malloc(100);
this should be totally prohibited. Always use new instead.
Mixing malloc and new is a big source of troubles.

Rene Brun


> 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:38 MET