Re: TFile file size?

Rene Brun (Rene.Brun@cern.ch)
Fri, 14 Nov 1997 19:12:37 +0100


Reid D Rivenburgh wrote:

> Hi,
>
> Does anyone have any suggestions as to how to determine the actual file
> size of the regular unix file associated with a TFile? I'm managing
> a collection of TFiles, and I'd like to be able to determine if
> one is getting near 2 gigabytes in size so that I can close it and
> open a new one before writing a new object to it. I tried using
> TFile::GetBytesWritten(), but when my program exits, the final file
> size is about 50% bigger than my cutoff threshold. For example, when
> GetBytesWritten determines that I've reached my testing cutoff of 10k in
> size, I open a new TFile, do some things, and exit; when I look at the
> first file, it's about 15k in size. The same thing was happening with
> a cutoff of 100k: the file wound up being 150k. What is the extra 50%,
> and can I always count on it? (Probably not, but I thought I'd ask...)

TFile::GetBytesWritten must return EXACTLY the number of bytes
written to the file at this point in time.
When you close the file, and in particular, if you use a Tree, you may
have buffers in memory. These buffers will be written to the file.
You may expect a very large discrepancy if you compare the result
of GetBytesWritten before and after closing the file if you make
this measurement on trivial file sizes of a few tens of kilobytes
because the file size is about the same size than the buffers in memory.
Just count the number of branches times the buffer size to evaluate
thesize of buffers in memory.

Rene Brun