Hi,
This is related to an earlier topic: “Read TTree from TFile, Fill it again and save to new TFile” ([url]Read TTree from TFile, Fill it again and save to new TFile
One of the branches of the TTree, is actually of type “std::string”.
For simpleness sake, suppose a code like this:
TTree* tree = new TTree( "mytree", "title" );
std::string m_chipIDstr;
tree->Branch("chipIDstr", &m_chipIDstr);
m_chipIDstr = "A6GH100";
tree->Fill();
This works fine. I can write the TTree to a file, and look at it with ROOT again and it looks good.
But, when I read in the TFile, apparantly it’s not possible to have a variable of type std::string. If I have a code like this:
std::string m_chipIDstr;
TTree* oldtree = (TTree*) hfile_OLD->Get( "mytree" );
oldtree->SetBranchAddress("chipIDstr", &m_chipIDstr);
ROOT gives a segmentation fault and tells me:
I can solve this by working with pointers to std::string:
std::string* m_chipIDstr;
TTree* oldtree = (TTree*) hfile_OLD->Get( "mytree" );
oldtree->SetBranchAddress("chipIDstr", &m_chipIDstr);
and then everything works fine, but I would like to know why this is.
Cheers,
Machiel