This page follows the file format description in ROOT’s
TFile.cxx
and the code of TKey, TDirectoryFile, TDatime,
TBufferFile and the compression routines (RZip.cxx,
ZipLZ4.cxx, Compression.h), all read 2026-11-12. Numbers are
big-endian. Pointers are 4 bytes in small files and 8 bytes in large files (over
2 GB), as the version numbers say.
File header
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 4 | magic | root. |
4 | 4 | fVersion | File format version; 1,000,000 or more means a large file whose pointers below are 8 bytes. |
8 | 4 | fBEGIN | Offset of the first record, fixed at 100; bytes 96 to 99 are reserved and must be 0 (rules added for the registered media type). |
12 | 4 or 8 | fEND | End of the file. |
| … | 4 or 8 | fSeekFree | Record holding the free segment list. |
| … | 4 | fNbytesFree | Its size. |
| … | 4 | nfree | Number of free segments. |
| … | 4 | fNbytesName | Size of the file name and title in the top directory record. |
| … | 1 | fUnits | Size of file pointers: 4 or 8. |
| … | 4 | fCompress | Compression setting: algorithm × 100 + level. |
| … | 4 or 8 | fSeekInfo | Record holding the streamer information. |
| … | 4 | fNbytesInfo | Its size. |
| … | 18 | fUUID | Universal unique ID. |
The top directory’s record follows at fBEGIN; the file name and title
are stored there with its directory data.
Keys
Every object is stored as a record: a key, then the object’s bytes, usually compressed.
| Field | Size | Meaning |
|---|---|---|
Nbytes | 4 | Size of the key and the compressed object together. When a new record only partly fills a deleted gap, the rest of the gap starts with its size as a negative number. |
Version | 2 | Key version; 1000 is added when the record lies beyond 2 GB and the pointers are 8 bytes. |
ObjLen | 4 | Size of the object uncompressed. |
Datime | 4 | When it was written, packed. |
KeyLen | 2 | Size of the key. |
Cycle | 2 | Cycle number: several versions of an object with the same name can coexist. |
SeekKey | 4 or 8 | Position of this record. |
SeekPdir | 4 or 8 | Position of the directory it belongs to. |
ClassName | string | The object’s class name. |
Name, Title | string |
Strings are a length byte and the characters; when the length is over 254, the byte is 255 and a 4-byte length follows.
Packed date
(year − 1995) << 26 | month << 22 | day << 17 | hour << 12 |
minute << 6 | second, in the writing machine’s local time with no time
zone.
Directories and special records
- Directory: version (2; current writers use 5, plus 1000 for 8-byte pointers), creation and modification dates (4 each), size of the key list (4), size of the name and title (4), and the positions of the directory itself, its parent and its key list (4 or 8 each), then the directory's UUID (see below). The key list record holds the number of keys (4) and then a copy of each key. A writer asked for reproducible files stores date 1 in both date fields.
- Free segments (
TFree): first and last byte of each piece of unused space, so a writer can reuse deleted gaps. - Streamer information: the
TStreamerInforecord atfSeekInfo, describing the stored classes.
Compressed blocks
Object data is compressed in blocks of at most 0xFFFFFF bytes, each
with a 9-byte header: a 2-letter algorithm code, a method byte, the compressed size
(3 bytes) and the uncompressed size (3 bytes), both little-endian.
| Code | Algorithm | fCompress algorithm |
|---|---|---|
ZL | zlib (Deflate) | 1 |
XZ | LZMA (xz) | 2 |
CS | ROOT’s own old algorithm | 3 |
L4 | LZ4, with an 8-byte XXH64 checksum of the compressed data after the header (counted in the compressed size) | 4 |
ZS | Zstandard | 5 |
fCompress 0 means use the global setting.
The StreamerInfo record and streamed objects
From ROOT's own page Format of StreamerInfo record and the related TObject and ROOTIO pages (read 2026-11-13). These describe release 3.02.06; the pages say so, and newer releases changed field versions, so use the version numbers in the file itself. Numbers are big-endian.
- Where it is. The file header's
fSeekInfopoints to a key (never compressed) with classTList, nameStreamerInfo, titleDoubly linked list. Its data is a TList ofTStreamerInfoobjects, one for every class used in a data record, apart from core records. The data portion is always compressed at level 1 if it is over 256 bytes, even if compression is off. One StreamerInfo record per file, written when a new or modified file is closed. - Byte counts. A streamed object starts with a 4-byte count of the remaining bytes ORed with
kByteCountMask(0x40000000). Then comes the class: the first time, the tag0xFFFFFFFF(kNewClassTag) followed by the NUL-terminated class name; afterwards the byte offset of that tag in the record plus 2, ORed withkClassMask(0x80000000). Then another count and a 2-byte class version, then the members. Strings are a length byte (the byte is 255 and a 4-byte length follows for longer ones) and the characters. - TObject data: version (2),
fUniqueID(4),fBits(4:0x01may be deleted from a list,0x08deleting it may require deleting others,0x10referenced by a persistent pointer,0x2000constructor succeeded but the object should not be used,0x01000000on the heap,0x02000000not deleted), andpidf(2) only if the object is referenced by a pointer to a persistent object; it names the recordProcessIDfollowed by the decimal number. Objects in the StreamerInfo are never referenced:fUniqueID0,fBits0x03000000. - TList in the record: count, version (2), a TObject, the list's name (a length byte; 0 here), the number of objects (4), then the objects.
- TStreamerInfo: count, class tag
TStreamerInfo, count, version; a TNamed base (name: the class it describes; title);fCheckSum(4; over all base classes and persistent non-static data members, fromTClass::GetCheckSum);fClassVersion(4); then aTObjArrayof streamer elements (count, class tag, count, version, TObject, name (empty), number of objects (4), lower bound (4, always 0), the objects). There is one element for each base class and for each persistent non-static data member (transient members, marked//!, are not written). - TStreamerElement (the base of every element class): count, version, a TNamed (the member or base class name, and title),
fType(4),fSize(4: size of a built-in type or pointer to one, else 0),fArrayLength(4),fArrayDim(4),fMaxIndex(five 4-byte dimensions),fTypeName(string;BASEfor a base class).
fType | Meaning |
|---|---|
| 1, 2, 3, 4, 5, 8 | char, short, int, long, float, double |
| 11, 12, 13, 14 | unsigned char, short, int, long |
| 6 | an array dimension counter |
| 15 | bit mask (the fBits field) |
| 20 + t | an array of built-in type t (23: array of int) |
| 40 + t | a pointer to built-in type t (43: pointer to int) |
| 65, 66, 67 | TString, TObject, TNamed |
| 0 | a base class other than TObject or TNamed |
| 61 | an object member derived from TObject (other than TObject or TNamed) |
| 62 | an object member not derived from TObject |
| 63, 64 | pointer to an object derived from TObject: 63 never null, 64 may be null |
| 500, 501 | an STL string or container; a pointer to an array of objects |
| Element class | Used for | Extra data after the TStreamerElement part |
|---|---|---|
TStreamerBase | A base class | fBaseVersion (4): version of the base class. |
TStreamerBasicType, TStreamerString, TStreamerObject, TStreamerObjectPointer, TStreamerObjectAny, TStreamerSTLString | A basic type; a TString; an object derived from TObject; a pointer to one; an object not derived from TObject; an STL string | None. |
TStreamerBasicPointer, TStreamerLoop | A pointer to an array of basic types; a pointer to an array of objects | fCountVersion (4), then the name of the member holding the count and the name of the class holding it, each a length-prefixed string. |
TStreamerSTL | An STL container | fSTLtype (4: 1 vector, 2 list, 3 deque, 4 map, 5 set, 6 multimap, 7 multiset) and fCtype (4: the contained type, values as fType plus 365 for an STL string). |
Streaming rules. A pointer is never stored as an address: the object
itself is written, or 4 bytes of 0 for a null pointer; a pointer written twice in
one operation writes its object once. A pointer to a basic type is an array whose
length comes from a comment //[length] (a constant or an earlier integer
member). long and unsigned long are always written as 8 bytes.
A few classes (TObject, TRef, TRefArray, ...) have hand-written streamers that may
not match their StreamerInfo.
TTree, TBranch and TBasket
From ROOT's pages on TTrees (release 3.02.06; read 2026-11-13). A TTree is split into
TBranches, recursively; each branch has TLeafs that describe
the variables (they hold no values), and the values live in TBaskets. The
default basket size is 32,000 bytes, per branch. A file has one TTree record per tree;
it holds, for each branch, exactly one basket; further baskets are separate records
(class TBasket, a variant of the TKey), in the same file unless the user
names another file for the branch (then a TBranch record is written there
too). There is no streamer information for TBasket: its streamer is
hand-written. The streamers of TTree, TBranch and TLeaf are the default generated
ones.
| Class (version) | Members in stream order |
|---|---|
TTree (6) | Bases TNamed, TAttLine, TAttFill, TAttMarker; fEntries, fTotBytes, fZipBytes, fSavedBytes (doubles); fTimerInterval, fScanField, fUpdate, fMaxEntryLoop, fMaxVirtualSize, fAutoSave, fEstimate (ints); fBranches, fLeaves (TObjArray); fIndexValues (TArrayD), fIndex (TArrayI); fFriends (TList*, may be null). |
TAttLine (1), TAttFill (1), TAttMarker (1) | Line colour, style, width (shorts); fill colour, style (shorts); marker colour, style (shorts) and size (float). |
TBranch (7) | Base TNamed; fCompress, fBasketSize, fEntryOffsetLen (initial length of the basket's entry offset table), fWriteBasket (last basket written), fEntryNumber, fOffset, fMaxBaskets, fSplitLevel (ints); fEntries, fTotBytes, fZipBytes (doubles); fBranches, fLeaves, fBaskets (TObjArray); then three arrays of fMaxBaskets entries: fBasketBytes (ints: lengths on file), fBasketEntry (ints: the first entry of each basket), fBasketSeek (file addresses of the baskets); fFileName (a TString, empty when the baskets are in the tree's file). |
TBranchElement (7) | Base TBranch; fClassName, fParentName, fClonesName (TString); fClassVersion, fID (the element's number in the class's streamer info), fType (branch type), fStreamerType, fMaximum (ints); fBranchCount, fBranchCount2 (pointers to the count branches). |
TLeaf (2) | Base TNamed; fLen (fixed-length elements), fLenType (bytes per value), fOffset (ints); fIsRange, fIsUnsigned (booleans); fLeafCount (pointer to the count leaf for a variable length). |
TLeafElement (1) | Base TLeaf; fID, fType (ints). |
A TClonesArray is a TObjArray of same-class objects that, by
default, is written split one level: all of each member for every object, then the next
member, which compresses better and lets members become separate branches.
The layout of the TBasket record is under TBasket
below, from the current source; the RNTuple replacement for TTree has its own page,
RNTuple.
Details from the current ROOT source
Read 2026-11-13 from the master branch of
root-project/root: io/io/src/TKey.cxx,
TDirectoryFile.cxx, TFile.cxx, TBufferFile.cxx,
core/base/src/TObject.cxx, TUUID.cxx, TProcessID.cxx,
TRef.cxx, core/cont/src/TList.cxx, TObjArray.cxx,
TClonesArray.cxx, TRefArray.cxx and tree/tree/src/TBasket.cxx,
with their headers. Class versions in this source: TKey 4, TDirectoryFile 5, TFile 8, TBasket 3,
TList 5, TObjArray 3, TClonesArray 4, TCollection 3, TRefArray 1, TRef 1, TProcessID 1, TUUID 1.
Version headers and byte counts
A class's streamed data starts with a 4-byte word and a 2-byte version. If bit
0x4000 of the first two bytes is set, those two bytes (with the bit removed) and the next two are the
two halves of a 32-bit byte count of what follows the count (the count word is thus written as
count | 0x40000000, as on this page above); the reader remembers the start so it can check the count
at the end and skip unknown trailing members. If the bit is not set (older files) there is no count and the first
two bytes are the version. A version of 0 or less on a class that has a checksum means the next 4 bytes are the
class checksum, from which the reader finds the matching TStreamerInfo.
Key details
- Current key version 4. The version gains 1000 when the record starts beyond 2,000,000,000 bytes
(
kStartBigFile). ATBasketkey always has 1000 added, so its pointers are always 8 bytes. - In a key with version over 1000,
SeekPdiris 8 bytes whose low 48 bits are the parent directory's position and whose high 16 bits arefPidOffset. It is zero in a new key; when a key or basket is copied to another file it is incremented, and is added to the process ID numbers stored byTObjectandTRefso they still find theirTProcessID. - A directory's key records the class name
TDirectory(notTDirectoryFile) so very old readers can read it; a reader maps the name back. - The title is cut to 32,000 characters.
- A writer asked for reproducible files stores the date 1 in every key date.
Directory details
The top directory's record is a key, then the file name and title strings (fNbytesName counts the key
and these strings), then the directory data written at fSeekDir + fNbytesName:
version (2), dates (4 each), fNbytesKeys (4), fNbytesName (4), fSeekDir,
fSeekParent, fSeekKeys (each 8 bytes when the version is over 1000, else 4), then the UUID,
written as a 2-byte version (1) and 16 bytes (fTimeLow 4, fTimeMid 2,
fTimeHiAndVersion 2, fClockSeqHiAndReserved 1, fClockSeqLow 1, node 6). Small
directories (version of 1000 or less) then have 12 zero bytes of padding so the record has the size of a big one.
A directory of version 2 has an unversioned 16-byte UUID with no version field; version 1 has no UUID.
The key list record at fSeekKeys is itself a key (named like the directory) followed by the number
of keys (4) and the key headers one after another (just the key fields, as in the table above, with no objects).
A reader treats a key whose position or parent position is under 64 or beyond the end of the file as an error
and stops reading the list.
TObject, as written by current code
Version (2), fUniqueID (4), fBits (4) and, if bit kIsReferenced
(0x10) is set, pidf (2). The bit constants are kCanDelete 0x01,
kMustCleanup 0x08, kIsReferenced 0x10, kHasUUID
0x20, kInvalidObject 0x2000; kIsOnHeap 0x01000000,
kNotDeleted 0x02000000 and kZombie 0x04000000 describe memory
state. Current writers remove kIsOnHeap and kNotDeleted before writing (they keep them only
when the file has the ROOT 6.30 forward-compatibility bit), so fBits is typically without
0x03000000; readers set kNotDeleted themselves, so values with it in older files
(as in the StreamerInfo above) read the same. For a referenced object fUniqueID is written with only
its low 24 bits (the high 8 bits hold the process ID number in memory); the reader rebuilds them from the
TProcessID.
TProcessID, TRef and TRefArray
TProcessID is a TNamed (default streaming) stored as an ordinary object in the file under
the key name ProcessID followed by its number in the file (ProcessID0,
ProcessID1, ...); its title is a UUID string. The number is the 2-byte pidf written by
TObject, TRef and TRefArray, so at most 65,535 per process. A reader adds
fPidOffset to pidf, finds the object named ProcessID<pidf> in the file and, if the process
ID (compared by UUID title) is already known in memory, uses that one.
- TRef (version 1): a
TObject(whosefUniqueIDis the referenced object's number within its process) and thenpidf(2). If the object has thekHasUUIDbit, the 2 bytes are replaced by aTStringholding the UUID string of the referenced object andfUniqueIDis a number local to the reader. Bits 16 and up offBitsin memory carry an execution id from the streamer element and are not read from the file. - TRefArray (version 1): count and version, a
TObject, the name (TString), the number of slots (4), the lower bound (4),pidf(2) once for the whole array, then one 32-bit unique ID per slot (0 is empty).
TList, TObjArray and TClonesArray
- TList (version 5): count and version, a
TObject, the list name (TString), the number of objects (4); then for each object the object itself (written as a pointer: class tag, or a reference to an earlier object or class, as in the byte-count description above) followed by its option string, a length byte (255 followed by a 4-byte length when longer than 254) and the characters. This is the form of theStreamerInfolist too, so there the option strings are present (empty) after each element. Before version 4 there are no option strings, and before version 3 noTObjectand before 2 no name. - TObjArray (version 3): count and version, a
TObject(version 3 and up), the name (TString, version 2 and up), the number of slots (4) = last non-empty index + 1, the lower bound (4), then one pointer per slot; an empty slot is 4 bytes of 0. Slots are written even when empty. - TClonesArray (version 4): count and version, a
TObject, the name, aTStringClassName;classVersion, the number of slots (4), the lower bound (4); then either, when the array "bypasses the streamer", all objects member-wise (the members of the stored class version, taken from its streamer information, each written for every object in turn), or, otherwise, for each slot a flag byte (0 for an empty slot) followed, if 1, by the object's own streamer data. The bypass state is recorded in the data, not chosen by the reader. A negative object count from very old files is read as its absolute value.
TTree, TBranch and TLeaf in current releases
The current classes (from tree/tree/inc/TTree.h, TBranch.h, TLeaf.h,
TBranchElement.h, TLeafElement.h and the Streamer functions in the matching
.cxx files) are written by the generated streamer, that is, from their TStreamerInfo: persistent
members in declaration order, transient ones (marked //!) left out. The versions are TTree 20, TBranch 13,
TBranchElement 10, TLeaf 2, TLeafElement 1. Members stored, in order, with 8-byte integers (Long64_t) where
the 3.02.06 table above has doubles:
| Class | Bases, then members |
|---|---|
TTree (20) | TNamed, TAttLine, TAttFill, TAttMarker; fEntries, fTotBytes, fZipBytes, fSavedBytes, fFlushedBytes (Long64); fWeight (double); fTimerInterval, fScanField, fUpdate, fDefaultEntryOffsetLen, fNClusterRange (int); fMaxEntries, fMaxEntryLoop, fMaxVirtualSize, fAutoSave, fAutoFlush, fEstimate (Long64); fClusterRangeEnd, fClusterSize (arrays of fNClusterRange Long64: the last entry of each extra cluster range and the number of entries per cluster in it); fIOFeatures (ROOT::TIOFeatures); fBranches, fLeaves (TObjArray); fAliases (TList*); fIndexValues (TArrayD), fIndex (TArrayI); fTreeIndex (pointer to TVirtualIndex); fFriends, fUserInfo (TList*); fBranchRef (TBranchRef*, the branch that holds the TRefTable). |
TBranch (13) | TNamed, TAttFill; fCompress, fBasketSize, fEntryOffsetLen, fWriteBasket (int); fEntryNumber (Long64); fIOFeatures; fOffset, fMaxBaskets, fSplitLevel (int); fEntries, fFirstEntry, fTotBytes, fZipBytes (Long64); fBranches, fLeaves, fBaskets (TObjArray); fBasketBytes (int), fBasketEntry (Long64), fBasketSeek (Long64), each an array of fMaxBaskets written with a flag byte first (as the pre-version-10 reader in TBranch.cxx shows for the same arrays), then the values; fFileName (TString). |
TBranchElement (10) | TBranch; fClassName, fParentName, fClonesName (TString); fCheckSum (unsigned 4); fClassVersion (2); fID, fType, fStreamerType, fMaximum (int); fBranchCount, fBranchCount2 (pointers to TBranchElement). Branch type fType: −1 unsplit object with a custom streamer when written; 0 unsplit object with the default streamer, or a simple data member of a split object; 1 base class of a split object; 2 class-typed member of a split object; 3 count branch of a split TClonesArray; 31 member of the content of a split TClonesArray; 4 count branch of a split STL collection; 41 member of the content of a split STL collection. |
TLeaf (2) | TNamed; fLen, fLenType, fOffset (int); fIsRange, fIsUnsigned (bool); fLeafCount (TLeaf*). |
TLeafElement (1) | TLeaf; fID, fType (int). |
The specialised leaf classes are TLeaf plus two members, fMinimum and fMaximum (the leaf's range),
of the leaf's value type: TLeafB (1) char, TLeafS (1) short, TLeafI (1) int, TLeafL (1)
Long64_t, TLeafG (1) Long_t, TLeafF (1) float, TLeafD (1) double,
TLeafC (1, a variable-length string) int, TLeafO (1) bool, TLeafF16 (2) Float16_t and
TLeafD32 (2) Double32_t; TLeafObject (4) adds the boolean fVirtual (the class name is written
with each object, for polymorphism). The streamed form of ROOT::TIOFeatures (a class whose only data member is the byte
fIOBits) was not traced through its dictionary.
TBasket
A basket is a key plus data. Its key (class name TBasket, name the branch name, title the tree name) is
followed, inside the key length KeyLen, by the basket header:
| Field | Size | Meaning |
|---|---|---|
| version | 2 | basket class version (3), with the byte-count form not used here |
fBufferSize | 4 | buffer length in bytes |
fNevBufSize | 4 | number of 4-byte slots in the entry-offset table, or, when there is no table, the fixed length of every entry. If the basket has IO feature bits this is written negated and the next field is present |
fIOBits | 1 | only present when fNevBufSize is negative. Bit 0 (kGenerateOffsetMap): the offset table was replaced by entry sizes or can be regenerated. Zero, or bit 7, or any bit not known is an error (the reader refuses the basket: written by a newer ROOT) |
fNevBuf | 4 | number of entries in the basket |
fLast | 4 | position of the last used byte of the buffer, counted from the start of the record (key included) |
| flag | 1 | see below |
Flag. Two kinds of basket exist. A basket stored as its own record in the file has a header-only key: the flag is 0, or 80 when
the offset table is regenerated, and the compressed data follows the key. A basket stored inside its TBranch record
(the first one of each branch) is streamed in full: flag 1 (an entry-offset table follows) or 2 (no table: entries have the fixed length
fNevBufSize), plus 10 if a data buffer follows, plus 40 if a displacement array follows, plus 80 if the offsets are
regenerated (then no table is written). After the flag, in this order: the offset table as a counted int array
(count = fNevBuf + 1 entries as written by WriteArray), then the displacement array if flagged (a counted array
of the same length), then the buffer (fLast bytes, plain). A flag over 20 and under 40 is the old form whose offsets have a
displacement in the top byte (0xFF000000 mask) and must be masked off.
Data record. After the key, the object part (the entry data, ObjLen bytes) is compressed in blocks as
above; the key and basket header are never compressed. If compression is off, or the result is no smaller, the data is stored as is
and Nbytes = KeyLen + ObjLen. The uncompressed object part is: the entry data
(fLast − KeyLen bytes), then the entry-offset table as a counted array of fNevBuf + 1 ints, then,
if present, the displacement array likewise. The offsets are positions from the start of the record, so the first is
KeyLen; the last is the end of the data. When bit 0 of fIOBits is set the table holds sizes instead:
entry i holds the size of entry i−1 (entry 0 holds 0) and the reader adds them up starting with
KeyLen (a table that can be calculated from the leaf, for example fixed-size values, is not written at all).
A basket with one entry that did not compress is flagged in memory only (kNotDecompressed) and is rewritten without
change.