You may try to define the tree variable when you're reading the data back.
Find below the example of macro which does what (I believe) you need.
regards, pasha.
-------------------------------------------- test.C
int test(int mode) {
char* ach = new char[100];
if (mode == 0) {
// writing
TFile* myfile = new TFile ("test.root", "RECREATE" );
TTree* tree = new TTree ("Tree", "ROOT test tree" );
TBranch* brach = tree->Branch("ach", (void*)ach, "ach/C", 8000 );
for (int i=0; i<99; i++) {
for (int j=0; j<i; j++) ach[j] = 48+i;
ach[i] = 0;
tree->Fill();
}
delete [] ach;
tree->Write();
delete myfile;
}
else {
// reading
TFile* myfile = new TFile( "test.root");
TTree* tree = (TTree* ) myfile->Get("Tree");
TBranch *brach = tree->GetBranch("ach");
brach->SetAddress((void*)ach);
for (int i=1; i<10; i++) {
ach[0] = 0C;
tree->GetEvent(i);
cout << ach << endl;
}
delete myfile;
}
return 0;
}
--------------------------------------------------
root [14] .L test.C
root [15] int rc;
root [16] rc = test(0)
(int)0
root [17] rc = test(1);
1
22
333
4444
55555
666666
7777777
88888888
999999999
root [18]