35constexpr auto gMaxInt_t = std::numeric_limits<Int_t>::max();
159 return nBytes>0 ? nBytes : -1;
203 Error(
"GetCalculatedEntryOffset",
"Basket entry offset calculation requested, but no associated TBranch!");
207 Error(
"GetCalculatedEntryOffset",
"Branch contains multiple leaves - unable to calculated entry offsets!");
221 if (
fBranch->GetNleaves() != 1) {
235 if (entryOffset)
offset = entryOffset[entry];
272 }
else if (st == 0) {
315 if (dentries >=
fNevBuf)
return;
321 bufbegin = entryOffset[dentries];
332 entryOffset[i] = entryOffset[i + dentries] - moved;
348 char *buffer = buf->
Buffer();
354#define OLD_CASE_EXPRESSION fObjlen==fNbytes-fKeylen && GetBranch()->GetCompressionLevel()!=0 && file->GetVersion()<=30401
417 if (curBufferSize <
len) {
472 char *rawUncompressedBuffer, *rawCompressedBuffer;
473 Int_t uncompressedBufferLen;
479 pf =
fBranch->GetTree()->GetReadCache(file);
484 char *buffer =
nullptr;
490 if (
len <= 0)
return -
len;
512 if (!readBufferRef) {
513 Error(
"ReadBasketBuffers",
"Unable to allocate buffer.");
527 }
else if (st == 0) {
559 rawCompressedBuffer = readBufferRef->
Buffer();
572 Error(
"ReadBasketBuffers",
"Unable to allocate buffer.");
582 Error(
"ReadBasketBuffers",
"The value of fKeylen is incorrect (%d) ; trying to recover by setting it to zero",
fKeylen);
588 Error(
"ReadBasketBuffers",
"The value of fObjlen is incorrect (%d) ; trying to recover by setting it to zero",
fObjlen);
594 Error(
"ReadBasketBuffers",
"The value of fNbytes is incorrect (%d) ; trying to recover by setting it to zero",
fNbytes);
600 Error(
"ReadBasketBuffers",
"fObjlen (%d) + fKeylen (%d) > max int (%d): cannot continue to read the key buffer.",
613 fBuffer = rawUncompressedBuffer;
628 memcpy(rawUncompressedBuffer, rawCompressedBuffer,
fKeylen);
629 char *rawUncompressedObjectBuffer = rawUncompressedBuffer+
fKeylen;
633 Int_t nin = 0, nbuf = 0;
634 Int_t nout = 0, noutot = 0, nintot = 0;
640 while (nbytesRemain >= ROOT::Internal::kZipHeaderSize) {
642 if (
R__unlikely(R__unzip_header(&nin, rawCompressedObjectBuffer, &nbuf) != 0)) {
643 Error(
"ReadBasketBuffers",
"Inconsistency found in header (nin=%d, nbuf=%d)", nin, nbuf);
651 if (
R__unlikely((nin > nbytesRemain) || (nbuf > objlenRemain))) {
655 R__unzip(&nin, rawCompressedObjectBuffer, &nbuf, (
unsigned char*) rawUncompressedObjectBuffer, &nout);
660 rawCompressedObjectBuffer += nin;
661 rawUncompressedObjectBuffer += nout;
663 objlenRemain -= nout;
668 Error(
"ReadBasketBuffers",
"fNbytes = %d, fKeylen = %d, fObjlen = %d, noutot = %d, nout=%d, nin=%d, nbuf=%d",
fNbytes,
fKeylen,
fObjlen, noutot,nout,nin,nbuf);
681 memcpy(rawUncompressedBuffer, rawCompressedBuffer,
len);
702 Warning(
"ReadBasketBuffers",
"basket:%s has fNevBuf=%d but fEntryOffset=0, pos=%lld, len=%d, fNbytes=%d, fObjlen=%d, trying to repair",
GetName(),
fNevBuf,pos,
len,
fNbytes,
fObjlen);
773#ifdef R__TRACK_BASKET_ALLOC_TIME
774 fResetAllocationTime = 0;
779 const auto maxbaskets =
fBranch->GetMaxBaskets();
780 if (!
fBufferRef || basketnumber >= maxbaskets)
785 const Float_t target_mem_ratio =
fBranch->GetTree()->GetTargetMemoryRatio();
786 const auto basketbytes =
fBranch->GetBasketBytes();
788 Int_t max_size = basketbytes[basketnumber];
789 for(
Int_t b = basketnumber + 1; (
b < maxbaskets) && (
b < (basketnumber+10)); ++
b) {
790 max_size = std::max(max_size, basketbytes[
b]);
797 Int_t target_size =
static_cast<Int_t>(cx * target_mem_ratio *
Float_t(max_size));
799 if (target_size && (curSize > target_size)) {
801 Int_t newSize = max_size + 512 - max_size % 512;
803 if ((newSize <= curSize - 8 * 1024) &&
804 (
static_cast<Float_t>(curSize) /
static_cast<Float_t>(newSize) > target_mem_ratio))
807 Info(
"ReadResetBuffer",
808 "Resizing %d to %d bytes (was %d); next 10 sizes are [%d, %d, %d, %d, %d, %d, %d, %d, %d, %d]. cx=%f ratio=%f max_size = %d ",
809 basketnumber, newSize, curSize,
810 basketbytes[basketnumber],
811 (basketnumber + 1) < maxbaskets ? basketbytes[basketnumber + 1] : 0,
812 (basketnumber + 2) < maxbaskets ? basketbytes[basketnumber + 2] : 0,
813 (basketnumber + 3) < maxbaskets ? basketbytes[basketnumber + 3] : 0,
814 (basketnumber + 4) < maxbaskets ? basketbytes[basketnumber + 4] : 0,
815 (basketnumber + 5) < maxbaskets ? basketbytes[basketnumber + 5] : 0,
816 (basketnumber + 6) < maxbaskets ? basketbytes[basketnumber + 6] : 0,
817 (basketnumber + 7) < maxbaskets ? basketbytes[basketnumber + 7] : 0,
818 (basketnumber + 8) < maxbaskets ? basketbytes[basketnumber + 8] : 0,
819 (basketnumber + 9) < maxbaskets ? basketbytes[basketnumber + 9] : 0,
820 cx, target_mem_ratio, max_size);
823#ifdef R__TRACK_BASKET_ALLOC_TIME
824 std::chrono::time_point<std::chrono::system_clock> start, end;
825 start = std::chrono::high_resolution_clock::now();
828#ifdef R__TRACK_BASKET_ALLOC_TIME
829 end = std::chrono::high_resolution_clock::now();
830 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
831 fResetAllocationTime = us.count();
846#ifdef R__TRACK_BASKET_ALLOC_TIME
847 fResetAllocationTime = 0;
861 if (curSize > 2*curLen)
864 if (curSize > 2*curBsize ) {
866 if (curSize > 2*avgSize) {
868 if (curLen > newSize) {
871 if (avgSize > newSize) {
874 newSize = newSize + 512 - newSize%512;
886 Float_t target_mem_ratio =
fBranch->GetTree()->GetTargetMemoryRatio();
889 if (max_size && (curSize > target_size) && (newSize == -1)) {
890 newSize = target_size;
891 newSize = newSize + 512 - newSize % 512;
893 if ((newSize > curSize - 8 * 1024) ||
894 (
static_cast<Float_t>(curSize) /
static_cast<Float_t>(newSize) < target_mem_ratio)) {
897 Info(
"Reset",
"Resizing to %ld bytes (was %d); last three sizes were [%d, %d, %d].", newSize, curSize,
904#ifdef R__TRACK_BASKET_ALLOC_TIME
905 std::chrono::time_point<std::chrono::system_clock> start, end;
906 start = std::chrono::high_resolution_clock::now();
909#ifdef R__TRACK_BASKET_ALLOC_TIME
910 end = std::chrono::high_resolution_clock::now();
911 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
912 fResetAllocationTime = us.count();
923 if (newNevBufSize==0) {
983 static std::atomic<Int_t> nerrors(0);
1003 Error(
"TBasket::Streamer",
1004 "The value of fNevBufSize (%d) or fIOBits (%d) is incorrect ; setting the buffer to a zombie.",
1011 Error(
"Streamer",
"The value of fIOBits (%s) contains unknown flags (supported flags "
1012 "are %s), indicating this was written with a newer version of ROOT "
1013 "utilizing critical IO features this version of ROOT does not support."
1014 " Refusing to deserialize.",
1015 std::bitset<32>(
static_cast<Int_t>(
fIOBits)).to_string().c_str(),
1017 }
else if (nerrors == 10) {
1018 Error(
"Streamer",
"Maximum number of errors has been reported; disabling further messages"
1019 "from this location until the process exits.");
1029 bool mustGenerateOffsets =
false;
1031 mustGenerateOffsets =
true;
1034 if (!mustGenerateOffsets && flag && (flag % 10 != 2)) {
1039 "Inconsistent length for the entry offset buffer (%d events for a buffer size of %d). The basket is "
1040 "corrupted and not usable.",
1056 "Inconsistent length for the entry offset buffer (expected %d elements, read %d). The basket is "
1057 "corrupted and not usable.",
1066 if (20<flag && flag<40) {
1077 "Inconsistent length for the displacement buffer (expected %d elements, read %d). The basket is "
1078 "corrupted and not usable.",
1085 }
else if (mustGenerateOffsets) {
1091 if (flag == 1 || flag > 10) {
1095 if (
v > 1)
b.ReadFastArray(buf,
fLast);
1096 else b.ReadArray(buf);
1128 flag = mustGenerateOffsets ? 80 : 0;
1142 if (mustGenerateOffsets) {
1153 b.WriteFastArray(buf,
fLast);
1179 if (
fBranch->GetWriteBasket() < 10) {
1180 fBranch->SetEntryOffsetLen(newsize);
1207 constexpr Int_t kWrite = 1;
1210 if (!file)
return 0;
1222 std::unique_lock<std::mutex> sentry(file->
fWriteMutex);
1244 return nBytes>0 ?
fKeylen+nout : -1;
1258 entryOffset[idx] -= entryOffset[idx - 1];
1268 entryOffset[idx] += entryOffset[idx - 1];
1271 }
else if (!hasOffsetBit) {
1281 Int_t nout, noutot, bufmax, nzip;
1298 Warning(
"WriteBuffer",
"Unable to allocate the compressed buffer");
1307 for (
Int_t i = 0; i < nbuffers; ++i) {
1308 if (i == nbuffers - 1) bufmax =
fObjlen - nzip;
1309 else bufmax = kMAXZIPBUF;
1319 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
1327 if (nout == 0 || nout >=
fObjlen) {
1337 Warning(
"WriteBuffer",
"Possible memory corruption due to compression algorithm, wrote %d bytes past the end of a block of %d bytes. fNbytes=%d, fObjLen=%d, fKeylen=%d",
1344 objbuf += kMAXZIPBUF;
1365 return nBytes>0 ?
fKeylen+nout : -1;
#define R__unlikely(expr)
true
Register systematic variations for multiple existing columns using auto-generated tags.
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
short Version_t
Class version identifier (short)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
float Float_t
Float 4 bytes (float)
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
static TBuffer * R__InitializeReadBasketBuffer(TBuffer *bufferRef, Int_t len, TFile *file)
Initialize a buffer for reading if it is not already initialized.
#define OLD_CASE_EXPRESSION
const UInt_t kDisplacementMask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
externTVirtualMutex * gROOTMutex
#define R__LOCKGUARD_IMT(mutex)
Int_t * fEntryOffset
[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime.
Int_t GetEntryPointer(Int_t Entry)
Get pointer to buffer for internal entry.
void AdoptBuffer(TBuffer *user_buffer)
Adopt a buffer from an external entity.
bool fHeaderOnly
True when only the basket header must be read/written.
TBranch * fBranch
Pointer to the basket support branch.
Long64_t CopyTo(TFile *to)
Copy the basket of this branch onto the file to.
void InitializeCompressedBuffer(Int_t len, TFile *file)
Initialize the compressed buffer; either from the TTree or create a local one.
UChar_t fNextBufferSizeRecord
! Index into fLastWriteBufferSize of the last buffer written to disk
Int_t ReadBasketBuffersUnzip(char *, Int_t, bool, TFile *)
We always create the TBuffer for the basket but it hold the buffer from the cache.
void DisownBuffer()
Disown all references to the internal buffer - some other object likely now owns it.
Int_t fLastWriteBufferSize[3]
! Size of the buffer last three buffers we wrote it to disk
Int_t ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
Read basket buffers in memory and cleanup.
UChar_t fIOBits
!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless nee...
virtual Int_t DropBuffers()
Drop buffers of this basket if it is not the current basket.
virtual void MoveEntries(Int_t dentries)
Remove the first dentries of this basket, moving entries at dentries to the start of the buffer.
bool fOwnsCompressedBuffer
! Whether or not we own the compressed buffer.
TBasket()
Default constructor.
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
virtual void SetReadMode()
Set read mode of basket.
virtual void SetWriteMode()
Set write mode of basket.
Int_t ReadBasketBuffersUncompressedCase()
By-passing buffer unzipping has been requested and is possible (only 1 entry in this basket).
Int_t fBufferSize
fBuffer length in bytes
bool fReadEntryOffset
!Set to true if offset array was read from a file.
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
virtual void ReadResetBuffer(Int_t basketnumber)
Reset the read basket TBuffer memory allocation if needed.
bool fResetAllocation
! True if last reset re-allocated the memory
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
void Streamer(TBuffer &) override
Stream a class object.
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=nullptr)
Load basket buffers in memory without unziping.
~TBasket() override
Basket destructor.
void Update(Int_t newlast)
Int_t fNevBufSize
Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
Int_t fNevBuf
Number of entries in basket.
Int_t * GetCalculatedEntryOffset()
Calculates the entry offset array, if possible.
TClass * IsA() const override
virtual void DeleteEntryOffset()
Delete fEntryOffset array.
TBuffer * fCompressedBufferRef
! Compressed buffer.
Int_t fLast
Pointer to last used byte in basket.
Int_t * fDisplacement
![fNevBuf] Displacement of entries in fBuffer(TKey)
bool CanGenerateOffsetArray()
Determine whether we can generate the offset array when this branch is read.
virtual void WriteReset()
Reset the write basket to the starting state.
virtual TFile * GetFile(Int_t mode=0)
Return pointer to the file where branch buffers reside, returns 0 in case branch buffers reside in th...
TDirectory * GetDirectory() const
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TBranch for reading/writing baskets.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Buffer base class used for serializing objects.
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
void SetBufferOffset(Int_t offset=0)
void SetReadMode()
Set buffer in read mode.
Bool_t IsWritable() const override
Describe directory structure in memory.
A cache when reading files over the network.
virtual Int_t GetUnzipBuffer(char **, Long64_t, Int_t, Bool_t *)
virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len)
Read buffer at position pos.
virtual void AddNoCacheReadCalls(Int_t reads)
virtual void AddNoCacheBytesRead(Long64_t len)
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
Int_t GetCompressionLevel() const
std::mutex fWriteMutex
!Lock for writing baskets / keys into the file.
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Int_t GetCompressionAlgorithm() const
Int_t GetRecordHeader(char *buf, Long64_t first, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen)
Read the logical record header starting at a certain postion.
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read a buffer from the file.
TFileCacheRead * GetCacheRead(const TObject *tree=nullptr) const
Return a pointer to the current read cache.
TBuffer * fBufferRef
Pointer to the TBuffer object.
Int_t fVersion
Key version identifier.
Short_t fKeylen
Number of bytes for the key itself.
TKey(const TKey &)=delete
virtual Int_t WriteFileKeepBuffer(TFile *f=nullptr)
Write the encoded object supported by this key.
Long64_t fSeekKey
Location of object on file.
char * fBuffer
Object buffer.
Int_t fNbytes
Number of bytes for the whole key on file (key header and data)
Int_t fObjlen
Length of uncompressed object in bytes.
void Reset()
Reset the key as it had not been 'filled' yet.
Short_t fCycle
Cycle number.
virtual void Create(Int_t nbytes, TFile *f=nullptr)
Create a TKey object of specified size.
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=nullptr)
Write the encoded object supported by this key.
TDirectory * fMotherDir
!pointer to mother directory
TString fClassName
Object Class name.
void Streamer(TBuffer &) override
Stream a class object.
TBuffer * GetBufferRef() const
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual bool CanGenerateOffsetArray()
virtual Int_t * GenerateOffsetArray(Int_t base, Int_t events)
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
The TTimeStamp encapsulates seconds and ns since EPOCH.
A cache to speed-up the reading of ROOT datasets.
A TTree represents a columnar dataset.
virtual TVirtualPerfStats * GetPerfStats() const
virtual void IncrementTotalBuffers(Int_t nbytes)
TTreeCache * GetReadCache(TFile *file) const
Find and return the TTreeCache registered with the file and which may contain branches for us.
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TTree for reading/writing baskets.
Provides the interface for the an internal performance measurement and event tracing.
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
EValues
Note: this is only temporarily a struct and will become a enum class hence the name convention used.
@ kInherit
Some objects use this value to denote that the compression algorithm should be inherited from the par...
@ kInherit
Some objects use this value to denote that the compression algorithm should be inherited from the par...