_ROOT Version: 6/20.02
_Platform: Mac OS Catalina
_Compiler: V 10.15.4
Hello,
I ran the tutorial tree1.C (see https://root.cern/doc/master/tree1_8C.html).
It created a Tree tree1.root with 10k events.
Next time I wanted to add to tree1.root another 10k events, so I ran again tree1.C.
I see that no new events have been added, instead it created the same Tree as before.
I have then changed the line TFilef(“tree1.root”,“recreate”); to TFile f(“tree1.root”,“update”); but the result remained the same. What is the modification I need to do in order to update my tree, i.e. to add to it new events? I couldn’t find an example of this in the tutorial.
Thanks,
Elemer
// ...
TFile *f = new TFile("tree1.root", "UPDATE"); // open in "update" mode
// ...
t1->SetBranchAddress("ev",&ev);
// add events to the tree
Int_t i0 = t1->GetEntries();
for (Int_t i = i0; i < (i0 + 10000); i++) {
gRandom->Rannor(px, py);
pz = px*px + py*py;
random = gRandom->Rndm();
ev = i;
t1->Fill();
}
// f->cd(); // where "t1" resides
t1->Write(); // flush it to the file
gROOT->cd(); // newly created histograms should go here
//create two histograms
// ...
Just another question:
I see that on the updated root file the old tree remained. So, after the update I have 2 trees, the original and the updated one. How can I remove the original and keep only the updated tree?
Thanks,
Elemer
The link you sent me for the answer contains unfortunately too much information to choose easily the right solution. So let me reformulate my question: could you please send me the line(s) I have to insert in the modified tree1.C macro to suppress from the tree1.root file the original tree before update, or if I need to do it outside the macro, the command to apply.
I intend to update my tree rather frequently with a small amount of new events, so the file will grow very rapidly if it will contain all the former and no more useful trees (old cycles). Thanks in advance,
Elemer
“Cycles” are normal when trees with many entries are created so you should not care about them (it’s ROOT which manages them automatically so that you will get the very last one, unless you explicitly ask for some specific one).
Yes indeed: adding the new cycles the size of the tree remains almost the same except the first time when it doubled. This triggered my concern but I see now there is no reason for this concern. Many thanks again for your help!