Looping over a TList to look for TTree's

Hello,

I need to loop over a TList in order to retrieve the TTree’s that are in.

I have
TList* modOutput
and
modOutput->Print()
shows that the TList contains one TTree (size = 1).

Anyway I am unable to loop over the TList:

TIter next(modOutput);
TObject* object = 0;
while ((object = next()))
{
cout << "HERE: " << object->InheritsFrom(TTree::Class()) << endl;
}

It looks I never am inside the while() cycle… Namely “Here” is never written on screen…

Any idea?

Thanks a lot,

Hi,

this should work; we’ll need the actual code.

Cheers, Axel.

Dear Axel,

first of all, thanks for your prompt reply. I expected the code to work but actually it does not…

The code is just here

 // modOutput is a TList*. It comes from a TAM module.
 //now I have the output (TList of each module)
  //
  //check it is ok:
  modOutput->Print();
  // try to loop on it 
 TIter next(modOutput);
  TObject* object = 0;
  while ((object = next()))
    {
      cout << "HERE: " << object->InheritsFrom(TTree::Class()) << endl;
    }

The output is

so it looks that the TTree is in a lower level of the hierarchy. Still, I don’t know how to retrieve it…

Thanks, ciao
Luciano

do:

TTree *T = (TTree*)modOuput->FindObject("BaseTriggerTree");
Rene

Dear Rene,

thanks for your reply

[quote=“brun”]do:

TTree *T = (TTree*)modOuput->FindObject("BaseTriggerTree");
Rene[/quote]

actually it does not work. T is a NULL pointer (while modOutput is not and in fact modOutput->Print() works ok).

Thanks,
Luciano

In FindObject, you must specify the object name, in your case “tree”, as shown in

[code]*Tree :tree : BaseTriggerTree *
*Entries : 10 : Total = 3840 bytes File Size = 0 *

  • : : Tree compression factor = 1.00 *
    [/code]
    Rene

[quote=“brun”]In FindObject, you must specify the object name, in your case “tree”, as shown in

[code]*Tree :tree : BaseTriggerTree *
*Entries : 10 : Total = 3840 bytes File Size = 0 *

  • : : Tree compression factor = 1.00 *
    [/code]
    Rene[/quote]
    you are right.

Anyway, both

  TTree *T = (TTree*)modOutput->FindObject("tree");
  TTree *T2 = (TTree*)modOutput->FindObject("BaseTriggerTree");

give NULL pointers and I really cannot understand why. The other point is that for my final application, I don’t know a priori the names of the TTrees in the TList. I have to scan the TList and look for TTrees inside…

Thanks again,
Luciano

Could you post the output of modOutput->ls() ?

Rene

Here it is the output of
modOutput->ls();

I understand that the problem may be with the hierachy of the TList…

Thanks again,
Luciano

You must use FindObject on the list containing the object, not on the list of lists.

Rene

Ok, I got this point. My following problem becomes: how do I do that if I don’t know a priori the object name?

Thanks
Luciano

Well, you must know either the name of your object or the position inside the list.
I am afraid that you have to provide a bit more info.

Rene