# Monitor a histogram while running

**URL:** <https://root-forum.cern.ch/t/monitor-a-histogram-while-running/22287>\
**Category:** ROOT\
**Created:** [November 30, 2016, 4:25pm UTC](https://root-forum.cern.ch/t/monitor-a-histogram-while-running/22287 "2016-11-30T16:25:28Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [December 1, 2016, 3:59pm UTC](https://root-forum.cern.ch/t/monitor-a-histogram-while-running/22287/6 "2016-12-01T15:59:01Z")

</div>

Yes, just take a look at this [Read a tfile while writing with another process](https://root-forum.cern.ch/t/read-a-tfile-while-writing-with-another-process/18608/1)

A simple (untested) implementation would be:

```auto
//Program 1
void filler() {
   TFile* f = new TFile("test.root","RECREATE");
   TH1D* h = new TH1D("h", "h", 100, 0, 10);
   for ( int i = 0; i < 1000000; i++ ) {
      usleep(10000);
      h->Fill(gRandom->Gaus(5,1));
      if(i%1000==0)
      {
          h->Write("",TObject::kWriteDelete);
          f->SaveSelf();
      }
   }
   f->Close();
   delete f;
   return;
}

//Program 2 in another terminal
void readnow() {
    TFile* f = TFile::Open("test.root");
    new TCanvas();
    TH1D *h; f->GetObject("h",h);
    h->Draw();
}

```

---

_[View the full topic](https://root-forum.cern.ch/t/monitor-a-histogram-while-running/22287)._
