Reading events from a TFile that is being written


Please read tips for efficient and successful posting and posting code

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:

  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:

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

See an working example at: Read histogram from TFile while actively writing to it (with example) (please also note the surrounding discussions)

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.

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

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