TTree autosaving problem [SOLVED]

Hi,
I wrote a program with my class , the main part of my program looks:
#include
#include
#include <TH2D.h>
#include <TApplication.h>
#include <TCanvas.h>
#include <TPad.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TVector.h>
#include <TLorentzVector.h>
#include <TROOT.h>
#include “Event.h”
#include “Particle.h”
#include <TTree.h>
#include <TFile.h>
#include <TBranch.h>
#include <TRandom3.h>
#include <TSystem.h>
#include <TCanvas.h>
#include <TH1D.h>
#include <TMath.h>
int main(int argc, char* argv[]) {
Int_t nev=100000;
TRandom3 *rand = new TRandom3();
Int_t multi=0;
TFile f(“EventXX.root”,“create”);;
TTree *T = new TTree(“T”,“Event example with Jets”);
T->SetAutoFlush(0);
Event *event= new Event();
std::cout<<“busy?”<<std::endl;
T->Branch(“event”,“Event”,&event,0,2);
Particle particle;
for (Int_t ev=0;ev<nev;ev++) {
multi=10+(Int_t)(rand->Exp(1.0)1000);
event->Build(multi);
for(int i=0;i<multi;i++){
particle=event->AddParticle();
particle->fPx=rand->Gaus(0.0,10.0);//0.0001
(Double_t)i+0.01
(Double_t)ev;
particle->fPy=rand->Gaus(0.0,10.0);;
particle->fPz=rand->Gaus(0.0,10.0);
particle->fE=0.0;
particle->fX=0.0;
particle->fY=0.0;
particle->fZ=0.0;
particle->fT=0.0;
particle->fID=101;
}
T->Fill();
if(ev%1000==0) std::cout<<“event”<<ev<<std::endl;

   }
   T->Write();
   T->Print();
   std::cout<<"print"<<std::endl;
   T->ResetBranchAddresses();
  f.Save();
  f.Close();
   std::cout<<"print"<<std::endl;
return 0;

}

And I have problem with filling the tfile, if I generate a small amount of Events, everything works fine, but if I try to generate a lot of Events with many Particles inside,lets say 50 000 then when I open this file with TBrowser I se 2 TTree folders, In first I have 50 k of Events in second less 43 k, if i try to generate more events(let say 100k), then I will get similar situation - 100 k in first tree and less (about 99-93 k ) in second tree, It’s seems that this second tree if kind of buffer but I don’t know how to turn it of, I try use SetAutoFlush but It will not be working for larger files if I don’t have enough memory.

Hi,

There is actually only one TTree in your file. The 2 things that you are seeing are two ‘revisions’ of the meta-data of your TTree. Intentionally, in order to improve chances of recovery if things go wrong, ROOT keeps the previous revision of the TTree meta-data when it does an autosave. In normal operation, you can simply ignore the ‘older’ revision. (See the User’s guide for more details).

Cheers,
Philippe.

I add T->Autosave(“overwrite”);
gDirectory->Purge() ;
and file->Write();
It’s works fine.
Thanks.