Well, I would like to store a single TString in a root tree. I thought that this would be a simple operation but for some reason it is proving to be quite the bear. I have done some searching and all the solutions seem to have a TString wrapped by a custom class so that other information can be stored. I would like to have just the TString stored. I need nothing else. I have tried the following block of code...
#include <TTree.h>
#include <TFile.h>
#include <TString.h>
#include <iostream>
using namespace std;
int main() {
TFile output("output.root", "RECREATE");
TTree *tree = new TTree("output", "output2");
TString *test_string = new TString();
tree->Branch("haha", &test_string);
*test_string = "This is a test";
tree->Fill();
tree->Write();
output.Close();
return(0);
}
So, when I compile it is goes super clean, and then when I run it, it runs fine… The problem is when I try to read it… I get a segmentation fault no matter what I do. Is there something fundamentally wrong with what I am trying to do?
[quote] Is there something fundamentally wrong with what I am trying to do? [/quote]Nothing … except maybe using a version of ROOT too old?
(You need ROOT v5.22 or up).
I am running 5.22 right now. That is what I used to generate the root file with the above code. Below is the output when I try to read the information from the root file....
D0 is running an old version of root for their p21 software release. I thought it was at least in the 5.00 and greater region but I guess they reverted… How would I need to modify my code to use this older version of root? Thanks for the pointers…
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 4.04/02b 3 June 2005 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
Compiled on 7 March 2007 for linux with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.169, Mar 14 2005
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.