Naive question about TFile::GetSize()

Please provide the following information:

ROOT Version (e.g. 6.12/02): 5.34.36
Platform, compiler (e.g. CentOS 7.3, gcc6.2): CentOS 7, gcc4.9.3

I am writing some events to a TFile. As I would like to know the size of the final file, just before closing it I am calling the GetSize() method on the TFile object but I am always getting a “cannot stat the file” error.
Why si this happening and how do I get the correct file size?

This is the final part of the code I am using (fTFileHandle is a TFile* object):

  Long64_t size = fTFileHandle->GetSize();
  fOutSizeTotal += size;

Thank you
Emanuele Leonardi

Hi @leonardi,

Please try getting the size of the file you are writing after you close it. This will ensure the contents are flushed to disk and you should not see the “cannot stat the file” error.



Hi Enric.

  I tried moving the GetSize()/GetBytesWritten() commands after the Close() but the result is the same.

My code now reads:

printf("RootIO::CloseOutFile - Closing output file %s\n",fOutFile.Data());
Long64_t size = fTFileHandle->GetSize();
Long64_t bytes = fTFileHandle->GetBytesWritten();
printf("File has size %lld and bytes %lld\n",size,bytes);

This code produced a file of 14808551 bytes but reports:

RootIO::CloseOutFile - Closing output file rawdata/run_15/run_15_000.root
Error in <TFile::GetSize>: cannot stat the file File has size -1 and bytes 0

Any ideas?

Thank you very much


Can this be a bug that was fixed later in ROOT 6? @pcanal any ideas on this?

I can not reproduce the problem. Is the name of your file (on disk) really ‘FIle’ ?

Note that TFile::GetSize() always ask the *filesystem for the current set of the file on disk at that moment.
while TFile::GetEND() will tell you the size of the data that was save to the TFile but might have have been flushed to disk yet. In both case, calling after Close is the ‘right’ thing to do if you want to know the final size.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.