Error reading a tree


I have a problem reading a tree that I have created. To demonstrate the “feature” I have created an example macro:

[code]#include “TObject.h”
#include “TTree.h”
#include “TFile.h”

class testclass : public TObject {
testclass () { n=0; test_array=0; }
virtual ~testclass () { delete[] test_array; }
void Clear (Option_t* opt="") { delete[] test_array; n=0; test_array=0; }

Int_t n;
Double_t *test_array; //[n]

ClassDef (testclass,1); // Test class

void makeerror () {
TFile::Open(“tmp.root”, “RECREATE”);

testclass *test = new testclass ();

TTree* tree = new TTree(“tree”, “tree”);
tree->Branch(“test”, &test);

for (int i=0; i<1000; i++) {
test->n = 400;
test->test_array = new Double_t[test->n];
for (int i=0; in; i++)
test->test_array[i] = i;

tree->Fill ();


TFile *out = TFile::Open(“makeerror.root”, “RECREATE”);

I run this with:

which correctly creates the file makeerror.root.

Now I try to do a plot with this tree like this:

$ root -l makeerror.root root [1] tree->Draw("test_array") <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 Error: Symbol G__exception is not defined in current scope (tmpfile):1: Error: type G__exception not defined FILE:(tmpfile) LINE:1 (void)0 *** Interpreter error recovered *** root [2] .q

Does anyone know the solution to this problem? (by the way the error message is not very useful…)



The problem is: TFile::Open("tmp.root", "RECREATE"); ... TTree* tree = new TTree("tree", "tree"); ... TFile *out = TFile::Open("makeerror.root", "RECREATE"); tree->Write();Where you end up storing the data itself in one file (“tmp.root”) but store the meta data in another file (“makeerror.root”).
This is actually supported but you need to be more explicitly in telling the TTree and TBranch that it is the case. To use a single file use: TFile *out = TFile::Open("tmp.root", "RECREATE"); ... TTree* tree = new TTree("tree", "tree"); ... tree->Write(); To store the data in a different file see … ch:SetFile


Hi Philippe,

thanks for your suggestion, which of course solves the problem.

But I must say that I find this behaviour extremely confusing…