Re: query

From: troy d. straszheim <troy_at_resophonic.com>
Date: Sun, 6 Aug 2006 13:00:28 -0400

On Fri, Aug 04, 2006 at 11:21:00AM -0400, Alex Mott wrote:
> if you must use a vector, you could do something like
>
> vector<Float_t>::iterator v1iter=v1.begin();
> vector<Float_t>::iterator v2iter=v2.begin();
> TGraph* graph = new TGraph(v1.size());
> Int_t curpoint=0;
> while(v1iter!=v1.end() && v2iter!=v2.end())
> graph->SetPoint(curpoint++,*(v1iter++),*(v2iter++));
>
> (I have assumed they are vectors of Float_t, modify depending on what
> you actually use)
> The problem with this is that it duplicates all the data and stores
> it in a graphs, so obviously if these
> vectors are big, this isn't a good idea. The following might work
> better in that case:
>
> TGraph* graph = new TGraph(v1.size());
> Int_t curpoint=0;
> for(Int_t i=0; i<v1.size();i++){
> graph->SetPoint(curpoint++,v1.at(v1.size()),v2.at(v2.size()));
> v1.pop_back();
> v2.pop_back();
> }
>
> this will destroy the vectors, and transfer their contents into the
> graph.
> (This code should work properly, but I recommend trying it on an
> unimportant vector first before
> letting it run over any important data, since it does destroy the
> vectors).
>

or

vector<float> v1, v2; // filled with stuff TGraph* graph = new TGraph(v1.size(), &v1.front(), &v2.front()); Received on Sun Aug 06 2006 - 18:59:15 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET