Adding a Branch of class to TTree

I would like to write a class object to tree.

I find the following method TTree::Branch() appropriate.

Should classname match the output of TObject::ClassName() and why at all is it necessary to indicated classname as this information is available to ROOT via TObject::ClassName().


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


You should not need it. This should work/be-sufficient:

MyClass *ptr = ....
...
tree->Branch("nameofbranch.", &ptr);
1 Like

Why do you put & before the pointer? I conclude that you refer to TBranch * TTree::Branch (const char * name, T * obj, Int_t bufsize = 32000, Int_t splitlevel = 99 ) and there obj is not a double pointer.

I was actually using: template TBranch * TTree::Branch ( const char * name, T ** addobj, Int_t bufsize = 32000, Int_t splitlevel = 99 )
But indeed you can also use the other alternative;

MyClass ptr{....};
...
tree->Branch("nameofbranch.", &ptr);

Cheers,
Philippe.
PS. Of course, there is other possible variation on how to use those functions :slight_smile:

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