Getting a primitive from a sub pad

From: OKUMURA, Akira <oxon_at_astro.isas.jaxa.jp>
Date: Sun, 10 Jul 2011 17:36:39 -0700


Hello ROOTers,

Could anyone tell me how to get a primitive from a sub pad of a saved TCanvas, please? When I try to do it without drawing the canvas, I cannot access to the pointer of a sub pad. I am using the SVN trunk on OS X 10.6.8.

If I draw the canvas before accessing a sub pad, I can get a primitive from the sub pad. But I have thousands of ROOT files, I do not want to draw each TCanvas.

Step 1: Save a TCanvas in a TFile
$ root

root [0] TCanvas* can = new TCanvas("can", "can")
root [1] can->Divide(2, 1)
root [2] can->cd(1)

(class TVirtualPad*)0x103e9d110
root [3] TH1D* hist = new TH1D("hist", "hist", 100, 0, 1)
root [4] hist->Draw()
root [5] can->SaveAs("can.root")

Info in <TCanvas::SaveAs>: ROOT file can.root has been created root [6] .q

Step 2: Access to the sub pad 1
$ root

root [0] TFile f("can.root")
root [1] TCanvas* can = (TCanvas*)f.Get("can")
root [2] can // OK

(class TCanvas*)0x103f24eb0

root [3] gPad // OK
(class TCanvas*)0x103f24eb0

root [4] can->cd(1) // cannot change the directory to sub pad 1
(class TVirtualPad*)0x0

root [5] gPad->GetPrimitive("hist")
(const class TObject*)0x0

root [6] can->cd(1)->GetPrimitive("hist") // So I cannot get "hist" Error: illegal pointer to class object cd(1) 0x0 73 (tmpfile):1: *** Interpreter error recovered ***

Regards,

--
OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
Institute of Space and Astronautical Science (ISAS/JAXA)
Now at KIPAC/SLAC/Stanford
Varian Physics #306, 382 Via Pueblo Mall, MC 4060
Stanford, CA 94305-4060
TEL 650-736-0971/FAX 650-724-5065
Skype : okumura.akira
Received on Mon Jul 11 2011 - 02:37:01 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 11 2011 - 11:50:01 CEST