# Read histogram from TFile while actively writing to it (with example)

**URL:** <https://root-forum.cern.ch/t/read-histogram-from-tfile-while-actively-writing-to-it-with-example/28273>\
**Category:** ROOT\
**Tags:** hist\
**Created:** [March 11, 2018, 10:37pm UTC](https://root-forum.cern.ch/t/read-histogram-from-tfile-while-actively-writing-to-it-with-example/28273 "2018-03-11T22:37:42Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![svpaulauskas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/svpaulauskas/32/13788_2.png) [@svpaulauskas](https://root-forum.cern.ch/u/svpaulauskas)\
**Post date:** [March 12, 2018, 10:47am UTC](https://root-forum.cern.ch/t/read-histogram-from-tfile-while-actively-writing-to-it-with-example/28273/3 "2018-03-12T10:47:24Z")

</div>

That is correct. I am using the method suggested in [this](https://root-forum.cern.ch/t/read-a-tfile-while-writing-with-another-process/18608/6) forum post. I had to remove the `const` modifier from the TFile argument in `reading` because ReadKeys is not marked as `const` (see error below).

I tried omitting `delete file->FindObject(name);`, but end up with this error

```auto
Error in <TFile::ReadKeys>: reading illegal key, exiting after 1 keys

```

If I use the method described in [this](https://root-forum.cern.ch/t/read-a-tfile-while-writing-with-another-process/18608/7) response, then I can view histograms as expected.

I should note that I’ve also read the the threads [here](https://root-forum.cern.ch/t/real-time-ttree-reading/18842) and [here](https://root-forum.cern.ch/t/monitor-a-histogram-while-running/22287/6).

### Error when using const TFile

```auto
In file included from input_line_12:9:
././viewOnline.C:11:9: error: member function 'ReadKeys' not viable: 'this' argument has type 'const TFile', but function is not marked const
        file->ReadKeys();
        ^~~~
/opt/root/v6-11-02-1447-g38586de/include/TDirectoryFile.h:105:24: note: 'ReadKeys' declared here
   virtual Int_t ReadKeys(Bool_t forceRead=kTRUE);
                       ^
In file included from input_line_12:9:
././viewOnline.C:13:15: error: no matching member function for call to 'GetObject'
        file->GetObject(name, hist1);
        ~~~~~~^~~~~~~~~
/opt/root/v6-11-02-1447-g38586de/include/TDirectoryFile.h:78:35: note: candidate function not viable: no known conversion from 'const TFile' to 'TDirectoryFile' for object argument
   template <class T> inline void GetObject(const char* namecycle, T*& ptr) // See TDirectory::Get for i...

```

---

_[View the full topic](https://root-forum.cern.ch/t/read-histogram-from-tfile-while-actively-writing-to-it-with-example/28273)._
