# Reading events from a TFile that is being written

**URL:** <https://root-forum.cern.ch/t/reading-events-from-a-tfile-that-is-being-written/42241>\
**Category:** Newbie\
**Created:** [November 11, 2020, 4:54pm UTC](https://root-forum.cern.ch/t/reading-events-from-a-tfile-that-is-being-written/42241 "2020-11-11T16:54:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonardi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/f0a364/32.png) [@leonardi](https://root-forum.cern.ch/u/leonardi)\
**Post date:** [November 11, 2020, 4:54pm UTC](https://root-forum.cern.ch/t/reading-events-from-a-tfile-that-is-being-written/42241/1 "2020-11-11T16:54:08Z")

</div>

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ 5.34.36  
_Platform:_ CentOS 7  
_Compiler:_ gcc 4.9

* * *

My data acquisition system writes data to ROOT files using the following code:

```auto
  fTFileHandle = TFile::Open(fOutFile,"NEW","PADME Merged Raw Events");
  if ( (!fTFileHandle) || fTFileHandle->IsZombie() ) {
    delete fTFileHandle;
    return ROOTIO_ERROR;
  }
  fTTreeMain = new TTree("RawEvents","PADME Raw Events Tree");
  fTTreeMain->Branch("RawEvent",&fTRawEvent);
...write many events to file...
  fTTreeMain->Write();
  fTFileHandle->Close();

```

It would be very useful for me if I could monitor the content of the events WHILE they are being written, i.e. doing something similar to the Unix command “tail -f”.

If I open the file that is being written with an external program I get some warning messages:

```auto
Warning in <TFile::Init>: file rawdata1/run_0030611_20201111_120928/run_0030611_20201111_120928_lvl1_00_006.root probably not closed, trying to recover
Info in <TFile::Recover>: rawdata1/run_0030611_20201111_120928/run_0030611_20201111_120928_lvl1_00_006.root, recovered key TTree:RawEvents at address 115620453
Warning in <TFile::Init>: successfully recovered 1 keys

```

I can then read the events only up to a certain point.  
If I close and reopen the file I get similar warning messages and can read a bit more events.  
Is there a way to open the file and keep it open while progressively reading the events shortly after they have been written to the file?

Thank you  
Emanuele Leonardi

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 11, 2020, 6:56pm UTC](https://root-forum.cern.ch/t/reading-events-from-a-tfile-that-is-being-written/42241/2 "2020-11-11T18:56:05Z")

</div>

See an working example at: [Read histogram from TFile while actively writing to it (with example)](https://root-forum.cern.ch/t/read-histogram-from-tfile-while-actively-writing-to-it-with-example/28273/12) (please also note the surrounding discussions)

---

<div class="post-metadata">

**Author:** ![leonardi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/f0a364/32.png) [@leonardi](https://root-forum.cern.ch/u/leonardi)\
**Post date:** [November 12, 2020, 6:03pm UTC](https://root-forum.cern.ch/t/reading-events-from-a-tfile-that-is-being-written/42241/3 "2020-11-12T18:03:11Z")

</div>

Thank you: exactly what I needed.  
One final question: is there any way to switch off the warning/info messages I get when I open a file that was not closed?  
E.g.

```auto
Warning in <TFile::Init>: file rawdata1/run_0030617_20201112_170343/run_0030617_20201112_170343_lvl1_00_034.root probably not closed, trying to recover
Info in <TFile::Recover>: rawdata1/run_0030617_20201112_170343/run_0030617_20201112_170343_lvl1_00_034.root, recovered key TTree:RawEvents at address 90885443
Warning in <TFile::Init>: successfully recovered 1 keys

```

Emanuele

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [November 12, 2020, 6:52pm UTC](https://root-forum.cern.ch/t/reading-events-from-a-tfile-that-is-being-written/42241/4 "2020-11-12T18:52:25Z")

</div>

Calling:  
`gErrorIgnoreLevel = kError`  
will reduce the printing to Error or Fatal messages.
