TTree with string


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>

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->Scan(); // Success
return t;

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

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


In your “readLines” routine, just before doing “return t;”, try to add:

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

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