TTree with string

Hi all,
I would create a Tree and to fill one branch with a std::string.
I tryed in this way:

TTree *theTree;
std::string ntnameRoll;

But of course doen’t work because this is valid for char.
Couls anybody help me?

Thanks a lot in advance


simply do:

TTree T("T","test") std::string ntnameRoll; T.Branch("s",&ntnameRoll) ntnameRoll="First" T.Fill() ntnameRoll="Second" T.Fill() T.Scan()

Use version 5.22 or newer


I used you code in interactive mode and it produce e segmentation violation.
But worst is the results when I use it in my c++ code.
In this last case there is a compiling error like that:

/afs/ In constructor MyRootNT::MyRootNT()': /afs/ error: no matching function for call toTTree::Branch(const char[11], std::string*)’
/afs/ note: candidates are: virtual Int_t TTree::Branch(TCollection*, Int_t, Int_t, const char*)
/afs/ note: virtual Int_t TTree::Branch(TList*, Int_t, Int_t)
/afs/ note: virtual Int_t TTree::Branch(const char*, Int_t, Int_t)
/afs/ note: virtual TBranch* TTree::Branch(const char*, void*, const char*, Int_t)
/afs/ note: virtual TBranch* TTree::Branch(const char*, const char*, void*, Int_t, Int_t)

Thanke again for your help

I think the problem is the version of root. I’m using lxplus version for CMSSW_2_1_9, which is 5.18.

In that case it is possible to solve my problem?

Thanks again

As I said, yyou must use 5.22 or newer.
With older versions only std:string *data is supported.


Infact, for me is impossible to use newer versions than 5.18 because I am costrained by CMSSW software which use also in the most recent version just 5.18.

Therefore I tried to use the pointer for string but it doesn’t work.
Could you please give me an example for this old version?

Thanks a lot


With 5.18, you must wrap your string into a class for which you generate a dictionary:class myStringWrapper { ... std::string fString; ... };Cheers,