Writing a tree without filling

Hi all,

We ran into a bizarre problem this morning - we have a tree in a file that we are constantly opening and closing and thus writing, but only sometimes filling. This works … for some small number (10-20ish) entries, but ultimately causes a bus error or segmentation fault. If we fill the tree every time before writing it, the code below works fine.

Any ideas for what could be causing this? We can and will rewrite our code so the file is not always being opened and closed like this if the tree will not be filled, but we would also like to understand the problem. Is there any fundamental reason this shouldn’t work?

Thanks,
Jahred


{

TFile *f = new TFile(“blah.root”,“RECREATE”);
f->cd();
struct mys{Float_t x[3];}; mys mys_t;

mys_t.x[0] = 1.1;
mys_t.x[1] = 12.2;
mys_t.x[2] = 13.3;

TTree *t = new TTree(“mytree”,“mytree”);
t->Branch(“mybranch”,&mys_t,“x[3]/F”);
t->Fill();
t->Write();
f->Close();

for (int i = 0; i < 500; i++) {
std::cerr << " i = " << i << std::endl;
TFile *fnew = new TFile(“blah.root”,“UPDATE”);
TTree tnew = (TTree)fnew->Get(“mytree”);
if (i % 3 == 0) tnew->Fill();
tnew->Write("",TObject::kOverwrite);
delete fnew;
}
}

Hi,

Thanks for reporting this issue. It has been corrected in the head of the SVN trunk (revision 27108).

Cheers,
Philippe.

PS. As a work around, do not call tnew->Write if there is no call to Fill.