From $ROOTSYS/tutorials/tree/circular.C

//  Example of a circular Tree
//  Circular Trees are interesting in online real time environments
//  to store the results of the last maxEntries events.
//  for more info, see TTree::SetCircular
// Author: Rene Brun
void circular() {
   gROOT->cd(); //make sure that the Tree is memory resident
   TTree *T = new TTree("T","test circular buffers");
   TRandom r;
   Float_t px,py,pz;
   Double_t random;
   UShort_t i;
   T->Branch("px",&px,"px/F");
   T->Branch("py",&py,"px/F");
   T->Branch("pz",&pz,"px/F");
   T->Branch("random",&random,"random/D");
   T->Branch("i",&i,"i/s");
   T->SetCircular(20000); //keep a maximum of 20000 entries in memory
   for (i = 0; i < 65000; i++) {
      r.Rannor(px,py);
      pz = px*px + py*py;
      random = r.Rndm();
      T->Fill();
   }
   T->Print();
}

 circular.C:1
 circular.C:2
 circular.C:3
 circular.C:4
 circular.C:5
 circular.C:6
 circular.C:7
 circular.C:8
 circular.C:9
 circular.C:10
 circular.C:11
 circular.C:12
 circular.C:13
 circular.C:14
 circular.C:15
 circular.C:16
 circular.C:17
 circular.C:18
 circular.C:19
 circular.C:20
 circular.C:21
 circular.C:22
 circular.C:23
 circular.C:24
 circular.C:25
 circular.C:26
 circular.C:27
 circular.C:28