Fill string to tree

Hi,

I woud like to fill strings to a tree, that is something like:

mytree->Branch(“text”, &text, “text/C”);

where ‘text’ would be some string (?).

Would you give a small example how to do that? And then how to read the strings back from the tree, because somehow this doesn’t work for me.

I can create a branch like above and fill it with something but when I am about to read it back it crashes…

Thanks,
Balint

See an example in $ROOTSYS/tutorials/tree/cernbuild.C and $ROOTSYS/tutorials/tree/cernstaff.C

Cheers,
Philippe

Hi,

it works, or at least I can create a TTree which contains the strings but I still cannot read it back.

Create (works):

Char_t var_name[512];
tree->Branch(“var_name”, var_name, “var_name/C”);
string s = “something”;
sscanf(s.c_str(), “%s”,var_name);

this works, because then if I make tree->Scan(“var_name”) everything looks okay.

Read back (doesn’t work):
Char_t myvar[512];
tree->SetBranchAddress(“var_name”, myvar);
cout << myvar << endl;

this compiles, but all I get is just empty strings…

Thanks for help,
Balint

Ahh…sorry, it works…I forgot the tree->GetEntry(i)…:wink:

Thanks!

Balint