Re: writing strings in a tree

Rene Brun (Rene.Brun@cern.ch)
Wed, 21 Jan 1998 13:39:09 +0100


Ludger Janauschek wrote:

> Hello,
>
> when I run the macro
>
> {
> gROOT->Reset();
>
> Char_t *string="test string";
>
> TFile f("tree-string.root", "RECREATE");
> TTree *t = new TTree("T", "an example");
> t->Branch("brString", string, "string/C", 1024);
>
> printf("mark 1\n");
> t->Fill();
> printf("mark 2\n");
>
> t->Print();
> f.Write();
> f.Close();
> }
>
> root (1.03/09 AIX 4.1) says
>
> mark 1
>
> *** Break *** illegal instruction
>
> What's wrong with the macro and/or how can a branch of a character string
> terminated by the 0 character be added to a tree?

There is an ambiguity in the case where the first data type in the branch
is a string. A TBranchObject is craeted instead.
The solution is to cast to a void *
t->Branch("brString",(void*)string,"string/C",1024);

Rene Brun