Dear All
I've been using the TRef auto-loading mechanism recently.
I plan to save a header object, which has a TRef data member pointed to a event object, in one TTree and save the event object in another TTree. So after I've loaded the header object, I could use the TRef auto-loading mechanism to load the event object automatically when I wanted to.
The header object and event object are all derived from TObject. The auto-loading is working now, I can use TRef::GetObject() to load the event object even if it was not in the same file. But here comes the problem:
The size of the TTree containing the event object gets larger nonlinearly when the entry number grows. When I save 10000 event, the file is only 2.1mb, but when I save 20000, the file will be 6.1mb, 30000 12mb, 40000 20mb......
Here's how I did the test:
[code]TFile* file1 = new TFile(“header.root”,“recreate”);
TFile* file2 = new TFile(“event.root”,“recreate”);
gDirectory->cd(“header.root:/”);
TTree* tree_1 = new TTree(“tree_header”,“tree for header”);
gDirectory->cd(“event.root:/”);
TTree* tree_2 = new TTree(“tree_event”,“tree for event”);
header* phw = NULL;
event* pew = NULL;
tree_1->Branch(“branch_for_header”,“header”,&phw);
tree_2->Branch(“branch_for_event”,“event”,&pew,64000,0);
tree_1->BranchRef();
tree_2->BranchRef();
tree_1->AddFriend(tree_2);
for(int i=0;i<10000;++i) {
//build header and event…
//…
//…
tree1->Fill();
tree2->Fill();
}
file1->Write();
file2->Write();
file2->Close();
file1->Close();
[/code]
I've realized that it is the size of the TBranchRef in the TTree containing referenced objects that caused the problem. The size of each entry gets bigger and bigger when the entry number grows:
root [2] TFile tf("event.root","read")
root [3] TTree *tree = (TTree*)tf.Get("tree_event;1")
root [4] TBranchRef *tbr = tree->GetBranchRef()
root [5] tbr->GetEntry()
(Int_t)16
root [6] tbr->GetEntry(1)
(Int_t)20
root [7] tbr->GetEntry(2)
(Int_t)24
root [8] tbr->GetEntry(3)
(Int_t)28
root [9] tbr->GetEntry(500)
(Int_t)2016
root [10] tbr->GetEntry(800)
(Int_t)3216
root [11] tbr->GetEntry(1800)
(Int_t)7216
The size of each entry of the TBranchRef gets 4 bytes bigger for each entry added. When the entry number grows big, the size of the TTree will be very huge. Is this normal or if there something I did wrong? And do you have a hint of what happened? Is there anything could I do to solve this problem?
Thank you in advance,
Li Teng