Moving through Collections of type Legend

I am a novice programmer, and after a few hours of trying to understand the examples and documentation, I am stuck. What I want to do is access a particular entry of my legend so I can adjust its text size. I can do using leg as my legend name:

TLegendEntry ent = (TLegendEntry)leg->GetListOfPrimitives()->First(); and get the first entry fine although I don’t fully understand the above line.

However, say I have a legend of 10 entries and want to access the third. I don’t understand the class TIter nor its use and TList very well either. I included my general idea on how I think I would do it to see if someone can help clear up my misunderstandings.

My thought was something along this line:

TList *listA = leg.GetListOfPrimitives(); //would create pointer of type TList which points to my legends Tlist collection which in turn contains all Objects of type TLegendEntry?
TIter itr(listA); //creates an iterator called itr which now points to the first TLegendEntry in listA?
itr.Next(); //points to 2nd

TLegendEntry tle = (TLegendEntry)itr.Next(); typecasts the itr.Next() which is now pointing to the third item in collection as a TLegendEntry;

tle->SetTextSize(.05);

Anyway, that is what I have. Any corrections in understanding would be welcome. Also a nice example that works for accessing only the nth item of a collection of type TLegendEntry would be nice too.

Brian

Hi Brian,

[quote=“bhunt9”]TLegendEntry ent = (TLegendEntry)leg->GetListOfPrimitives()->First(); and get the first entry fine although I don’t fully understand the above line.[/quote]See the TList::First() documentation.

And to access a given item in the list, you can simply use the TList::At(Int_t idx) method. For example, to access the third entry in the list:

Cheers, Bertrand.

Thanks,

I missed that method while searching the documentation. That is much simpler.

Brian