Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBasket.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id: 4e77188fbf1e7fd026a984989de66663c49b12fc $
2// Author: Rene Brun 19/01/96
3/*************************************************************************
4 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include <chrono>
12
13#include "TBasket.h"
14#include "TBuffer.h"
15#include "TBufferFile.h"
16#include "TTree.h"
17#include "TBranch.h"
18#include "TFile.h"
19#include "TLeaf.h"
20#include "TMath.h"
21#include "TROOT.h"
22#include "TTreeCache.h"
23#include "TVirtualMutex.h"
24#include "TVirtualPerfStats.h"
25#include "TTimeStamp.h"
26#include "ROOT/TIOFeatures.hxx"
27#include "RZip.h"
28
29#include <bitset>
30
31const UInt_t kDisplacementMask = 0xFF000000; // In the streamer the two highest bytes of
32 // the fEntryOffset are used to stored displacement.
33
34
35/** \class TBasket
36\ingroup tree
37
38Manages buffers for branches of a Tree.
39
40See picture in TTree.
41*/
42
43////////////////////////////////////////////////////////////////////////////////
44/// Default constructor.
45
49
50////////////////////////////////////////////////////////////////////////////////
51/// Constructor used during reading.
52
56
57////////////////////////////////////////////////////////////////////////////////
58/// Basket normal constructor, used during writing.
59
60TBasket::TBasket(const char *name, const char *title, TBranch *branch)
61 : TKey(branch->GetDirectory()), fBufferSize(branch->GetBasketSize()), fNevBufSize(branch->GetEntryOffsetLen()),
62 fHeaderOnly(true), fIOBits(branch->GetIOFeatures().GetFeatures())
63{
65 SetTitle(title);
66 fClassName = "TBasket";
67 fBuffer = nullptr;
69 fVersion += 1000;
70 if (branch->GetDirectory()) {
71 TFile *file = branch->GetFile();
72 fBufferRef->SetParent(file);
73 }
74 if (branch->GetTree()) {
75#ifdef R__USE_IMT
76 fCompressedBufferRef = branch->GetTransientBuffer(fBufferSize);
77#else
78 fCompressedBufferRef = branch->GetTree()->GetTransientBuffer(fBufferSize);
79#endif
84 }
85 }
90 fLast = fKeylen;
91 fBuffer = nullptr;
92 fHeaderOnly = false;
93 if (fNevBufSize) {
95 for (Int_t i=0;i<fNevBufSize;i++) fEntryOffset[i] = 0;
96 }
97 branch->GetTree()->IncrementTotalBuffers(fBufferSize);
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Basket destructor.
102
104{
105 if (fDisplacement) delete [] fDisplacement;
107 if (fBufferRef) delete fBufferRef;
108 fBufferRef = nullptr;
109 fBuffer = nullptr;
110 fDisplacement= nullptr;
111 // Note we only delete the compressed buffer if we own it
114 fCompressedBufferRef = nullptr;
115 }
116 // TKey::~TKey will use fMotherDir to attempt to remove they key
117 // from the directory's list of key. A basket is never in that list
118 // and in some cases (eg. f = new TFile(); TTree t; delete f;) the
119 // directory is gone before the TTree.
120 fMotherDir = nullptr;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Increase the size of the current fBuffer up to newsize.
125
141
142////////////////////////////////////////////////////////////////////////////////
143/// Copy the basket of this branch onto the file to.
144
146{
150 Create(nout, to);
152 fHeaderOnly = true;
154 fHeaderOnly = false;
156
157 return nBytes>0 ? nBytes : -1;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Delete fEntryOffset array.
162
168
169////////////////////////////////////////////////////////////////////////////////
170/// Drop buffers of this basket if it is not the current basket.
171
173{
174 if (!fBuffer && !fBufferRef) return 0;
175
176 if (fDisplacement) delete [] fDisplacement;
178 if (fBufferRef) delete fBufferRef;
180 fBufferRef = nullptr;
181 fCompressedBufferRef = nullptr;
182 fBuffer = nullptr;
183 fDisplacement= nullptr;
184 fEntryOffset = nullptr;
186 return fBufferSize;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Calculates the entry offset array, if possible.
191///
192/// Result is cached, meaning that this should only be invoked once per basket.
193
195{
196 if (fEntryOffset != reinterpret_cast<Int_t *>(-1)) {
197 return fEntryOffset;
198 }
199
200 if (R__unlikely(!fBranch)) {
201 Error("GetCalculatedEntryOffset", "Basket entry offset calculation requested, but no associated TBranch!");
202 return nullptr;
203 }
204 if (R__unlikely(fBranch->GetNleaves() != 1)) {
205 Error("GetCalculatedEntryOffset", "Branch contains multiple leaves - unable to calculated entry offsets!");
206 return nullptr;
207 }
208 TLeaf *leaf = static_cast<TLeaf *>((*fBranch->GetListOfLeaves())[0]);
209 fEntryOffset = leaf->GenerateOffsetArray(fKeylen, fNevBuf);
210 return fEntryOffset;
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Determine whether we can generate the offset array when this branch is read.
215///
216
218{
219 if (fBranch->GetNleaves() != 1) {
220 return false;
221 }
222 TLeaf *leaf = static_cast<TLeaf *>((*fBranch->GetListOfLeaves())[0]);
223 return leaf->CanGenerateOffsetArray();
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Get pointer to buffer for internal entry.
228
238
239////////////////////////////////////////////////////////////////////////////////
240/// Load basket buffers in memory without unziping.
241/// This function is called by TTreeCloner.
242/// The function returns 0 in case of success, 1 in case of error.
243
245{
246 if (fBufferRef) {
247 // Reuse the buffer if it exist.
248 fBufferRef->Reset();
249
250 // We use this buffer both for reading and writing, we need to
251 // make sure it is properly sized for writing.
253 if (fBufferRef->BufferSize() < len) {
255 }
257 } else {
259 }
260 fBufferRef->SetParent(file);
261 char *buffer = fBufferRef->Buffer();
262 file->Seek(pos);
263 TFileCacheRead *pf = tree->GetReadCache(file);
264 if (pf) {
266 if (tree->GetPerfStats()) gPerfStats = tree->GetPerfStats();
267 Int_t st = pf->ReadBuffer(buffer,pos,len);
268 if (st < 0) {
269 return 1;
270 } else if (st == 0) {
271 // fOffset might have been changed via TFileCacheRead::ReadBuffer(), reset it
272 file->Seek(pos);
273 // If we are using a TTreeCache, disable reading from the default cache
274 // temporarily, to force reading directly from file
275 TTreeCache *fc = dynamic_cast<TTreeCache*>(file->GetCacheRead());
276 if (fc) fc->Disable();
277 Int_t ret = file->ReadBuffer(buffer,len);
278 if (fc) fc->Enable();
279 pf->AddNoCacheBytesRead(len);
280 pf->AddNoCacheReadCalls(1);
281 if (ret) {
282 return 1;
283 }
284 }
285 gPerfStats = temp;
286 // fOffset might have been changed via TFileCacheRead::ReadBuffer(), reset it
287 file->SetOffset(pos + len);
288 } else {
290 if (tree->GetPerfStats() != nullptr) gPerfStats = tree->GetPerfStats();
291 if (file->ReadBuffer(buffer,len)) {
292 gPerfStats = temp;
293 return 1; //error while reading
294 }
295 else gPerfStats = temp;
296 }
297
301
302 return 0;
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Remove the first dentries of this basket, moving entries at
307/// dentries to the start of the buffer.
308
310{
311 Int_t i;
312
313 if (dentries >= fNevBuf) return;
315 Int_t moved;
316
318 if (entryOffset) {
321
322 // First store the original location in the fDisplacement array
323 // and record the new start offset
324
325 if (!fDisplacement) {
327 }
328 for (i = 0; i<(fNevBufSize-dentries); ++i) {
331 }
332 for (i = fNevBufSize-dentries; i<fNevBufSize; ++i) {
333 fDisplacement[i] = 0;
334 entryOffset[i] = 0;
335 }
336
337 } else {
338 // If there is no EntryOffset array, this means
339 // that each entry has the same size and that
340 // it does not point to other objects (hence there
341 // is no need for a displacement array).
344 }
345 TBuffer *buf = GetBufferRef();
346 char *buffer = buf->Buffer();
347 memmove(buffer+GetKeylen(),buffer+bufbegin,buf->Length()-bufbegin);
348 buf->SetBufferOffset(buf->Length()-moved);
349 fNevBuf -= dentries;
350}
351
352#define OLD_CASE_EXPRESSION fObjlen==fNbytes-fKeylen && GetBranch()->GetCompressionLevel()!=0 && file->GetVersion()<=30401
353////////////////////////////////////////////////////////////////////////////////
354/// By-passing buffer unzipping has been requested and is
355/// possible (only 1 entry in this basket).
356
358{
360
361 // Make sure that the buffer is set at the END of the data
363
364 // Indicate that this buffer is weird.
366
367 // Usage of this mode assume the existence of only ONE
368 // entry in this basket.
370 delete [] fDisplacement; fDisplacement = nullptr;
371
373 return 0;
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// We always create the TBuffer for the basket but it hold the buffer from the cache.
378
380{
381 if (fBufferRef) {
384 fBufferRef->Reset();
385 } else {
387 }
388 fBufferRef->SetParent(file);
389
391
392 if (IsZombie()) {
393 return -1;
394 }
395
397
400 }
401
403 return fObjlen+fKeylen;
404}
405
406////////////////////////////////////////////////////////////////////////////////
407/// Initialize a buffer for reading if it is not already initialized
408
410{
412 if (R__likely(bufferRef)) {
413 bufferRef->SetReadMode();
414 Int_t curBufferSize = bufferRef->BufferSize();
415 if (curBufferSize < len) {
416 // Experience shows that giving 5% "wiggle-room" decreases churn.
417 bufferRef->Expand(Int_t(len*1.05));
418 }
419 bufferRef->Reset();
421 } else {
423 }
424 result->SetParent(file);
425 return result;
426}
427
428////////////////////////////////////////////////////////////////////////////////
429/// Initialize the compressed buffer; either from the TTree or create a local one.
430
439
441{
442 if (fEntryOffset != reinterpret_cast<Int_t *>(-1)) {
443 delete[] fEntryOffset;
444 }
445 fEntryOffset = nullptr;
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Read basket buffers in memory and cleanup.
450///
451/// Read a basket buffer. Check if buffers of previous ReadBasket
452/// should not be dropped. Remember, we keep buffers in memory up to
453/// fMaxVirtualSize.
454/// The function returns 0 in case of success, 1 in case of error
455/// This function was modified with the addition of the parallel
456/// unzipping, it will try to get the unzipped file from the cache
457/// receiving only a pointer to that buffer (so we shall not
458/// delete that pointer), although we get a new buffer in case
459/// it's not found in the cache.
460/// There is a lot of code duplication but it was necessary to assure
461/// the expected behavior when there is no cache.
462
464{
465 if(!fBranch->GetDirectory()) {
466 return -1;
467 }
468
469 bool oldCase;
472
473 // See if the cache has already unzipped the buffer for us.
474 TFileCacheRead *pf = nullptr;
475 {
476 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
477 pf = fBranch->GetTree()->GetReadCache(file);
478 }
479 if (pf) {
480 Int_t res = -1;
481 bool free = true;
482 char *buffer = nullptr;
483 res = pf->GetUnzipBuffer(&buffer, pos, len, &free);
484 if (R__unlikely(res >= 0)) {
485 len = ReadBasketBuffersUnzip(buffer, res, free, file);
486 // Note that in the kNotDecompressed case, the above function will return 0;
487 // In such a case, we should stop processing
488 if (len <= 0) return -len;
489 goto AfterBuffer;
490 }
491 }
492
493 // Determine which buffer to use, so that we can avoid a memcpy in case of
494 // the basket was not compressed.
497 // Initialize the buffer to hold the uncompressed data.
500 } else {
501 // Initialize the buffer to hold the compressed data.
504 }
505
506 // fBufferSize is likely to be change in the Streamer call (below)
507 // and we will re-add the new size later on.
509
510 if (!readBufferRef) {
511 Error("ReadBasketBuffers", "Unable to allocate buffer.");
512 return 1;
513 }
514
515 if (pf) {
517 if (fBranch->GetTree()->GetPerfStats() != nullptr) gPerfStats = fBranch->GetTree()->GetPerfStats();
518 Int_t st = 0;
519 {
520 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
521 st = pf->ReadBuffer(readBufferRef->Buffer(),pos,len);
522 }
523 if (st < 0) {
524 return 1;
525 } else if (st == 0) {
526 // Read directly from file, not from the cache
527 // If we are using a TTreeCache, disable reading from the default cache
528 // temporarily, to force reading directly from file
529 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
530 TTreeCache *fc = dynamic_cast<TTreeCache*>(file->GetCacheRead());
531 if (fc) fc->Disable();
532 Int_t ret = file->ReadBuffer(readBufferRef->Buffer(),pos,len);
533 if (fc) fc->Enable();
534 pf->AddNoCacheBytesRead(len);
535 pf->AddNoCacheReadCalls(1);
536 if (ret) {
537 return 1;
538 }
539 }
540 gPerfStats = temp;
541 } else {
542 // Read from the file and unstream the header information.
544 if (fBranch->GetTree()->GetPerfStats() != nullptr) gPerfStats = fBranch->GetTree()->GetPerfStats();
545 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
546 if (file->ReadBuffer(readBufferRef->Buffer(),pos,len)) {
547 gPerfStats = temp;
548 return 1;
549 }
550 else gPerfStats = temp;
551 }
553 if (IsZombie()) {
554 return 1;
555 }
556
558
559 // Are we done?
560 if (R__unlikely(readBufferRef == fBufferRef)) // We expect most basket to be compressed.
561 {
563 // The basket was really not compressed as expected.
564 goto AfterBuffer;
565 } else {
566 // Well, somehow the buffer was compressed anyway, we have the compressed data in the uncompressed buffer
567 // Make sure the compressed buffer is initialized, and memcpy.
570 Error("ReadBasketBuffers", "Unable to allocate buffer.");
571 return 1;
572 }
573 fBufferRef->Reset();
576 }
577 }
578
579 // Initialize buffer to hold the uncompressed data
580 // Note that in previous versions we didn't allocate buffers until we verified
581 // the zip headers; this is no longer beforehand as the buffer lifetime is scoped
582 // to the TBranch.
587
589 // Case where ROOT thinks the buffer is compressed. Copy over the key and uncompress the object
590 if (fObjlen > fNbytes-fKeylen || oldCase) {
593 }
594
595 // Optional monitor for zip time profiling.
596 Double_t start = 0;
597 if (R__unlikely(gPerfStats)) {
598 start = TTimeStamp();
599 }
600
604 Int_t nin, nbuf;
605 Int_t nout = 0, noutot = 0, nintot = 0;
606
607 // Unzip all the compressed objects in the compressed object buffer.
608 while (true) {
609 // Check the header for errors.
611 Error("ReadBasketBuffers", "Inconsistency found in header (nin=%d, nbuf=%d)", nin, nbuf);
612 break;
613 }
614 if (R__unlikely(oldCase && (nin > fObjlen || nbuf > fObjlen))) {
615 //buffer was very likely not compressed in an old version
617 goto AfterBuffer;
618 }
619
621 if (!nout) break;
622 noutot += nout;
623 nintot += nin;
624 if (noutot >= fObjlen) break;
627 }
628
629 // Make sure the uncompressed numbers are consistent with header.
630 if (R__unlikely(noutot != fObjlen)) {
631 Error("ReadBasketBuffers", "fNbytes = %d, fKeylen = %d, fObjlen = %d, noutot = %d, nout=%d, nin=%d, nbuf=%d", fNbytes,fKeylen,fObjlen, noutot,nout,nin,nbuf);
633 return 1;
634 }
637 if (fBranch->GetTree()->GetPerfStats() != nullptr) gPerfStats = fBranch->GetTree()->GetPerfStats();
638 if (R__unlikely(gPerfStats)) {
639 gPerfStats->UnzipEvent(fBranch->GetTree(),pos,start,nintot,fObjlen);
640 }
641 gPerfStats = temp;
642 } else {
643 // Nothing is compressed - copy over wholesale.
645 }
646
648
650
651 // Read offsets table if needed.
652 // If there's no EntryOffsetLen in the branch -- or the fEntryOffset is marked to be calculated-on-demand --
653 // then we skip reading out.
654 if (!fBranch->GetEntryOffsetLen() || (fEntryOffset == reinterpret_cast<Int_t *>(-1))) {
655 return 0;
656 }
657 // At this point, we're required to read out an offset array.
658 ResetEntryOffset(); // TODO: every basket, we reset the offset array. Is this necessary?
659 // Could we instead switch to std::vector?
663 fEntryOffset = new Int_t[fNevBuf+1];
665 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);
666 return 0;
667 }
669 // In this case, we cannot regenerate the offset array at runtime -- but we wrote out an array of
670 // sizes instead of offsets (as sizes compress much better).
672 for (Int_t idx = 1; idx < fNevBuf + 1; idx++) {
673 fEntryOffset[idx] += fEntryOffset[idx - 1];
674 }
675 }
676 fReadEntryOffset = true;
677 // Read the array of displacement if any.
678 delete [] fDisplacement;
679 fDisplacement = nullptr;
680 if (fBufferRef->Length() != len) {
681 // There is more data in the buffer! It is the displacement
682 // array. If len is less than TBuffer::kMinimalSize the actual
683 // size of the buffer is too large, so we can not use the
684 // fBufferRef->BufferSize()
686 }
687
688 return 0;
689}
690
691////////////////////////////////////////////////////////////////////////////////
692/// Read basket buffers in memory and cleanup
693///
694/// Read first bytes of a logical record starting at position pos
695/// return record length (first 4 bytes of record).
696
698{
699 const Int_t len = 128;
700 char buffer[len];
702 file->GetRecordHeader(buffer, pos,len, fNbytes, fObjlen, keylen);
703 fKeylen = keylen;
704 return fNbytes;
705}
706
707////////////////////////////////////////////////////////////////////////////////
708/// Disown all references to the internal buffer - some other object likely now
709/// owns it.
710///
711/// This TBasket is now useless and invalid until it is told to adopt a buffer.
713{
714 fBufferRef = nullptr;
715}
716
717
718////////////////////////////////////////////////////////////////////////////////
719/// Adopt a buffer from an external entity
725
726////////////////////////////////////////////////////////////////////////////////
727/// Reset the read basket TBuffer memory allocation if needed.
728///
729/// This allows to reduce the number of memory allocation while avoiding to
730/// always use the maximum size.
731
733{
734 // By default, we don't reallocate.
735 fResetAllocation = false;
736#ifdef R__TRACK_BASKET_ALLOC_TIME
738#endif
739
740 // Downsize the buffer if needed.
741
742 const auto maxbaskets = fBranch->GetMaxBaskets();
744 return;
745
747
749 const auto basketbytes = fBranch->GetBasketBytes();
750
751 Int_t max_size = basketbytes[basketnumber];
752 for(Int_t b = basketnumber + 1; (b < maxbaskets) && (b < (basketnumber+10)); ++b) {
753 max_size = std::max(max_size, basketbytes[b]);
754 }
755
756 Float_t cx = 1;
757 if (fBranch->GetZipBytes())
759
760 Int_t target_size = static_cast<Int_t>(cx * target_mem_ratio * Float_t(max_size));
761
762 if (target_size && (curSize > target_size)) {
763 /// Only reduce the size if significant enough?
764 Int_t newSize = max_size + 512 - max_size % 512; // Wiggle room and alignment, as above.
765 // We only bother with a resize if it saves 8KB (two normal memory pages).
766 if ((newSize <= curSize - 8 * 1024) &&
767 (static_cast<Float_t>(curSize) / static_cast<Float_t>(newSize) > target_mem_ratio))
768 {
769 if (gDebug > 0) {
770 Info("ReadResetBuffer",
771 "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 ",
783 cx, target_mem_ratio, max_size);
784 }
785 fResetAllocation = true;
786#ifdef R__TRACK_BASKET_ALLOC_TIME
787 std::chrono::time_point<std::chrono::system_clock> start, end;
788 start = std::chrono::high_resolution_clock::now();
789#endif
790 fBufferRef->Expand(newSize, false); // Expand without copying the existing data.
791#ifdef R__TRACK_BASKET_ALLOC_TIME
792 end = std::chrono::high_resolution_clock::now();
793 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
794 fResetAllocationTime = us.count();
795#endif
796 }
797 }
798}
799
800////////////////////////////////////////////////////////////////////////////////
801/// Reset the write basket to the starting state. i.e. as it was after calling
802/// the constructor (and potentially attaching a TBuffer.)
803/// Reduce memory used by fEntryOffset and the TBuffer if needed ..
804
806{
807 // By default, we don't reallocate.
808 fResetAllocation = false;
809#ifdef R__TRACK_BASKET_ALLOC_TIME
811#endif
812
813 // Name, Title, fClassName, fBranch
814 // stay the same.
815
816 // Downsize the buffer if needed.
817 // See if our current buffer size is significantly larger (>2x) than the historical average.
818 // If so, try decreasing it at this flush boundary to closer to the size from OptimizeBaskets
819 // (or this historical average).
821 // fBufferLen at this point is already reset, so use indirect measurements
823 Longptr_t newSize = -1;
824 if (curSize > 2*curLen)
825 {
827 if (curSize > 2*curBsize ) {
828 Longptr_t avgSize = (Longptr_t)(fBranch->GetTotBytes() / (1+fBranch->GetWriteBasket())); // Average number of bytes per basket so far
829 if (curSize > 2*avgSize) {
831 if (curLen > newSize) {
832 newSize = curLen;
833 }
834 if (avgSize > newSize) {
836 }
837 newSize = newSize + 512 - newSize%512; // Wiggle room and alignment (512 is same as in OptimizeBaskets)
838 }
839 }
840 }
841 // If fBufferRef grew since we last saw it, shrink it to "target memory ratio" of the occupied size
842 // This discourages us from having poorly-occupied buffers on branches with little variability.
843 //
844 // Does not help protect against a burst in event sizes, but does help in the cases where the basket
845 // size jumps from 4MB to 8MB while filling the basket, but we only end up utilizing 4.1MB.
846 //
847 // The above code block is meant to protect against extremely large events.
848
851 Int_t target_size = static_cast<Int_t>(target_mem_ratio * Float_t(max_size));
852 if (max_size && (curSize > target_size) && (newSize == -1)) {
854 newSize = newSize + 512 - newSize % 512; // Wiggle room and alignment, as above.
855 // We only bother with a resize if it saves 8KB (two normal memory pages).
856 if ((newSize > curSize - 8 * 1024) ||
857 (static_cast<Float_t>(curSize) / static_cast<Float_t>(newSize) < target_mem_ratio)) {
858 newSize = -1;
859 } else if (gDebug > 0) {
860 Info("Reset", "Resizing to %ld bytes (was %d); last three sizes were [%d, %d, %d].", newSize, curSize,
862 }
863 }
864
865 if (newSize != -1) {
866 fResetAllocation = true;
867#ifdef R__TRACK_BASKET_ALLOC_TIME
868 std::chrono::time_point<std::chrono::system_clock> start, end;
869 start = std::chrono::high_resolution_clock::now();
870#endif
871 fBufferRef->Expand(newSize,false); // Expand without copying the existing data.
872#ifdef R__TRACK_BASKET_ALLOC_TIME
873 end = std::chrono::high_resolution_clock::now();
874 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
875 fResetAllocationTime = us.count();
876#endif
877 }
878
879 // Record the actual occupied size of the buffer.
882
883 TKey::Reset();
884
886 if (newNevBufSize==0) {
888 } else if ((newNevBufSize != fNevBufSize) || (fEntryOffset <= reinterpret_cast<Int_t *>(-1))) {
891 }
893
894 fNevBuf = 0;
896 fEntryOffset = nullptr;
898 fDisplacement= nullptr;
899 fBuffer = nullptr;
900
901 fBufferRef->Reset();
903
904 fHeaderOnly = true;
905 fLast = 0; //Must initialize before calling Streamer()
906
908
911 fLast = fKeylen;
912 fBuffer = nullptr;
913 fHeaderOnly = false;
916 if (fNevBufSize) {
917 for (Int_t i=0;i<fNevBufSize;i++) fEntryOffset[i] = 0;
918 }
919}
920
921////////////////////////////////////////////////////////////////////////////////
922/// Set read mode of basket.
923
929
930////////////////////////////////////////////////////////////////////////////////
931/// Set write mode of basket.
932
938
939////////////////////////////////////////////////////////////////////////////////
940/// Stream a class object.
941
943{
944 // As in TBranch::GetBasket, this is used as a half-hearted measure to suppress
945 // the error reporting when many failures occur.
946 static std::atomic<Int_t> nerrors(0);
947
948 char flag;
949 if (b.IsReading()) {
950 TKey::Streamer(b); //this must be first
951 Version_t v = b.ReadVersion();
952 b >> fBufferSize;
953 // NOTE: we now use the upper-bit of the fNevBufSize to see if we have serialized any of the
954 // optional IOBits. If that bit is set, we immediately read out the IOBits; to replace this
955 // (minimal) safeguard against corruption, we will set aside the upper-bit of fIOBits to do
956 // the same thing (the fact this bit is reserved is tested in the unit tests). If there is
957 // someday a need for more than 7 IOBits, we'll widen the field using the same trick.
958 //
959 // We like to keep this safeguard because we immediately will allocate a buffer based on
960 // the value of fNevBufSize -- and would like to avoid wildly inappropriate allocations.
961 b >> fNevBufSize;
962 if (fNevBufSize < 0) {
964 b >> fIOBits;
965 if (!fIOBits || (fIOBits & (1 << 7))) {
966 Error("TBasket::Streamer",
967 "The value of fNevBufSize (%d) or fIOBits (%d) is incorrect ; setting the buffer to a zombie.",
969 MakeZombie();
970 fNevBufSize = 0;
971 } else if (fIOBits && (fIOBits & ~static_cast<Int_t>(EIOBits::kSupported))) {
972 nerrors++;
973 if (nerrors < 10) {
974 Error("Streamer", "The value of fIOBits (%s) contains unknown flags (supported flags "
975 "are %s), indicating this was written with a newer version of ROOT "
976 "utilizing critical IO features this version of ROOT does not support."
977 " Refusing to deserialize.",
978 std::bitset<32>(static_cast<Int_t>(fIOBits)).to_string().c_str(),
979 std::bitset<32>(static_cast<Int_t>(EIOBits::kSupported)).to_string().c_str());
980 } else if (nerrors == 10) {
981 Error("Streamer", "Maximum number of errors has been reported; disabling further messages"
982 "from this location until the process exits.");
983 }
984 fNevBufSize = 0;
985 MakeZombie();
986 }
987 }
988 b >> fNevBuf;
989 b >> fLast;
990 b >> flag;
992 bool mustGenerateOffsets = false;
993 if (flag >= 80) {
994 mustGenerateOffsets = true;
995 flag -= 80;
996 }
997 if (!mustGenerateOffsets && flag && (flag % 10 != 2)) {
1000 if (fNevBuf) b.ReadArray(fEntryOffset);
1001 if (20<flag && flag<40) {
1002 for(int i=0; i<fNevBuf; i++){
1004 }
1005 }
1006 if (flag>40) {
1008 b.ReadArray(fDisplacement);
1009 }
1010 } else if (mustGenerateOffsets) {
1011 // We currently believe that in all cases when offsets can be generated, then the
1012 // displacement array must be zero.
1013 assert(flag <= 40);
1014 fEntryOffset = reinterpret_cast<Int_t *>(-1);
1015 }
1016 if (flag == 1 || flag > 10) {
1018 fBufferRef->SetParent(b.GetParent());
1019 char *buf = fBufferRef->Buffer();
1020 if (v > 1) b.ReadFastArray(buf,fLast);
1021 else b.ReadArray(buf);
1023 // This is now done in the TBranch streamer since fBranch might not
1024 // yet be set correctly.
1025 // fBranch->GetTree()->IncrementTotalBuffers(fBufferSize);
1026 }
1027 } else {
1028
1029 TKey::Streamer(b); //this must be first
1030 b.WriteVersion(TBasket::IsA());
1031 if (fBufferRef) {
1033 if (!fHeaderOnly && !fSeekKey && curLast > fLast) fLast = curLast;
1034 }
1036
1037 b << fBufferSize;
1038 if (fIOBits) {
1039 b << -fNevBufSize;
1040 b << fIOBits;
1041 } else {
1042 b << fNevBufSize;
1043 }
1044 b << fNevBuf;
1045 b << fLast;
1049 // We currently believe that in all cases when offsets can be generated, then the
1050 // displacement array must be zero.
1052 if (fHeaderOnly) {
1053 flag = mustGenerateOffsets ? 80 : 0;
1054 b << flag;
1055 } else {
1056 // On return from this function, we are guaranteed that fEntryOffset
1057 // is either a valid pointer or nullptr.
1058 if (fNevBuf) {
1060 }
1061 flag = 1;
1062 if (!fNevBuf || !fEntryOffset)
1063 flag = 2;
1064 if (fBufferRef) flag += 10;
1065 if (fDisplacement) flag += 40;
1066 // Test if we can skip writing out the offset map.
1067 if (mustGenerateOffsets) {
1068 flag += 80;
1069 }
1070 b << flag;
1071
1073 b.WriteArray(fEntryOffset, fNevBuf);
1074 if (fDisplacement) b.WriteArray(fDisplacement, fNevBuf);
1075 }
1076 if (fBufferRef) {
1077 char *buf = fBufferRef->Buffer();
1078 b.WriteFastArray(buf, fLast);
1079 }
1080 }
1081 }
1082}
1083
1084////////////////////////////////////////////////////////////////////////////////
1085/// Update basket header and EntryOffset table.
1086
1088{
1090 if (entryOffset) {
1091 if (fNevBuf+1 >= fNevBufSize) {
1094 fNevBufSize);
1095 if (fDisplacement) {
1097 fNevBufSize);
1099 }
1102
1103 //Update branch only for the first 10 baskets
1104 if (fBranch->GetWriteBasket() < 10) {
1106 }
1107 }
1109
1110 if (skipped!=offset && !fDisplacement){
1112 for (Int_t i = 0; i<fNevBufSize; i++) fDisplacement[i] = fEntryOffset[i];
1113 }
1114 if (fDisplacement) {
1117 }
1118 }
1119
1120 fNevBuf++;
1121}
1122
1123////////////////////////////////////////////////////////////////////////////////
1124/// Write buffer of this basket on the current file.
1125///
1126/// The function returns the number of bytes committed to the memory.
1127/// If a write error occurs, the number of bytes returned is -1.
1128/// If no data are written, the number of bytes returned is 0.
1129
1131{
1132 constexpr Int_t kWrite = 1;
1133
1134 TFile *file = fBranch->GetFile(kWrite);
1135 if (!file) return 0;
1136 if (!file->IsWritable()) {
1137 return -1;
1138 }
1139 fMotherDir = file; // fBranch->GetDirectory();
1140
1141 // This mutex prevents multiple TBasket::WriteBuffer invocations from interacting
1142 // with the underlying TFile at once - TFile is assumed to *not* be thread-safe.
1143 //
1144 // The only parallelism we'd like to exploit (right now!) is the compression
1145 // step - everything else should be serialized at the TFile level.
1146#ifdef R__USE_IMT
1147 std::unique_lock<std::mutex> sentry(file->fWriteMutex);
1148#endif // R__USE_IMT
1149
1151 // Read the basket information that was saved inside the buffer.
1152 bool writing = fBufferRef->IsWriting();
1155
1159
1161
1162 Create(nout,file);
1164 fHeaderOnly = true;
1165
1166 Streamer(*fBufferRef); //write key itself again
1168 fHeaderOnly = false;
1169 return nBytes>0 ? fKeylen+nout : -1;
1170 }
1171
1172 // Transfer fEntryOffset table at the end of fBuffer.
1173 fLast = fBufferRef->Length();
1175 if (entryOffset) {
1177 if (!CanGenerateOffsetArray()) {
1178 // If we have set the offset map flag, but cannot dynamically generate the map, then
1179 // we should at least convert the offset array to a size array. Note that we always
1180 // write out (fNevBuf+1) entries to match the original case.
1181 if (hasOffsetBit) {
1182 for (Int_t idx = fNevBuf; idx > 0; idx--) {
1183 entryOffset[idx] -= entryOffset[idx - 1];
1184 }
1185 entryOffset[0] = 0;
1186 }
1188 // Convert back to offset format: keeping both sizes and offsets in-memory were considered,
1189 // but it seems better to use CPU than memory.
1190 if (hasOffsetBit) {
1191 entryOffset[0] = fKeylen;
1192 for (Int_t idx = 1; idx < fNevBuf + 1; idx++) {
1193 entryOffset[idx] += entryOffset[idx - 1];
1194 }
1195 }
1196 } else if (!hasOffsetBit) { // In this case, write out as normal
1198 }
1199 if (fDisplacement) {
1201 delete[] fDisplacement;
1202 fDisplacement = nullptr;
1203 }
1204 }
1205
1206 Int_t nout, noutot, bufmax, nzip;
1207
1209
1210 fHeaderOnly = true;
1214 cxlevel = file->GetCompressionLevel();
1218 if (cxlevel > 0) {
1219 Int_t nbuffers = 1 + (fObjlen - 1) / kMAXZIPBUF;
1220 Int_t buflen = fKeylen + fObjlen + 9 * nbuffers + 28; //add 28 bytes in case object is placed in a deleted gap
1221 InitializeCompressedBuffer(buflen, file);
1222 if (!fCompressedBufferRef) {
1223 Warning("WriteBuffer", "Unable to allocate the compressed buffer");
1224 return -1;
1225 }
1228 char *objbuf = fBufferRef->Buffer() + fKeylen;
1229 char *bufcur = &fBuffer[fKeylen];
1230 noutot = 0;
1231 nzip = 0;
1232 for (Int_t i = 0; i < nbuffers; ++i) {
1233 if (i == nbuffers - 1) bufmax = fObjlen - nzip;
1234 else bufmax = kMAXZIPBUF;
1235 // Compress the buffer. Note that we allow multiple TBasket compressions to occur at once
1236 // for a given TFile: that's because the compression buffer when we use IMT is no longer
1237 // shared amongst several threads.
1238#ifdef R__USE_IMT
1239 sentry.unlock();
1240#endif // R__USE_IMT
1241 // NOTE this is declared with C linkage, so it shouldn't except. Also, when
1242 // USE_IMT is defined, we are guaranteed that the compression buffer is unique per-branch.
1243 // (see fCompressedBufferRef in constructor).
1245#ifdef R__USE_IMT
1246 sentry.lock();
1247#endif // R__USE_IMT
1248
1249 // test if buffer has really been compressed. In case of small buffers
1250 // when the buffer contains random data, it may happen that the compressed
1251 // buffer is larger than the input. In this case, we write the original uncompressed buffer
1252 if (nout == 0 || nout >= fObjlen) {
1253 nout = fObjlen;
1254 // We used to delete fBuffer here, we no longer want to since
1255 // the buffer (held by fCompressedBufferRef) might be re-used later.
1257 Create(fObjlen,file);
1259
1260 Streamer(*fBufferRef); //write key itself again
1261 if ((nout+fKeylen)>buflen) {
1262 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",
1263 (nout+fKeylen-buflen),buflen,fNbytes,fObjlen,fKeylen);
1264 }
1265 goto WriteFile;
1266 }
1267 bufcur += nout;
1268 noutot += nout;
1269 objbuf += kMAXZIPBUF;
1270 nzip += kMAXZIPBUF;
1271 }
1272 nout = noutot;
1273 Create(noutot,file);
1275
1276 Streamer(*fBufferRef); //write key itself again
1278 } else {
1280 Create(fObjlen,file);
1282
1283 Streamer(*fBufferRef); //write key itself again
1284 nout = fObjlen;
1285 }
1286
1287WriteFile:
1289 fHeaderOnly = false;
1290 return nBytes>0 ? fKeylen+nout : -1;
1291}
#define R__likely(expr)
Definition RConfig.hxx:595
#define R__unlikely(expr)
Definition RConfig.hxx:594
#define b(i)
Definition RSha256.hxx:100
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
static TBuffer * R__InitializeReadBasketBuffer(TBuffer *bufferRef, Int_t len, TFile *file)
Initialize a buffer for reading if it is not already initialized.
Definition TBasket.cxx:409
#define OLD_CASE_EXPRESSION
Definition TBasket.cxx:352
const UInt_t kDisplacementMask
Definition TBasket.cxx:31
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
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)
#define gPerfStats
Int_t * fEntryOffset
[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime.
Definition TBasket.h:71
Int_t GetEntryPointer(Int_t Entry)
Get pointer to buffer for internal entry.
Definition TBasket.cxx:229
void AdoptBuffer(TBuffer *user_buffer)
Adopt a buffer from an external entity.
Definition TBasket.cxx:720
bool fHeaderOnly
True when only the basket header must be read/written.
Definition TBasket.h:66
TBranch * fBranch
Pointer to the basket support branch.
Definition TBasket.h:73
Long64_t CopyTo(TFile *to)
Copy the basket of this branch onto the file to.
Definition TBasket.cxx:145
Int_t * GetEntryOffset()
Definition TBasket.h:124
void InitializeCompressedBuffer(Int_t len, TFile *file)
Initialize the compressed buffer; either from the TTree or create a local one.
Definition TBasket.cxx:431
UChar_t fNextBufferSizeRecord
! Index into fLastWriteBufferSize of the last buffer written to disk
Definition TBasket.h:77
Int_t ReadBasketBuffersUnzip(char *, Int_t, bool, TFile *)
We always create the TBuffer for the basket but it hold the buffer from the cache.
Definition TBasket.cxx:379
void DisownBuffer()
Disown all references to the internal buffer - some other object likely now owns it.
Definition TBasket.cxx:712
Int_t fLastWriteBufferSize[3]
! Size of the buffer last three buffers we wrote it to disk
Definition TBasket.h:75
Int_t ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
Read basket buffers in memory and cleanup.
Definition TBasket.cxx:463
UChar_t fIOBits
!IO feature flags. Serialized in custom portion of streamer to avoid forward compat issues unless nee...
Definition TBasket.h:67
virtual Int_t DropBuffers()
Drop buffers of this basket if it is not the current basket.
Definition TBasket.cxx:172
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:309
bool fOwnsCompressedBuffer
! Whether or not we own the compressed buffer.
Definition TBasket.h:68
void ResetEntryOffset()
Definition TBasket.cxx:440
TBasket()
Default constructor.
Definition TBasket.cxx:46
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
Definition TBasket.cxx:126
virtual void SetReadMode()
Set read mode of basket.
Definition TBasket.cxx:924
virtual void SetWriteMode()
Set write mode of basket.
Definition TBasket.cxx:933
Int_t ReadBasketBuffersUncompressedCase()
By-passing buffer unzipping has been requested and is possible (only 1 entry in this basket).
Definition TBasket.cxx:357
Int_t fBufferSize
fBuffer length in bytes
Definition TBasket.h:62
bool fReadEntryOffset
!Set to true if offset array was read from a file.
Definition TBasket.h:69
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
Definition TBasket.cxx:697
virtual void ReadResetBuffer(Int_t basketnumber)
Reset the read basket TBuffer memory allocation if needed.
Definition TBasket.cxx:732
bool fResetAllocation
! True if last reset re-allocated the memory
Definition TBasket.h:76
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
Definition TBasket.cxx:1130
void Streamer(TBuffer &) override
Stream a class object.
Definition TBasket.cxx:942
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=nullptr)
Load basket buffers in memory without unziping.
Definition TBasket.cxx:244
~TBasket() override
Basket destructor.
Definition TBasket.cxx:103
void Update(Int_t newlast)
Definition TBasket.h:152
Int_t fNevBufSize
Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
Definition TBasket.h:63
Int_t fNevBuf
Number of entries in basket.
Definition TBasket.h:64
Int_t * GetCalculatedEntryOffset()
Calculates the entry offset array, if possible.
Definition TBasket.cxx:194
TClass * IsA() const override
Definition TBasket.h:156
virtual void DeleteEntryOffset()
Delete fEntryOffset array.
Definition TBasket.cxx:163
TBuffer * fCompressedBufferRef
! Compressed buffer.
Definition TBasket.h:74
Int_t fLast
Pointer to last used byte in basket.
Definition TBasket.h:65
Int_t * fDisplacement
![fNevBuf] Displacement of entries in fBuffer(TKey)
Definition TBasket.h:70
bool CanGenerateOffsetArray()
Determine whether we can generate the offset array when this branch is read.
Definition TBasket.cxx:217
virtual void WriteReset()
Reset the write basket to the starting state.
Definition TBasket.cxx:805
A TTree is a list of TBranches.
Definition TBranch.h:93
Int_t GetCompressionLevel() const
Definition TBranch.h:305
Int_t GetCompressionAlgorithm() const
Definition TBranch.h:299
TTree * GetTree() const
Definition TBranch.h:252
Int_t GetWriteBasket() const
Definition TBranch.h:238
Int_t GetNleaves() const
Definition TBranch.h:249
virtual void SetEntryOffsetLen(Int_t len, bool updateSubBranches=false)
Update the default value for the branch's fEntryOffsetLen if and only if it was already non zero (and...
Definition TBranch.cxx:2833
Int_t GetMaxBaskets() const
Definition TBranch.h:248
Int_t * GetBasketBytes() const
Definition TBranch.h:214
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...
Definition TBranch.cxx:1852
Long64_t GetTotBytes(Option_t *option="") const
Return total number of bytes in the branch (excluding current buffer) if option ="*" includes all sub...
Definition TBranch.cxx:2219
virtual Int_t GetBasketSize() const
Definition TBranch.h:217
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...
Definition TBranch.cxx:2237
TObjArray * GetListOfLeaves()
Definition TBranch.h:247
TDirectory * GetDirectory() const
Definition TBranch.h:224
Int_t GetEntryOffsetLen() const
Definition TBranch.h:227
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
@ kNotDecompressed
Definition TBufferIO.h:66
Buffer base class used for serializing objects.
Definition TBuffer.h:43
void SetWriteMode()
Set buffer in write mode.
Definition TBuffer.cxx:314
virtual void Reset()=0
void SetParent(TObject *parent)
Set parent owning this buffer.
Definition TBuffer.cxx:269
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
Definition TBuffer.cxx:222
Int_t BufferSize() const
Definition TBuffer.h:98
virtual void WriteArray(const Bool_t *b, Int_t n)=0
virtual Int_t ReadArray(Bool_t *&b)=0
@ kWrite
Definition TBuffer.h:73
@ kRead
Definition TBuffer.h:73
Bool_t IsWriting() const
Definition TBuffer.h:87
void SetBuffer(void *buf, UInt_t bufsize=0, Bool_t adopt=kTRUE, ReAllocCharFun_t reallocfunc=nullptr)
Sets a new buffer in an existing TBuffer object.
Definition TBuffer.cxx:186
void SetBufferOffset(Int_t offset=0)
Definition TBuffer.h:93
void SetReadMode()
Set buffer in read mode.
Definition TBuffer.cxx:301
virtual void SetBufferDisplacement()=0
Int_t Length() const
Definition TBuffer.h:100
char * Buffer() const
Definition TBuffer.h:96
Bool_t IsWritable() const override
Describe directory structure in memory.
Definition TDirectory.h:45
A cache when reading files over the network.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
Definition TFile.cxx:2304
Int_t GetCompressionLevel() const
Definition TFile.h:474
std::mutex fWriteMutex
!Lock for writing baskets / keys into the file.
Definition TFile.h:197
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition TFile.cxx:2283
Int_t GetCompressionAlgorithm() const
Definition TFile.h:468
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.
Definition TFile.cxx:1290
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read a buffer from the file.
Definition TFile.cxx:1800
TFileCacheRead * GetCacheRead(const TObject *tree=nullptr) const
Return a pointer to the current read cache.
Definition TFile.cxx:1251
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
Int_t GetKeylen() const
Definition TKey.h:84
Int_t GetObjlen() const
Definition TKey.h:87
TBuffer * fBufferRef
Pointer to the TBuffer object.
Definition TKey.h:50
Int_t fVersion
Key version identifier.
Definition TKey.h:39
Short_t fKeylen
Number of bytes for the key itself.
Definition TKey.h:43
virtual Int_t WriteFileKeepBuffer(TFile *f=nullptr)
Write the encoded object supported by this key.
Definition TKey.cxx:1491
Long64_t fSeekKey
Location of object on file.
Definition TKey.h:45
char * fBuffer
Object buffer.
Definition TKey.h:49
Int_t fNbytes
Number of bytes for the object on file.
Definition TKey.h:40
Int_t fObjlen
Length of uncompressed object in bytes.
Definition TKey.h:41
void Reset()
Reset the key as it had not been 'filled' yet.
Definition TKey.cxx:1306
Short_t fCycle
Cycle number.
Definition TKey.h:44
virtual void Create(Int_t nbytes, TFile *f=nullptr)
Create a TKey object of specified size.
Definition TKey.cxx:461
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=nullptr)
Write the encoded object supported by this key.
Definition TKey.cxx:1459
TDirectory * fMotherDir
!pointer to mother directory
Definition TKey.h:52
TString fClassName
Object Class name.
Definition TKey.h:47
void Streamer(TBuffer &) override
Stream a class object.
Definition TKey.cxx:1362
TBuffer * GetBufferRef() const
Definition TKey.h:79
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:159
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
void MakeZombie()
Definition TObject.h:53
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition TStorage.cxx:257
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:45
A cache to speed-up the reading of ROOT datasets.
Definition TTreeCache.h:32
A TTree represents a columnar dataset.
Definition TTree.h:89
virtual TVirtualPerfStats * GetPerfStats() const
Definition TTree.h:585
virtual void IncrementTotalBuffers(Int_t nbytes)
Definition TTree.h:625
TTreeCache * GetReadCache(TFile *file) const
Find and return the TTreeCache registered with the file and which may contain branches for us.
Definition TTree.cxx:6399
Float_t GetTargetMemoryRatio() const
Definition TTree.h:599
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.
Definition TMathBase.h:251
EValues
Note: this is only temporarily a struct and will become a enum class hence the name convention used.
Definition Compression.h:88
@ kInherit
Some objects use this value to denote that the compression algorithm should be inherited from the par...
Definition Compression.h:91
@ kInherit
Some objects use this value to denote that the compression algorithm should be inherited from the par...
Definition Compression.h:68