Re: Adding TGraph to a Directory

From: Jacek M. Holeczek <holeczek_at_us.edu.pl>
Date: Thu, 10 Mar 2005 16:42:02 +0100 (MET)


Hi,
when I met this problems, I solved it by replacing :

        gDirectory->Add(ge);
with

        gROOT->GetListOfSpecials()->Add(ge);
Then the graphs are "saved" in the "Specials" ROOT folder (try the TBrowser to see it).
In any moment you can still easily "find it" using :

        gROOT->FindObject("mygraph")

The code that creates and saves graphs is :

	TFolder *fSpecials = (TFolder *)gROOT->GetRootFolder()->GetListOfFolders()->FindObject("Specials");
	if (fSpecials) fSpecials->Clear();

...
// create your graphs and add them to the folder ...
...
Double_t x[3] = {0, 1, 2}; Double_t y[3] = {10, 11, 12}; TGraph *ge = new TGraph(3,x,y); ge->SetName("mygraph"); gROOT->GetListOfSpecials()->Add(ge);
...
if (fSpecials) fSpecials->SaveAs("file_name.root"); The code that reads the file and draws histograms is : TFolder *fSpecials = (TFolder *)gROOT->GetRootFolder()->GetListOfFolders()->FindObject("Specials"); if (fSpecials) fSpecials->Clear(); TFile *f = new TFile("file_name.root", "READ"); f->cd();
...
// draw graphs ...
...
((TGraph *)f->FindObjectAny("mygraph"))->Draw("AL");
... or ...
((TGraph *)gROOT->FindObject("mygraph"))->Draw("AL");
...
delete f;

Hope it helps,
Jacek. Received on Thu Mar 10 2005 - 16:42:09 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET