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,
Axel
March 29, 2010, 4:32pm
2
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
Output of GerdaBaseTriggerModule:
Collection name=‘TList’, class=‘TList’, size=1
*Tree :tree : BaseTriggerTree *
*Entries : 10 : Total = 3840 bytes File Size = 0 *
*Br 0 :event : event/I *
*Entries : 10 : Total Size= 674 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 1 :baseline : baseline/D *
*Entries : 10 : Total Size= 740 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 2 :baselineSpread : baselineSpread/D *
*Entries : 10 : Total Size= 776 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 3 :trigger : trigger/I *
*Entries : 10 : Total Size= 686 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
*Br 4 :chanID : chanID/I *
*Entries : 10 : Total Size= 680 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
…
Collection name=‘GerdaBaseTriggerModule’, class=‘TAMOutput’, size=0
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
brun
March 30, 2010, 8:23am
4
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
brun
March 30, 2010, 9:22am
6
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
brun
March 30, 2010, 10:08am
8
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
brun
March 30, 2010, 10:47am
10
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
brun
March 30, 2010, 12:47pm
12
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