Problems with TGraph Arrays

Hello Rooters,
I am trying to read a bunch of TGraphs into an array of TGraphs. It works and I can work with individual graphs, but when I try to do this in a loop, I get and error. See below for the code snippet and comments. Any ideas?
Cheers,

{
TGraph *g[5];

TFile *f6=new TFile("input_file.root", "READ");

for(int a=0; a<5;a++){
g[a]=(TGraph*)f6->Get(Form("Graph;%d",a));
}
cout<<g[2]->GetN()<<endl;//<- this works

for(int a=0; a<5;a++){
cout<<g[a]->GetN()<<endl; ///<- this gives error
}
}


What error do you get?
If you only have 5 graphs, you can easily check if this line

cout<<g[2]->GetN()<<endl;

works for all graphs (“Graph;0” to “Graph;4”), not only for g[2]. Probably “Graph;0” doesn’t exist?

Yes, it was because Graph;0 did not exist! Silly me!
Thanks for the reply

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.