Logo ROOT  
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 
30 class TFile;
31 class TTree;
32 class TBranch;
33 
34 class TBasket : public TKey {
35 friend class TBranch;
36 
37 private:
38  TBasket(const TBasket&); ///< TBasket objects are not copiable.
39  TBasket& operator=(const TBasket&); ///< TBasket objects are not copiable.
40 
41  // Internal corner cases for ReadBasketBuffers
44 
45  // Helper for managing the compressed buffer.
47 
48  // Handles special logic around deleting / reseting the entry offset pointer.
49  void ResetEntryOffset();
50 
51  // Get entry offset as result of a calculation.
53 
54  // Returns true if the underlying TLeaf can regenerate the entry offsets for us.
56 
57  // Manage buffer ownership.
58  void DisownBuffer();
59  void AdoptBuffer(TBuffer *user_buffer);
60 
61 protected:
62  Int_t fBufferSize{0}; ///< fBuffer length in bytes
63  Int_t fNevBufSize{0}; ///< Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
64  Int_t fNevBuf{0}; ///< Number of entries in basket
65  Int_t fLast{0}; ///< Pointer to last used byte in basket
66  Bool_t fHeaderOnly{kFALSE}; ///< True when only the basket header must be read/written
67  UChar_t fIOBits{0}; ///<!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless needed.
68  Bool_t fOwnsCompressedBuffer{kFALSE}; ///<! Whether or not we own the compressed buffer.
69  Bool_t fReadEntryOffset{kFALSE}; ///<!Set to true if offset array was read from a file.
70  Int_t *fDisplacement{nullptr}; ///<![fNevBuf] Displacement of entries in fBuffer(TKey)
71  Int_t *fEntryOffset{nullptr}; ///<[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime. Special value
72  /// of `-1` indicates that the offset generation MUST be performed on first read.
73  TBranch *fBranch{nullptr}; ///<Pointer to the basket support branch
74  TBuffer *fCompressedBufferRef{nullptr}; ///<! Compressed buffer.
75  Int_t fLastWriteBufferSize[3] = {0,0,0}; ///<! Size of the buffer last three buffers we wrote it to disk
76  Bool_t fResetAllocation{false}; ///<! True if last reset re-allocated the memory
77  UChar_t fNextBufferSizeRecord{0}; ///<! Index into fLastWriteBufferSize of the last buffer written to disk
78 #ifdef R__TRACK_BASKET_ALLOC_TIME
79  ULong64_t fResetAllocationTime{0}; ///<! Time spent reallocating baskets in microseconds during last Reset operation.
80 #endif
81 
82  virtual void ReadResetBuffer(Int_t basketnumber);
83 
84 public:
85  // The IO bits flag is to provide improved forward-compatibility detection.
86  // Any new non-forward compatibility flags related serialization should be
87  // added here. When a new flag is added, set it in the kSupported field;
88  //
89  // The values and names of this (and EUnsupportedIOBits) enum need not be aligned
90  // with the values of the various TIOFeatures enums, as there's a clean separation
91  // between these two interfaces. Practically, it is reasonable to keep them as aligned
92  // as possible in order to avoid confusion.
93  //
94  // If (fIOBits & ~kSupported) is non-zero -- i.e., an unknown IO flag is set
95  // in the fIOBits -- then the zombie flag will be set for this object.
96  //
97  enum class EIOBits : Char_t {
98  // The following to bits are reserved for now; when supported, set
99  // kSupported = kGenerateOffsetMap | kBasketClassMap
100  kGenerateOffsetMap = BIT(0),
101  // kBasketClassMap = BIT(1),
103  };
104  // This enum covers IOBits that are known to this ROOT release but
105  // not supported; provides a mechanism for us to have experimental
106  // changes that are not going go into a supported release.
107  //
108  // (kUnsupported | kSupported) should result in the '|' of all IOBits.
109  enum class EUnsupportedIOBits : Char_t { kUnsupported = 0 };
110  // The number of known, defined IOBits.
111  static constexpr int kIOBitCount = 1;
112 
113  TBasket();
114  TBasket(TDirectory *motherDir);
115  TBasket(const char *name, const char *title, TBranch *branch);
116  virtual ~TBasket();
117 
118  virtual void AdjustSize(Int_t newsize);
119  virtual void DeleteEntryOffset();
120  virtual Int_t DropBuffers();
121  TBranch *GetBranch() const {return fBranch;}
122  Int_t GetBufferSize() const {return fBufferSize;}
125  {
126  return R__likely(fEntryOffset != reinterpret_cast<Int_t *>(-1)) ? fEntryOffset : GetCalculatedEntryOffset();
127  }
128  Int_t GetEntryPointer(Int_t Entry);
129  Int_t GetNevBuf() const {return fNevBuf;}
130  Int_t GetNevBufSize() const {return fNevBufSize;}
131  Int_t GetLast() const {return fLast;}
132  virtual void MoveEntries(Int_t dentries);
133  virtual void PrepareBasket(Long64_t /* entry */) {};
136  virtual void WriteReset();
137 
138 // Time spent reseting basket sizes (typically, at event cluster boundaries), in microseconds
139 #ifdef R__TRACK_BASKET_ALLOC_TIME
140  ULong64_t GetResetAllocationTime() const { return fResetAllocationTime; }
141 #endif
142  // Count of resets performed of basket size.
144 
146  Long64_t CopyTo(TFile *to);
147 
148  void SetBranch(TBranch *branch) { fBranch = branch; }
150  virtual void SetReadMode();
151  virtual void SetWriteMode();
152  inline void Update(Int_t newlast) { Update(newlast,newlast); };
153  virtual void Update(Int_t newlast, Int_t skipped);
154  virtual Int_t WriteBuffer();
155 
156  ClassDef(TBasket, 3); // the TBranch buffers
157 };
158 
159 #endif
TBasket::TBasket
TBasket()
Default contructor.
Definition: TBasket.cxx:47
TBasket::InitializeCompressedBuffer
void InitializeCompressedBuffer(Int_t len, TFile *file)
Initialize the compressed buffer; either from the TTree or create a local one.
Definition: TBasket.cxx:432
n
const Int_t n
Definition: legend1.C:16
TBasket::ReadBasketBuffers
Int_t ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:464
TBasket::DisownBuffer
void DisownBuffer()
Disown all references to the internal buffer - some other object likely now owns it.
Definition: TBasket.cxx:713
TBasket::EUnsupportedIOBits
EUnsupportedIOBits
Definition: TBasket.h:109
TBasket::SetNevBufSize
void SetNevBufSize(Int_t n)
Definition: TBasket.h:149
tree
Definition: tree.py:1
TBasket::fReadEntryOffset
Bool_t fReadEntryOffset
!Set to true if offset array was read from a file.
Definition: TBasket.h:69
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TTree
Definition: TTree.h:79
TBasket::GetResetAllocationCount
Bool_t GetResetAllocationCount() const
Definition: TBasket.h:143
TBasket::CanGenerateOffsetArray
Bool_t CanGenerateOffsetArray()
Determine whether we can generate the offset array when this branch is read.
Definition: TBasket.cxx:218
Int_t
int Int_t
Definition: RtypesCore.h:45
TBasket::fNevBufSize
Int_t fNevBufSize
Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
Definition: TBasket.h:63
R__likely
#define R__likely(expr)
Definition: RConfig.hxx:605
TBasket::fBranch
TBranch * fBranch
Pointer to the basket support branch.
Definition: TBasket.h:73
TBasket::kIOBitCount
static constexpr int kIOBitCount
Definition: TBasket.h:111
TBasket::GetBranch
TBranch * GetBranch() const
Definition: TBasket.h:121
TBasket::CopyTo
Long64_t CopyTo(TFile *to)
Copy the basket of this branch onto the file to.
Definition: TBasket.cxx:146
TBuffer
Definition: TBuffer.h:43
TBasket::GetNevBuf
Int_t GetNevBuf() const
Definition: TBasket.h:129
TBasket::fLastWriteBufferSize
Int_t fLastWriteBufferSize[3]
! Size of the buffer last three buffers we wrote it to disk
Definition: TBasket.h:75
bool
TBasket::ResetEntryOffset
void ResetEntryOffset()
Definition: TBasket.cxx:441
TBasket::MoveEntries
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:310
TBasket::ReadBasketBytes
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:698
TBasket::fDisplacement
Int_t * fDisplacement
![fNevBuf] Displacement of entries in fBuffer(TKey)
Definition: TBasket.h:70
TBasket::DropBuffers
virtual Int_t DropBuffers()
Drop buffers of this basket if it is not the current basket.
Definition: TBasket.cxx:173
TBranch
Definition: TBranch.h:89
TBasket::fIOBits
UChar_t fIOBits
!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless nee...
Definition: TBasket.h:67
TBasket::DeleteEntryOffset
virtual void DeleteEntryOffset()
Delete fEntryOffset array.
Definition: TBasket.cxx:164
TBasket::SetWriteMode
virtual void SetWriteMode()
Set write mode of basket.
Definition: TBasket.cxx:934
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TBasket::fLast
Int_t fLast
Pointer to last used byte in basket.
Definition: TBasket.h:65
TBasket::LoadBasketBuffers
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=0)
Load basket buffers in memory without unziping.
Definition: TBasket.cxx:245
BIT
#define BIT(n)
Definition: Rtypes.h:85
TBasket::GetEntryOffset
Int_t * GetEntryOffset()
Definition: TBasket.h:124
TBasket::EUnsupportedIOBits::kUnsupported
@ kUnsupported
TBasket::fEntryOffset
Int_t * fEntryOffset
[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime.
Definition: TBasket.h:71
TBasket::GetCalculatedEntryOffset
Int_t * GetCalculatedEntryOffset()
Calculates the entry offset array, if possible.
Definition: TBasket.cxx:195
TBasket::fBufferSize
Int_t fBufferSize
fBuffer length in bytes
Definition: TBasket.h:62
TBasket::fNevBuf
Int_t fNevBuf
Number of entries in basket.
Definition: TBasket.h:64
TFile
Definition: TFile.h:54
TBasket::operator=
TBasket & operator=(const TBasket &)
TBasket objects are not copiable.
TBasket::GetNevBufSize
Int_t GetNevBufSize() const
Definition: TBasket.h:130
TBasket::PrepareBasket
virtual void PrepareBasket(Long64_t)
Definition: TBasket.h:133
TKey
Definition: TKey.h:28
TBasket::GetLast
Int_t GetLast() const
Definition: TBasket.h:131
TBasket::fHeaderOnly
Bool_t fHeaderOnly
True when only the basket header must be read/written.
Definition: TBasket.h:66
TBasket::WriteBuffer
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
Definition: TBasket.cxx:1131
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
TBasket
Definition: TBasket.h:34
TBasket::GetBufferSize
Int_t GetBufferSize() const
Definition: TBasket.h:122
TBasket::SetReadMode
virtual void SetReadMode()
Set read mode of basket.
Definition: TBasket.cxx:925
TBasket::GetDisplacement
Int_t * GetDisplacement() const
Definition: TBasket.h:123
TBasket::EIOBits
EIOBits
Definition: TBasket.h:97
TBasket::fResetAllocation
Bool_t fResetAllocation
! True if last reset re-allocated the memory
Definition: TBasket.h:76
file
Definition: file.py:1
TBasket::ReadBasketBuffersUnzip
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:380
TBasket::ReadResetBuffer
virtual void ReadResetBuffer(Int_t basketnumber)
Reset the read basket TBuffer memory allocation if needed.
Definition: TBasket.cxx:733
UChar_t
unsigned char UChar_t
Definition: RtypesCore.h:38
TBasket::AdjustSize
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
Definition: TBasket.cxx:127
TBasket::ReadBasketBuffersUncompressedCase
Int_t ReadBasketBuffersUncompressedCase()
By-passing buffer unzipping has been requested and is possible (only 1 entry in this basket).
Definition: TBasket.cxx:358
TBasket::GetEntryPointer
Int_t GetEntryPointer(Int_t Entry)
Get pointer to buffer for internal entry.
Definition: TBasket.cxx:230
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TBasket::fNextBufferSizeRecord
UChar_t fNextBufferSizeRecord
! Index into fLastWriteBufferSize of the last buffer written to disk
Definition: TBasket.h:77
TBasket::~TBasket
virtual ~TBasket()
Basket destructor.
Definition: TBasket.cxx:104
name
char name[80]
Definition: TGX11.cxx:110
TDirectory
Definition: TDirectory.h:40
TKey.h
TBasket::SetBranch
void SetBranch(TBranch *branch)
Definition: TBasket.h:148
TBasket::fOwnsCompressedBuffer
Bool_t fOwnsCompressedBuffer
! Whether or not we own the compressed buffer.
Definition: TBasket.h:68
TBasket::EIOBits::kGenerateOffsetMap
@ kGenerateOffsetMap
TBasket::Update
void Update(Int_t newlast)
Definition: TBasket.h:152
Char_t
char Char_t
Definition: RtypesCore.h:33
TBasket::fCompressedBufferRef
TBuffer * fCompressedBufferRef
! Compressed buffer.
Definition: TBasket.h:74
TBasket::AdoptBuffer
void AdoptBuffer(TBuffer *user_buffer)
Adopt a buffer from an external entity.
Definition: TBasket.cxx:721
TBasket::EIOBits::kSupported
@ kSupported
int
TBasket::WriteReset
virtual void WriteReset()
Reset the write basket to the starting state.
Definition: TBasket.cxx:806