Re: writing strings in a tree

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Jan 21 1998 - 13:39:09 MET


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



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:29 MET