Logo ROOT   6.16/01
Reference Guide
TBasket.h
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Rene Brun 19/01/96
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TBasket
13#define ROOT_TBasket
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// TBasket //
18// //
19// The TBasket objects are created at run time to collect TTree entries //
20// in buffers. When a Basket is full, it is written to the file. //
21// The Basket is kept in memory if there is enough space. //
22// (see the fMaxVirtualsize of TTree). //
23// //
24// The Basket class derives from TKey. //
25//////////////////////////////////////////////////////////////////////////
26
27
28#include "TKey.h"
29
30class TFile;
31class TTree;
32class TBranch;
33
34class TBasket : public TKey {
35
36private:
37 TBasket(const TBasket&); ///< TBasket objects are not copiable.
38 TBasket& operator=(const TBasket&); ///< TBasket objects are not copiable.
39
40 // Internal corner cases for ReadBasketBuffers
43
44 // Helper for managing the compressed buffer.
46
47 // Handles special logic around deleting / reseting the entry offset pointer.
48 void ResetEntryOffset();
49
50 // Get entry offset as result of a calculation.
52
53 // Returns true if the underlying TLeaf can regenerate the entry offsets for us.
55
56protected:
57 Int_t fBufferSize{0}; ///< fBuffer length in bytes
58 Int_t fNevBufSize{0}; ///< Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
59 Int_t fNevBuf{0}; ///< Number of entries in basket
60 Int_t fLast{0}; ///< Pointer to last used byte in basket
61 Bool_t fHeaderOnly{kFALSE}; ///< True when only the basket header must be read/written
62 UChar_t fIOBits{0}; ///<!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless needed.
63 Bool_t fOwnsCompressedBuffer{kFALSE}; ///<! Whether or not we own the compressed buffer.
64 Bool_t fReadEntryOffset{kFALSE}; ///<!Set to true if offset array was read from a file.
65 Int_t *fDisplacement{nullptr}; ///<![fNevBuf] Displacement of entries in fBuffer(TKey)
66 Int_t *fEntryOffset{nullptr}; ///<[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime. Special value
67 /// of `-1` indicates that the offset generation MUST be performed on first read.
68 TBranch *fBranch{nullptr}; ///<Pointer to the basket support branch
69 TBuffer *fCompressedBufferRef{nullptr}; ///<! Compressed buffer.
70 Int_t fLastWriteBufferSize[3] = {0,0,0}; ///<! Size of the buffer last three buffers we wrote it to disk
71 Bool_t fResetAllocation{false}; ///<! True if last reset re-allocated the memory
72 UChar_t fNextBufferSizeRecord{0}; ///<! Index into fLastWriteBufferSize of the last buffer written to disk
73#ifdef R__TRACK_BASKET_ALLOC_TIME
74 ULong64_t fResetAllocationTime{0}; ///<! Time spent reallocating baskets in microseconds during last Reset operation.
75#endif
76
77public:
78 // The IO bits flag is to provide improved forward-compatibility detection.
79 // Any new non-forward compatibility flags related serialization should be
80 // added here. When a new flag is added, set it in the kSupported field;
81 //
82 // The values and names of this (and EUnsupportedIOBits) enum need not be aligned
83 // with the values of the various TIOFeatures enums, as there's a clean separation
84 // between these two interfaces. Practically, it is reasonable to keep them as aligned
85 // as possible in order to avoid confusion.
86 //
87 // If (fIOBits & ~kSupported) is non-zero -- i.e., an unknown IO flag is set
88 // in the fIOBits -- then the zombie flag will be set for this object.
89 //
90 enum class EIOBits : Char_t {
91 // The following to bits are reserved for now; when supported, set
92 // kSupported = kGenerateOffsetMap | kBasketClassMap
94 // kBasketClassMap = BIT(1),
96 };
97 // This enum covers IOBits that are known to this ROOT release but
98 // not supported; provides a mechanism for us to have experimental
99 // changes that are not going go into a supported release.
100 //
101 // (kUnsupported | kSupported) should result in the '|' of all IOBits.
103 // The number of known, defined IOBits.
104 static constexpr int kIOBitCount = 1;
105
106 TBasket();
107 TBasket(TDirectory *motherDir);
108 TBasket(const char *name, const char *title, TBranch *branch);
109 virtual ~TBasket();
110
111 virtual void AdjustSize(Int_t newsize);
112 virtual void DeleteEntryOffset();
113 virtual Int_t DropBuffers();
114 TBranch *GetBranch() const {return fBranch;}
118 {
119 return R__likely(fEntryOffset != reinterpret_cast<Int_t *>(-1)) ? fEntryOffset : GetCalculatedEntryOffset();
120 }
122 Int_t GetNevBuf() const {return fNevBuf;}
124 Int_t GetLast() const {return fLast;}
125 virtual void MoveEntries(Int_t dentries);
126 virtual void PrepareBasket(Long64_t /* entry */) {};
129 virtual void Reset();
130
131// Time spent reseting basket sizes (typically, at event cluster boundaries), in microseconds
132#ifdef R__TRACK_BASKET_ALLOC_TIME
133 ULong64_t GetResetAllocationTime() const { return fResetAllocationTime; }
134#endif
135 // Count of resets performed of basket size.
137
139 Long64_t CopyTo(TFile *to);
140
141 void SetBranch(TBranch *branch) { fBranch = branch; }
143 virtual void SetReadMode();
144 virtual void SetWriteMode();
145 inline void Update(Int_t newlast) { Update(newlast,newlast); };
146 virtual void Update(Int_t newlast, Int_t skipped);
147 virtual Int_t WriteBuffer();
148
149 ClassDef(TBasket, 3); // the TBranch buffers
150};
151
152#endif
#define R__likely(expr)
Definition: RConfig.hxx:579
int Int_t
Definition: RtypesCore.h:41
unsigned char UChar_t
Definition: RtypesCore.h:34
char Char_t
Definition: RtypesCore.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
unsigned long long ULong64_t
Definition: RtypesCore.h:70
#define ClassDef(name, id)
Definition: Rtypes.h:324
#define BIT(n)
Definition: Rtypes.h:82
Manages buffers for branches of a Tree.
Definition: TBasket.h:34
virtual void Reset()
Reset the basket to the starting state.
Definition: TBasket.cxx:707
Int_t * fEntryOffset
[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime.
Definition: TBasket.h:66
Int_t GetEntryPointer(Int_t Entry)
Get pointer to buffer for internal entry.
Definition: TBasket.cxx:226
Bool_t fOwnsCompressedBuffer
! Whether or not we own the compressed buffer.
Definition: TBasket.h:63
TBranch * fBranch
Pointer to the basket support branch.
Definition: TBasket.h:68
Int_t GetNevBufSize() const
Definition: TBasket.h:123
Long64_t CopyTo(TFile *to)
Copy the basket of this branch onto the file to.
Definition: TBasket.cxx:142
Int_t * GetEntryOffset()
Definition: TBasket.h:117
Int_t * GetDisplacement() const
Definition: TBasket.h:116
void InitializeCompressedBuffer(Int_t len, TFile *file)
Initialize the compressed buffer; either from the TTree or create a local one.
Definition: TBasket.cxx:428
Int_t GetNevBuf() const
Definition: TBasket.h:122
UChar_t fNextBufferSizeRecord
! Index into fLastWriteBufferSize of the last buffer written to disk
Definition: TBasket.h:72
Bool_t CanGenerateOffsetArray()
Determine whether we can generate the offset array when this branch is read.
Definition: TBasket.cxx:214
Bool_t fHeaderOnly
True when only the basket header must be read/written.
Definition: TBasket.h:61
Int_t fLastWriteBufferSize[3]
! Size of the buffer last three buffers we wrote it to disk
Definition: TBasket.h:70
EUnsupportedIOBits
Definition: TBasket.h:102
void SetBranch(TBranch *branch)
Definition: TBasket.h:141
Int_t ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:460
UChar_t fIOBits
!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless nee...
Definition: TBasket.h:62
virtual Int_t DropBuffers()
Drop buffers of this basket if it is not the current basket.
Definition: TBasket.cxx:169
virtual void PrepareBasket(Long64_t)
Definition: TBasket.h:126
virtual void MoveEntries(Int_t dentries)
Remove the first dentries of this basket, moving entries at dentries to the start of the buffer.
Definition: TBasket.cxx:306
void SetNevBufSize(Int_t n)
Definition: TBasket.h:142
void ResetEntryOffset()
Definition: TBasket.cxx:437
static constexpr int kIOBitCount
Definition: TBasket.h:104
Int_t GetBufferSize() const
Definition: TBasket.h:115
TBranch * GetBranch() const
Definition: TBasket.h:114
TBasket()
Default contructor.
Definition: TBasket.cxx:48
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
Definition: TBasket.cxx:123
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=0)
Load basket buffers in memory without unziping.
Definition: TBasket.cxx:241
Bool_t fResetAllocation
! True if last reset re-allocated the memory
Definition: TBasket.h:71
virtual void SetReadMode()
Set read mode of basket.
Definition: TBasket.cxx:826
virtual void SetWriteMode()
Set write mode of basket.
Definition: TBasket.cxx:835
Int_t ReadBasketBuffersUncompressedCase()
By-passing buffer unzipping has been requested and is possible (only 1 entry in this basket).
Definition: TBasket.cxx:354
Bool_t GetResetAllocationCount() const
Definition: TBasket.h:136
Int_t fBufferSize
fBuffer length in bytes
Definition: TBasket.h:57
Int_t ReadBasketBuffersUnzip(char *, Int_t, Bool_t, TFile *)
We always create the TBuffer for the basket but it hold the buffer from the cache.
Definition: TBasket.cxx:376
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:692
TBasket & operator=(const TBasket &)
TBasket objects are not copiable.
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
Definition: TBasket.cxx:1032
Int_t GetLast() const
Definition: TBasket.h:124
void Update(Int_t newlast)
Definition: TBasket.h:145
TBasket(const TBasket &)
TBasket objects are not copiable.
Int_t fNevBufSize
Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
Definition: TBasket.h:58
Int_t fNevBuf
Number of entries in basket.
Definition: TBasket.h:59
Int_t * GetCalculatedEntryOffset()
Calculates the entry offset array, if possible.
Definition: TBasket.cxx:191
Bool_t fReadEntryOffset
!Set to true if offset array was read from a file.
Definition: TBasket.h:64
virtual ~TBasket()
Basket destructor.
Definition: TBasket.cxx:105
EIOBits
Definition: TBasket.h:90
virtual void DeleteEntryOffset()
Delete fEntryOffset array.
Definition: TBasket.cxx:160
TBuffer * fCompressedBufferRef
! Compressed buffer.
Definition: TBasket.h:69
Int_t fLast
Pointer to last used byte in basket.
Definition: TBasket.h:60
Int_t * fDisplacement
![fNevBuf] Displacement of entries in fBuffer(TKey)
Definition: TBasket.h:65
A TTree is a list of TBranches.
Definition: TBranch.h:64
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Describe directory structure in memory.
Definition: TDirectory.h:34
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
A TTree object has a header with a name and a title.
Definition: TTree.h:71
const Int_t n
Definition: legend1.C:16
Definition: file.py:1
Definition: tree.py:1