Apologies if this question has been answered somewhere previously.
Basically I have written a custom class for objects which I want to store in a TTree, I have built the dictionary and can apparently store the objects successfully. However, it would seem I do not understand how to retrieve them properly. For every entry, I can retrieve all the object data members in turn and rebuild the object one piece at a a time from them, but this is quite laborious. I want to be able to pull a completely reconstructed object at the first attempt as it was when I filled the tree. All my attempts to do so have just resulted in the object taking default values. Clearly I am missing something. Below is some dummy code which illustrates my issues.
TTree * _ntp1 = (TTree*) myFile.Get(“ntp1”)
myClass * ptr=0;
_ntp1->SetBranchAddress(“myClass”,&ptr); //I want to write a line like this but figure it is probably wrong
ptr->DisplayDataMember1();//some appropriate handle on member 1
The output I get would be something like:
myClass = NULL
datamember1 = val1X
datemember2 = val2X
val1X val2X (from cout line)
defaultValue1 (from access methods)
I would want the access methods to return the appropriate values.
Hope this example makes sense…
I appreciate that I am probably being naive in thinking how these objects are stored in the TTree, and I dont understand why the show gives a value NULL next to the myClass pointer (and therefore why do I not get a segv when calling the access methods?). Any help most appreciated.