How do i store a TLegend in a ROOT-Directory?

Hi all.
How can I store (and restore) a TLegend-Object in a ROOT-Directory. To store i use the following (sorry for dirty CINT syntax :wink: )

legend = new TLegend(0.4,0.5,0.6,0.7);
legend->SetName(“myLegend”);
gDirectory->GetList()->Add(legend) ;
// compare with other objects:
multi= new TMultiGraph(“myMulti”,“myMulti”) ;
gDirectory->GetList()->Add(multi);
//
//
gDirectory->ls();
Produces the output.

TROOT* Rint The ROOT of EVERYTHING
TLegend X1= 0.400000 Y1=0.500000 X2=0.600000 Y2=0.700000 myLegend
OBJ: TMultiGraph myMulti myMulti : 0 at: 0x8978f08

Note teh missing "OBJ: " in front of TLegend.
Getting the TLegend back from the directory is not possible to me:
gDirectory->FindObject(“myLegend”)
Produces:
(const class TObject*)0x0

Please tell me how to store a TLegend properly in a directory,
Cheers,
J.

Hi,

If you have only one legend, you can retrieve it using:

If you have more than on TLegend, you will need to wrap them in a holder class inheriting from TNamed (so that you can actually set a name)

Cheers,
Philippe.

That’s what I thought, too, but at least with ROOT 3.10 this also does not work.

Only classes that implement the function IsSortable returning kTRUE can be added to a TDirectory (this is a THashList).

I will implement this function and the associated function Hash for all TPave family classes in the next version.

Rene

Thank you, for this answer. Is this fact (about TDirectory or even about THasLIst) written in the ROOT Users Guide (and I only oversaw it) or should i write this as request do the “ROOT Documentation” forum :wink: ?