#include "TFile.h" #include "TMacro.h" #include "TSystem.h" #include "TTree.h" #include "TObjString.h" #include #include #include #include #include #include using namespace std; double energy = 1.5; char volume[80] = "test"; TTree* CreateNewHitTree(TString name, TString desc); int FillTree() { ProcInfo_t info; gSystem->GetProcInfo(&info); cout << "Start: " << " mem res = " << info.fMemResident << " mem virt = " << info.fMemVirtual << endl; int detnum = 24; int nevents = 2e6; TString fileName = "tree.root"; TFile* tfile = new TFile("file://"+fileName,"RECREATE"); tfile->cd(); tfile->mkdir("G4SimDir"); tfile->mkdir("G4SettingsInfoDir"); tfile->cd("/G4SimDir"); std::vector detTree; for(int i=0; iGetProcInfo(&info); cout << "Created TTree # " << i << " mem res = " << info.fMemResident << " mem virt = " << info.fMemVirtual << endl; } for(int n=0; nFill(); } if(n%100000==0) { gSystem->GetProcInfo(&info); cout << "Fill #events: " << n << " mem res = " << info.fMemResident << " mem virt = " << info.fMemVirtual << endl; } } for (size_t i = 0; i < detTree.size(); i++) { tfile->cd("/G4SimDir"); detTree[i]->Write(); delete detTree[i]; detTree[i] = 0; gSystem->GetProcInfo(&info); cout << "Deleted TTree # " << i << " mem res = " << info.fMemResident << " mem virt = " << info.fMemVirtual << endl; } detTree.clear(); tfile->cd("/"); tfile->Write("", TObject::kOverwrite); tfile->Close(); gSystem->GetProcInfo(&info); cout << "Closed TFile " << " mem res = " << info.fMemResident << " mem virt = " << info.fMemVirtual << endl; return 0; } TTree* CreateNewHitTree(TString name, TString desc) { int autoFlushSize = 5000000; TTree* theTree = new TTree(name, desc); theTree->SetAutoFlush(-autoFlushSize); // Buffer size between flushes theTree->SetAutoSave(-10*autoFlushSize); // Basket size between writing for(int i=0; i<30; i++) theTree->Branch("Energy", &energy, "Energy/D"); for(int i=0; i<4; i++) theTree->Branch("Volume", volume, "Volume/C"); return theTree; }