TGraph::Expand

I am using root 5.10/00. I have created a TGraph object with 4 points. Sometime later I call the TGraph::Expand method with 16 points.

My expectation is that the new value for Npoints would be 16, this does not appear to be so. What would be a better way of doing this?
Chris

Hi Chris,

Use TGraph::Set(Int_t n). This sets the number of points to the specified value.

Cheers, Mathias

You do not need to call TGraph::Expand or TGraph::Set

When calling TGraph::SetPoint(i,x,y), the dynamic array is automatically expanded to accomodate the new cpoint i

Rene

Hi Rene,
What I have done is made an interface to a series of digital to analog devices. The interface allows the user to obtain a time series and manipulate it with fft etc.

I used to allocate arrays seperately and then call Tgraph at the end of the process. After looking at the code, I noticed that when TGraph is called with a number, some large arrays are allocated. It seemed better from a coding standpoint to let TGraph manage the arrays and fill them. It appears to allocate quite a bit and only plot what has been filled. Hence the message before was pretty handy.

I’d rather do a set after increasing the size such that if a memory allocation needs to occur it won’t occur during he middle of an acquisition.

Make sense?
Chris

Chris,

TGraph::SetPoint double the current number of allocated points in case you try to set a point outside the current allocation.
You can tune this process by calling, eg TGraph::Expand(newsize,step)

Rene