63 :
TKey(branch->GetDirectory()), fBufferSize(branch->GetBasketSize()), fNevBufSize(branch->GetEntryOffsetLen()),
64 fHeaderOnly(
kTRUE), fIOBits(branch->GetIOFeatures().GetFeatures())
154 return nBytes>0 ? nBytes : -1;
198 Error(
"GetCalculatedEntryOffset",
"Basket entry offset calculation requested, but no associated TBranch!");
202 Error(
"GetCalculatedEntryOffset",
"Branch contains multiple leaves - unable to calculated entry offsets!");
230 if (entryOffset) offset = entryOffset[entry];
267 }
else if (st == 0) {
273 if (
fc)
fc->Disable();
274 Int_t ret =
file->ReadBuffer(buffer,len);
275 if (
fc)
fc->Enable();
284 file->SetOffset(pos + len);
288 if (
file->ReadBuffer(buffer,len)) {
310 if (dentries >=
fNevBuf)
return;
316 bufbegin = entryOffset[dentries];
327 entryOffset[i] = entryOffset[i + dentries] - moved;
343 char *buffer = buf->
Buffer();
349#define OLD_CASE_EXPRESSION fObjlen==fNbytes-fKeylen && GetBranch()->GetCompressionLevel()!=0 && file->GetVersion()<=30401
412 if (curBufferSize < len) {
467 char *rawUncompressedBuffer, *rawCompressedBuffer;
468 Int_t uncompressedBufferLen;
479 char *buffer =
nullptr;
485 if (len <= 0)
return -len;
507 if (!readBufferRef) {
508 Error(
"ReadBasketBuffers",
"Unable to allocate buffer.");
522 }
else if (st == 0) {
528 if (
fc)
fc->Disable();
530 if (
fc)
fc->Enable();
543 if (
file->ReadBuffer(readBufferRef->
Buffer(),pos,len)) {
549 Streamer(*readBufferRef);
554 rawCompressedBuffer = readBufferRef->
Buffer();
567 Error(
"ReadBasketBuffers",
"Unable to allocate buffer.");
583 fBuffer = rawUncompressedBuffer;
598 memcpy(rawUncompressedBuffer, rawCompressedBuffer,
fKeylen);
599 char *rawUncompressedObjectBuffer = rawUncompressedBuffer+
fKeylen;
602 Int_t nout = 0, noutot = 0, nintot = 0;
608 Error(
"ReadBasketBuffers",
"Inconsistency found in header (nin=%d, nbuf=%d)", nin, nbuf);
617 R__unzip(&nin, rawCompressedObjectBuffer, &nbuf, (
unsigned char*) rawUncompressedObjectBuffer, &nout);
622 rawCompressedObjectBuffer += nin;
623 rawUncompressedObjectBuffer += nout;
628 Error(
"ReadBasketBuffers",
"fNbytes = %d, fKeylen = %d, fObjlen = %d, noutot = %d, nout=%d, nin=%d, nbuf=%d",
fNbytes,
fKeylen,
fObjlen, noutot,nout,nin,nbuf);
641 memcpy(rawUncompressedBuffer, rawCompressedBuffer, len);
662 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);
696 const Int_t len = 128;
733#ifdef R__TRACK_BASKET_ALLOC_TIME
734 fResetAllocationTime = 0;
740 if (!
fBufferRef || basketnumber >= maxbaskets)
748 Int_t max_size = basketbytes[basketnumber];
749 for(
Int_t b = basketnumber + 1; (
b < maxbaskets) && (
b < (basketnumber+10)); ++
b) {
750 max_size = std::max(max_size, basketbytes[
b]);
757 Int_t target_size =
static_cast<Int_t>(cx * target_mem_ratio *
Float_t(max_size));
759 if (target_size && (curSize > target_size)) {
761 Int_t newSize = max_size + 512 - max_size % 512;
763 if ((newSize <= curSize - 8 * 1024) &&
764 (
static_cast<Float_t>(curSize) /
static_cast<Float_t>(newSize) > target_mem_ratio))
767 Info(
"ReadResetBuffer",
768 "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 ",
769 basketnumber, newSize, curSize,
770 basketbytes[basketnumber],
771 (basketnumber + 1) < maxbaskets ? basketbytes[basketnumber + 1] : 0,
772 (basketnumber + 2) < maxbaskets ? basketbytes[basketnumber + 2] : 0,
773 (basketnumber + 3) < maxbaskets ? basketbytes[basketnumber + 3] : 0,
774 (basketnumber + 4) < maxbaskets ? basketbytes[basketnumber + 4] : 0,
775 (basketnumber + 5) < maxbaskets ? basketbytes[basketnumber + 5] : 0,
776 (basketnumber + 6) < maxbaskets ? basketbytes[basketnumber + 6] : 0,
777 (basketnumber + 7) < maxbaskets ? basketbytes[basketnumber + 7] : 0,
778 (basketnumber + 8) < maxbaskets ? basketbytes[basketnumber + 8] : 0,
779 (basketnumber + 9) < maxbaskets ? basketbytes[basketnumber + 9] : 0,
780 cx, target_mem_ratio, max_size);
783#ifdef R__TRACK_BASKET_ALLOC_TIME
784 std::chrono::time_point<std::chrono::system_clock> start, end;
785 start = std::chrono::high_resolution_clock::now();
788#ifdef R__TRACK_BASKET_ALLOC_TIME
789 end = std::chrono::high_resolution_clock::now();
790 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
791 fResetAllocationTime =
us.count();
806#ifdef R__TRACK_BASKET_ALLOC_TIME
807 fResetAllocationTime = 0;
821 if (curSize > 2*curLen)
824 if (curSize > 2*curBsize ) {
826 if (curSize > 2*avgSize) {
828 if (curLen > newSize) {
831 if (avgSize > newSize) {
834 newSize = newSize + 512 - newSize%512;
849 if (max_size && (curSize > target_size) && (newSize == -1)) {
850 newSize = target_size;
851 newSize = newSize + 512 - newSize % 512;
853 if ((newSize > curSize - 8 * 1024) ||
854 (
static_cast<Float_t>(curSize) /
static_cast<Float_t>(newSize) < target_mem_ratio)) {
857 Info(
"Reset",
"Resizing to %ld bytes (was %d); last three sizes were [%d, %d, %d].", newSize, curSize,
864#ifdef R__TRACK_BASKET_ALLOC_TIME
865 std::chrono::time_point<std::chrono::system_clock> start, end;
866 start = std::chrono::high_resolution_clock::now();
869#ifdef R__TRACK_BASKET_ALLOC_TIME
870 end = std::chrono::high_resolution_clock::now();
871 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
872 fResetAllocationTime =
us.count();
883 if (newNevBufSize==0) {
943 static std::atomic<Int_t> nerrors(0);
963 Error(
"TBasket::Streamer",
964 "The value of fNevBufSize (%d) or fIOBits (%d) is incorrect ; setting the buffer to a zombie.",
971 Error(
"Streamer",
"The value of fIOBits (%s) contains unknown flags (supported flags "
972 "are %s), indicating this was written with a newer version of ROOT "
973 "utilizing critical IO features this version of ROOT does not support."
974 " Refusing to deserialize.",
975 std::bitset<32>(
static_cast<Int_t>(
fIOBits)).to_string().c_str(),
977 }
else if (nerrors == 10) {
978 Error(
"Streamer",
"Maximum number of errors has been reported; disabling further messages"
979 "from this location until the process exits.");
989 Bool_t mustGenerateOffsets =
false;
991 mustGenerateOffsets =
true;
994 if (!mustGenerateOffsets && flag && (flag % 10 != 2)) {
998 if (20<flag && flag<40) {
1007 }
else if (mustGenerateOffsets) {
1013 if (flag == 1 || flag > 10) {
1017 if (
v > 1)
b.ReadFastArray(buf,
fLast);
1018 else b.ReadArray(buf);
1027 b.WriteVersion(TBasket::IsA());
1050 flag = mustGenerateOffsets ? 80 : 0;
1064 if (mustGenerateOffsets) {
1075 b.WriteFastArray(buf,
fLast);
1129 const Int_t kWrite = 1;
1132 if (!
file)
return 0;
1133 if (!
file->IsWritable()) {
1144 std::unique_lock<std::mutex> sentry(
file->fWriteMutex);
1166 return nBytes>0 ?
fKeylen+nout : -1;
1180 entryOffset[idx] -= entryOffset[idx - 1];
1190 entryOffset[idx] += entryOffset[idx - 1];
1193 }
else if (!hasOffsetBit) {
1203 Int_t lbuf, nout, noutot, bufmax, nzip;
1216 Warning(
"WriteBuffer",
"Unable to allocate the compressed buffer");
1225 for (
Int_t i = 0; i < nbuffers; ++i) {
1226 if (i == nbuffers - 1) bufmax =
fObjlen - nzip;
1227 else bufmax = kMAXZIPBUF;
1237 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
1245 if (nout == 0 || nout >=
fObjlen) {
1255 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",
1262 objbuf += kMAXZIPBUF;
1283 return nBytes>0 ?
fKeylen+nout : -1;
#define R__unlikely(expr)
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
R__EXTERN TVirtualMutex * gROOTMutex
void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout)
int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout)
#define R__LOCKGUARD_IMT(mutex)
static struct mg_connection * fc(struct mg_context *ctx)
Manages buffers for branches of a Tree.
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_t fOwnsCompressedBuffer
! Whether or not we own the compressed buffer.
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
Bool_t CanGenerateOffsetArray()
Determine whether we can generate the offset array when this branch is read.
Bool_t fHeaderOnly
True when only the basket header must be read/written.
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.
TBasket()
Default contructor.
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=0)
Load basket buffers in memory without unziping.
Bool_t fResetAllocation
! True if last reset re-allocated the memory
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
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.
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.
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
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.
Bool_t fReadEntryOffset
!Set to true if offset array was read from a file.
virtual ~TBasket()
Basket destructor.
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)
virtual void WriteReset()
Reset the write basket to the starting state.
A TTree is a list of TBranches.
Int_t GetCompressionLevel() const
Int_t GetCompressionAlgorithm() const
Int_t GetWriteBasket() const
virtual void SetEntryOffsetLen(Int_t len, Bool_t updateSubBranches=kFALSE)
Update the default value for the branch's fEntryOffsetLen if and only if it was already non zero (and...
Int_t GetMaxBaskets() const
Int_t * GetBasketBytes() const
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...
Long64_t GetTotBytes(Option_t *option="") const
Return total number of bytes in the branch (excluding current buffer) if option ="*" includes all sub...
virtual Int_t GetBasketSize() const
Long64_t GetZipBytes(Option_t *option="") const
Return total number of zip bytes in the branch if option ="*" includes all sub-branches of this branc...
TObjArray * GetListOfLeaves()
TDirectory * GetDirectory() const
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TBranch for reading/writing baskets.
Int_t GetEntryOffsetLen() const
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Buffer base class used for serializing objects.
void SetWriteMode()
Set buffer in write mode.
void SetParent(TObject *parent)
Set parent owning this buffer.
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
virtual void WriteArray(const Bool_t *b, Int_t n)=0
virtual Int_t ReadArray(Bool_t *&b)=0
void SetBuffer(void *buf, UInt_t bufsiz=0, Bool_t adopt=kTRUE, ReAllocCharFun_t reallocfunc=0)
Sets a new buffer in an existing TBuffer object.
void SetBufferOffset(Int_t offset=0)
void SetReadMode()
Set buffer in read mode.
virtual void SetBufferDisplacement()=0
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 ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
TBuffer * fBufferRef
Pointer to the TBuffer object.
Int_t fVersion
Key version identifier.
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
Short_t fKeylen
Number of bytes for the key itself.
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
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 object on file.
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.
TDirectory * fMotherDir
!pointer to mother directory
TString fClassName
Object Class name.
TBuffer * GetBufferRef() const
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual Bool_t CanGenerateOffsetArray()
virtual Int_t * GenerateOffsetArray(Int_t base, Int_t events)
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetName() const
Returns name of object.
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
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
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.
Float_t GetTargetMemoryRatio() const
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TTree for reading/writing baskets.
Provides the interface for the PROOF internal performance measurement and event tracing.
static constexpr double us
Short_t Max(Short_t a, Short_t b)
EValues
Note: this is only temporarily a struct and will become a enum class hence the name.