Getting Histograms from TCanvases

Hi Rooters.
I have many TCanvases in my hard disk. They are stored as rootfiles.
Each canvas contains various objects, as histograms, functions, etc…

Now, I need a procedure to extract these objects from a given canvas and use them.

The way I usually do that (from CINT) is outlined in these 3 steps:

  1. open the rootfile:
    root[1] TFile* file= new TFile(“Canvas.root”)

  2. See the list of the pointers
    root[2] Canvasname->ls()
    A list like the following is provided:

OBJ: TH1F histo1 : 0x8879330
OBJ: TH2F histo2 : 0x8335023
…etcetc…

  1. Get each single object by means of its pointer, e.g.:

root[3] TH1F* aaa1 = (TH1F*)0x8879330
root[4] TH2F* aaa2 = (TH2F*)0x8335023
…etc.etc.

This is not a very smart procedure. For instance, I would like to use a more automatic way for getting these objects (e.g. using their names instead of their pointers).
Note that command file->Get(“histo1”) does not work in this case, as “file” does not see “histo1”…

Example

{ TFile *file = new TFile("Canvas.root"); TCanvas *canvas = (TCanvas*)file->Get("Canvasname"); TH1F *histo1 = (TH1F*)canvas->GetPrimitive("histo1"); }

Rene

There is also another way to do the same, using the FindObject method from TCanvas (inherited directly from TObject…).
So:

{
    TFile *file = new TFile("Canvas.root");
    TCanvas *canvas = (TCanvas*)file->Get("Canvasname");
    TH1F *histo1 = (TH1F*)canvas->FindObject("histo1");
}

Isn’t it?!

Cheers,
Matteo