Problem with entering a character string into a ROOT Tree


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.24/08
Platform: Ubuntu 18.04 (bionic)
Compiler: GCC 7.4.0

Hi all,

In ROOT 5.34/38 I had a ROOT macro that correctly stored a character string in a TTree via the following code

TTree\* otree=new TTree(“T”,”GRB data”);
TString aap=”GRB120511B”;
otree–>Branch(“name”,aap.Data(),”name/C”);

…. and then fill the tree

However, now that I have switched to ROOT6 (i.e. version 6.24/08) this code gives me an error in ACliC, since due to the fact thet aap.Data() returns a char*, it gets confused with the other Branch memberfunction.

I tried otree–>Branch(“name”,&aap,”name/C”);

which doesn’t give me an error message, but when I do a scan of the Tree, the stored name shows weird characters, and not the string “GRB120511B”.

Could anyone please tell me how to solve this (silly) problem.


Hello @Nick_van_Eijndhoven,

thank you for your question. Maybe @pcanal could help here?

Cheers,

Marta

Hi all,

I solved the problem. It seems that in ROOT6 the inline overload of TTree:Branch(…) doesn’t work anymore. The problem is solved by using explicit casting to void*

otree–>Branch(“name”,(void*)(aap.Data()),”name/C”);

I would like to ask you to indicate this explicitly in the docs, in order to avoid further confusion.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.