Reading sub-branches

Dear all,
I have to read a root tree, which contains a branch inside another branch.
As I can see in the TBrowser(), I have this structure:
Events (TTree)
| EventAuxiliary (TBranch)
|-----------------> id_ (TNonSplitBrowsable)
|--------------------------- > event_ (TLeaf)

I open the file, and then I create the TTree and when I do Print() it prints everything. But, I can not go further, to the next Branch.
Any suggestions?

Thank you in advance!

How about posting the (full) output of “Events->Print();” here.

Hi Coyote,
thanks for the reply.Because, it is too big, I have attached a file(print.txt).
print.txt (493 KB)

It seems to me that “EventAuxiliary” is the very first branch of your “Events” tree:
*Br 0 :EventAuxiliary : edm::EventAuxiliary *
and it keeps “edm::EventAuxiliary” objects (of the “EventAuxiliary” class from the “edm” namespace).
Most probably, “id_” and " event_" are simply “data members” of that class.

See different “tree*.C” ROOT Tutorials: Trees I/O, Queries, Graphics examples which deal with classes / structures being saved in a ROOT TTree.


If I do:

TFile *inf = new TFile("FC948371-06D6-E111-90E8-002618943983.root")
TTree *t1 = (TTree*)inf->Get("Events")
TBranch *bra1 = t1->GetBranch("EventAuxiliary")

and then I print the bra1

root [10] tbra1->Print()
*Br 0 :EventAuxiliary : edm::EventAuxiliary *
*Entries : 2886 : Total Size= 436786 bytes File Size = 228847 *
*Baskets : 578 : Basket Size= 1100 bytes Compression= 1.86 *

Does this means something more?

I also tried TBranch *bra2 = t1->GetBranch(“EventAuxiliary/id_”)
but when I tried to print it I got error:

root [12] bra2->Print()
Error: illegal pointer to class object bra2 0x0 2427 (tmpfile):1:
*** Interpreter error recovered ***

Try: [code]{
edm::EventAuxiliary *e = new edm::EventAuxiliary();

TFile *f = new TFile(“FC948371-06D6-E111-90E8-002618943983.root”, “READ”);
TTree *t = 0; f->GetObject(“Events”, t);
TBranch *b = t->GetBranch(“EventAuxiliary”);

Long64_t n = t->GetEntries();
for (Long64_t i = 0; i < n; i++) {
b->GetEntry(i); // … or … t->GetEntry(i);
std::cout << "i = " << i << " "
<< "id_ = " << e->id_ << " "
<< "event_ = " << e->event_
<< std::endl;

t->ResetBranchAddresses(); // … or … t->ResetBranchAddress(b);
delete f; f = t = b = 0; // automatically deletes the “t” TTree, too
delete e; e = 0;
See also: ROOT User’s Guide - Chapter 12. Trees - Example 4: A Tree with an Event Class

Thank you for the code Coyote!
I tried it, but I am getting errors about edm.

error: 'edm' has not been declared error: 'e' was not declared in this scope error: expected type-specifier before 'edm' error: expected ';' before 'edm'
It seems that it doesn’t know it as a namespace. Do you think I should include a header file which provides the declaration of edm?

(Sorry for the noob questions)

You need to load the shared library which provides the (compiled) dictionary for the “edm::EventAuxiliary” class. One or more lines in form (ask the one who created your “Events” tree which libraries you need and in which order they should be loaded):
Then, in the beginning of your ROOT macro you could put something like:
if (!TClassTable::GetDict(“edm::EventAuxiliary”)) {

Ok Coyote,
I will do them as you said and I 'll let you know.
I hope I would be able to mark it as Solved.
Thanks again!