TFile
class description - source file - inheritance tree
private:
TFile TFile(const TFile&)
void operator=(const TFile&)
protected:
void Init(Bool_t create)
virtual Int_t SysClose(Int_t fd)
virtual Int_t SysOpen(const char* pathname, Int_t flags, UInt_t mode)
virtual Int_t SysRead(Int_t fd, void* buf, Int_t len)
virtual Seek_t SysSeek(Int_t fd, Seek_t offset, Int_t whence)
virtual Int_t SysSync(Int_t fd)
virtual Int_t SysWrite(Int_t fd, const void* buf, Int_t len)
public:
TFile TFile()
TFile TFile(const Text_t* fname, Option_t* option, const Text_t* ftitle, Int_t compress = 1)
virtual void ~TFile()
TClass* Class()
virtual void Close(Option_t* option)
virtual void Copy(TObject&)
virtual void Delete(const Text_t* namecycle)
virtual void Draw(Option_t* option)
virtual void FillBuffer(char*& buffer)
virtual void Flush()
Int_t GetBestBuffer()
Double_t GetBytesRead() const
Double_t GetBytesWritten() const
Float_t GetCompressionFactor()
Int_t GetCompressionLevel()
virtual Seek_t GetEND()
Int_t GetFd() const
Double_t GetFileBytesRead()
Double_t GetFileBytesWritten()
TList* GetListOfFree()
virtual Int_t GetNfree()
virtual Option_t* GetOption() const
Int_t GetVersion() const
virtual TClass* IsA() const
virtual Bool_t IsOpen() const
virtual void ls(Option_t* option)
virtual void MakeFree(Seek_t first, Seek_t last)
virtual void Map()
TFile* Open(const Text_t* name, Option_t* option, const Text_t* ftitle, Int_t compress = 1)
virtual void Paint(Option_t* option)
virtual void Print(Option_t* option)
virtual Bool_t ReadBuffer(char* buf, int len)
virtual void ReadFree()
virtual void Recover()
virtual void Seek(Seek_t offset, TFile::ERelativeTo pos = kBeg)
virtual void SetCompressionLevel(Int_t level = 1)
virtual void SetEND(Seek_t last)
void SetFileBytesRead(Double_t bytes = 0)
void SetFileBytesWritten(Double_t bytes = 0)
virtual void SetOption(Option_t* option = >)
virtual void ShowMembers(TMemberInspector& insp, char* parent)
virtual Int_t Sizeof() const
virtual void Streamer(TBuffer& b)
void SumBuffer(Int_t bufsize)
virtual void Write(const Text_t* name = 0, Int_t opt = 0, Int_t bufsiz = 0)
virtual Bool_t WriteBuffer(const char* buf, int len)
virtual void WriteFree()
virtual void WriteHeader()
protected:
Int_t fD File descriptor
Seek_t fBEGIN First used byte in file
Seek_t fEND Last used byte in file
Int_t fVersion File format version
Int_t fCompress (=1 file is compressed, 0 otherwise)
TString fOption File options
Char_t fUnits Number of bytes for file pointers
Seek_t fSeekFree Location on disk of free segments structure
Int_t fNbytesFree Number of bytes for free segments structure
Int_t fWritten Number of objects written so far
Double_t fSumBuffer Sum of buffer sizes of objects written so far
Double_t fSum2Buffer Sum of squares of buffer sizes of objects written so far
TList* fFree Free segments linked list table
Double_t fBytesWrite Number of bytes written to this file
Double_t fBytesRead Number of bytes read from this file
static Double_t fgBytesWrite Number of bytes written by all TFile objects
static Double_t fgBytesRead Number of bytes read by all TFile objects
static const Int_t kBegin
static const Char_t kUnits
public:
static const TFile::ERelativeTo kBeg
static const TFile::ERelativeTo kCur
static const TFile::ERelativeTo kEnd
See also
-
TNetFile, TWebFile
TFile() : TDirectory()
*-*-*-*-*-*-*-*-*-*-*-*File default Constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ========================
TFile(const Text_t *fname1, Option_t *option, const Text_t *ftitle, Int_t compress)
:TDirectory()
*-*-*-*-*-*-*-*-*-*-*-*File Constructor*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ================
If Option = NEW or CREATE create a new file and open it for writing,
if the file already exists the file is
not opened.
= RECREATE create a new file, if the file already
exists it will be overwritten.
= UPDATE open an existing file for writing.
= READ open an existing file for reading.
Use IsOpen() to check if the file is opened successfuly.
The parameter name is used to identify the file in the current job
name may be different in a job writing the file and another job
reading/writing the file.
When the file is created, the name of the file seen from the file system
is fname. It is recommended to specify fname as "file.root"
The suffix root will be used by object browsers to automatically
identify ROOT files.
The title of the file (ftitle) will be shown by the ROOT browsers.
A ROOT file (like a Unix file system) may contain objects and
directories. There are no restrictions for the number of levels
of directories.
A ROOT file is designed such that one can write in the file in pure
sequential mode (case of BATCH jobs). In this case, the file may be
read sequentially again without using the file index written
at the end of the file. In case of a job crash, all the information
on the file is therefore protected.
A ROOT file can be used interactively. In this case, one has the
possibility to delete existing objects and add new ones.
When an object is deleted from the file, the freed space is added
into the FREE linked list (lFree). The FREE list consists of a chain
of consecutive free segments on the file. At the same time, the first
4 bytes of the freed record on the file are overwritten by GAPSIZE
where GAPSIZE = -(Number of bytes occupied by the record).
compress = 0 objects written to this file will not be compressed.
compress = 1 minimal compression level but fast.
....
compress = 9 maximal compression level but slow.
Note that the compression level may be changed at any time.
The new compression level will only apply to newly written objects.
The function TFile::Map shows the compression factor
for each object written to this file.
The function TFile::GetCompressionFactor returns the global
compression factor for this file.
A ROOT file is a suite of consecutive data records with the following
format (see also the TKey class);
TKey ---------------------
byte 1->4 Nbytes = Length of compressed object (in bytes)
5->6 Version = TKey version identifier
7->10 ObjLen = Length of uncompressed object
11->14 Datime = Date and time when object was written to file
15->16 KeyLen = Length of the key structure (in bytes)
17->18 Cycle = Cycle of key
19->22 SeekKey = Pointer to record itself (consistency check)
23->26 SeekPdir = Pointer to directory header
27->27 lname = Number of bytes in the class name
28->.. ClassName = Object Class Name
..->.. lname = Number of bytes in the object name
..->.. Name = lName bytes with the name of the object
..->.. lTitle = Number of bytes in the object title
..->.. Title = Title of the object
-----> DATA = Data bytes associated to the object
The first data record starts at byte fBEGIN (currently set to kBegin)
Bytes 1->kBegin contain the file description:
byte 1->4 "root" = Root file identifier
5->8 fVersion = File format version
9->12 fBEGIN = Pointer to first data record
13->16 fEND = Pointer to first free word at the EOF
17->20 fSeekFree = Pointer to FREE data record
21->24 fNbytesFree = Number of bytes in FREE data record
25->28 nfree = Number of free data records
29->32 fNbytesName = Number of bytes in TNamed at creation time
33->33 fUnits = Number of bytes for file pointers
34->37 fCompress = Zip compression level
/*
*/
The structure of a directory is shown in TDirectory::TDirectory
TFile(const TFile &file)
~TFile()
*-*-*-*-*-*-*-*-*-*-*-*File destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ===============
void Init(Bool_t create)
Initialize a TFile object.
void Close(Option_t *)
*-*-*-*-*-*-*-*-*-*-*-*Close a file*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ============
void Delete(const Text_t *namecycle)
*-*-*-*-*-*-*-*-*-*-*-*-*Delete object namecycle*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =======================
namecycle identifies an object in the top directory of the file
namecycle has the format name;cycle
name = * means all
cycle = * means all cycles (memory and keys)
cycle = "" or cycle = 9999 ==> apply to a memory object
When name=* use T* to delete subdirectories also
examples:
foo : delete object named foo in memory
foo;1 : delete cycle 1 of foo on file
foo;* : delete all cycles of foo on disk and also from memory
*;2 : delete all objects on file having the cycle 2
*;* : delete all objects from memory and file
T*;* : delete all objects from memory and file and all subdirectories
void Draw(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*-*Fill Graphics Structure and Paint-*-*-*-*-*-*-*-*-*-*
*-* =================================
Loop on all objects (memory or file) and all subdirectories
void Flush()
Synchornize a file's in-core and on-disk states.
void FillBuffer(char *&buffer)
*-*-*-*-*-*-*-*-*-*-*-*Encode file output buffer*-*-*-*-*-*-*
*-* =========================
The file output buffer contains only the FREE data record
Int_t GetBestBuffer()
*-*-*-*-*-*-*-*Return the best buffer size of objects on this file*-*-*-*-*-*
*-* ===================================================
The best buffer size is estimated based on the current mean value
and standard deviation of all objects written so far to this file.
Returns mean value + one standard deviation.
Float_t GetCompressionFactor()
*-*-*-*-*-*-*-*-*-*Return the file compression factor*-*-*-*-*-*-*-*-*-*
*-* =================================
Add total number of compressed/uncompressed bytes for each key.
return ratio of the two.
void ls(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*-*List File contents*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ==================
Indentation is used to identify the file tree
Subdirectories are listed first
then objects in memory
then objects on the file
Bool_t IsOpen() const
Returns kTRUE in case file is open and kFALSE if file is not open.
void MakeFree(Seek_t first, Seek_t last)
*-*-*-*-*-*-*-*-*-*-*-*Mark unused bytes on the file*-*-*-*-*-*-*-*-*-*-*
*-* =============================
The list of free segments is in the lFree linked list
When an object is deleted from the file, the freed space is added
into the FREE linked list (lFree). The FREE list consists of a chain
of consecutive free segments on the file. At the same time, the first
4 bytes of the freed record on the file are overwritten by GAPSIZE
where GAPSIZE = -(Number of bytes occupied by the record).
void Map()
*-*-*-*-*-*-*-*-*-*List the contents of a file sequentially*-*-*-*-*-*
*-* ========================================
For each logical record found, it prints
Date/Time Record_Adress Logical_Record_Length ClassName CompressionFactor
Example of output
960122/105933 At:64 N=160 TFile
960122/105933 At:224 N=402 TH1F CX = 2.09
960122/105934 At:626 N=1369 TH2F CX = 5.57
960122/105934 At:1995 N=1761 TProfile CX = 1.63
960122/105936 At:3756 N=181640 THN CX = 1.10
960122/105936 At:185396 N=326 TFile
960122/105936 At:185722 N=98 TFile
void Paint(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*-*Paint all objects in the file*-*-*-*-*-*-*-*-*-*-*
*-* =============================
void Print(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*-*Print all objects in the file*-*-*-*-*-*-*-*-*-*-*
*-* =============================
Bool_t ReadBuffer(char *buf, int len)
Read a buffer from the file. This is the basic low level read operation.
Returns kTRUE in case of failure.
void ReadFree()
*-*-*-*-*-*-*-*-*-*-*-*-*Read the FREE linked list*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =========================
Every file has a linked list (fFree) of free segments
This linked list has been written on the file via WriteFree
as a single data record
void Recover()
*-*-*-*-*-*-*-*-*Attempt to recover file if not correctly closed*-*-*-*-*
*-* ===============================================
void Seek(Seek_t offset, ERelativeTo pos)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
void SetCompressionLevel(Int_t level)
*-*-*-*-*-*-*-*-*-*Set level of compression for this file*-*-*-*-*-*-*-*
*-* ======================================
level = 0 objects written to this file will not be compressed.
level = 1 minimal compression level but fast.
....
level = 9 maximal compression level but slow.
Note that the compression level may be changed at any time.
The new compression level will only apply to newly written objects.
The function TFile::Map shows the compression factor
for each object written to this file.
The function TFile::GetCompressionFactor returns the global
compression factor for this file.
Int_t Sizeof() const
*-*-*-*-*-*-*Return the size in bytes of the file header-*-*-*-*-*-*-*-*
*-* ===========================================
void Streamer(TBuffer &b)
Stream a TFile object.
void SumBuffer(Int_t bufsize)
*-*-*-*-*Increment statistics for buffer sizes of objects in this file*-*-*
*-* =============================================================
void Write(const Text_t *, Int_t opt, Int_t bufsiz)
*-*-*-*-*-*-*-*-*-*Write memory objects to this file*-*-*-*-*-*-*-*-*-*
*-* =================================
Loop on all objects in memory (including subdirectories).
A new key is created in the KEYS linked list for each object.
The list of keys is then saved on the file (via WriteKeys)
as a single data record.
For values of opt see TObject::Write().
The directory header info is rewritten on the directory header record.
The linked list of FREE segments is written.
The file header is written (bytes 1->fBEGIN).
Bool_t WriteBuffer(const char *buf, int len)
Write a buffer to the file. This is the basic low level write operation.
Returns kTRUE in case of failure.
void WriteFree()
*-*-*-*-*-*-*-*-*-*-*-*Write FREE linked list on the file *-*-*-*-*-*-*-*
*-* ==================================
The linked list of FREE segments (fFree) is written as a single data
record
void WriteHeader()
*-*-*-*-*-*-*-*-*-*-*-*Write File Header*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =================
TFile* Open(const Text_t *name, Option_t *option, const Text_t *ftitle, Int_t compress)
Static member function allowing the creation/opening of either a
TFile, TNetFile, TWebFile or a TRFIOFile. The returned type of TFile
depends on the file name. If the file starts with "root:" a TNetFile
object will be returned, with "http:" a TWebFile, with "rfio:" a
TRFIOFile and with "file:" or the default a local TFile. However,
before opening a file via TNetFile a check is made to see if the URL
specifies a local file. If that is the case the file will be opened
via a normal TFile. To force the opening of a local file via a
TNetFile use either TNetFile directly or specify as host "localhost".
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Interface to system open. All arguments like in "man 2 open".
Int_t SysClose(Int_t fd)
Interface to system close. All arguments like in "man 2 close".
Int_t SysRead(Int_t fd, void *buf, Int_t len)
Interface to system read. All arguments like in "man 2 read".
Int_t SysWrite(Int_t fd, const void *buf, Int_t len)
Interface to system write. All arguments like in "man 2 write".
Seek_t SysSeek(Int_t fd, Seek_t offset, Int_t whence)
Interface to system lseek. All arguments like in "man 2 lseek"
except that the offset and return value are Long_t to be able to
handle 64 bit file systems.
Int_t SysSync(Int_t fd)
Interface to system fsync. All arguments like in "man 2 fsync".
Double_t GetFileBytesRead()
Double_t GetFileBytesWritten()
void SetFileBytesRead(Double_t bytes)
void SetFileBytesWritten(Double_t bytes)
Inline Functions
void operator=(const TFile&)
void Copy(TObject&)
Int_t GetCompressionLevel()
Seek_t GetEND()
Int_t GetFd() const
TList* GetListOfFree()
Int_t GetNfree()
Option_t* GetOption() const
Double_t GetBytesRead() const
Double_t GetBytesWritten() const
Int_t GetVersion() const
void SetEND(Seek_t last)
void SetOption(Option_t* option = >)
TClass* Class()
TClass* IsA() const
void ShowMembers(TMemberInspector& insp, char* parent)
Author: Rene Brun 28/11/94
Last update: 2.23/03 10/10/99 15.45.04 by Fons Rademakers
Copyright (c) 1995-1999, The ROOT System, All rights reserved. *
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.