Hello. I have been having problems with this, and I hope someone can help me out.
I have a ROOT file that contains a tree called “I0” (except I “don’t know” what this name is in the program, and I am trying to get a pointer to this tree). What I am doing is this:
TFile *f1 = new TFile("file.root","READ");
TList *list = f1->GetList();
TTree *Itree = (TTree*)(list->First());
This process works fine using the CINT interpreter in ROOT (by going into ROOT and typing in each line separately in the interpreter). However, when I do this in my program and run it (using “root file.c”) the TTree “Itree” does not seem to give a pointer to a tree. What I mean by this is that I get:
when I try to access the tree like:
Itree->GetName();
However, just to test things, I put a “cout” in the program to print the location of the pointer to “I0” (to compare this pointer to “Itree”, which should be the same), and everything worked after that! So, this is what I changed:
TFile *f1 = new TFile("file.root","READ");
TList *list = f1->GetList();
cout<<I0<<endl;
TTree *Itree = (TTree*)(list->First());
After this, I was able to access the tree “Itree” just fine and I got no problems at all (and “I0” and “Itree” point to the same object). What is causing this? And, if something like this is required each time, how would I do it without knowing the name of the TTree (which is “I0” in this case)?
Thank you for your help.
Corey