148 return nBytes>0 ? nBytes : -1;
192 Error(
"GetCalculatedEntryOffset",
"Basket entry offset calculation requested, but no associated TBranch!");
196 Error(
"GetCalculatedEntryOffset",
"Branch contains multiple leaves - unable to calculated entry offsets!");
224 if (entryOffset) offset = entryOffset[entry];
261 }
else if (st == 0) {
304 if (dentries >=
fNevBuf)
return;
310 bufbegin = entryOffset[dentries];
321 entryOffset[i] = entryOffset[i + dentries] - moved;
337 char *buffer = buf->
Buffer();
343 #define OLD_CASE_EXPRESSION fObjlen==fNbytes-fKeylen && GetBranch()->GetCompressionLevel()!=0 && file->GetVersion()<=30401 406 if (curBufferSize < len) {
461 char *rawUncompressedBuffer, *rawCompressedBuffer;
462 Int_t uncompressedBufferLen;
473 char *buffer =
nullptr;
479 if (len <= 0)
return -len;
499 if (!readBufferRef) {
500 Error(
"ReadBasketBuffers",
"Unable to allocate buffer.");
514 }
else if (st == 0) {
541 Streamer(*readBufferRef);
546 rawCompressedBuffer = readBufferRef->
Buffer();
559 Error(
"ReadBasketBuffers",
"Unable to allocate buffer.");
575 fBuffer = rawUncompressedBuffer;
590 memcpy(rawUncompressedBuffer, rawCompressedBuffer, fKeylen);
591 char *rawUncompressedObjectBuffer = rawUncompressedBuffer+
fKeylen;
592 UChar_t *rawCompressedObjectBuffer = (
UChar_t*)rawCompressedBuffer+fKeylen;
594 Int_t nout = 0, noutot = 0, nintot = 0;
600 Error(
"ReadBasketBuffers",
"Inconsistency found in header (nin=%d, nbuf=%d)", nin, nbuf);
605 memcpy(rawUncompressedBuffer+fKeylen, rawCompressedObjectBuffer+fKeylen,
fObjlen);
609 R__unzip(&nin, rawCompressedObjectBuffer, &nbuf, (
unsigned char*) rawUncompressedObjectBuffer, &nout);
614 rawCompressedObjectBuffer += nin;
615 rawUncompressedObjectBuffer += nout;
620 Error(
"ReadBasketBuffers",
"fNbytes = %d, fKeylen = %d, fObjlen = %d, noutot = %d, nout=%d, nin=%d, nbuf=%d",
fNbytes,fKeylen,
fObjlen, noutot,nout,nin,nbuf);
633 memcpy(rawUncompressedBuffer, rawCompressedBuffer, len);
654 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);
688 const Int_t len = 128;
711 if (curSize > 2*curLen)
714 if (curSize > 2*curBsize ) {
716 if (curSize > 2*avgSize) {
718 if (curLen > newSize) {
721 if (avgSize > newSize) {
724 newSize = newSize + 512 - newSize%512;
745 if (newNevBufSize==0) {
805 static std::atomic<Int_t> nerrors(0);
821 if (fNevBufSize < 0) {
824 if (!fIOBits || (fIOBits & (1 << 7))) {
825 Error(
"TBasket::Streamer",
826 "The value of fNevBufSize (%d) or fIOBits (%d) is incorrect ; setting the buffer to a zombie.",
827 -fNevBufSize, fIOBits);
833 Error(
"Streamer",
"The value of fIOBits (%s) contains unknown flags (supported flags " 834 "are %s), indicating this was written with a newer version of ROOT " 835 "utilizing critical IO features this version of ROOT does not support." 836 " Refusing to deserialize.",
837 std::bitset<32>(static_cast<Int_t>(fIOBits)).to_string().c_str(),
839 }
else if (nerrors == 10) {
840 Error(
"Streamer",
"Maximum number of errors has been reported; disabling further messages" 841 "from this location until the process exits.");
850 if (fLast > fBufferSize) fBufferSize =
fLast;
851 Bool_t mustGenerateOffsets =
false;
852 if (flag && (flag >= 80)) {
853 mustGenerateOffsets =
true;
856 if (!mustGenerateOffsets && flag && (flag % 10 != 2)) {
860 if (20<flag && flag<40) {
869 }
else if (mustGenerateOffsets) {
875 if (flag == 1 || flag > 10) {
912 flag = mustGenerateOffsets ? 80 : 0;
926 if (mustGenerateOffsets) {
991 const Int_t kWrite = 1;
1006 std::unique_lock<std::mutex> sentry(file->
fWriteMutex);
1007 #endif // R__USE_IMT 1028 return nBytes>0 ? fKeylen+nout : -1;
1042 entryOffset[idx] -= entryOffset[idx - 1];
1052 entryOffset[idx] += entryOffset[idx - 1];
1055 }
else if (!hasOffsetBit) {
1065 Int_t lbuf, nout, noutot, bufmax, nzip;
1078 Warning(
"WriteBuffer",
"Unable to allocate the compressed buffer");
1087 for (
Int_t i = 0; i < nbuffers; ++i) {
1088 if (i == nbuffers - 1) bufmax =
fObjlen - nzip;
1089 else bufmax = kMAXZIPBUF;
1095 #endif // R__USE_IMT 1099 R__zipMultipleAlgorithm(cxlevel, &bufmax, objbuf, &bufmax, bufcur, &nout, cxAlgorithm);
1102 #endif // R__USE_IMT 1107 if (nout == 0 || nout >=
fObjlen) {
1116 if ((nout+fKeylen)>buflen) {
1117 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",
1124 objbuf += kMAXZIPBUF;
1145 return nBytes>0 ? fKeylen+nout : -1;
Int_t fVersion
Key version identifier.
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
virtual const char * GetName() const
Returns name of object.
void SetBufferOffset(Int_t offset=0)
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Bool_t fHeaderOnly
True when only the basket header must be read/written.
Bool_t fReadEntryOffset
!Set to true if offset array was read from a file.
virtual void SetReadMode()
Set read mode of basket.
void Update(Int_t newlast)
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
Int_t ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
Read basket buffers in memory and cleanup.
virtual Int_t GetBasketSize() const
Int_t * fDisplacement
![fNevBuf] Displacement of entries in fBuffer(TKey)
virtual void IncrementTotalBuffers(Int_t nbytes)
virtual Int_t * GenerateOffsetArray(Int_t base, Int_t events)
Provides the interface for the PROOF internal performance measurement and event tracing.
Int_t GetCompressionLevel() const
A cache when reading files over the network.
TObject * GetParent() const
Return pointer to parent of this buffer.
Int_t fBufferSize
fBuffer length in bytes
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Int_t * fEntryOffset
[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime.
virtual void SetName(const char *name)
Set the name of the TNamed.
A specialized TFileCacheRead object for a TTree.
TBranch * fBranch
Pointer to the basket support branch.
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read a buffer from the file.
Buffer base class used for serializing objects.
TDirectory * GetDirectory() const
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
R__EXTERN TVirtualMutex * gROOTMutex
void SetParent(TObject *parent)
Set parent owning this buffer.
Int_t GetCompressionAlgorithm() const
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
Int_t fNevBuf
Number of entries in basket.
char * fBuffer
Object buffer.
Int_t GetEntryOffsetLen() const
TDirectory * fMotherDir
!pointer to mother directory
TBuffer * GetBufferRef() const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Long64_t GetTotBytes(Option_t *option="") const
Return total number of bytes in the branch (excluding current buffer) if option ="*" includes all sub...
static struct mg_connection * fc(struct mg_context *ctx)
virtual void WriteArray(const Bool_t *b, Int_t n)=0
std::mutex fWriteMutex
!Lock for writing baskets / keys into the file.
virtual TVirtualPerfStats * GetPerfStats() const
virtual void Reset()
Reset the basket to the starting state.
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
Write the encoded object supported by this key.
int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout)
Short_t fKeylen
Number of bytes for the key itself.
TString fClassName
Object Class name.
Bool_t CanGenerateOffsetArray()
Determine whether we can generate the offset array when this branch is read.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
void InitializeCompressedBuffer(Int_t len, TFile *file)
Initialize the compressed buffer; either from the TTree or create a local one.
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
ECompressionAlgorithm
The global settings depend on a global variable named R__ZipMode which can be modified by a global fu...
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.
UChar_t fIOBits
!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless nee...
Bool_t fOwnsCompressedBuffer
! Whether or not we own the compressed buffer.
virtual void AddNoCacheReadCalls(Int_t reads)
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
Int_t ReadBasketBuffersUncompressedCase()
By-passing buffer unzipping has been requested and is possible (only 1 entry in this basket)...
Int_t GetWriteBasket() const
virtual Bool_t CanGenerateOffsetArray()
Int_t GetEntryPointer(Int_t Entry)
Get pointer to buffer for internal entry.
#define OLD_CASE_EXPRESSION
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Manages buffers for branches of a Tree.
TBuffer * fCompressedBufferRef
! Compressed buffer.
void SetReadMode()
Set buffer in read mode.
virtual void Reset()
Reset the key as it had not been 'filled' yet.
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TBranch for reading/writing baskets.
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
TBuffer * fBufferRef
Pointer to the TBuffer object.
Int_t fNevBufSize
Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null! ...
Long64_t fSeekKey
Location of object on file.
Short_t fCycle
Cycle number.
Describe directory structure in memory.
The TTimeStamp encapsulates seconds and ns since EPOCH.
static TBuffer * R__InitializeReadBasketBuffer(TBuffer *bufferRef, Int_t len, TFile *file)
Initialize a buffer for reading if it is not already initialized.
TObjArray * GetListOfLeaves()
virtual ~TBasket()
Basket destructor.
void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout)
Int_t fObjlen
Length of uncompressed object in bytes.
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
virtual Int_t GetUnzipBuffer(char **, Long64_t, Int_t, Bool_t *)
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...
virtual void DeleteEntryOffset()
Delete fEntryOffset array.
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TTree for reading/writing baskets.
virtual Int_t DropBuffers()
Drop buffers of this basket if it is not the current basket.
#define R__unlikely(expr)
Short_t Max(Short_t a, Short_t b)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Int_t fLast
Pointer to last used byte in basket.
Int_t * GetCalculatedEntryOffset()
Calculates the entry offset array, if possible.
virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len)
Read buffer at position pos.
TFileCacheRead * GetCacheRead(TObject *tree=0) const
Return a pointer to the current read cache.
Int_t fNbytes
Number of bytes for the object on file.
A TTree object has a header with a name and a title.
Long64_t CopyTo(TFile *to)
Copy the basket of this branch onto the file to.
#define R__LOCKGUARD_IMT2(mutex)
const UInt_t kDisplacementMask
Bool_t IsWritable() 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...
virtual void SetBufferDisplacement()=0
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.
A TTree is a list of TBranches.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
TBasket()
Default contructor.
virtual void SetWriteMode()
Set write mode of basket.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
void SetWriteMode()
Set buffer in write mode.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=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.
virtual Int_t ReadArray(Bool_t *&b)=0
virtual void AddNoCacheBytesRead(Long64_t len)
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=0)
Load basket buffers in memory without unziping.
virtual void MoveEntries(Int_t dentries)
Remove the first dentries of this basket, moving entries at dentries to the start of the buffer...