Array of strings as TTree branch

hi,
I am trying to add to a TTree a branch which is a vector of string names.
say, i have

TTree* T = new TTree(“T”,“T”);
int N;
T->Branch(“N”,&N,“N/I”);
double E[10];
T->Branch(“E”,E,“E[N]/D”);
std::string S[10];
T->Branch(“S”,S,“S[N][256]/C”);

N=2;
E[0]=3.1; S[0]=“MU6”;
E[1]=2.5; S[1]=“MU11”;
T->Fill();

then in a root session
T->Scan(“S”);
does not seem to behave properly. thus my question, how can i add an array of strings to a TTree?
many thanks in advance

Hi,

[quote]std::string S[10];
T->Branch(“S”,S,“S[N][256]/C”);[/quote]is not consistent as the 2nd line is expecting the address to be pointing to a char [][256]). You will be better off (i.e. more likely to work) to use:std::vector<std::string> > S; T->Branch("S",S);

Cheers,
Philippe

sorry, i must miss something here, but there is no method Branch(const char*, std::vectorstd::string)
thanks.

forget about my comment, found this link
root.cern.ch/viewvc/trunk/root/t … t=roottest

Hi,

Indeed there is no Branch overload specific to vector instead we have a templated Branch overload that can handle any type (which have a dictionary).

Cheers,
Philippe.