Try:
{
TFile *f = TFile::Open("test.root");
// f->ls();
TGraph *o;
TMultiGraph *mg = new TMultiGraph();
TString name = ""; // usually "Graph" or ""
for (Int_t i = 1; i < 9999 ; i++) { // 9999 = a "memory object"
#if 1 /* 0 or 1 */
// checks that the object with the given "name" is a TGraph
f->GetObject(name + ";" + ((Long_t)i), o);
#else /* 0 or 1 */
// assumes that any object with the given "name" is a TGraph
o = ((TGraph *)(f->Get(name + ";" + ((Long_t)i))));
#endif /* 0 or 1 */
// if (o) f->Remove(o); // needed for TH* and similar objects
if (!o) break; // no more TGraph found
mg->Add(o);
}
if (mg->GetListOfGraphs()) mg->Draw("A");
}
BTW. If you need to retrieve, e.g., TGraphAsymmErrors objects, replace all occurrences of TGraph in this macro with TGraphAsymmErrors.