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

That is correct. I am using the method suggested in this 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

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

If I use the method described in this response, then I can view histograms as expected.

I should note that I’ve also read the the threads here and here.

Error when using const TFile

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...