[Solved] Trouble getting list of objects in compiled code

Dear All,

I am finishing up a GUI app and I wanted to know how to perform this operation in a compiled code (C++).

With Cint we can do:

[0]TH1D *h1  = new TH1D("name","name", 10, 0 , 1);
[1]h1->Fill(1);
[2]h1->Draw();

This of course gives us a pretty plot.

Then we can return the list of objects on that pad/canvas in a few ways, one being below

[3]gPad->ls()

This returns a variety of things including the histogram primitive.

Now in compiled code, at the moment, all it seems like I can do is search for:

gPad->FindObject("name");

Is there any way to return a list in C++ of objects in a pad currently? I want to try to avoid calling FindObject too often.

Thanks,
John Perry
ISR-1, LANL

Personally I do not see any problem of calling FindObject() many times.

Maybe you are thinking in a way to handle an object after you found it?

TH1D *h1_handle  =  (TH1D*) gPad->FindObject("name");
h1_handle ->SetTitle("Notice h1 is own by the current directory");

Anyways, you can also try

gPad->GetListOfPrimitives()

In return a TList, something you can handle as a list.

I hope this helps.
Cheers,

Thank you, I will check out this function. This is what I was looking for.

For posterities sake, a little bit of C++ implementation:

TList *MyList = EmpeddedCanvasObject->GetCanvas()->GetListOfPrimitives();
TObject *obj1;
TIter next(MyList);

while(obj1=(TObject *)next())
{
   std::cout << "object class name " << obj1->ClassName() << std::endl;
}

Cheers,
John