Tree with a class, why 'member function' is add to the tree

Dear you,

My ROOT is: ROOT 5.34/00 (branches/v5-34-00-patches@44569, Jun 05 2012, 15:31:56 on win32)

I want to build a “TTree” with a class named TBoard, which contains a ‘TBoard *’ member point to itself, and two member function:

class TBoard {
protected:
long           fHandle;         //! 
TBoard*        pSelfObj;        //!
//....... other data memters
public:
//.......other member functions
virtual long   GetHandle() const {return fHandle;}
virtual TBoard* GetSelfObj() const {return pSelfObj;}      //!
ClassDef(TBoard, 1);
};

The tree branch is add use something as following:

tree->Branch("name", tborad->Class_Name(), tborad->GetSelfObj());

In the tree there have a branch 'GetSelfObj() ’ and a leaf ‘GetHandle()’ as shown in the picture. And the branch 'GetSelfObj() ’ is an infinite recursion.
I do not want to include this two ‘member function’ in the tree.

Any help is appreciated.
Han

[quote]I do not want to include this two ‘member function’ in the tree.[/quote]They are not ‘included’ in the TTree, they are ‘only’ presented in the TBrowser because they are function member of the class.

Cheers,
Philippe.

PS. Besides, it is like a design mistake to have such a method in your class definition (i.e. I don’t understand its purpose!)

Dear Philippe,

Thank you very much.

I have another qustion, in the ‘TBoard’ class I have a lot of member functions, but why only this two functions were presented in the TBrowser?

[quote=“pcanal”]
PS. Besides, it is like a design mistake to have such a method in your class definition (i.e. I don’t understand its purpose!)[/quote]

I have several classes inherit from ‘TBoard’, my ideal is read a class name (char*) form a ‘txt’ file, and then use the TClass::New() to create an object. The ‘TBoard *’ pointer in the 'TBoard’class is used to add a ‘Branch’ to a ‘tree’, just as the following:

tree->Branch(“name”, tborad->Class_Name(), tborad->[color=#FF0000]GetSelfObj()[/color]);

the ‘tboard’ is a pointer (TBoard *) point to different classes which is inherit form ‘TBoard’. Maybe this ideal is stupid, however this is the way which can I think out.

Thank you,
Han

Hi Han,

In you description and code snipper I see no difference between the value of ‘tborad’ and the value returned by GetSelfObj … I am guessing that you constructor contains something like: pSelfObj = this;?

I am guessing that you might have meant to have:virtual TBoard** GetSelfObj() const {return &pSelfObj;} so that you could pass the address of a pointer to Branch.

In modern version of ROOT, this is no longer necessary and thus the following might just work:tree->Branch("name", tborad->Class_Name(), tborad);

Cheers,
Philippe.

PS. However SetBranchAddress still requires the address of a pointer.

Dear Philippe

Thank you very much.

I should use the following method:

Best wishes,
Han