Check if TFile is already open

Dear ROOTers

I am running several root executables in parallel which are accessing the same TFile to write results in the file. For this I would like to know if there is a method to check if a TFile is already opened (I do not mean already created, I mean already opened by an other executable). The reason is to avoid conflicts in overwriting data when having the TFile open in parallel by several executables.

Many thanks and cheers,

Hi Chris,

TFile:IsOpen() maybe?

Cheers, Bertrand.

Hi Betrand

Thanks for your reply!
But TFile::IsOpen() only checks if a file in the same executable is open, right?
I tried it in two root terminals:
I opened the same file in both terminals and closed it in one of terminal. According to your reply if I call in this terminal f->IsOpen() it should give true (because it is still open in the other one), but indeed the output is false.

Cheers, Chris

Then I think there is no simple solution…

Cheers, Bertrand.

Hi Bertrand

OK, then there is only and outside-ROOT solution possible which would be using lsof called via gSystem, e.g. gSystem->Exec(“lsof /”)

Cheers, Christian

Hi Christian,

Oh yes, sure, you can use gSystem->GetFromPipe(“lsof /”).

Cheers, Bertrand.