Error message writing mem resid. TTrees, New in 5.05/1

In root 5.05/1 (win32 platform, P4):

When I write to a memory resident TTree (gFile is attached to a root file opened with “READ” option) I get a bunch of error message, TTree::Print() produces goofy information, but the TTree appears to be ok (I can Draw(), etc)…

In root 4.02/0, I get no error messages, TTree::Print() behaves properly.

The following demonstrates the problem:

[code]void demo()
{
// create a reaonly root file to demonstrate problem
TFile *f = new TFile(“memresdemo.root”,“recreate”);
TH1F *ph = new TH1F(“ph”,"…",100,-100,100);
f->Write();
f->Close();
delete f;
f = new TFile(“memresdemo.root”,“READ”);

// create the memory resident ntuple
float x,y;
TNtuple *nt = new TNtuple("nt","demo","x:y:z");
TRandom r;
for(int i=0;i<200000;i++)
{
	r.Rannor(x,y);
	nt->Fill(x,y,x*x+y*y);
}

}
[/code]

Here’s what I get w/ 5.05.1[quote]root [0] .L ntupledemo.cpp
root [1] demo()
Error in TNtuple::Fill: Failed filling branch:nt.x, nbytes=-1
Error in TNtuple::Fill: Failed filling branch:nt.y, nbytes=-1
Error in TNtuple::Fill: Failed filling branch:nt.z, nbytes=-1
Error in TNtuple::Fill: Failed filling branch:nt.x, nbytes=-1
.
.
.
.
root [2] nt->Print()


*Tree :nt : demo *
*Entries : 200000 : Total = 2413498 bytes File Size = -75 *

  •    :          : Tree compression factor = -32000.00                       *
    

*Br 0 :x : *
*Entries : 200000 : Total Size= 804556 bytes All baskets in memory *
*Baskets : 25 : Basket Size= 32000 bytes Compression= -32000.00 *

*Br 1 :y : *
*Entries : 200000 : Total Size= 804556 bytes All baskets in memory *
*Baskets : 25 : Basket Size= 32000 bytes Compression= -32000.00 *

*Br 2 :z : *
*Entries : 200000 : Total Size= 804556 bytes All baskets in memory *
*Baskets : 25 : Basket Size= 32000 bytes Compression= -32000.00 *

root [3]
[/quote]

I see the same problem wuth TTree or TNtuple. TTree::SetMaxVirtualSize(100000000) does not help…

Also, if gFILE==0 (e.g. also memory resident) there is no problem. Is this new behavior intentional? If so, what is the reasoning? Thanks!

Ed Oltman

Hi Ed,

Usually, this kind of setup (attaching a TTree to a read-only file) is done by mistake (i.e. either the wrong file was the current directory when creating the TTree or the file was mistakenly open read-only). Hence we chose to warn the user that something went (probably wrong).

[quote]Also, if gFILE==0 (e.g. also memory resident) there is no problem.[/quote]Having the directory of the TTree to be 0 or gROOT is the way to tell ROOT that it is a memory resident tree.

Cheers,
Philippe.

Hi,

here is a slight variation of the above (this time with TTree’s):

[code]void demo()
{
// create a reaonly root file to demonstrate problem
TFile *f = new TFile(“memresdemo.root”,“recreate”);
TH1F *ph = new TH1F(“ph”,"…",100,-100,100);
f->Write();
f->Close();
delete f;
f = new TFile(“memresdemo.root”,“READ”);

// create the memory resident ntuple
float x,y;
TTree *t = new TTree(“t”,“demo”);
t->Branch(“x”,&x,“x/F”);
t->Branch(“y”,&y,“y/F”);
t->SetDirectory(0);
TRandom r;
for(int i=0;i<200000;i++)
{
r.Rannor(x,y);
t->Fill();
}
TTree *t2 = t->CloneTree(); // NEW !!!
}
[/code]

The Fill() command does not produce the warnings since the directory is
set to 0, I guess. But the CloneTree() does (see below). Is there a way of suppressing
those warnings as well?

Thanks
Frank

P.S.: I am using ROOT 4.04/02b

Error in TTree::Fill: Failed filling branch:t.x, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.y, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.x, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.y, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.x, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.y, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.x, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.y, nbytes=-1
Error in TTree::Fill: Failed filling branch:t.x, nbytes=-1

[quote]The Fill() command does not produce the warnings since the directory is set to 0, I guess. But the CloneTree() does (see below). Is there a way of suppressing those warnings as well?
[/quote]For that simply use:[code] // create the memory resident ntuple
gROOT->cd();

float x,y;
TTree *t = new TTree(“t”,“demo”);
t->Branch(“x”,&x,“x/F”);
t->Branch(“y”,&y,“y/F”);
TRandom r;
for(int i=0;i<200000;i++)
{
r.Rannor(x,y);
t->Fill();
}
TTree *t2 = t->CloneTree(); // NEW !!! [/code]

Cheers,
Philippe.