Reading branch names from a tree etc

Hello, I have the following piece of code, where I chain a series of Ttree in 2 sets and I want to compare each branch from these 2 sets.

[code]{
TChain SLAC = new TChain(“MeritTuple”);
TChain LYON = new TChain(“MeritTuple”);
char nome[200];
for (int i=0;i<10;i++){
sprintf(nome,“noMask/allGamma-GR-v15r39-noMask-%06i-merit.root”,i);
//cout << nome << endl;
SLAC.Add(nome);
sprintf(nome,“Lyon-noMask/allGamma-GR-v15r39-Lyon-noMask-%06i-merit.root”,i);
//cout << nome << endl;
LYON.Add(nome);
}
SLAC->AddFriend(LYON,“LYON”);
TObjArray
brlist = SLAC->GetListOfBranches();
int nbr = brlist->GetEntries();
TIterator
itr=brlist->MakeIterator();
char buffer[200];
for(int i=0;i!=nbr;i++){
char* name=itr()->GetName();
std::cout<<name<<std::endl;
sts=TString(name);
if(sts.Last(’]’)!=-1) continue;
sprintf(buffer,"%s-LYON.%s!=0",name,name);
int brentries=SLAC->GetEntries(buffer);
//std::cout<<sts<<":"<<brentries<<std::endl;
}

}[/code]

As is, my code crash at the second iteration, and it seems to crash at char* name=itr()->GetName();
But if I comment int brentries=SLAC->GetEntries(buffer); then the loop correctly iterates until the end!!!
What am I doing wrong???
thanks in advance (I am using a recent svn build).

Johann

  • modified to use the [ code ] … [ \ code ] markup

Hi,

The pointer to the list of branch is a property of the underlying TTree and is deleted each time the TChain move from files to files.

In order to execute GetEntries(cut), the TChain must open all the files in order to look at the data in each TTree. Hence your call to GetEntries(buffer) deleted brlist and hence itr() returns a random value.

Instead use int nbr = SLAC->GetListOfBranches()->GetEntries(); for(int i=0;i!=nbr;i++){ char* name=SLAC->GetListOfBranches()->At(i)->GetName(); std::cout<<name<<std::endl; sts=TString(name); if(sts.Last(']')!=-1) continue; sprintf(buffer,"%s-LYON.%s!=0",name,name); int brentries=SLAC->GetEntries(buffer); //std::cout<<sts<<":"<<brentries<<std::endl; }

Cheers,
Philippe.

hmmm, char* name=SLAC->GetListOfBranches()->GetName(); seems to return the string TObjArray; not the actual name of the branch. And this seems logical given that this is what LAC->GetListOfBranches() is.

Did you mean something else?
thanks,
johann

Sorry for the typo, it was missing ->At(i)
(See correct version).

Cheers,
Philippe.

Thanks Philippe, it now works.