TTree with string

Hi,

I’m trying to create a TTree with a string in it, but the code keeps segfaulting. Here’s what I’m doing:

[code]#include <TTree.h>
#include

TTree* readLines() {
TTree* t = new TTree(“t”, “t”);
string name;
float b;

t->Branch(“name”, &name);
t->Branch(“b”, &b, “b/F”);

name = “test”;
b = 1;
t->Fill();
t->Scan(); // Success
return t;
}

void test() {
TTree* tLocal = readLines();
tLocal->Scan(); // Segfault
}
[/code]

.x test.C+ makes the code segfault when trying to scan the returned tree. Why is this happening?

N.

In your “readLines” routine, just before doing “return t;”, try to add:
t->ResetBranchAddresses();

This indeed works. Could you explain why it’s needed?

Search for the string “ResetBranch” in the TTree class description.