I guess it must have been discussed somewhere, but I have troubles finding. How to access TTrees in a file that are still being written? I guess I can make a loop which will be periodically calling GetEntries() and checking if the number has changed (still, I don’t know if it can change, or do I have to close and reopen the TTree?), but maybe there are better methods, including check if the TFile was closed or not, etc.
// How to write a Tree in one process and view it from another process
// ===================================================================
// The following two scripts illustrate how to do this.
// The script treew.C is executed by process1, treer.C by process2
//
// ----- script treew.C
// void treew() {
// TFile f("test.root","recreate");
// TNtuple *ntuple = new TNtuple("ntuple","Demo","px:py:pz:random:i");
// Float_t px, py, pz;
// for ( Int_t i=0; i<10000000; i++) {
// gRandom->Rannor(px,py);
// pz = px*px + py*py;
// Float_t random = gRandom->Rndm(1);
// ntuple->Fill(px,py,pz,random,i);
// if (i%1000 == 1) ntuple->AutoSave("SaveSelf");
// }
// }
//
// ----- script treer.C
// void treer() {
// TFile f("test.root");
// TTree *ntuple = (TTree*)f.Get("ntuple");
// TCanvas c1;
// Int_t first = 0;
// while(1) {
// if (first == 0) ntuple->Draw("px>>hpx", "","",10000000,first);
// else ntuple->Draw("px>>+hpx","","",10000000,first);
// first = (Int_t)ntuple->GetEntries();
// c1.Update();
// gSystem->Sleep(1000); //sleep 1 second
// ntuple->Refresh();
// }
// }