Char_t * in a Branch

Dear All,

I am trying to fill a TBranch with a table of characters, but the way I did it doesn’t work correctly…

G4String name;
Int_t Nsampler;
const Char_t SamplerName[20];
TTree
SamplerTree = new TTree(“AllDetectors”, “Sampler output”);

SamplerTree->Branch(“Nsampler”,&Nsampler,“Nsampler/I”);
SamplerTree>Branch(“SamplerName”,(void*)SamplerName,“SamplerName[Nsampler]/C”);


// Place where I fill the Branch
for(Int_t i=0;i<Nsampler;i++)
{

SamplerName[i]=name.c_str();

}
sTree->Fill();
Please tell me where I am wrong.

Hayg

Hi,

Variable size array of string is not supported via the leaflist method of branch creation (the one you use).

Instead you need to create an object holding them (a TObjArray of TObjString, a std::vectorstd::string or a custom object for which you create a dictionary).

Cheers,
Philippe.