Read a specific value from TBranch

Dears,
I’m trying to read a specific value from a TBranch of a TTree, using the following command:
x= my_ttree->GetBranch(“my_branch”)->GetEntry(i);
but I obtain the size, like int_64, as written in the guide, but I would like obtain the number stored in the i position of Tbranch.
Thanks in advance for your help!! :slight_smile:

“Specific value” -> so I assume your branch just contains a number? Then:

auto br = my_ttree->GetBranch("my_branch");

Int_t value_of_my_branch; // put the correct type here
br->SetAddress(&value_of_my_branch);
br->GetEntry(i);
std::cout << "I have read " << value_of_my_branch << '\n';

It works like this if you want to read a “simple” value.

Alternatively, have a look at the TTreeReader / TTreeReaderValue classes.

Thanks for the reply.
Yes the values are a number.
But it doesn’t works… probably because the auto:
warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
error: ‘br’ does not name a type

Obviously you are using ROOT5 which has no C++11 support. Please note that it is 2017 now, consider switching to ROOT 6. C++ got massive usability improvements with the 2011 standard.

In ROOT 5, you need to spell out the type:
TBranch *br = my_ttree->GetBranch("my_branch");

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.