void fw() { // example showing how to save objects to a file such that they // can be read in parallel by another Root session. // Every kUPDATE entries, the current histograms and ntuple // are written to the file replacing the previous objects // // In a different Root session, one can look at the objects without // reopening the file. See for example macro fr.C // // void fr() { // if (gROOT->GetListOfFiles()->FindObject("hsi.root")) { // gDirectory->ReadKeys(); // } else { // TFile *file = new TFile("hsi.root"); // } // TNtuple *ntuple = (TNtuple*)gDirectory->Get("ntuple"); // printf("ntuple has now %d entries\n",ntuple->GetEntries()); // delete ntuple; //} // // To test this facility, do: // process1, run root // root > .x fw.C // process2, run a new version of root // root > .x fr.C // root > .x fr.C, etc TFile *hfile = new TFile("hsi.root","RECREATE"); // Create some histograms, a profile histogram and an ntuple hpx = new TH1F("hpx","This is the px distribution",100,-4,4); hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4); hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20); ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i"); // Fill histograms randomly gRandom->SetSeed(); Float_t px, py, pz; const Int_t kUPDATE = 10000; Int_t mode = TObject::kWriteDelete; for (Int_t i = 0; i < 25000000; i++) { gRandom->Rannor(px,py); pz = px*px + py*py; Float_t random = gRandom->Rndm(1); hpx->Fill(px); hpxpy->Fill(px,py); hprof->Fill(px,pz); ntuple->Fill(px,py,pz,random,i); if (i && (i%kUPDATE) == 0) { hpx->Write(0,mode); hpxpy->Write(0,mode); hprof->Write(0,mode); ntuple->Write(0,mode); hfile->SaveSelf(); //this is the key statement } } hfile->Write(); }