Problem with branch from TObject subclas with TString member

Dear experts,

I am trying to create a TTree with a TBranch defined from an object of the class MyEventClass, inheriting from TObject. MyEventClass has a TString member called test_string.
I create the TTree with the following code:

[code]#include “CreateSimpleEventTree.hh”

using namespace std;

int main()
{
TString name = “MyEventTree”;
TString title = “MyEventTree”;
TTree *tree = new TTree(name, title);
MyEventClass event;
MyEventClass::Class()->IgnoreTObjectStreamer(); //this is to remove the TObject branch with fUniqueID and fBits leaves.
TBranch *branch = tree->Branch(“event”, &event,32000,2);

for (int i=0;i<10;i++) {
event.test_var_01 = i;
event.test_var_02 = i*10;
event.test_string.Form("%d",i);
tree->Fill();
}

TFile OutputFile(“outputs/MyEventTree.root”,“RECREATE”);
tree->Write();
return 0;
}
[/code]

Class definition and dictionary files in attachment.

When I try to open the TTree with a TBrowser the TString member is in a separate branch with lot of leaves containing members like IsLong() GetShortSize() etc…
Also, method TTree::Show() does not print any value for the variable test_string.

What am I doing wrong?

Thank you.

gianluca
MyEventClass.hh.txt (355 Bytes)
MyEventClass.cc.txt (61 Bytes)
MyDict.h.txt (2.08 KB)
MyDict.cc.txt (25.9 KB)

event.test_string.Form("%d",i); … MyEventClass.hh:13: error: ‘TString MyEventClass::test_string’ is protected

For the TString class data members and methods see http://root.cern.ch/root/html/TString.html

Try:
root [0] .L MyEventClass.cc++
root [1] .x CreateSimpleEventTree.cc++
root [2] TFile *MyFile = new TFile(“MyEventTree.root”, “READ”)
root [3] MyFile->ls()
root [4] MyEventTree->Print()
root [5] MyEventTree->Show(0)
root [6] MyEventTree->Scan()
MyEventClass.hh.txt (355 Bytes)
MyEventClass.cc (85 Bytes)
CreateSimpleEventTree.cc (863 Bytes)

Hi Pepe,

Thank you for your answer.

Sorry, I sent you the wrong class header, of course the variable test_string should be public.

I understand the values of test_string are visible with TTree::Show() or TTree::Scan() and I can plot them with TTree::Draw(), but I still do not understand the strange behaviour with TBrowser, why is that?

You save a TString object and you retrieve it back … a FULL / COMPLETE / WHOLE / ENTIRE object: http://root.cern.ch/root/htmldoc/TString.html

Got it!

Thank you again.

g