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;
theTree->Branch(“ntnameRoll”,&ntnameRoll,“ntnameRoll/C”);

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

Thanks a lot in advance

Raffaello

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

Rene

Sorry,
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/cern.ch/user/t/trentad/scratch0/CMSSW_2_1_9/src/Noise/MyNoise/src/././MyRootNT.h: In constructor MyRootNT::MyRootNT()': /afs/cern.ch/user/t/trentad/scratch0/CMSSW_2_1_9/src/Noise/MyNoise/src/././MyRootNT.h:225: error: no matching function for call toTTree::Branch(const char[11], std::string*)’
/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.18.00a-cms12/include/TTree.h:202: note: candidates are: virtual Int_t TTree::Branch(TCollection*, Int_t, Int_t, const char*)
/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.18.00a-cms12/include/TTree.h:203: note: virtual Int_t TTree::Branch(TList*, Int_t, Int_t)
/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.18.00a-cms12/include/TTree.h:204: note: virtual Int_t TTree::Branch(const char*, Int_t, Int_t)
/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.18.00a-cms12/include/TTree.h:205: note: virtual TBranch* TTree::Branch(const char*, void*, const char*, Int_t)
/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.18.00a-cms12/include/TTree.h:207: note: virtual TBranch* TTree::Branch(const char*, const char*, void*, Int_t, Int_t)

Thanke again for your help
Raffaello

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
Raffaello

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

Rene

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
Raffaello

Hi,

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