Problem reading a TTree

Hi,
I’ve a problem in reading a TTree: I’ve written the following code

void entropyf()
{
TTree friend_ch;
TFile
f = TFile::Open(“data.root”);
friend_ch = (TTree*)f->Get(“T”);
friend_ch->Show(1);
friend_ch->SetMakeClass(1);
Double_t SS = -1;
TBranch *branch_entropyQP = 0;
cout<<friend_ch<<endl;
int ret = friend_ch->SetBranchAddress(“entropyQP”, &SS, &branch_entropyQP);
cout<<ret<<endl;
friend_ch->GetEntry(1);
cout<<"S entry 1 “<<SS<<” “<<branch_entropyQP->GetEntries()<<” "<<friend_ch->GetEntries()<<endl;
}

and it works ONLY if I add the line
friend_ch->Show(1);
otherwise it crashes :
0x8ca48f0 //friend_ch value
3 /ret value
Error: Symbol U��WVS��
�c����� is not defined in current scope (tmpfile):1:
signal(11) Error: Segmentation violation (tmpfile):1:

Press return or process will be terminated in 10 sec by timeout.

FILE:(tmpfile) LINE:1 cint>

entropyQP is a variable in my TTree. I’ve checked in the Tree and the value is correct.

However, when I add Show(1) and I try to exit ROOT, it crashes as well…

Can you help me to understand why, please?
Thank you
Cheers

Paola

PS I’m not able to read the right value of my variable even using t->MakeSelector()…

Hi,

can you give us access to the file?

Cheers, Axel.

Hi Alex,
you have in attachment my root file.
Thank you for your help

Cheers

Paola
TreeFriend_output.root (8.35 KB)

Hi Paola,

The segmentation fault are because SetMakeClass was called but some of the branch addresses for branch that are read have not been set (more specifically the branches corresponding to the content of a TClonesArray).

You can work around the problem by either setting of the addresses (for example by using MakeSelector) or you reading just the branch you need: int ret = friend_ch->SetBranchAddress("entropyQP", &SS, &branch_entropyQP); cout<<ret<<endl; //friend_ch->GetEntry(1); branch_entropyQP->GetEntry(1); cout<<"S entry 1 "<<SS<<" "<<branch_entropyQP->GetEntries()<<" "<<friend_ch->GetEntries()<<endl;

Cheers,
Philippe.

PS. [quote]I’m not able to read the right value of my variable even using t->MakeSelector()…[/quote]humm … I can not reproduce this … did you call GetEntry appropriately inside Process?