Hi All,
I have a series of questions regarding TTrees of the same name and different namecycles. I’d like to make sure I know what is going on because, even after several years of being a ROOTer, I still am unsure about this and haven’t been able to find it explained fully
I currently have a root file with two trees: myTree;1 and myTree;2. This file was created by a script which defined and wrote only one instance of the tree to the root file. Here is the code:
typedef struct {Float_t x,y,z;} POINT;
void ttreeNameCycles(){
POINT point;
TFile *file = new TFile("myTree.root","RECREATE");
TTree *tree = new TTree("myTree","myTree");
tree->Branch("point",&point,"x:y:z",10);
TRandom3 rand(0);
for (Int_t i=0; i<1000000; i++){
point.x = i;
point.y = rand.Uniform(0,1);
point.z = rand.Uniform(0,1);
tree->Fill();
}
tree->Write();
}
Here are my questions:
-
My understanding of why I have two trees of the same name is the following. ROOT began by filling a tree called myTree;1. When that tree became larger than its buffer size it was written to the file and ROOT continued on writing to a tree called myTree;2. Is this correct?
-
When I examine the two tree individually I find that myTree;1 contains 612246 entries and that myTree;2 contains the full 1000000 entries. And that the first 612246 entries of myTree;2 are identical to those in myTree;1. Is it always guaranteed that myTree;1 will be a subset of myTree;2?
-
When I look at the file size of myTree.root I find that it is ~35MB. If I then open the root file and delete myTree;1 using TFile::Delete() I would expect the file size to be reduced. But this doesn’t seem to be the case! Why?
-
When I want to read a tree from a file like this I find that retrieving the tree from the file via TFile::Get() returns to me a pointer to a tree that contains all the entries - 1000000 in this case. Presumably then ROOT is smart enough to know it should always pick the tree with the greatest namecycle? Is this the default behavior?
-
If my understanding is all correct it really seems that a more intuitive behavior for writing the file would be to delete myTree;1 and leave me only with myTree;2. Why does this not happen? Why is myTree;1 still kept as a key in the final file?
My thanks for your answers and corrections!
Cheers,
Chris