TTree size: on file vs. in memory

Hello,
My application spins through a TTree object several times. For small TTree’s (less than a few 10’s of MB) I create a memory resident copy as follows:[code]
TFile *f = new TFile(“file.root”);
TTree *pDisk = (TTree *)f->Get(“myTree”);

pDisk->SetBranchAddress(“x”,&x); // etc, for each branch

TTree *pMem = (TTree *)pDisk->Clone(“pMem”);
pDisk->CopyAddress(pMem);
pMem->Reset();

for(int i=0;iGetEntries();i++){
pDisk->GetEntries();
pMem->Fill();
//(other stuff goes here - thats why I don’t use CloneTree)
}
[/code] So when the above code is done, pMem is memory resident and I use it in other parts of the code. pDisk and pMem behave the same, apart from pMem being faster (disk access and decompression not needed). My question is: Why does pMem use twice as much memory as it needs, even after accounting for compression? What follows are the TTree::Print()'s Or is the Print() in error? I’m using win32gdk 3.10/1 on wn2k. Thanks,

Ed

Here’s pMem. Note hreg branch: 584780 shorts should only use 1.17MB, not 2.34MB. Same with the rest…
[ul]


*Tree :ntf : Fast (sampled) raw data tuple *
*Entries : 584780 : Total = 56305994 bytes File Size = 0 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :hreg : hit/S *
*Entries : 584780 : Total Size= 2338703 bytes All baskets in memory *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :x : x/S *
*Entries : 584780 : Total Size= 2338472 bytes All baskets in memory *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 2 :y : y/S *
*Entries : 584780 : Total Size= 2338472 bytes All baskets in memory *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 3 :z : z/i *
*Entries : 584780 : Total Size= 4696698 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 4 :tof : tof/F *
*Entries : 584780 : Total Size= 4697002 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 5 :delta : delta/S *
*Entries : 584780 : Total Size= 2338784 bytes All baskets in memory *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 6 :v : vs/F *
*Entries : 584780 : Total Size= 4696701 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 7 :vap : vap/F *
*Entries : 584780 : Total Size= 4697002 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 8 :pulse : pulse/F *
*Entries : 584780 : Total Size= 4697306 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 9 :erate : erate/F *
*Entries : 584780 : Total Size= 4697306 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 10 :current : current/F *
*Entries : 584780 : Total Size= 4697610 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 11 :t0 : t0/s *
*Entries : 584780 : Total Size= 2338550 bytes All baskets in memory *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 12 :tstage : tstage/s *
*Entries : 584780 : Total Size= 2338862 bytes All baskets in memory *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 13 :Vpa1 : Vpa1/F *
*Entries : 584780 : Total Size= 4697154 bytes All baskets in memory *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 14 :Vpa2 : Vpa2/F *
*Entries : 584780 : Total Size= 4697154 bytes All baskets in memory *
Baskets : 73 : Basket Size= 32000 bytes Compression= 1.00 *

root [2]
[/ul]
and here’s pDisk. Note same number of entries. The file size is right. Assuming compression is right, pMem (not compressed) should only be about 3.73
7.5MB = 28MB, not 56MB!
[ul]
root [2] gAn->m_ntRawFull->Print()


*Tree :nth : Leap Hit data *
*Entries : 584780 : Total = 28793765 bytes File Size = 7571631 *

  •    :          : Tree compression factor =   3.73                       *
    

*Br 0 :hreg : hit/S *
*Entries : 584780 : Total Size= 1216391 bytes File Size = 123732 *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 9.31 *

*Br 1 :x : x/S *
*Entries : 584780 : Total Size= 1216266 bytes File Size = 859595 *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.34 *

*Br 2 :y : y/S *
*Entries : 584780 : Total Size= 1216266 bytes File Size = 867310 *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 1.33 *

*Br 3 :z : z/i *
*Entries : 584780 : Total Size= 2388161 bytes File Size = 816553 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 2.86 *

*Br 4 :tof : tof/F *
*Entries : 584780 : Total Size= 2388319 bytes File Size = 1909713 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.22 *

*Br 5 :delta : delta/S *
*Entries : 584780 : Total Size= 1216438 bytes File Size = 433769 *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 2.66 *

*Br 6 :v : vs/F *
*Entries : 584780 : Total Size= 2388164 bytes File Size = 383535 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 6.09 *

*Br 7 :vap : vap/F *
*Entries : 584780 : Total Size= 2388319 bytes File Size = 22677 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 103.00 *

*Br 8 :pulse : pulse/F *
*Entries : 584780 : Total Size= 2388481 bytes File Size = 1197593 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 1.95 *

*Br 9 :erate : erate/F *
*Entries : 584780 : Total Size= 2388481 bytes File Size = 455336 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 5.13 *

*Br 10 :current : current/F *
*Entries : 584780 : Total Size= 2388639 bytes File Size = 53538 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 43.63 *

*Br 11 :t0 : t0/s *
*Entries : 584780 : Total Size= 1216308 bytes File Size = 304438 *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 3.78 *

*Br 12 :tstage : tstage/s *
*Entries : 584780 : Total Size= 1216480 bytes File Size = 10516 *
*Baskets : 36 : Basket Size= 32000 bytes Compression= 109.54 *

*Br 13 :Vpa1 : Vpa1/F *
*Entries : 584780 : Total Size= 2388400 bytes File Size = 27203 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 85.87 *

*Br 14 :Vpa2 : Vpa2/F *
*Entries : 584780 : Total Size= 2388400 bytes File Size = 28871 *
*Baskets : 73 : Basket Size= 32000 bytes Compression= 80.91 *

[/ul]

Hi Ed,

I see the problem and I will investigate. It looks like a counter is not reset.
The number of entries and number of baskets are correct.
Note that in your loop, you should replace
pDisk->GetEntries();
pMem->Fill();
by
pDisk->GetEntry(i);
pMem->Fill();

I strongly suggest to replace your current logic by a call
to CloneTree(0). See examples in tutorials copytree.C, copytree2.C and copytree3.C

Rene

Rene,
OK, thanks…[quote]
Note that in your loop, you should replace
pDisk->GetEntries();
pMem->Fill();
by
pDisk->GetEntry(i);
pMem->Fill(); [/quote] Oops - that was a mistake in my email - that is what I do in real life. And I will replace TTree *pMem = (TTree *)pDisk->Clone("pMem"); pDisk->CopyAddress(pMem); pMem->Reset(); with

TTree *pMem = pDisk->CloneTree(0); Thanks!

Ed