Delete or Clear a Temporary Tree

Dear all

I need to save some entries from an input tree temporaly inside a loop, before saving them definitively in an output tree. Since cloning the tree was the most obvious thing to do to have exactly the datastructure fitted for those entries I wanted to save (temporaly) I used that approach:

TTree *tIn = (TTree *) gFile->Get(“tpTree/fitter_tree”);
TFile *fOut = new TFile(“tnpZ_addBestZPiet.root”, “RECREATE”);
fOut->mkdir(“tpTree”)->cd();
TTree *tOut = tIn->CloneTree(0);

if(debug) n = 100;
if(!debug) n = tIn->GetEntries();

for (UInt_t i = 0; i < n; ++i) {
tIn->GetEntry(i);
TTree *tTemp = tIn->CloneTree(0);
tTemp->Fill();

}

The behaviour I desired was that the cloned tree is deleted at the end of the loop. Invoking the delete call directly at the end of the loop by tTemp->Delete(); did not work. I found out that this cloned tree is actually owned by the original tree and that it is only deleted when the original tree is.

Alternatively I could live with a way to delete entries of that tree (I would move the declaration of the tree outside the loop then), but I could not find the command to do so. I can not use a circular tree, since I don’t know on beforehand how many entries this temporary tree has to contain.

How can I delete the temporary tree or how can i delete all entries inside. Or is there another datatype/structure I should use? $ROOTSYS/tutorials/tree/copytree3.C is not an option for me because I cannot make a different copy for every 10^12 entries my loop is running over. I am not interested to keep these entries in the temp tree until the end of the program, this would consume too much precious memory.

Thanks a lot
Kind regards
Piet Verwilligen

Hi All

I kind of avoided the problem by keeping a vector of entrynumbers and asking the entries afterwards directly from the original tree. I do understand that this is from performance point of view better than copying the whole entry. Anyway would be interesting to know how to delete a tree made by the clone “constructor” or how to delete a specific entry. Or in case its not possible / allowed, what the strategy behind this is.
Thanks
Piet