Logo ROOT  
Reference Guide
TBranch.cxx
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Rene Brun 12/01/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TBranchCacheInfo.h"
13 
14 #include "TBranch.h"
15 
16 #include "Bytes.h"
17 #include "Compression.h"
18 #include "TBasket.h"
19 #include "TBranchBrowsable.h"
20 #include "TBrowser.h"
21 #include "TBuffer.h"
22 #include "TClass.h"
23 #include "TBufferFile.h"
24 #include "TClonesArray.h"
25 #include "TFile.h"
26 #include "TLeaf.h"
27 #include "TLeafB.h"
28 #include "TLeafC.h"
29 #include "TLeafD.h"
30 #include "TLeafD32.h"
31 #include "TLeafF.h"
32 #include "TLeafF16.h"
33 #include "TLeafI.h"
34 #include "TLeafL.h"
35 #include "TLeafG.h"
36 #include "TLeafO.h"
37 #include "TLeafObject.h"
38 #include "TLeafS.h"
39 #include "TMessage.h"
40 #include "TROOT.h"
41 #include "TSystem.h"
42 #include "TMath.h"
43 #include "TTree.h"
44 #include "TTreeCache.h"
45 #include "TTreeCacheUnzip.h"
46 #include "TVirtualMutex.h"
47 #include "TVirtualPad.h"
48 #include "TVirtualPerfStats.h"
49 #include "strlcpy.h"
50 #include "snprintf.h"
51 
52 #include "TBranchIMTHelper.h"
53 
54 #include "ROOT/TIOFeatures.hxx"
55 
56 #include <atomic>
57 #include <cstddef>
58 #include <cstring>
59 #include <cstdio>
60 
61 
63 
64 /** \class TBranch
65 \ingroup tree
66 
67 A TTree is a list of TBranches
68 
69 A TBranch supports:
70  - The list of TLeaf describing this branch.
71  - The list of TBasket (branch buffers).
72 
73 See TBranch structure in TTree.
74 
75 See also specialized branches:
76  - TBranchObject in case the branch is one object
77  - TBranchClones in case the branch is an array of clone objects
78 */
79 
81 
82 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Default constructor. Used for I/O by default.
86 
88 : TNamed()
89 , TAttFill(0, 1001)
90 , fCompress(0)
91 , fBasketSize(32000)
92 , fEntryOffsetLen(1000)
93 , fWriteBasket(0)
94 , fEntryNumber(0)
95 , fExtraBasket(nullptr)
96 , fOffset(0)
97 , fMaxBaskets(10)
98 , fNBaskets(0)
99 , fSplitLevel(0)
100 , fNleaves(0)
101 , fReadBasket(0)
102 , fReadEntry(-1)
103 , fFirstBasketEntry(-1)
104 , fNextBasketEntry(-1)
105 , fCurrentBasket(0)
106 , fEntries(0)
107 , fFirstEntry(0)
108 , fTotBytes(0)
109 , fZipBytes(0)
110 , fBranches()
111 , fLeaves()
112 , fBaskets(fMaxBaskets)
113 , fBasketBytes(0)
114 , fBasketEntry(0)
115 , fBasketSeek(0)
116 , fTree(0)
117 , fMother(0)
118 , fParent(0)
119 , fAddress(0)
120 , fDirectory(0)
121 , fFileName("")
122 , fEntryBuffer(0)
123 , fTransientBuffer(0)
124 , fBrowsables(0)
125 , fBulk(*this)
126 , fSkipZip(kFALSE)
127 , fReadLeaves(&TBranch::ReadLeavesImpl)
128 , fFillLeaves(&TBranch::FillLeavesImpl)
129 {
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Create a Branch as a child of a Tree
135 ///
136 /// * address is the address of the first item of a structure
137 /// or the address of a pointer to an object (see example in TTree.cxx).
138 /// * leaflist is the concatenation of all the variable names and types
139 /// separated by a colon character :
140 /// The variable name and the variable type are separated by a
141 /// slash (/). The variable type must be 1 character. (Characters
142 /// after the first are legal and will be appended to the visible
143 /// name of the leaf, but have no effect.) If no type is given, the
144 /// type of the variable is assumed to be the same as the previous
145 /// variable. If the first variable does not have a type, it is
146 /// assumed of type F by default. The list of currently supported
147 /// types is given below:
148 /// - `C` : a character string terminated by the 0 character
149 /// - `B` : an 8 bit signed integer (`Char_t`)
150 /// - `b` : an 8 bit unsigned integer (`UChar_t`)
151 /// - `S` : a 16 bit signed integer (`Short_t`)
152 /// - `s` : a 16 bit unsigned integer (`UShort_t`)
153 /// - `I` : a 32 bit signed integer (`Int_t`)
154 /// - `i` : a 32 bit unsigned integer (`UInt_t`)
155 /// - `F` : a 32 bit floating point (`Float_t`)
156 /// - `f` : a 24 bit floating point with truncated mantissa (`Float16_t`)
157 /// - `D` : a 64 bit floating point (`Double_t`)
158 /// - `d` : a 24 bit truncated floating point (`Double32_t`)
159 /// - `L` : a 64 bit signed integer (`Long64_t`)
160 /// - `l` : a 64 bit unsigned integer (`ULong64_t`)
161 /// - `G` : a long signed integer, stored as 64 bit (`Long_t`)
162 /// - `g` : a long unsigned integer, stored as 64 bit (`ULong_t`)
163 /// - `O` : [the letter `o`, not a zero] a boolean (`Bool_t`)
164 ///
165 /// Arrays of values are supported with the following syntax:
166 /// - If leaf name has the form var[nelem], where nelem is alphanumeric, then
167 /// if nelem is a leaf name, it is used as the variable size of the array,
168 /// otherwise return 0.
169 /// The leaf referred to by nelem **MUST** be an int (/I),
170 /// - If leaf name has the form var[nelem], where nelem is a non-negative integers, then
171 /// it is used as the fixed size of the array.
172 /// - If leaf name has the form of a multi dimension array (e.g. var[nelem][nelem2])
173 /// where nelem and nelem2 are non-negative integers) then
174 /// it is used as a 2 dimensional array of fixed size.
175 /// - In case of the truncated floating point types (Float16_t and Double32_t) you can
176 /// furthermore specify the range in the style [xmin,xmax] or [xmin,xmax,nbits] after
177 /// the type character. See `TStreamerElement::GetRange()` for further information.
178 /// - Any of other form is not supported.
179 ///
180 /// Note that the TTree will assume that all the item are contiguous in memory.
181 /// On some platform, this is not always true of the member of a struct or a class,
182 /// due to padding and alignment. Sorting your data member in order of decreasing
183 /// sizeof usually leads to their being contiguous in memory.
184 ///
185 /// * bufsize is the buffer size in bytes for this branch
186 /// The default value is 32000 bytes and should be ok for most cases.
187 /// You can specify a larger value (e.g. 256000) if your Tree is not split
188 /// and each entry is large (Megabytes)
189 /// A small value for bufsize is optimum if you intend to access
190 /// the entries in the Tree randomly and your Tree is in split mode.
191 ///
192 /// See an example of a Branch definition in the TTree constructor.
193 ///
194 /// Note that in case the data type is an object, this branch can contain
195 /// only this object.
196 ///
197 /// Note that this function is invoked by TTree::Branch
198 
199 TBranch::TBranch(TTree *tree, const char *name, void *address, const char *leaflist, Int_t basketsize, Int_t compress)
200  : TNamed(name, leaflist)
201 , TAttFill(0, 1001)
202 , fCompress(compress)
203 , fBasketSize((basketsize < 100) ? 100 : basketsize)
204 , fEntryOffsetLen(0)
205 , fWriteBasket(0)
206 , fEntryNumber(0)
207 , fExtraBasket(nullptr)
208 , fIOFeatures(tree ? tree->GetIOFeatures().GetFeatures() : 0)
209 , fOffset(0)
210 , fMaxBaskets(10)
211 , fNBaskets(0)
212 , fSplitLevel(0)
213 , fNleaves(0)
214 , fReadBasket(0)
215 , fReadEntry(-1)
216 , fFirstBasketEntry(-1)
217 , fNextBasketEntry(-1)
218 , fCurrentBasket(0)
219 , fEntries(0)
220 , fFirstEntry(0)
221 , fTotBytes(0)
222 , fZipBytes(0)
223 , fBranches()
224 , fLeaves()
225 , fBaskets(fMaxBaskets)
226 , fBasketBytes(0)
227 , fBasketEntry(0)
228 , fBasketSeek(0)
229 , fTree(tree)
230 , fMother(0)
231 , fParent(0)
232 , fAddress((char *)address)
233 , fDirectory(fTree->GetDirectory())
234 , fFileName("")
235 , fEntryBuffer(0)
236 , fTransientBuffer(0)
237 , fBrowsables(0)
238 , fBulk(*this)
239 , fSkipZip(kFALSE)
240 , fReadLeaves(&TBranch::ReadLeavesImpl)
241 , fFillLeaves(&TBranch::FillLeavesImpl)
242 {
243  Init(name,leaflist,compress);
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 /// Create a Branch as a child of another Branch
248 ///
249 /// See documentation for
250 /// TBranch::TBranch(TTree *, const char *, void *, const char *, Int_t, Int_t)
251 
252 TBranch::TBranch(TBranch *parent, const char *name, void *address, const char *leaflist, Int_t basketsize,
253  Int_t compress)
254 : TNamed(name, leaflist)
255 , TAttFill(0, 1001)
256 , fCompress(compress)
257 , fBasketSize((basketsize < 100) ? 100 : basketsize)
258 , fEntryOffsetLen(0)
259 , fWriteBasket(0)
260 , fEntryNumber(0)
261 , fExtraBasket(nullptr)
262 , fIOFeatures(parent->fIOFeatures)
263 , fOffset(0)
264 , fMaxBaskets(10)
265 , fNBaskets(0)
266 , fSplitLevel(0)
267 , fNleaves(0)
268 , fReadBasket(0)
269 , fReadEntry(-1)
270 , fFirstBasketEntry(-1)
271 , fNextBasketEntry(-1)
272 , fCurrentBasket(0)
273 , fEntries(0)
274 , fFirstEntry(0)
275 , fTotBytes(0)
276 , fZipBytes(0)
277 , fBranches()
278 , fLeaves()
279 , fBaskets(fMaxBaskets)
280 , fBasketBytes(0)
281 , fBasketEntry(0)
282 , fBasketSeek(0)
283 , fTree(parent ? parent->GetTree() : 0)
284 , fMother(parent ? parent->GetMother() : 0)
285 , fParent(parent)
286 , fAddress((char *)address)
287 , fDirectory(fTree ? fTree->GetDirectory() : 0)
288 , fFileName("")
289 , fEntryBuffer(0)
290 , fTransientBuffer(0)
291 , fBrowsables(0)
292 , fBulk(*this)
293 , fSkipZip(kFALSE)
294 , fReadLeaves(&TBranch::ReadLeavesImpl)
295 , fFillLeaves(&TBranch::FillLeavesImpl)
296 {
297  Init(name,leaflist,compress);
298 }
299 
300 void TBranch::Init(const char* name, const char* leaflist, Int_t compress)
301 {
302  // Initialization routine called from the constructor. This should NOT be made virtual.
303 
305  if ((compress == -1) && fTree->GetDirectory()) {
306  TFile* bfile = fTree->GetDirectory()->GetFile();
307  if (bfile) {
309  }
310  }
311 
315 
316  for (Int_t i = 0; i < fMaxBaskets; ++i) {
317  fBasketBytes[i] = 0;
318  fBasketEntry[i] = 0;
319  fBasketSeek[i] = 0;
320  }
321 
322  //
323  // Decode the leaflist (search for : as separator).
324  //
325 
326  char* nameBegin = const_cast<char*>(leaflist);
327  Int_t offset = 0;
328  auto len = strlen(leaflist);
329  // FIXME: Make these string streams instead.
330  char* leafname = new char[len + 1];
331  char* leaftype = new char[320];
332  // Note: The default leaf type is a float.
333  strlcpy(leaftype, "F",320);
334  char* pos = const_cast<char*>(leaflist);
335  const char* leaflistEnd = leaflist + len;
336  for (; pos <= leaflistEnd; ++pos) {
337  // -- Scan leaf specification and create leaves.
338  if ((*pos == ':') || (*pos == 0)) {
339  // -- Reached end of a leaf spec, create a leaf.
340  Int_t lenName = pos - nameBegin;
341  char* ctype = 0;
342  if (lenName) {
343  strncpy(leafname, nameBegin, lenName);
344  leafname[lenName] = 0;
345  ctype = strstr(leafname, "/");
346  if (ctype) {
347  *ctype = 0;
348  strlcpy(leaftype, ctype + 1,320);
349  }
350  }
351  if (lenName == 0 || ctype == leafname) {
352  Warning("TBranch","No name was given to the leaf number '%d' in the leaflist of the branch '%s'.",fNleaves,name);
353  snprintf(leafname,640,"__noname%d",fNleaves);
354  }
355  TLeaf* leaf = 0;
356  if (leaftype[1] == '[' && !strchr(leaftype, ',')) {
357  Warning("TBranch", "Array size for branch '%s' must be specified after leaf name, not after the type name!", name);
358  // and continue for backward compatibility?
359  } else if (leaftype[1] && !strchr(leaftype, ',')) {
360  Warning("TBranch", "Extra characters after type tag '%s' for branch '%s'; must be one character.", leaftype, name);
361  // and continue for backward compatibility?
362  }
363  if (*leaftype == 'C') {
364  leaf = new TLeafC(this, leafname, leaftype);
365  } else if (*leaftype == 'O') {
366  leaf = new TLeafO(this, leafname, leaftype);
367  } else if (*leaftype == 'B') {
368  leaf = new TLeafB(this, leafname, leaftype);
369  } else if (*leaftype == 'b') {
370  leaf = new TLeafB(this, leafname, leaftype);
371  leaf->SetUnsigned();
372  } else if (*leaftype == 'S') {
373  leaf = new TLeafS(this, leafname, leaftype);
374  } else if (*leaftype == 's') {
375  leaf = new TLeafS(this, leafname, leaftype);
376  leaf->SetUnsigned();
377  } else if (*leaftype == 'I') {
378  leaf = new TLeafI(this, leafname, leaftype);
379  } else if (*leaftype == 'i') {
380  leaf = new TLeafI(this, leafname, leaftype);
381  leaf->SetUnsigned();
382  } else if (*leaftype == 'F') {
383  leaf = new TLeafF(this, leafname, leaftype);
384  } else if (*leaftype == 'f') {
385  leaf = new TLeafF16(this, leafname, leaftype);
386  } else if (*leaftype == 'L') {
387  leaf = new TLeafL(this, leafname, leaftype);
388  } else if (*leaftype == 'l') {
389  leaf = new TLeafL(this, leafname, leaftype);
390  leaf->SetUnsigned();
391  } else if (*leaftype == 'D') {
392  leaf = new TLeafD(this, leafname, leaftype);
393  } else if (*leaftype == 'd') {
394  leaf = new TLeafD32(this, leafname, leaftype);
395  } else if (*leaftype == 'G') {
396  leaf = new TLeafG(this, leafname, leaftype);
397  } else if (*leaftype == 'g') {
398  leaf = new TLeafG(this, leafname, leaftype);
399  leaf->SetUnsigned();
400  }
401  if (!leaf) {
402  Error("TLeaf", "Illegal data type for %s/%s", name, leaflist);
403  delete[] leaftype;
404  delete [] leafname;
405  MakeZombie();
406  return;
407  }
408  if (leaf->IsZombie()) {
409  delete leaf;
410  leaf = 0;
411  auto msg = "Illegal leaf: %s/%s. If this is a variable size C array it's possible that the branch holding the size is not available.";
412  Error("TBranch", msg, name, leaflist);
413  delete [] leafname;
414  delete[] leaftype;
415  MakeZombie();
416  return;
417  }
418  leaf->SetBranch(this);
419  leaf->SetAddress((char*) (fAddress + offset));
420  leaf->SetOffset(offset);
421  if (leaf->GetLeafCount()) {
422  // -- Leaf is a varying length array, we need an offset array.
423  fEntryOffsetLen = 1000;
424  }
425  if (leaf->InheritsFrom(TLeafC::Class())) {
426  // -- Leaf is a character string, we need an offset array.
427  fEntryOffsetLen = 1000;
428  }
429  ++fNleaves;
430  fLeaves.Add(leaf);
431  fTree->GetListOfLeaves()->Add(leaf);
432  if (*pos == 0) {
433  // -- We reached the end of the leaf specification.
434  break;
435  }
436  nameBegin = pos + 1;
437  offset += leaf->GetLenType() * leaf->GetLen();
438  }
439  }
440  delete[] leafname;
441  leafname = 0;
442  delete[] leaftype;
443  leaftype = 0;
444 
445 }
446 
447 ////////////////////////////////////////////////////////////////////////////////
448 /// Destructor.
449 
451 {
452  delete fBrowsables;
453  fBrowsables = 0;
454 
455  // Note: We do *not* have ownership of the buffer.
456  fEntryBuffer = 0;
457 
458  delete [] fBasketSeek;
459  fBasketSeek = 0;
460 
461  delete [] fBasketEntry;
462  fBasketEntry = 0;
463 
464  delete [] fBasketBytes;
465  fBasketBytes = 0;
466 
467  fBaskets.Delete();
468  fNBaskets = 0;
469  fCurrentBasket = 0;
470  fFirstBasketEntry = -1;
471  fNextBasketEntry = -1;
472 
473  // Remove our leaves from our tree's list of leaves.
474  if (fTree) {
475  TObjArray* lst = fTree->GetListOfLeaves();
476  if (lst && lst->GetLast()!=-1) {
477  lst->RemoveAll(&fLeaves);
478  }
479  }
480  // And delete our leaves.
481  fLeaves.Delete();
482 
483  fBranches.Delete();
484 
485  // If we are in a directory and that directory is not the same
486  // directory that our tree is in, then try to find an open file
487  // with the name fFileName. If we find one, delete that file.
488  // We are attempting to close any alternate file which we have
489  // been directed to write our baskets to.
490  // FIXME: We make no attempt to check if someone else might be
491  // using this file. This is very user hostile. A violation
492  // of the principle of least surprises.
493  //
494  // Warning. Must use FindObject by name instead of fDirectory->GetFile()
495  // because two branches may point to the same file and the file
496  // may have already been deleted in the previous branch.
497  if (fDirectory && (!fTree || fDirectory != fTree->GetDirectory())) {
498  TString bFileName( GetRealFileName() );
499 
501  TFile* file = (TFile*)gROOT->GetListOfFiles()->FindObject(bFileName);
502  if (file){
503  file->Close();
504  delete file;
505  file = 0;
506  }
507  }
508 
509  fTree = 0;
510  fDirectory = 0;
511 
512  if (fTransientBuffer) {
513  delete fTransientBuffer;
514  fTransientBuffer = 0;
515  }
516 }
517 
518 ////////////////////////////////////////////////////////////////////////////////
519 /// Returns the transient buffer currently used by this TBranch for reading/writing baskets.
520 
522 {
523  if (fTransientBuffer) {
524  if (fTransientBuffer->BufferSize() < size) {
525  fTransientBuffer->Expand(size);
526  }
527  return fTransientBuffer;
528  }
530  return fTransientBuffer;
531 }
532 
533 ////////////////////////////////////////////////////////////////////////////////
534 /// Add the basket to this branch.
535 ///
536 /// Warning: if the basket are not 'flushed/copied' in the same
537 /// order as they were created, this will induce a slow down in
538 /// the insert (since we'll need to move all the record that are
539 /// entere 'too early').
540 /// Warning we also assume that the __current__ write basket is
541 /// not present (aka has been removed).
542 
543 void TBranch::AddBasket(TBasket& b, Bool_t ondisk, Long64_t startEntry)
544 {
545  TBasket *basket = &b;
546 
547  basket->SetBranch(this);
548 
549  if (fWriteBasket >= fMaxBaskets) {
551  }
552  Int_t where = fWriteBasket;
553 
554  if (where && startEntry < fBasketEntry[where-1]) {
555  // Need to find the right location and move the possible baskets
556 
557  if (!ondisk) {
558  Warning("AddBasket","The assumption that out-of-order basket only comes from disk based ntuple is false.");
559  }
560 
561  if (startEntry < fBasketEntry[0]) {
562  where = 0;
563  } else {
564  for(Int_t i=fWriteBasket-1; i>=0; --i) {
565  if (fBasketEntry[i] < startEntry) {
566  where = i+1;
567  break;
568  } else if (fBasketEntry[i] == startEntry) {
569  Error("AddBasket","An out-of-order basket matches the entry number of an existing basket.");
570  }
571  }
572  }
573 
574  if (where < fWriteBasket) {
575  // We shall move the content of the array
576  for (Int_t j=fWriteBasket; j > where; --j) {
577  fBasketEntry[j] = fBasketEntry[j-1];
578  fBasketBytes[j] = fBasketBytes[j-1];
579  fBasketSeek[j] = fBasketSeek[j-1];
580  }
581  }
582  }
583  fBasketEntry[where] = startEntry;
584 
585  if (ondisk) {
586  fBasketBytes[where] = basket->GetNbytes(); // not for in mem
587  fBasketSeek[where] = basket->GetSeekKey(); // not for in mem
589  ++fWriteBasket;
590  } else {
591  ++fNBaskets;
594  }
595 
596  fEntries += basket->GetNevBuf();
597  fEntryNumber += basket->GetNevBuf();
598  if (ondisk) {
599  fTotBytes += basket->GetObjlen() + basket->GetKeylen() ;
600  fZipBytes += basket->GetNbytes();
601  fTree->AddTotBytes(basket->GetObjlen() + basket->GetKeylen());
602  fTree->AddZipBytes(basket->GetNbytes());
603  }
604 }
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 /// Add the start entry of the write basket (not yet created)
608 
610 {
611  if (fWriteBasket >= fMaxBaskets) {
613  }
614  Int_t where = fWriteBasket;
615 
616  if (where && startEntry < fBasketEntry[where-1]) {
617  // Need to find the right location and move the possible baskets
618 
619  Fatal("AddBasket","The last basket must have the highest entry number (%s/%lld/%d).",GetName(),startEntry,fWriteBasket);
620 
621  }
622  fBasketEntry[where] = startEntry;
624 }
625 
626 ////////////////////////////////////////////////////////////////////////////////
627 /// Loop on all leaves of this branch to back fill Basket buffer.
628 ///
629 /// Use this routine instead of TBranch::Fill when filling a branch individually
630 /// to catch up with the number of entries already in the TTree.
631 ///
632 /// First it calls TBranch::Fill and then if the number of entries of the branch
633 /// reach one of TTree cluster's boundary, the basket is flushed.
634 ///
635 /// The function returns the number of bytes committed to the memory basket.
636 /// If a write error occurs, the number of bytes returned is -1.
637 /// If no data are written, because e.g. the branch is disabled,
638 /// the number of bytes returned is 0.
639 ///
640 /// To insure that the baskets of each cluster are located close by in the
641 /// file, when back-filling multiple branches make sure to call BackFill
642 /// for the same entry for all the branches consecutively
643 /// ~~~ {.cpp}
644 /// for( auto e = 0; e < tree->GetEntries(); ++e ) { // loop over entries.
645 /// for( auto branch : branchCollection) {
646 /// ... Make change to the data associated with the branch ...
647 /// branch->BackFill();
648 /// }
649 /// }
650 /// // Since we loop over all the branches for each new entry
651 /// // all the baskets for a cluster are consecutive in the file.
652 /// ~~~
653 /// rather than doing all the entries of one branch at a time.
654 /// ~~~ {.cpp}
655 /// // Do NOT do things in the following order, it will lead to
656 /// // poorly clustered files.
657 /// for(auto branch : branchCollection) {
658 /// for( auto e = 0; e < tree->GetEntries(); ++e ) { // loop over entries.
659 /// ... Make change to the data associated with the branch ...
660 /// branch->BackFill();
661 /// }
662 /// }
663 /// // Since we loop over all the entries for one branch
664 /// // all the baskets for that branch are consecutive.
665 /// ~~~
666 
668 
669  // Get the end of the next cluster.
670  auto cluster = GetTree()->GetClusterIterator( GetEntries() );
671  cluster.Next();
672  auto endCluster = cluster.GetNextEntry();
673 
674  auto result = FillImpl(nullptr);
675 
676  if ( result && GetEntries() >= endCluster ) {
677  FlushBaskets();
678  }
679 
680  return result;
681 }
682 
683 ////////////////////////////////////////////////////////////////////////////////
684 /// Browser interface.
685 
687 {
688  if (fNleaves > 1) {
689  fLeaves.Browse(b);
690  } else {
691  // Get the name and strip any extra brackets
692  // in order to get the full arrays.
693  TString name = GetName();
694  Int_t pos = name.First('[');
695  if (pos!=kNPOS) name.Remove(pos);
696 
697  GetTree()->Draw(name, "", b ? b->GetDrawOption() : "");
698  if (gPad) gPad->Update();
699  }
700 }
701 
702  ///////////////////////////////////////////////////////////////////////////////
703  /// Loop on all branch baskets. If the file where branch buffers reside is
704  /// writable, free the disk space associated to the baskets of the branch,
705  /// then call Reset(). If the option contains "all", delete also the baskets
706  /// for the subbranches.
707  /// The branch is reset.
708  ///
709  /// NOTE that this function must be used with extreme care. Deleting branch baskets
710  /// fragments the file and may introduce inefficiencies when adding new entries
711  /// in the Tree or later on when reading the Tree.
712 
714 {
715  TString opt = option;
716  opt.ToLower();
717  TFile *file = GetFile(0);
718 
719  if(fDirectory && (fDirectory != gROOT) && fDirectory->IsWritable()) {
720  for(Int_t i=0; i<fWriteBasket; i++) {
721  if (fBasketSeek[i]) file->MakeFree(fBasketSeek[i],fBasketSeek[i]+fBasketBytes[i]-1);
722  }
723  }
724 
725  // process subbranches
726  if (opt.Contains("all")) {
728  Int_t nb = lb->GetEntriesFast();
729  for (Int_t j = 0; j < nb; j++) {
730  TBranch* branch = (TBranch*) lb->UncheckedAt(j);
731  if (branch) branch->DeleteBaskets("all");
732  }
733  }
734  DropBaskets("all");
735  Reset();
736 }
737 
738 ////////////////////////////////////////////////////////////////////////////////
739 /// Loop on all branch baskets. Drop all baskets from memory except readbasket.
740 /// If the option contains "all", drop all baskets including
741 /// read- and write-baskets (unless they are not stored individually on disk).
742 /// The option "all" also lead to DropBaskets being called on the sub-branches.
743 
745 {
746  Bool_t all = kFALSE;
747  if (options && options[0]) {
748  TString opt = options;
749  opt.ToLower();
750  if (opt.Contains("all")) all = kTRUE;
751  }
752 
753  TBasket *basket;
754  Int_t nbaskets = fBaskets.GetEntriesFast();
755 
756  if ( (fNBaskets>1) || all ) {
757  //slow case
758  for (Int_t i=0;i<nbaskets;i++) {
759  basket = (TBasket*)fBaskets.UncheckedAt(i);
760  if (!basket) continue;
761  if ((i == fReadBasket || i == fWriteBasket) && !all) continue;
762  // if the basket is not yet on file but already has event in it
763  // we must continue to avoid dropping the basket (and thus losing data)
764  if (fBasketBytes[i]==0 && basket->GetNevBuf() > 0) continue;
765  basket->DropBuffers();
766  --fNBaskets;
767  fBaskets.RemoveAt(i);
768  if (basket == fCurrentBasket) {
769  fCurrentBasket = 0;
770  fFirstBasketEntry = -1;
771  fNextBasketEntry = -1;
772  }
773  delete basket;
774  }
775 
776  // process subbranches
777  if (all) {
779  Int_t nb = lb->GetEntriesFast();
780  for (Int_t j = 0; j < nb; j++) {
781  TBranch* branch = (TBranch*) lb->UncheckedAt(j);
782  if (!branch) continue;
783  branch->DropBaskets("all");
784  }
785  }
786  } else {
787  //fast case
788  if (nbaskets > 0) {
789  Int_t i = fBaskets.GetLast();
790  basket = (TBasket*)fBaskets.UncheckedAt(i);
791  if (basket && fBasketBytes[i]!=0) {
792  basket->DropBuffers();
793  if (basket == fCurrentBasket) {
794  fCurrentBasket = 0;
795  fFirstBasketEntry = -1;
796  fNextBasketEntry = -1;
797  }
798  delete basket;
799  fBaskets.AddAt(0,i);
800  fBaskets.SetLast(-1);
801  fNBaskets = 0;
802  }
803  }
804  }
805 
806 }
807 
808 ////////////////////////////////////////////////////////////////////////////////
809 /// Increase BasketEntry buffer of a minimum of 10 locations
810 /// and a maximum of 50 per cent of current size.
811 
813 {
814  Int_t newsize = TMath::Max(10,Int_t(1.5*fMaxBaskets));
817  newsize*sizeof(Long64_t),fMaxBaskets*sizeof(Long64_t));
819  newsize*sizeof(Long64_t),fMaxBaskets*sizeof(Long64_t));
820 
821  fMaxBaskets = newsize;
822 
823  fBaskets.Expand(newsize);
824 
825  for (Int_t i=fWriteBasket;i<fMaxBaskets;i++) {
826  fBasketBytes[i] = 0;
827  fBasketEntry[i] = 0;
828  fBasketSeek[i] = 0;
829  }
830 }
831 
832 ////////////////////////////////////////////////////////////////////////////////
833 /// Loop on all leaves of this branch to fill Basket buffer.
834 ///
835 /// If TBranchIMTHelper is non-null and it is time to WriteBasket, then we will
836 /// use TBB to compress in parallel.
837 ///
838 /// The function returns the number of bytes committed to the memory basket.
839 /// If a write error occurs, the number of bytes returned is -1.
840 /// If no data are written, because e.g. the branch is disabled,
841 /// the number of bytes returned is 0.
842 
844 {
845  if (TestBit(kDoNotProcess)) {
846  return 0;
847  }
848 
850  if (!basket) {
851  basket = fTree->CreateBasket(this); // create a new basket
852  if (!basket) return 0;
853  ++fNBaskets;
855  }
856  TBuffer* buf = basket->GetBufferRef();
857 
858  // Fill basket buffer.
859 
860  Int_t nsize = 0;
861 
862  if (buf->IsReading()) {
863  basket->SetWriteMode();
864  }
865 
866  if (!TestBit(kDoNotUseBufferMap)) {
867  buf->ResetMap();
868  }
869 
870  Int_t lnew = 0;
871  Int_t nbytes = 0;
872 
873  if (fEntryBuffer) {
874  nbytes = FillEntryBuffer(basket,buf,lnew);
875  } else {
876  Int_t lold = buf->Length();
877  basket->Update(lold);
878  ++fEntries;
879  ++fEntryNumber;
880  (this->*fFillLeaves)(*buf);
881  if (buf->GetMapCount()) {
882  // The map is used.
884  }
885  lnew = buf->Length();
886  nbytes = lnew - lold;
887  }
888 
889  if (fEntryOffsetLen) {
890  Int_t nevbuf = basket->GetNevBuf();
891  // Total size in bytes of EntryOffset table.
892  nsize = nevbuf * sizeof(Int_t);
893  } else {
894  if (!basket->GetNevBufSize()) {
895  basket->SetNevBufSize(nbytes);
896  }
897  }
898 
899  // Should we create a new basket?
900  // fSkipZip force one entry per buffer (old stuff still maintained for CDF)
901  // Transfer full compressed buffer only
902 
903  // If GetAutoFlush() is less than zero, then we are determining the end of the autocluster
904  // based upon the number of bytes already flushed. This is incompatible with one-basket-per-cluster
905  // (since we will grow the basket indefinitely and never flush!). Hence, we wait until the
906  // first event cluster is written out and *then* enable one-basket-per-cluster mode.
907  bool noFlushAtCluster = !fTree->TestBit(TTree::kOnlyFlushAtCluster) || (fTree->GetAutoFlush() < 0);
908 
909  if (noFlushAtCluster && !fTree->TestBit(TTree::kCircular) &&
911  ((lnew + (2 * nsize) + nbytes) >= fBasketSize))) {
912  Int_t nout = WriteBasketImpl(basket, fWriteBasket, imtHelper);
913  if (nout < 0) Error("TBranch::Fill", "Failed to write out basket.\n");
914  return (nout >= 0) ? nbytes : -1;
915  }
916  return nbytes;
917 }
918 
919 ////////////////////////////////////////////////////////////////////////////////
920 /// Copy the data from fEntryBuffer into the current basket.
921 
923 {
924  Int_t nbytes = 0;
925  Int_t objectStart = 0;
926  Int_t last = 0;
927  Int_t lold = buf->Length();
928 
929  // Handle the special case of fEntryBuffer != 0
930  if (fEntryBuffer->IsA() == TMessage::Class()) {
931  objectStart = 8;
932  }
934  // The buffer given as input has not been decompressed.
935  if (basket->GetNevBuf()) {
936  // If the basket already contains entry we need to close it
937  // out. (This is because we can only transfer full compressed
938  // buffer)
939  WriteBasket(basket,fWriteBasket);
940  // And restart from scratch
941  return Fill();
942  }
943  Int_t startpos = fEntryBuffer->Length();
945  static TBasket toread_fLast;
947  toread_fLast.Streamer(*fEntryBuffer);
949  last = toread_fLast.GetLast();
950  // last now contains the decompressed number of bytes.
951  fEntryBuffer->SetBufferOffset(startpos);
952  buf->SetBufferOffset(0);
954  basket->Update(lold);
955  } else {
956  // We are required to copy starting at the version number (so not
957  // including the class name.
958  // See if byte count is here, if not it class still be a newClass
959  const UInt_t kNewClassTag = 0xFFFFFFFF;
960  const UInt_t kByteCountMask = 0x40000000; // OR the byte count with this
961  UInt_t tag = 0;
962  UInt_t startpos = fEntryBuffer->Length();
963  fEntryBuffer->SetBufferOffset(objectStart);
964  *fEntryBuffer >> tag;
965  if (tag & kByteCountMask) {
966  *fEntryBuffer >> tag;
967  }
968  if (tag == kNewClassTag) {
969  UInt_t maxsize = 256;
970  char* s = new char[maxsize];
971  Int_t name_start = fEntryBuffer->Length();
972  fEntryBuffer->ReadString(s, maxsize); // Reads at most maxsize - 1 characters, plus null at end.
973  while (strlen(s) == (maxsize - 1)) {
974  // The classname is too large, try again with a large buffer.
975  fEntryBuffer->SetBufferOffset(name_start);
976  maxsize *= 2;
977  delete[] s;
978  s = new char[maxsize];
979  fEntryBuffer->ReadString(s, maxsize); // Reads at most maxsize - 1 characters, plus null at end
980  }
981  delete[] s;
982  } else {
983  fEntryBuffer->SetBufferOffset(objectStart);
984  }
985  objectStart = fEntryBuffer->Length();
986  fEntryBuffer->SetBufferOffset(startpos);
987  basket->Update(lold, objectStart - fEntryBuffer->GetBufferDisplacement());
988  }
989  fEntries++;
990  fEntryNumber++;
991  UInt_t len = 0;
992  UInt_t startpos = fEntryBuffer->Length();
993  if (startpos > UInt_t(objectStart)) {
994  // We assume this buffer have just been directly filled
995  // the current position in the buffer indicates the end of the object!
996  len = fEntryBuffer->Length() - objectStart;
997  } else {
998  // The buffer have been acquired either via TSocket or via
999  // TBuffer::SetBuffer(newloc,newsize)
1000  // Only the actual size of the memory buffer gives us an hint about where
1001  // the object ends.
1002  len = fEntryBuffer->BufferSize() - objectStart;
1003  }
1004  buf->WriteBuf(fEntryBuffer->Buffer() + objectStart, len);
1006  // The original buffer came pre-compressed and thus the buffer Length
1007  // does not really show the really object size
1008  // lnew = nbytes = basket->GetLast();
1009  nbytes = last;
1010  lnew = last;
1011  } else {
1012  lnew = buf->Length();
1013  nbytes = lnew - lold;
1014  }
1015 
1016  return nbytes;
1017 }
1018 
1019 ////////////////////////////////////////////////////////////////////////////////
1020 /// Find the immediate sub-branch with passed name.
1021 
1023 {
1024  // We allow the user to pass only the last dotted component of the name.
1025  std::string longnm;
1026  longnm.reserve(fName.Length()+strlen(name)+3);
1027  longnm = fName.Data();
1028  if (longnm[longnm.length()-1]==']') {
1029  std::size_t dim = longnm.find_first_of("[");
1030  if (dim != std::string::npos) {
1031  longnm.erase(dim);
1032  }
1033  }
1034  if (longnm[longnm.length()-1] != '.') {
1035  longnm += '.';
1036  }
1037  longnm += name;
1038  UInt_t namelen = strlen(name);
1039 
1040  Int_t nbranches = fBranches.GetEntries();
1041  TBranch* branch = 0;
1042  for(Int_t i = 0; i < nbranches; ++i) {
1043  branch = (TBranch*) fBranches.UncheckedAt(i);
1044 
1045  const char *brname = branch->fName.Data();
1046  UInt_t brlen = branch->fName.Length();
1047  if (brname[brlen-1]==']') {
1048  const char *dim = strchr(brname,'[');
1049  if (dim) {
1050  brlen = dim - brname;
1051  }
1052  }
1053  if (namelen == brlen /* same effective size */
1054  && strncmp(name,brname,brlen) == 0) {
1055  return branch;
1056  }
1057  if (brlen == (size_t)longnm.length()
1058  && strncmp(longnm.c_str(),brname,brlen) == 0) {
1059  return branch;
1060  }
1061  }
1062  return 0;
1063 }
1064 
1065 ////////////////////////////////////////////////////////////////////////////////
1066 /// Find the leaf corresponding to the name 'searchname'.
1067 
1068 TLeaf* TBranch::FindLeaf(const char* searchname)
1069 {
1070  TString leafname;
1071  TString leaftitle;
1072  TString longname;
1073  TString longtitle;
1074 
1075  // We allow the user to pass only the last dotted component of the name.
1076  TIter next(GetListOfLeaves());
1077  TLeaf* leaf = 0;
1078  while ((leaf = (TLeaf*) next())) {
1079  leafname = leaf->GetName();
1080  Ssiz_t dim = leafname.First('[');
1081  if (dim >= 0) leafname.Remove(dim);
1082 
1083  if (leafname == searchname) return leaf;
1084 
1085  // The leaf element contains the branch name in its name, let's use the title.
1086  leaftitle = leaf->GetTitle();
1087  dim = leaftitle.First('[');
1088  if (dim >= 0) leaftitle.Remove(dim);
1089 
1090  if (leaftitle == searchname) return leaf;
1091 
1092  TBranch* branch = leaf->GetBranch();
1093  if (branch) {
1094  longname.Form("%s.%s",branch->GetName(),leafname.Data());
1095  dim = longname.First('[');
1096  if (dim>=0) longname.Remove(dim);
1097  if (longname == searchname) return leaf;
1098 
1099  // The leaf element contains the branch name in its name.
1100  longname.Form("%s.%s",branch->GetName(),searchname);
1101  if (longname==leafname) return leaf;
1102 
1103  longtitle.Form("%s.%s",branch->GetName(),leaftitle.Data());
1104  dim = longtitle.First('[');
1105  if (dim>=0) longtitle.Remove(dim);
1106  if (longtitle == searchname) return leaf;
1107 
1108  // The following is for the case where the branch is only
1109  // a sub-branch. Since we do not see it through
1110  // TTree::GetListOfBranches, we need to see it indirectly.
1111  // This is the less sturdy part of this search ... it may
1112  // need refining ...
1113  if (strstr(searchname, ".") && !strcmp(searchname, branch->GetName())) return leaf;
1114  }
1115  }
1116  return 0;
1117 }
1118 
1119 ////////////////////////////////////////////////////////////////////////////////
1120 /// Flush to disk all the baskets of this branch and any of subbranches.
1121 /// Return the number of bytes written or -1 in case of write error.
1122 
1124 {
1125  UInt_t nerror = 0;
1126  Int_t nbytes = 0;
1127 
1128  Int_t maxbasket = fWriteBasket + 1;
1129  // The following protection is not necessary since we should always
1130  // have fWriteBasket < fBasket.GetSize()
1131  //if (fBaskets.GetSize() < maxbasket) {
1132  // maxbasket = fBaskets.GetSize();
1133  //}
1134  for(Int_t i=0; i != maxbasket; ++i) {
1135  if (fBaskets.UncheckedAt(i)) {
1136  Int_t nwrite = FlushOneBasket(i);
1137  if (nwrite<0) {
1138  ++nerror;
1139  } else {
1140  nbytes += nwrite;
1141  }
1142  }
1143  }
1144  Int_t len = fBranches.GetEntriesFast();
1145  for (Int_t i = 0; i < len; ++i) {
1146  TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
1147  if (!branch) {
1148  continue;
1149  }
1150  Int_t nwrite = branch->FlushBaskets();
1151  if (nwrite<0) {
1152  ++nerror;
1153  } else {
1154  nbytes += nwrite;
1155  }
1156  }
1157  if (nerror) {
1158  return -1;
1159  } else {
1160  return nbytes;
1161  }
1162 }
1163 
1164 ////////////////////////////////////////////////////////////////////////////////
1165 /// If we have a write basket in memory and it contains some entries and
1166 /// has not yet been written to disk, we write it and delete it from memory.
1167 /// Return the number of bytes written;
1168 
1170 {
1171  Int_t nbytes = 0;
1172  if (fDirectory && fBaskets.GetEntries()) {
1173  TBasket *basket = (TBasket*)fBaskets.UncheckedAt(ibasket);
1174 
1175  if (basket) {
1176  if (basket->GetNevBuf()
1177  && fBasketSeek[ibasket]==0) {
1178  // If the basket already contains entry we need to close it out.
1179  // (This is because we can only transfer full compressed buffer)
1180 
1181  if (basket->GetBufferRef()->IsReading()) {
1182  basket->SetWriteMode();
1183  }
1184  nbytes = WriteBasket(basket,ibasket);
1185 
1186  } else {
1187  // If the basket is empty or has already been written.
1188  if ((Int_t)ibasket==fWriteBasket) {
1189  // Nothing to do.
1190  } else {
1191  basket->DropBuffers();
1192  if (basket == fCurrentBasket) {
1193  fCurrentBasket = 0;
1194  fFirstBasketEntry = -1;
1195  fNextBasketEntry = -1;
1196  }
1197  delete basket;
1198  --fNBaskets;
1199  fBaskets[ibasket] = 0;
1200  }
1201  }
1202  }
1203  }
1204  return nbytes;
1205 }
1206 
1207 ////////////////////////////////////////////////////////////////////////////////
1208 /// Return pointer to basket basketnumber in this Branch
1209 ///
1210 /// If a new buffer must be created and the user_buffer argument is non-null,
1211 /// then the memory in the user_bufer will be shared with the returned TBasket.
1212 
1213 TBasket* TBranch::GetBasketImpl(Int_t basketnumber, TBuffer *user_buffer)
1214 {
1215  // This counter in the sequential case collects errors coming also from
1216  // different files (suppose to have a program reading f1.root, f2.root ...)
1217  // In the mt case, it is made atomic: it safely collects errors from
1218  // different files processed simultaneously.
1219  static std::atomic<Int_t> nerrors(0);
1220 
1221  // reference to an existing basket in memory ?
1222  if (basketnumber <0 || basketnumber > fWriteBasket) return 0;
1223  TBasket *basket = (TBasket*)fBaskets.UncheckedAt(basketnumber);
1224  if (basket) return basket;
1225  if (basketnumber == fWriteBasket) return 0;
1226 
1227  // create/decode basket parameters from buffer
1228  TFile *file = GetFile(0);
1229  if (file == 0) {
1230  return 0;
1231  }
1232  // if cluster pre-fetching or retaining is on, do not re-use existing baskets
1233  // unless a new cluster is used.
1235  basket = GetFreshCluster();
1236  else
1237  basket = GetFreshBasket(basketnumber, user_buffer);
1238 
1239  // fSkipZip is old stuff still maintained for CDF
1241  if (fBasketBytes[basketnumber] == 0) {
1242  fBasketBytes[basketnumber] = basket->ReadBasketBytes(fBasketSeek[basketnumber],file);
1243  }
1244  //add branch to cache (if any)
1245  {
1246  R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
1248  if (pf){
1249  if (pf->IsLearning()) pf->LearnBranch(this, kFALSE);
1250  if (fSkipZip) pf->SetSkipZip();
1251  }
1252  }
1253 
1254  //now read basket
1255  Int_t badread = basket->ReadBasketBuffers(fBasketSeek[basketnumber],fBasketBytes[basketnumber],file);
1256  if (R__unlikely(badread || basket->GetSeekKey() != fBasketSeek[basketnumber] || basket->IsZombie())) {
1257  nerrors++;
1258  if (nerrors > 10) return 0;
1259  if (nerrors == 10) {
1260  printf(" file probably overwritten: stopping reporting error messages\n");
1261  if (fBasketSeek[basketnumber] > 2000000000) {
1262  printf("===>File is more than 2 Gigabytes\n");
1263  return 0;
1264  }
1265  if (fBasketSeek[basketnumber] > 1000000000) {
1266  printf("===>Your file is may be bigger than the maximum file size allowed on your system\n");
1267  printf(" Check your AFS maximum file size limit for example\n");
1268  return 0;
1269  }
1270  }
1271  Error("GetBasket","File: %s at byte:%lld, branch:%s, entry:%lld, badread=%d, nerrors=%d, basketnumber=%d",file->GetName(),basket->GetSeekKey(),GetName(),fReadEntry,badread,nerrors.load(),basketnumber);
1272  return 0;
1273  }
1274 
1275  ++fNBaskets;
1276 
1277  fCacheInfo.SetUsed(basketnumber);
1278  auto perfStats = GetTree()->GetPerfStats();
1279  if (perfStats)
1280  perfStats->SetUsed(this, basketnumber);
1281 
1282  fBaskets.AddAt(basket,basketnumber);
1283  return basket;
1284 }
1285 
1286 ////////////////////////////////////////////////////////////////////////////////
1287 /// Return address of basket in the file
1288 
1290 {
1291  if (basketnumber <0 || basketnumber > fWriteBasket) return 0;
1292  return fBasketSeek[basketnumber];
1293 }
1294 
1295 ////////////////////////////////////////////////////////////////////////////////
1296 /// Returns (and, if 0, creates) browsable objects for this branch
1297 /// See TVirtualBranchBrowsable::FillListOfBrowsables.
1298 
1300  if (fBrowsables) return fBrowsables;
1301  fBrowsables=new TList();
1303  return fBrowsables;
1304 }
1305 
1306 ////////////////////////////////////////////////////////////////////////////////
1307 /// Return the name of the user class whose content is stored in this branch,
1308 /// if any. If this branch was created using the 'leaflist' technique, this
1309 /// function returns an empty string.
1310 
1311 const char * TBranch::GetClassName() const
1312 {
1313  return "";
1314 }
1315 
1316 ////////////////////////////////////////////////////////////////////////////////
1317 /// Return icon name depending on type of branch.
1318 
1319 const char* TBranch::GetIconName() const
1320 {
1321  if (IsFolder())
1322  return "TBranchElement-folder";
1323  else
1324  return "TBranchElement-leaf";
1325 }
1326 
1327 ////////////////////////////////////////////////////////////////////////////////
1328 /// A helper function to locate the correct basket - and its first entry.
1329 /// Extracted to a common private function because it is needed by both GetEntry
1330 /// and GetBulkEntries. It should not be called directly.
1331 ///
1332 /// If a new basket must be constructed and the user_buffer is provided, then
1333 /// the user_buffer will back the memory of the newly-constructed basket.
1334 ///
1335 /// Assumes that this branch is enabled.
1336 ///
1337 /// Returns -1 if the entry does not exist
1338 /// Returns -2 in case of error
1339 /// Returns the index of the basket in case of success.
1341  TBuffer *user_buffer)
1342 {
1343  Long64_t updatedNext = fNextBasketEntry;
1344  Long64_t entry = fReadEntry;
1345  if (R__likely(fCurrentBasket && fFirstBasketEntry <= entry && entry < fNextBasketEntry)) {
1346  // We have found the basket containing this entry.
1347  // make sure basket buffers are in memory.
1348  basket = fCurrentBasket;
1350  return fReadBasket;
1351  } else {
1352  if ((entry < fFirstEntry) || (entry >= fEntryNumber)) {
1353  return -1;
1354  }
1356  Long64_t last = fNextBasketEntry - 1;
1357  // Are we still in the same ReadBasket?
1358  if ((entry < first) || (entry > last)) {
1360  if (fReadBasket < 0) {
1361  fNextBasketEntry = -1;
1362  Error("GetBasketAndFirst", "In the branch %s, no basket contains the entry %lld\n", GetName(), entry);
1363  return -2;
1364  }
1365  if (fReadBasket == fWriteBasket) {
1367  } else {
1369  }
1370  updatedNext = fNextBasketEntry;
1372  }
1373  // We have found the basket containing this entry.
1374  // make sure basket buffers are in memory.
1375  basket = (TBasket*) fBaskets.UncheckedAt(fReadBasket);
1376  if (!basket) {
1377  basket = GetBasketImpl(fReadBasket, user_buffer);
1378  if (!basket) {
1379  fCurrentBasket = 0;
1380  fFirstBasketEntry = -1;
1381  fNextBasketEntry = -1;
1382  return -2;
1383  }
1384  if (fTree->GetClusterPrefetch()) {
1385  TTree::TClusterIterator clusterIterator = fTree->GetClusterIterator(entry);
1386  clusterIterator.Next();
1387  Int_t nextClusterEntry = clusterIterator.GetNextEntry();
1388  for (Int_t i = fReadBasket + 1; i < fMaxBaskets && fBasketEntry[i] < nextClusterEntry; i++) {
1389  GetBasket(i);
1390  }
1391  }
1392  // Getting the next basket might reset the current one and
1393  // cause a reset of the first / next basket entries back to -1.
1395  fNextBasketEntry = updatedNext;
1396  if (user_buffer) {
1397  // Disassociate basket from memory buffer for bulk IO
1398  // When the user provides a memory buffer (i.e., for bulk IO), we should
1399  // make sure to drop all references to that buffer in the TTree afterward.
1400  fCurrentBasket = nullptr;
1401  fBaskets[fReadBasket] = nullptr;
1402  } else {
1403  fCurrentBasket = basket;
1404  }
1405  } else {
1406  fCurrentBasket = basket;
1407  }
1408  return fReadBasket;
1409  }
1410 }
1411 
1412 ////////////////////////////////////////////////////////////////////////////////
1413 /// Returns true if this branch supports bulk IO, false otherwise.
1414 ///
1415 /// This will return true if all the various preconditions necessary hold true
1416 /// to perform bulk IO (reasonable type, single TLeaf, etc); the bulk IO may
1417 /// still fail, depending on the contents of the individual TBaskets loaded.
1419  return (fNleaves == 1) &&
1420  (static_cast<TLeaf*>(fLeaves.UncheckedAt(0))->GetDeserializeType() != TLeaf::DeserializeType::kDestructive);
1421 }
1422 
1423 ////////////////////////////////////////////////////////////////////////////////
1424 /// Read as many events as possible into the given buffer, using zero-copy
1425 /// mechanisms.
1426 ///
1427 /// Returns -1 in case of a failure. On success, returns a (non-zero) number of
1428 /// events of the type held by this branch currently in the buffer.
1429 ///
1430 /// On success, the caller should be able to access the contents of buf as
1431 ///
1432 /// static_cast<T*>(buf.GetCurrent())
1433 ///
1434 /// where T is the type stored on this branch. The array's length is the return
1435 /// value of this function.
1436 ///
1437 /// NOTES:
1438 /// - This interface is meant to be used by higher-level, type-safe wrappers, not
1439 /// by end-users.
1440 /// - This only returns events
1441 ///
1442 
1444 {
1445  // TODO: eventually support multiple leaves.
1446  if (R__unlikely(fNleaves != 1)) return -1;
1447  TLeaf *leaf = static_cast<TLeaf*>(fLeaves.UncheckedAt(0));
1449 
1450  // Remember which entry we are reading.
1451  fReadEntry = entry;
1452 
1453  Bool_t enabled = !TestBit(kDoNotProcess);
1454  if (R__unlikely(!enabled)) return -1;
1455  TBasket *basket = nullptr;
1456  Long64_t first;
1457  Int_t result = GetBasketAndFirst(basket, first, &user_buf);
1458  if (R__unlikely(result < 0)) return -1;
1459  // Only support reading from full clusters.
1460  if (R__unlikely(entry != first)) {
1461  //printf("Failed to read from full cluster; first entry is %ld; requested entry is %ld.\n", first, entry);
1462  return -1;
1463  }
1464 
1465  basket->PrepareBasket(entry);
1466  TBuffer* buf = basket->GetBufferRef();
1467 
1468  // Test for very old ROOT files.
1469  if (R__unlikely(!buf)) {
1470  Error("GetBulkEntries", "Failed to get a new buffer.\n");
1471  return -1;
1472  }
1473  // Test for displacements, which aren't supported in fast mode.
1474  if (R__unlikely(basket->GetDisplacement())) {
1475  Error("GetBulkEntries", "Basket has displacement.\n");
1476  return -1;
1477  }
1478 
1479  if (&user_buf != buf) {
1480  // The basket was already in memory and might (and might not) be backed by persistent
1481  // storage.
1482  R__ASSERT(result == fReadBasket);
1483  if (fBasketSeek[fReadBasket]) {
1484  // It is backed, so we can be destructive
1485  user_buf.SetBuffer(buf->Buffer(), buf->BufferSize());
1487  fCurrentBasket = nullptr;
1488  fBaskets[fReadBasket] = nullptr;
1489  } else {
1490  // This is the only copy, we can't return it as is to the user, just make a copy.
1491  if (user_buf.BufferSize() < buf->BufferSize()) {
1492  user_buf.AutoExpand(buf->BufferSize());
1493  }
1494  memcpy(user_buf.Buffer(), buf->Buffer(), buf->BufferSize());
1495  }
1496  }
1497 
1498  Int_t bufbegin = basket->GetKeylen();
1499  user_buf.SetBufferOffset(bufbegin);
1500 
1502  //printf("Requesting %d events; fNextBasketEntry=%lld; first=%lld.\n", N, fNextBasketEntry, first);
1503  if (R__unlikely(!leaf->ReadBasketFast(user_buf, N))) {
1504  Error("GetBulkEntries", "Leaf failed to read.\n");
1505  return -1;
1506  }
1507  user_buf.SetBufferOffset(bufbegin);
1508 
1509  if (fCurrentBasket == nullptr) {
1510  R__ASSERT(fExtraBasket == nullptr && "fExtraBasket should have been set to nullptr by GetFreshBasket");
1511  fExtraBasket = basket;
1512  basket->DisownBuffer();
1513  }
1514 
1515  return N;
1516 }
1517 
1518 // TODO: Template this and the call above; only difference is the TLeaf function (ReadBasketFast vs
1519 // ReadBasketSerialized
1521 {
1522  // TODO: eventually support multiple leaves.
1523  if (R__unlikely(fNleaves != 1)) { return -1; }
1524  TLeaf *leaf = static_cast<TLeaf*>(fLeaves.UncheckedAt(0));
1526  Error("GetEntriesSerialized", "Encountered a branch with destructive deserialization; failing.\n");
1527  return -1;
1528  }
1529 
1530  // Remember which entry we are reading.
1531  fReadEntry = entry;
1532 
1533  Bool_t enabled = !TestBit(kDoNotProcess);
1534  if (R__unlikely(!enabled)) { return -1; }
1535  TBasket *basket = nullptr;
1536  Long64_t first;
1537  Int_t result = GetBasketAndFirst(basket, first, &user_buf);
1538  if (R__unlikely(result < 0)) { return -1; }
1539  // Only support reading from full clusters.
1540  if (R__unlikely(entry != first)) {
1541  Error("GetEntriesSerialized", "Failed to read from full cluster; first entry is %lld; requested entry is %lld.\n", first, entry);
1542  return -1;
1543  }
1544 
1545  basket->PrepareBasket(entry);
1546  TBuffer* buf = basket->GetBufferRef();
1547 
1548  // Test for very old ROOT files.
1549  if (R__unlikely(!buf)) {
1550  Error("GetEntriesSerialized", "Failed to get a new buffer.\n");
1551  return -1;
1552  }
1553  // Test for displacements, which aren't supported in fast mode.
1554  if (R__unlikely(basket->GetDisplacement())) {
1555  Error("GetEntriesSerialized", "Basket has displacement.\n");
1556  return -1;
1557  }
1558 
1559  if (&user_buf != buf) {
1560  // The basket was already in memory and might (and might not) be backed by persistent
1561  // storage.
1562  R__ASSERT(result == fReadBasket);
1563  if (fBasketSeek[fReadBasket]) {
1564  // It is backed, so we can be destructive
1565  user_buf.SetBuffer(buf->Buffer(), buf->BufferSize());
1567  fCurrentBasket = nullptr;
1568  fBaskets[fReadBasket] = nullptr;
1569  } else {
1570  // This is the only copy, we can't return it as is to the user, just make a copy.
1571  if (user_buf.BufferSize() < buf->BufferSize()) {
1572  user_buf.AutoExpand(buf->BufferSize());
1573  }
1574  memcpy(user_buf.Buffer(), buf->Buffer(), buf->BufferSize());
1575  }
1576  }
1577 
1578  Int_t bufbegin = basket->GetKeylen();
1579  user_buf.SetBufferOffset(bufbegin);
1580 
1582  //Info("GetEntriesSerialized", "Requesting %d events; fNextBasketEntry=%lld; first=%lld.\n", N, fNextBasketEntry, first);
1583 
1584  if (R__unlikely(!leaf->ReadBasketSerialized(user_buf, N))) {
1585  Error("GetEntriesSerialized", "Leaf failed to read.\n");
1586  return -1;
1587  }
1588  user_buf.SetBufferOffset(bufbegin);
1589 
1590  if (count_buf) {
1591  TLeaf *count_leaf = leaf->GetLeafCount();
1592  if (count_leaf) {
1593  //printf("Getting leaf count entries.\n");
1594  TBranch *count_branch = count_leaf->GetBranch();
1595  if (R__unlikely(count_branch->GetEntriesSerialized(entry, *count_buf) < 0)) {
1596  Error("GetEntriesSerialized", "Failed to read count leaf.\n");
1597  return -1;
1598  }
1599  } else {
1600  // TODO: if you ask for a count on a fixed-size branch, maybe we should
1601  // just fail?
1602  Int_t entry_count_serialized;
1603  char *tmp_ptr = reinterpret_cast<char*>(&entry_count_serialized);
1604  tobuf(tmp_ptr, leaf->GetLenType() * leaf->GetNdata());
1605  Int_t cur_offset = count_buf->GetCurrent() - count_buf->Buffer();
1606  for (int idx=0; idx<N; idx++) {
1607  *count_buf << entry_count_serialized;
1608  }
1609  count_buf->SetBufferOffset(cur_offset);
1610  }
1611  }
1612 
1613  return N;
1614 }
1615 
1616 ////////////////////////////////////////////////////////////////////////////////
1617 /// Read all leaves of entry and return total number of bytes read.
1618 ///
1619 /// The input argument "entry" is the entry number in the current tree.
1620 /// In case of a TChain, the entry number in the current Tree must be found
1621 /// before calling this function. For example:
1622 ///
1623 ///~~~ {.cpp}
1624 /// TChain* chain = ...;
1625 /// Long64_t localEntry = chain->LoadTree(entry);
1626 /// branch->GetEntry(localEntry);
1627 ///~~~
1628 ///
1629 /// The function returns the number of bytes read from the input buffer.
1630 /// If entry does not exist, the function returns 0.
1631 /// If an I/O error occurs, the function returns -1.
1632 ///
1633 /// See IMPORTANT REMARKS in TTree::GetEntry.
1634 
1636 {
1637  // Remember which entry we are reading.
1638  fReadEntry = entry;
1639 
1640  if (R__unlikely(TestBit(kDoNotProcess) && !getall)) { return 0; }
1641 
1642  TBasket *basket; // will be initialized in the if/then clauses.
1643  Long64_t first;
1644 
1645  Int_t result = GetBasketAndFirst(basket, first, nullptr);
1646  if (R__unlikely(result < 0)) { return result + 1; }
1647 
1648  basket->PrepareBasket(entry);
1649  TBuffer* buf = basket->GetBufferRef();
1650 
1651  // This test necessary to read very old Root files (NvE).
1652  if (R__unlikely(!buf)) {
1653  TFile* file = GetFile(0);
1654  if (!file) return -1;
1656  buf = basket->GetBufferRef();
1657  }
1658 
1659  // Set entry offset in buffer.
1660  if (!TestBit(kDoNotUseBufferMap)) {
1661  buf->ResetMap();
1662  }
1663  if (R__unlikely(!buf->IsReading())) {
1664  basket->SetReadMode();
1665  }
1666 
1667  Int_t* entryOffset = basket->GetEntryOffset();
1668  Int_t bufbegin = 0;
1669  if (entryOffset) {
1670  bufbegin = entryOffset[entry-first];
1671  buf->SetBufferOffset(bufbegin);
1672  Int_t* displacement = basket->GetDisplacement();
1673  if (R__unlikely(displacement)) {
1674  buf->SetBufferDisplacement(displacement[entry-first]);
1675  }
1676  } else {
1677  bufbegin = basket->GetKeylen() + ((entry-first) * basket->GetNevBufSize());
1678  buf->SetBufferOffset(bufbegin);
1679  }
1680 
1681  // Int_t bufbegin = buf->Length();
1682  (this->*fReadLeaves)(*buf);
1683  return buf->Length() - bufbegin;
1684 }
1685 
1686 ////////////////////////////////////////////////////////////////////////////////
1687 /// Read all leaves of an entry and export buffers to real objects in a TClonesArray list.
1688 ///
1689 /// Returns total number of bytes read.
1690 
1692 {
1693  // Remember which entry we are reading.
1694  fReadEntry = entry;
1695 
1696  if (TestBit(kDoNotProcess)) {
1697  return 0;
1698  }
1699  if ((entry < 0) || (entry >= fEntryNumber)) {
1700  return 0;
1701  }
1702  Int_t nbytes = 0;
1704  Long64_t last = fNextBasketEntry - 1;
1705  // Are we still in the same ReadBasket?
1706  if ((entry < first) || (entry > last)) {
1708  if (fReadBasket < 0) {
1709  fNextBasketEntry = -1;
1710  Error("In the branch %s, no basket contains the entry %d\n", GetName(), entry);
1711  return -1;
1712  }
1713  if (fReadBasket == fWriteBasket) {
1715  } else {
1717  }
1719  }
1720 
1721  // We have found the basket containing this entry.
1722  // Make sure basket buffers are in memory.
1723  TBasket* basket = GetBasketImpl(fReadBasket, nullptr);
1724  fCurrentBasket = basket;
1725  if (!basket) {
1726  fFirstBasketEntry = -1;
1727  fNextBasketEntry = -1;
1728  return 0;
1729  }
1730  TBuffer* buf = basket->GetBufferRef();
1731  // Set entry offset in buffer and read data from all leaves.
1732  if (!TestBit(kDoNotUseBufferMap)) {
1733  buf->ResetMap();
1734  }
1735  if (R__unlikely(!buf->IsReading())) {
1736  basket->SetReadMode();
1737  }
1738  Int_t* entryOffset = basket->GetEntryOffset();
1739  Int_t bufbegin = 0;
1740  if (entryOffset) {
1741  bufbegin = entryOffset[entry-first];
1742  buf->SetBufferOffset(bufbegin);
1743  Int_t* displacement = basket->GetDisplacement();
1744  if (R__unlikely(displacement)) {
1745  buf->SetBufferDisplacement(displacement[entry-first]);
1746  }
1747  } else {
1748  bufbegin = basket->GetKeylen() + ((entry-first) * basket->GetNevBufSize());
1749  buf->SetBufferOffset(bufbegin);
1750  }
1751  TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(0);
1752  leaf->ReadBasketExport(*buf, li, nentries);
1753  nbytes = buf->Length() - bufbegin;
1754  return nbytes;
1755 }
1756 
1757 ////////////////////////////////////////////////////////////////////////////////
1758 /// Fill expectedClass and expectedType with information on the data type of the
1759 /// object/values contained in this branch (and thus the type of pointers
1760 /// expected to be passed to Set[Branch]Address
1761 /// return 0 in case of success and > 0 in case of failure.
1762 
1763 Int_t TBranch::GetExpectedType(TClass *&expectedClass,EDataType &expectedType)
1764 {
1765  expectedClass = 0;
1766  expectedType = kOther_t;
1767  TLeaf* l = (TLeaf*) GetListOfLeaves()->At(0);
1768  if (l) {
1769  expectedType = (EDataType) gROOT->GetType(l->GetTypeName())->GetType();
1770  return 0;
1771  } else {
1772  Error("GetExpectedType", "Did not find any leaves in %s",GetName());
1773  return 1;
1774  }
1775 }
1776 
1777 ////////////////////////////////////////////////////////////////////////////////
1778 /// Return pointer to the file where branch buffers reside, returns 0
1779 /// in case branch buffers reside in the same file as tree header.
1780 /// If mode is 1 the branch buffer file is recreated.
1781 
1783 {
1784  if (fDirectory) return fDirectory->GetFile();
1785 
1786  // check if a file with this name is in the list of Root files
1787  TFile *file = 0;
1788  {
1790  file = (TFile*)gROOT->GetListOfFiles()->FindObject(fFileName.Data());
1791  if (file) {
1792  fDirectory = file;
1793  return file;
1794  }
1795  }
1796 
1797  if (fFileName.Length() == 0) return 0;
1798 
1799  TString bFileName( GetRealFileName() );
1800 
1801  // Open file (new file if mode = 1)
1802  {
1803  TDirectory::TContext ctxt;
1804  if (mode) file = TFile::Open(bFileName, "recreate");
1805  else file = TFile::Open(bFileName);
1806  }
1807  if (!file) return 0;
1808  if (file->IsZombie()) {delete file; return 0;}
1810  return file;
1811 }
1812 
1813 ////////////////////////////////////////////////////////////////////////////////
1814 /// Return a fresh basket by either resusing an existing basket that needs
1815 /// to be drop (according to TTree::MemoryFull) or create a new one.
1816 ///
1817 /// If the user_buffer argument is non-null, then the memory in the
1818 /// user-provided buffer will be utilized by the underlying basket.
1819 ///
1820 /// The basket number is used to estimate the required buffer size
1821 /// and try to optimize memory usage and number of memory allocation.
1822 
1823 TBasket* TBranch::GetFreshBasket(Int_t basketnumber, TBuffer* user_buffer)
1824 {
1825  TBasket *basket = 0;
1826  if (user_buffer && fExtraBasket) {
1827  basket = fExtraBasket;
1828  fExtraBasket = nullptr;
1829  basket->AdoptBuffer(user_buffer);
1830  } else {
1831  if (GetTree()->MemoryFull(0)) {
1832  if (fNBaskets==1) {
1833  // Steal the existing basket
1834  Int_t oldindex = fBaskets.GetLast();
1835  basket = (TBasket*)fBaskets.UncheckedAt(oldindex);
1836  if (!basket) {
1837  fBaskets.SetLast(-2); // For recalculation of Last.
1838  oldindex = fBaskets.GetLast();
1839  if (oldindex != fBaskets.LowerBound()-1) {
1840  basket = (TBasket*)fBaskets.UncheckedAt(oldindex);
1841  }
1842  }
1843  if (basket && fBasketBytes[oldindex]!=0) {
1844  if (basket == fCurrentBasket) {
1845  fCurrentBasket = 0;
1846  fFirstBasketEntry = -1;
1847  fNextBasketEntry = -1;
1848  }
1849  fBaskets.AddAt(0,oldindex);
1850  fBaskets.SetLast(-1);
1851  fNBaskets = 0;
1852  basket->ReadResetBuffer(basketnumber);
1853 #ifdef R__TRACK_BASKET_ALLOC_TIME
1854  fTree->AddAllocationTime(basket->GetResetAllocationTime());
1855 #endif
1857  } else {
1858  basket = fTree->CreateBasket(this);
1859  }
1860  } else if (fNBaskets == 0) {
1861  // There is nothing to drop!
1862  basket = fTree->CreateBasket(this);
1863  } else {
1864  // Memory is full and there is more than one basket,
1865  // Let DropBaskets do it job.
1866  DropBaskets();
1867  basket = fTree->CreateBasket(this);
1868  }
1869  } else {
1870  basket = fTree->CreateBasket(this);
1871  }
1872  if (user_buffer)
1873  basket->AdoptBuffer(user_buffer);
1874  }
1875  return basket;
1876 }
1877 
1878 ////////////////////////////////////////////////////////////////////////////////
1879 /// Drops the cluster two behind the current cluster and returns a fresh basket
1880 /// by either reusing or creating a new one
1881 
1883 {
1884  TBasket *basket = 0;
1885 
1886  // If GetClusterIterator is called with a negative entry then GetStartEntry will be 0
1887  // So we need to check if we reach the zero before we have gone back (1-VirtualSize) clusters
1888  // if this is the case, we want to keep everything in memory so we return a new basket
1890  if (iter.GetStartEntry() == 0) {
1891  return fTree->CreateBasket(this);
1892  }
1893 
1894  // Iterate backwards (1-VirtualSize) clusters to reach cluster to be unloaded from memory,
1895  // skipped if VirtualSize > 0.
1896  for (Int_t j = 0; j < -fTree->GetMaxVirtualSize(); j++) {
1897  if (iter.Previous() == 0) {
1898  return fTree->CreateBasket(this);
1899  }
1900  }
1901 
1902  Int_t entryToUnload = iter.Previous();
1903  // Finds the basket to unload from memory. Since the basket should be close to current
1904  // basket, just iterate backwards until the correct basket is reached. This should
1905  // be fast as long as the number of baskets per cluster is small
1906  Int_t basketToUnload = fReadBasket;
1907  while (fBasketEntry[basketToUnload] != entryToUnload) {
1908  basketToUnload--;
1909  if (basketToUnload < 0) {
1910  return fTree->CreateBasket(this);
1911  }
1912  }
1913 
1914  // Retrieves the basket that is going to be unloaded from memory. If the basket did not
1915  // exist, create a new one
1916  basket = (TBasket *)fBaskets.UncheckedAt(basketToUnload);
1917  if (basket) {
1918  fBaskets.AddAt(0, basketToUnload);
1919  --fNBaskets;
1920  } else {
1921  basket = fTree->CreateBasket(this);
1922  }
1923  ++basketToUnload;
1924 
1925  // Clear the rest of the baskets. While it would be ideal to reuse these baskets
1926  // for other baskets in the new cluster. It would require the function to go
1927  // beyond its current scope. In the ideal case when each cluster only has 1 basket
1928  // this will perform well
1929  iter.Next();
1930  while (fBasketEntry[basketToUnload] < iter.GetStartEntry()) {
1931  TBasket *oldbasket = (TBasket *)fBaskets.UncheckedAt(basketToUnload);
1932  if (oldbasket) {
1933  oldbasket->DropBuffers();
1934  delete oldbasket;
1935  fBaskets.AddAt(0, basketToUnload);
1936  --fNBaskets;
1937  }
1938  ++basketToUnload;
1939  }
1940  fBaskets.SetLast(-1);
1941  return basket;
1942 }
1943 
1944 ////////////////////////////////////////////////////////////////////////////////
1945 /// Return the 'full' name of the branch. In particular prefix the mother's name
1946 /// when it does not end in a trailing dot and thus is not part of the branch name
1948 {
1949  TBranch* mother = GetMother();
1950  if (!mother || mother==this) {
1951  return fName;
1952  }
1953  TString motherName(mother->GetName());
1954  if (motherName.Length() && (motherName[motherName.Length()-1] == '.')) {
1955  return fName;
1956  }
1957  return motherName + "." + fName;
1958 }
1959 
1960 ////////////////////////////////////////////////////////////////////////////////
1961 /// Return pointer to the 1st Leaf named name in thisBranch
1962 
1963 TLeaf* TBranch::GetLeaf(const char* name) const
1964 {
1965  Int_t i;
1966  for (i=0;i<fNleaves;i++) {
1967  TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
1968  if (!strcmp(leaf->GetName(),name)) return leaf;
1969  }
1970  return 0;
1971 }
1972 
1973 ////////////////////////////////////////////////////////////////////////////////
1974 /// Get real file name
1975 
1977 {
1978  if (fFileName.Length()==0) {
1979  return fFileName;
1980  }
1981  TString bFileName = fFileName;
1982 
1983  // check if branch file name is absolute or a URL (e.g. root://host/...)
1984  char *bname = gSystem->ExpandPathName(fFileName.Data());
1985  if (!gSystem->IsAbsoluteFileName(bname) && !strstr(bname, ":/") && fTree && fTree->GetCurrentFile()) {
1986 
1987  // if not, get filename where tree header is stored
1988  const char *tfn = fTree->GetCurrentFile()->GetName();
1989 
1990  // If it is an archive file we need a special treatment
1991  TUrl arc(tfn);
1992  if (strlen(arc.GetAnchor()) > 0) {
1994  bFileName = arc.GetUrl();
1995  } else {
1996  // if this is an absolute path or a URL then prepend this path
1997  // to the branch file name
1998  char *tname = gSystem->ExpandPathName(tfn);
1999  if (gSystem->IsAbsoluteFileName(tname) || strstr(tname, ":/")) {
2000  bFileName = gSystem->GetDirName(tname);
2001  bFileName += "/";
2002  bFileName += fFileName;
2003  }
2004  delete [] tname;
2005  }
2006  }
2007  delete [] bname;
2008 
2009  return bFileName;
2010 }
2011 
2012 ////////////////////////////////////////////////////////////////////////////////
2013 /// Return all elements of one row unpacked in internal array fValues
2014 /// [Actually just returns 1 (?)]
2015 
2017 {
2018  return 1;
2019 }
2020 
2021 ////////////////////////////////////////////////////////////////////////////////
2022 /// Return whether this branch is in a mode where the object are decomposed
2023 /// or not (Also known as MakeClass mode).
2024 
2026 {
2027  // Regular TBranch and TBrancObject can not be in makeClass mode
2028 
2029  return kFALSE;
2030 }
2031 
2032 ////////////////////////////////////////////////////////////////////////////////
2033 /// Get our top-level parent branch in the tree.
2034 
2036 {
2037  if (fMother) return fMother;
2038 
2039  const TObjArray* array = fTree->GetListOfBranches();
2040  Int_t n = array->GetEntriesFast();
2041  for (Int_t i = 0; i < n; ++i) {
2042  TBranch* branch = (TBranch*) array->UncheckedAt(i);
2043  TBranch* parent = branch->GetSubBranch(this);
2044  if (parent) {
2045  const_cast<TBranch*>(this)->fMother = branch; // We can not yet use the 'mutable' keyword
2046  return branch;
2047  }
2048  }
2049  return 0;
2050 }
2051 
2052 ////////////////////////////////////////////////////////////////////////////////
2053 /// Find the parent branch of child.
2054 /// Return 0 if child is not in this branch hierarchy.
2055 
2057 {
2058  // Handle error condition, if the parameter is us, we cannot find the parent.
2059  if (this == child) {
2060  // Note: We cast away any const-ness of "this".
2061  return (TBranch*) this;
2062  }
2063 
2064  if (child->fParent) {
2065  return child->fParent;
2066  }
2067 
2068  Int_t len = fBranches.GetEntriesFast();
2069  for (Int_t i = 0; i < len; ++i) {
2070  TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
2071  if (!branch) {
2072  continue;
2073  }
2074  if (branch == child) {
2075  // We are the direct parent of child.
2076  const_cast<TBranch*>(child)->fParent = (TBranch*)this; // We can not yet use the 'mutable' keyword
2077  // Note: We cast away any const-ness of "this".
2078  const_cast<TBranch*>(child)->fParent = (TBranch*)this; // We can not yet use the 'mutable' keyword
2079  return (TBranch*) this;
2080  }
2081  // FIXME: This is a tail-recursion!
2082  TBranch* parent = branch->GetSubBranch(child);
2083  if (parent) {
2084  return parent;
2085  }
2086  }
2087  // We failed to find the parent.
2088  return 0;
2089 }
2090 
2091 ////////////////////////////////////////////////////////////////////////////////
2092 /// Return total number of bytes in the branch (including current buffer)
2093 
2095 {
2096  TBufferFile b(TBuffer::kWrite, 10000);
2097  // This intentionally only store the TBranch part and thus slightly
2098  // under-estimate the space used.
2099  // Since the TBranchElement part contains pointers to other branches (branch count),
2100  // doing regular Streaming would end up including those and thus greatly over-estimate
2101  // the size used.
2102  const_cast<TBranch *>(this)->TBranch::Streamer(b);
2103 
2104  Long64_t totbytes = 0;
2105  if (fZipBytes > 0) totbytes = fTotBytes;
2106  return totbytes + b.Length();
2107 }
2108 
2109 ////////////////////////////////////////////////////////////////////////////////
2110 /// Return total number of bytes in the branch (excluding current buffer)
2111 /// if option ="*" includes all sub-branches of this branch too
2112 
2114 {
2115  Long64_t totbytes = fTotBytes;
2116  if (!option) return totbytes;
2117  if (option[0] != '*') return totbytes;
2118  //scan sub-branches
2119  Int_t len = fBranches.GetEntriesFast();
2120  for (Int_t i = 0; i < len; ++i) {
2121  TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
2122  if (branch) totbytes += branch->GetTotBytes(option);
2123  }
2124  return totbytes;
2125 }
2126 
2127 ////////////////////////////////////////////////////////////////////////////////
2128 /// Return total number of zip bytes in the branch
2129 /// if option ="*" includes all sub-branches of this branch too
2130 
2132 {
2133  Long64_t zipbytes = fZipBytes;
2134  if (!option) return zipbytes;
2135  if (option[0] != '*') return zipbytes;
2136  //scan sub-branches
2137  Int_t len = fBranches.GetEntriesFast();
2138  for (Int_t i = 0; i < len; ++i) {
2139  TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
2140  if (branch) zipbytes += branch->GetZipBytes(option);
2141  }
2142  return zipbytes;
2143 }
2144 
2145 ////////////////////////////////////////////////////////////////////////////////
2146 /// Returns the IO settings currently in use for this branch.
2147 
2149 {
2150  return fIOFeatures;
2151 }
2152 
2153 ////////////////////////////////////////////////////////////////////////////////
2154 /// Return kTRUE if an existing object in a TBranchObject must be deleted.
2155 
2157 {
2158  return TestBit(kAutoDelete);
2159 }
2160 
2161 ////////////////////////////////////////////////////////////////////////////////
2162 /// Return kTRUE if more than one leaf or browsables, kFALSE otherwise.
2163 
2165 {
2166  if (fNleaves > 1) {
2167  return kTRUE;
2168  }
2169  TList* browsables = const_cast<TBranch*>(this)->GetBrowsables();
2170  return browsables && browsables->GetSize();
2171 }
2172 
2173 ////////////////////////////////////////////////////////////////////////////////
2174 /// keep a maximum of fMaxEntries in memory
2175 
2177 {
2178  Int_t dentries = (Int_t) (fEntries - maxEntries);
2179  TBasket* basket = (TBasket*) fBaskets.UncheckedAt(0);
2180  if (basket) basket->MoveEntries(dentries);
2181  fEntries = maxEntries;
2182  fEntryNumber = maxEntries;
2183  //loop on sub branches
2185  for (Int_t i = 0; i < nb; ++i) {
2186  TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
2187  branch->KeepCircular(maxEntries);
2188  }
2189 }
2190 
2191 ////////////////////////////////////////////////////////////////////////////////
2192 /// Baskets associated to this branch are forced to be in memory.
2193 /// You can call TTree::SetMaxVirtualSize(maxmemory) to instruct
2194 /// the system that the total size of the imported baskets does not
2195 /// exceed maxmemory bytes.
2196 ///
2197 /// The function returns the number of baskets that have been put in memory.
2198 /// This method may be called to force all baskets of one or more branches
2199 /// in memory when random access to entries in this branch is required.
2200 /// See also TTree::LoadBaskets to load all baskets of all branches in memory.
2201 
2203 {
2204  Int_t nimported = 0;
2205  Int_t nbaskets = fWriteBasket;
2206  TFile *file = GetFile(0);
2207  if (!file) return 0;
2208  TBasket *basket;
2209  for (Int_t i=0;i<nbaskets;i++) {
2210  basket = (TBasket*)fBaskets.UncheckedAt(i);
2211  if (basket) continue;
2212  basket = GetFreshBasket(i, nullptr);
2213  if (fBasketBytes[i] == 0) {
2214  fBasketBytes[i] = basket->ReadBasketBytes(fBasketSeek[i],file);
2215  }
2216  Int_t badread = basket->ReadBasketBuffers(fBasketSeek[i],fBasketBytes[i],file);
2217  if (badread) {
2218  Error("Loadbaskets","Error while reading basket buffer %d of branch %s",i,GetName());
2219  return -1;
2220  }
2221  ++fNBaskets;
2222  fBaskets.AddAt(basket,i);
2223  nimported++;
2224  }
2225  return nimported;
2226 }
2227 
2228 ////////////////////////////////////////////////////////////////////////////////
2229 /// Print TBranch parameters
2230 ///
2231 /// If options contains "basketsInfo" print the entry number, location and size
2232 /// of each baskets.
2233 
2234 void TBranch::Print(Option_t *option) const
2235 {
2236  const int kLINEND = 77;
2237  Float_t cx = 1;
2238 
2239  TString titleContent(GetTitle());
2240  if ( titleContent == GetName() ) {
2241  titleContent.Clear();
2242  }
2243 
2244  if (fLeaves.GetEntries() == 1) {
2245  if (titleContent.Length()>=2 && titleContent[titleContent.Length()-2]=='/' && isalpha(titleContent[titleContent.Length()-1])) {
2246  // The type is already encoded. Nothing to do.
2247  } else {
2248  TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(0);
2249  if (titleContent.Length()) {
2250  titleContent.Prepend(" ");
2251  }
2252  // titleContent.Append("type: ");
2253  titleContent.Prepend(leaf->GetTypeName());
2254  }
2255  }
2256  Int_t titleLength = titleContent.Length();
2257 
2258  Int_t aLength = titleLength + strlen(GetName());
2259  aLength += (aLength / 54 + 1) * 80 + 100;
2260  if (aLength < 200) aLength = 200;
2261  char *bline = new char[aLength];
2262 
2263  Long64_t totBytes = GetTotalSize();
2264  if (fZipBytes) cx = (fTotBytes+0.00001)/fZipBytes;
2265  if (titleLength) snprintf(bline,aLength,"*Br%5d :%-9s : %-54s *",fgCount,GetName(),titleContent.Data());
2266  else snprintf(bline,aLength,"*Br%5d :%-9s : %-54s *",fgCount,GetName()," ");
2267  if (strlen(bline) > UInt_t(kLINEND)) {
2268  char *tmp = new char[strlen(bline)+1];
2269  if (titleLength) strlcpy(tmp, titleContent.Data(),strlen(bline)+1);
2270  snprintf(bline,aLength,"*Br%5d :%-9s : ",fgCount,GetName());
2271  int pos = strlen (bline);
2272  int npos = pos;
2273  int beg=0, end;
2274  while (beg < titleLength) {
2275  for (end=beg+1; end < titleLength-1; end ++)
2276  if (tmp[end] == ':') break;
2277  if (npos + end-beg+1 >= 78) {
2278  while (npos < kLINEND) {
2279  bline[pos ++] = ' ';
2280  npos ++;
2281  }
2282  bline[pos ++] = '*';
2283  bline[pos ++] = '\n';
2284  bline[pos ++] = '*';
2285  npos = 1;
2286  for (; npos < 12; npos ++)
2287  bline[pos ++] = ' ';
2288  bline[pos-2] = '|';
2289  }
2290  for (int n = beg; n <= end; n ++)
2291  bline[pos+n-beg] = tmp[n];
2292  pos += end-beg+1;
2293  npos += end-beg+1;
2294  beg = end+1;
2295  }
2296  while (npos < kLINEND) {
2297  bline[pos ++] = ' ';
2298  npos ++;
2299  }
2300  bline[pos ++] = '*';
2301  bline[pos] = '\0';
2302  delete[] tmp;
2303  }
2304  Printf("%s", bline);
2305 
2306  if (fTotBytes > 2000000000) {
2307  Printf("*Entries :%lld : Total Size=%11lld bytes File Size = %lld *",fEntries,totBytes,fZipBytes);
2308  } else {
2309  if (fZipBytes > 0) {
2310  Printf("*Entries :%9lld : Total Size=%11lld bytes File Size = %10lld *",fEntries,totBytes,fZipBytes);
2311  } else {
2312  if (fWriteBasket > 0) {
2313  Printf("*Entries :%9lld : Total Size=%11lld bytes All baskets in memory *",fEntries,totBytes);
2314  } else {
2315  Printf("*Entries :%9lld : Total Size=%11lld bytes One basket in memory *",fEntries,totBytes);
2316  }
2317  }
2318  }
2319  Printf("*Baskets :%9d : Basket Size=%11d bytes Compression= %6.2f *",fWriteBasket,fBasketSize,cx);
2320 
2321  if (strncmp(option,"basketsInfo",strlen("basketsInfo"))==0) {
2322  Int_t nbaskets = fWriteBasket;
2323  for (Int_t i=0;i<nbaskets;i++) {
2324  Printf("*Basket #%4d entry=%6lld pos=%6lld size=%5d",
2325  i, fBasketEntry[i], fBasketSeek[i], fBasketBytes[i]);
2326  }
2327  }
2328 
2329  Printf("*............................................................................*");
2330  delete [] bline;
2331  fgCount++;
2332 }
2333 
2334 ////////////////////////////////////////////////////////////////////////////////
2335 /// Print the information we have about which basket is currently cached and
2336 /// whether they have been 'used'/'read' from the cache.
2337 
2339 {
2341 }
2342 
2343 ////////////////////////////////////////////////////////////////////////////////
2344 /// Loop on all leaves of this branch to read Basket buffer.
2345 
2347 {
2348  // fLeaves->ReadBasket(basket);
2349 }
2350 
2351 ////////////////////////////////////////////////////////////////////////////////
2352 /// Loop on all leaves of this branch to read Basket buffer.
2353 
2355 {
2356  for (Int_t i = 0; i < fNleaves; ++i) {
2357  TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
2358  leaf->ReadBasket(b);
2359  }
2360 }
2361 
2362 ////////////////////////////////////////////////////////////////////////////////
2363 /// Read zero leaves without the overhead of a loop.
2364 
2366 {
2367 }
2368 
2369 ////////////////////////////////////////////////////////////////////////////////
2370 /// Read one leaf without the overhead of a loop.
2371 
2373 {
2374  ((TLeaf*) fLeaves.UncheckedAt(0))->ReadBasket(b);
2375 }
2376 
2377 ////////////////////////////////////////////////////////////////////////////////
2378 /// Read two leaves without the overhead of a loop.
2379 
2381 {
2382  ((TLeaf*) fLeaves.UncheckedAt(0))->ReadBasket(b);
2383  ((TLeaf*) fLeaves.UncheckedAt(1))->ReadBasket(b);
2384 }
2385 
2386 ////////////////////////////////////////////////////////////////////////////////
2387 /// Loop on all leaves of this branch to fill Basket buffer.
2388 
2390 {
2391  for (Int_t i = 0; i < fNleaves; ++i) {
2392  TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
2393  leaf->FillBasket(b);
2394  }
2395 }
2396 
2397 ////////////////////////////////////////////////////////////////////////////////
2398 /// Refresh this branch using new information in b
2399 /// This function is called by TTree::Refresh
2400 
2402 {
2403  if (b==0) return;
2404 
2405  fEntryOffsetLen = b->fEntryOffsetLen;
2406  fWriteBasket = b->fWriteBasket;
2407  fEntryNumber = b->fEntryNumber;
2408  fMaxBaskets = b->fMaxBaskets;
2409  fEntries = b->fEntries;
2410  fTotBytes = b->fTotBytes;
2411  fZipBytes = b->fZipBytes;
2412  fReadBasket = 0;
2413  fReadEntry = -1;
2414  fFirstBasketEntry = -1;
2415  fNextBasketEntry = -1;
2416  fCurrentBasket = 0;
2417  delete [] fBasketBytes;
2418  delete [] fBasketEntry;
2419  delete [] fBasketSeek;
2423  Int_t i;
2424  for (i=0;i<fMaxBaskets;i++) {
2425  fBasketBytes[i] = b->fBasketBytes[i];
2426  fBasketEntry[i] = b->fBasketEntry[i];
2427  fBasketSeek[i] = b->fBasketSeek[i];
2428  }
2429  fBaskets.Delete();
2430  Int_t nbaskets = b->fBaskets.GetSize();
2431  fBaskets.Expand(nbaskets);
2432  // If the current fWritebasket is in memory, take it (just swap)
2433  // from the Tree being read
2434  TBasket *basket = (TBasket*)b->fBaskets.UncheckedAt(fWriteBasket);
2435  fBaskets.AddAt(basket,fWriteBasket);
2436  if (basket) {
2437  fNBaskets = 1;
2438  --(b->fNBaskets);
2439  b->fBaskets.RemoveAt(fWriteBasket);
2440  basket->SetBranch(this);
2441  }
2442 }
2443 
2444 ////////////////////////////////////////////////////////////////////////////////
2445 /// Reset a Branch.
2446 ///
2447 /// - Existing buffers are deleted.
2448 /// - Entries, max and min are reset.
2449 
2451 {
2452  fReadBasket = 0;
2453  fReadEntry = -1;
2454  fFirstBasketEntry = -1;
2455  fNextBasketEntry = -1;
2456  fCurrentBasket = 0;
2457  fWriteBasket = 0;
2458  fEntries = 0;
2459  fTotBytes = 0;
2460  fZipBytes = 0;
2461  fEntryNumber = 0;
2462 
2463  if (fBasketBytes) {
2464  for (Int_t i = 0; i < fMaxBaskets; ++i) {
2465  fBasketBytes[i] = 0;
2466  }
2467  }
2468 
2469  if (fBasketEntry) {
2470  for (Int_t i = 0; i < fMaxBaskets; ++i) {
2471  fBasketEntry[i] = 0;
2472  }
2473  }
2474 
2475  if (fBasketSeek) {
2476  for (Int_t i = 0; i < fMaxBaskets; ++i) {
2477  fBasketSeek[i] = 0;
2478  }
2479  }
2480 
2481  fBaskets.Delete();
2482  fNBaskets = 0;
2483 }
2484 
2485 ////////////////////////////////////////////////////////////////////////////////
2486 /// Reset a Branch.
2487 ///
2488 /// - Existing buffers are deleted.
2489 /// - Entries, max and min are reset.
2490 
2492 {
2493  fReadBasket = 0;
2494  fReadEntry = -1;
2495  fFirstBasketEntry = -1;
2496  fNextBasketEntry = -1;
2497  fCurrentBasket = 0;
2498  fWriteBasket = 0;
2499  fEntries = 0;
2500  fTotBytes = 0;
2501  fZipBytes = 0;
2502  fEntryNumber = 0;
2503 
2504  if (fBasketBytes) {
2505  for (Int_t i = 0; i < fMaxBaskets; ++i) {
2506  fBasketBytes[i] = 0;
2507  }
2508  }
2509 
2510  if (fBasketEntry) {
2511  for (Int_t i = 0; i < fMaxBaskets; ++i) {
2512  fBasketEntry[i] = 0;
2513  }
2514  }
2515 
2516  if (fBasketSeek) {
2517  for (Int_t i = 0; i < fMaxBaskets; ++i) {
2518  fBasketSeek[i] = 0;
2519  }
2520  }
2521 
2522  TBasket *reusebasket = (TBasket*)fBaskets[fWriteBasket];
2523  if (reusebasket) {
2524  fBaskets[fWriteBasket] = 0;
2525  } else {
2526  reusebasket = (TBasket*)fBaskets[fReadBasket];
2527  if (reusebasket) {
2528  fBaskets[fReadBasket] = 0;
2529  }
2530  }
2531  fBaskets.Delete();
2532  if (reusebasket) {
2533  fNBaskets = 1;
2534  reusebasket->WriteReset();
2535  fBaskets[0] = reusebasket;
2536  } else {
2537  fNBaskets = 0;
2538  }
2539 }
2540 
2541 ////////////////////////////////////////////////////////////////////////////////
2542 /// Reset the address of the branch.
2543 
2545 {
2546  fAddress = 0;
2547 
2548  // Reset last read entry number, we have will had new user object now.
2549  fReadEntry = -1;
2550 
2551  for (Int_t i = 0; i < fNleaves; ++i) {
2552  TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
2553  leaf->SetAddress(0);
2554  }
2555 
2556  Int_t nbranches = fBranches.GetEntriesFast();
2557  for (Int_t i = 0; i < nbranches; ++i) {
2558  TBranch* abranch = (TBranch*) fBranches[i];
2559  // FIXME: This is a tail recursion.
2560  abranch->ResetAddress();
2561  }
2562 }
2563 
2564 ////////////////////////////////////////////////////////////////////////////////
2565 /// Static function resetting fgCount
2566 
2568 {
2569  fgCount = 0;
2570 }
2571 
2572 ////////////////////////////////////////////////////////////////////////////////
2573 /// Set address of this branch.
2574 
2575 void TBranch::SetAddress(void* addr)
2576 {
2577  if (TestBit(kDoNotProcess)) {
2578  return;
2579  }
2580  fReadEntry = -1;
2581  fFirstBasketEntry = -1;
2582  fNextBasketEntry = -1;
2583  fAddress = (char*) addr;
2584  for (Int_t i = 0; i < fNleaves; ++i) {
2585  TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
2586  Int_t offset = leaf->GetOffset();
2587  if (TestBit(kIsClone)) {
2588  offset = 0;
2589  }
2590  if (fAddress) leaf->SetAddress(fAddress + offset);
2591  else leaf->SetAddress(0);
2592  }
2593 }
2594 
2595 ////////////////////////////////////////////////////////////////////////////////
2596 /// Set the automatic delete bit.
2597 ///
2598 /// This bit is used by TBranchObject::ReadBasket to decide if an object
2599 /// referenced by a TBranchObject must be deleted or not before reading
2600 /// a new entry.
2601 ///
2602 /// If autodel is kTRUE, this existing object will be deleted, a new object
2603 /// created by the default constructor, then read from disk by the streamer.
2604 ///
2605 /// If autodel is kFALSE, the existing object is not deleted. Root assumes
2606 /// that the user is taking care of deleting any internal object or array
2607 /// (this can be done in the streamer).
2608 
2610 {
2611  if (autodel) {
2612  SetBit(kAutoDelete, 1);
2613  } else {
2614  SetBit(kAutoDelete, 0);
2615  }
2616 }
2617 
2618 ////////////////////////////////////////////////////////////////////////////////
2619 /// Set the basket size
2620 /// The function makes sure that the basket size is greater than fEntryOffsetlen
2621 
2623 {
2624  Int_t minsize = 100 + fName.Length();
2625  if (buffsize < minsize+fEntryOffsetLen) buffsize = minsize+fEntryOffsetLen;
2626  fBasketSize = buffsize;
2627  TBasket *basket = (TBasket*)fBaskets[fWriteBasket];
2628  if (basket) {
2629  basket->AdjustSize(fBasketSize);
2630  }
2631 }
2632 
2633 ////////////////////////////////////////////////////////////////////////////////
2634 /// Set address of this branch directly from a TBuffer to avoid streaming.
2635 ///
2636 /// Note: We do not take ownership of the buffer.
2637 
2639 {
2640  // Check this is possible
2641  if ( (fNleaves != 1)
2642  || (strcmp("TLeafObject",fLeaves.UncheckedAt(0)->ClassName())!=0) ) {
2643  Error("TBranch::SetAddress","Filling from a TBuffer can only be done with a not split object branch. Request ignored.");
2644  } else {
2645  fReadEntry = -1;
2646  fNextBasketEntry = -1;
2647  fFirstBasketEntry = -1;
2648  // Note: We do not take ownership of the buffer.
2649  fEntryBuffer = buf;
2650  }
2651 }
2652 
2653 ////////////////////////////////////////////////////////////////////////////////
2654 /// Set compression algorithm.
2655 
2657 {
2658  if (algorithm < 0 || algorithm >= ROOT::RCompressionSetting::EAlgorithm::kUndefined) algorithm = 0;
2659  if (fCompress < 0) {
2661  } else {
2662  int level = fCompress % 100;
2663  fCompress = 100 * algorithm + level;
2664  }
2665 
2667  for (Int_t i=0;i<nb;i++) {
2668  TBranch *branch = (TBranch*)fBranches.UncheckedAt(i);
2669  branch->SetCompressionAlgorithm(algorithm);
2670  }
2671 }
2672 
2673 ////////////////////////////////////////////////////////////////////////////////
2674 /// Set compression level.
2675 
2677 {
2678  if (level < 0) level = 0;
2679  if (level > 99) level = 99;
2680  if (fCompress < 0) {
2681  fCompress = level;
2682  } else {
2683  int algorithm = fCompress / 100;
2684  if (algorithm >= ROOT::RCompressionSetting::EAlgorithm::kUndefined) algorithm = 0;
2685  fCompress = 100 * algorithm + level;
2686  }
2687 
2689  for (Int_t i=0;i<nb;i++) {
2690  TBranch *branch = (TBranch*)fBranches.UncheckedAt(i);
2691  branch->SetCompressionLevel(level);
2692  }
2693 }
2694 
2695 ////////////////////////////////////////////////////////////////////////////////
2696 /// Set compression settings.
2697 
2699 {
2700  fCompress = settings;
2701 
2703  for (Int_t i=0;i<nb;i++) {
2704  TBranch *branch = (TBranch*)fBranches.UncheckedAt(i);
2705  branch->SetCompressionSettings(settings);
2706  }
2707 }
2708 
2709 ////////////////////////////////////////////////////////////////////////////////
2710 /// Update the default value for the branch's fEntryOffsetLen if and only if
2711 /// it was already non zero (and the new value is not zero)
2712 /// If updateExisting is true, also update all the existing branches.
2713 
2714 void TBranch::SetEntryOffsetLen(Int_t newdefault, Bool_t updateExisting)
2715 {
2716  if (fEntryOffsetLen && newdefault) {
2717  fEntryOffsetLen = newdefault;
2718  }
2719  if (updateExisting) {
2720  TIter next( GetListOfBranches() );
2721  TBranch *b;
2722  while ( ( b = (TBranch*)next() ) ) {
2723  b->SetEntryOffsetLen( newdefault, kTRUE );
2724  }
2725  }
2726 }
2727 
2728 ////////////////////////////////////////////////////////////////////////////////
2729 /// Set the number of entries in this branch.
2730 
2732 {
2733  fEntries = entries;
2734  fEntryNumber = entries;
2735 }
2736 
2737 ////////////////////////////////////////////////////////////////////////////////
2738 /// Set file where this branch writes/reads its buffers.
2739 /// By default the branch buffers reside in the file where the
2740 /// Tree was created.
2741 /// If the file name where the tree was created is an absolute
2742 /// path name or an URL (e.g. or root://host/...)
2743 /// and if the fname is not an absolute path name or an URL then
2744 /// the path of the tree file is prepended to fname to make the
2745 /// branch file relative to the tree file. In this case one can
2746 /// move the tree + all branch files to a different location in
2747 /// the file system and still access the branch files.
2748 /// The ROOT file will be connected only when necessary.
2749 /// If called by TBranch::Fill (via TBasket::WriteFile), the file
2750 /// will be created with the option "recreate".
2751 /// If called by TBranch::GetEntry (via TBranch::GetBasket), the file
2752 /// will be opened in read mode.
2753 /// To open a file in "update" mode or with a certain compression
2754 /// level, use TBranch::SetFile(TFile *file).
2755 
2757 {
2758  if (file == 0) file = fTree->GetCurrentFile();
2760  if (file == fTree->GetCurrentFile()) fFileName = "";
2761  else fFileName = file->GetName();
2762 
2763  if (file && fCompress == -1) {
2764  fCompress = file->GetCompressionLevel();
2765  }
2766 
2767  // Apply to all existing baskets.
2768  TIter nextb(GetListOfBaskets());
2769  TBasket *basket;
2770  while ((basket = (TBasket*)nextb())) {
2771  basket->SetParent(file);
2772  }
2773 
2774  // Apply to sub-branches as well.
2775  TIter next(GetListOfBranches());
2776  TBranch *branch;
2777  while ((branch = (TBranch*)next())) {
2778  branch->SetFile(file);
2779  }
2780 }
2781 
2782 ////////////////////////////////////////////////////////////////////////////////
2783 /// Set file where this branch writes/reads its buffers.
2784 /// By default the branch buffers reside in the file where the
2785 /// Tree was created.
2786 /// If the file name where the tree was created is an absolute
2787 /// path name or an URL (e.g. root://host/...)
2788 /// and if the fname is not an absolute path name or an URL then
2789 /// the path of the tree file is prepended to fname to make the
2790 /// branch file relative to the tree file. In this case one can
2791 /// move the tree + all branch files to a different location in
2792 /// the file system and still access the branch files.
2793 /// The ROOT file will be connected only when necessary.
2794 /// If called by TBranch::Fill (via TBasket::WriteFile), the file
2795 /// will be created with the option "recreate".
2796 /// If called by TBranch::GetEntry (via TBranch::GetBasket), the file
2797 /// will be opened in read mode.
2798 /// To open a file in "update" mode or with a certain compression
2799 /// level, use TBranch::SetFile(TFile *file).
2800 
2801 void TBranch::SetFile(const char* fname)
2802 {
2803  fFileName = fname;
2804  fDirectory = 0;
2805 
2806  //apply to sub-branches as well
2807  TIter next(GetListOfBranches());
2808  TBranch *branch;
2809  while ((branch = (TBranch*)next())) {
2810  branch->SetFile(fname);
2811  }
2812 }
2813 
2814 ////////////////////////////////////////////////////////////////////////////////
2815 /// Set the branch in a mode where the object are decomposed
2816 /// (Also known as MakeClass mode).
2817 /// Return whether the setting was possible (it is not possible for
2818 /// TBranch and TBranchObject).
2819 
2821 {
2822  // Regular TBranch and TBrancObject can not be in makeClass mode
2823  return kFALSE;
2824 }
2825 
2826 ////////////////////////////////////////////////////////////////////////////////
2827 /// Set object this branch is pointing to.
2828 
2829 void TBranch::SetObject(void * /* obj */)
2830 {
2831  if (TestBit(kDoNotProcess)) {
2832  return;
2833  }
2834  Warning("SetObject","is not supported in TBranch objects");
2835 }
2836 
2837 ////////////////////////////////////////////////////////////////////////////////
2838 /// Set branch status to Process or DoNotProcess.
2839 
2841 {
2842  if (status) ResetBit(kDoNotProcess);
2843  else SetBit(kDoNotProcess);
2844 }
2845 
2846 ////////////////////////////////////////////////////////////////////////////////
2847 /// Stream a class object
2848 
2849 void TBranch::Streamer(TBuffer& b)
2850 {
2851  if (b.IsReading()) {
2852  UInt_t R__s, R__c;
2853  fTree = 0; // Will be set by TTree::Streamer
2854  fAddress = 0;
2855  gROOT->SetReadingObject(kTRUE);
2856 
2857  // Reset transients.
2859  fCurrentBasket = 0;
2860  fFirstBasketEntry = -1;
2861  fNextBasketEntry = -1;
2862 
2863  Version_t v = b.ReadVersion(&R__s, &R__c);
2864  if (v > 9) {
2865  b.ReadClassBuffer(TBranch::Class(), this, v, R__s, R__c);
2866 
2867  if (fWriteBasket>=fBaskets.GetSize()) {
2869  }
2870  fDirectory = 0;
2872  for (Int_t i=0;i<fNleaves;i++) {
2873  TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
2874  leaf->SetBranch(this);
2875  }
2876 
2878  for (Int_t j=fWriteBasket,n=0;j>=0 && n<fNBaskets;--j) {
2879  TBasket *bk = (TBasket*)fBaskets.UncheckedAt(j);
2880  if (bk) {
2881  bk->SetBranch(this);
2882  // GetTree()->IncrementTotalBuffers(bk->GetBufferSize());
2883  ++n;
2884  }
2885  }
2886  if (fWriteBasket >= fMaxBaskets) {
2887  //old versions may need this fix
2892 
2893  }
2895  gROOT->SetReadingObject(kFALSE);
2896  if (IsA() == TBranch::Class()) {
2897  if (fNleaves == 0) {
2899  } else if (fNleaves == 1) {
2901  } else if (fNleaves == 2) {
2903  } else {
2905  }
2906  }
2907  return;
2908  }
2909  //====process old versions before automatic schema evolution
2910  Int_t n,i,j,ijunk;
2911  if (v > 5) {
2912  Stat_t djunk;
2913  TNamed::Streamer(b);
2914  if (v > 7) TAttFill::Streamer(b);
2915  b >> fCompress;
2916  b >> fBasketSize;
2917  b >> fEntryOffsetLen;
2918  b >> fWriteBasket;
2919  b >> ijunk; fEntryNumber = (Long64_t)ijunk;
2920  b >> fOffset;
2921  b >> fMaxBaskets;
2922  if (v > 6) b >> fSplitLevel;
2923  b >> djunk; fEntries = (Long64_t)djunk;
2924  b >> djunk; fTotBytes = (Long64_t)djunk;
2925  b >> djunk; fZipBytes = (Long64_t)djunk;
2926 
2927  fBranches.Streamer(b);
2928  fLeaves.Streamer(b);
2929  fBaskets.Streamer(b);
2933  Char_t isArray;
2934  b >> isArray;
2935  b.ReadFastArray(fBasketBytes,fMaxBaskets);
2936  b >> isArray;
2937  for (i=0;i<fMaxBaskets;i++) {b >> ijunk; fBasketEntry[i] = ijunk;}
2938  b >> isArray;
2939  for (i=0;i<fMaxBaskets;i++) {
2940  if (isArray == 2) b >> fBasketSeek[i];
2941  else {Int_t bsize; b >> bsize; fBasketSeek[i] = (Long64_t)bsize;};
2942  }
2943  fFileName.Streamer(b);
2944  b.CheckByteCount(R__s, R__c, TBranch::IsA());
2945  fDirectory = 0;
2947  for (i=0;i<fNleaves;i++) {
2948  TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
2949  leaf->SetBranch(this);
2950  }
2952  for (j=fWriteBasket,n=0;j>=0 && n<fNBaskets;--j) {
2953  TBasket *bk = (TBasket*)fBaskets.UncheckedAt(j);
2954  if (bk) {
2955  bk->SetBranch(this);
2956  //GetTree()->IncrementTotalBuffers(bk->GetBufferSize());
2957  ++n;
2958  }
2959  }
2960  if (fWriteBasket >= fMaxBaskets) {
2961  //old versions may need this fix
2966 
2967  }
2968  // Check Byte Count is not needed since it was done in ReadBuffer
2970  gROOT->SetReadingObject(kFALSE);
2971  b.CheckByteCount(R__s, R__c, TBranch::IsA());
2972  if (IsA() == TBranch::Class()) {
2973  if (fNleaves == 0) {
2975  } else if (fNleaves == 1) {
2977  } else if (fNleaves == 2) {
2979  } else {
2981  }
2982  }
2983  return;
2984  }
2985  //====process very old versions
2986  Stat_t djunk;
2987  TNamed::Streamer(b);
2988  b >> fCompress;
2989  b >> fBasketSize;
2990  b >> fEntryOffsetLen;
2991  b >> fMaxBaskets;
2992  b >> fWriteBasket;
2993  b >> ijunk; fEntryNumber = (Long64_t)ijunk;
2994  b >> djunk; fEntries = (Long64_t)djunk;
2995  b >> djunk; fTotBytes = (Long64_t)djunk;
2996  b >> djunk; fZipBytes = (Long64_t)djunk;
2997  b >> fOffset;
2998  fBranches.Streamer(b);
2999  fLeaves.Streamer(b);
3001  for (i=0;i<fNleaves;i++) {
3002  TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
3003  leaf->SetBranch(this);
3004  }
3005  fBaskets.Streamer(b);
3006  Int_t nbaskets = fBaskets.GetEntries();
3007  for (j=fWriteBasket,n=0;j>0 && n<nbaskets;--j) {
3008  TBasket *bk = (TBasket*)fBaskets.UncheckedAt(j);
3009  if (bk) {
3010  bk->SetBranch(this);
3011  //GetTree()->IncrementTotalBuffers(bk->GetBufferSize());
3012  ++n;
3013  }
3014  }
3016  b >> n;
3017  for (i=0;i<n;i++) {b >> ijunk; fBasketEntry[i] = ijunk;}
3019  if (v > 4) {
3020  n = b.ReadArray(fBasketBytes);
3021  } else {
3022  for (n=0;n<fMaxBaskets;n++) fBasketBytes[n] = 0;
3023  }
3024  if (v < 2) {
3026  for (n=0;n<fWriteBasket;n++) {
3027  TBasket *basket = GetBasketImpl(n, nullptr);
3028  fBasketSeek[n] = basket ? basket->GetSeekKey() : 0;
3029  }
3030  } else {
3032  b >> n;
3033  for (n=0;n<fMaxBaskets;n++) {
3034  Int_t aseek;
3035  b >> aseek;
3036  fBasketSeek[n] = Long64_t(aseek);
3037  }
3038  }
3039  if (v > 2) {
3040  fFileName.Streamer(b);
3041  }
3042  fDirectory = 0;
3043  if (v < 4) SetAutoDelete(kTRUE);
3045  gROOT->SetReadingObject(kFALSE);
3046  b.CheckByteCount(R__s, R__c, TBranch::IsA());
3047  //====end of old versions
3048  if (IsA() == TBranch::Class()) {
3049  if (fNleaves == 0) {
3051  } else if (fNleaves == 1) {
3053  } else if (fNleaves == 2) {
3055  } else {
3057  }
3058  }
3059  } else {
3060  Int_t maxBaskets = fMaxBaskets;
3062  Int_t lastBasket = fMaxBaskets;
3063  if (fMaxBaskets < 10) fMaxBaskets = 10;
3064 
3065  TBasket **stash = new TBasket *[lastBasket];
3066  for (Int_t i = 0; i < lastBasket; ++i) {
3067  TBasket *ba = (TBasket *)fBaskets.UncheckedAt(i);
3068  if (ba && (fBasketBytes[i] || ba->GetNevBuf()==0)) {
3069  // Already on disk or empty.
3070  stash[i] = ba;
3071  fBaskets[i] = nullptr;
3072  } else {
3073  stash[i] = nullptr;
3074  }
3075  }
3076 
3077  b.WriteClassBuffer(TBranch::Class(), this);
3078 
3079  for (Int_t i = 0; i < lastBasket; ++i) {
3080  if (stash[i]) fBaskets[i] = stash[i];
3081  }
3082 
3083  delete[] stash;
3084  fMaxBaskets = maxBaskets;
3085  }
3086 }
3087 
3088 ////////////////////////////////////////////////////////////////////////////////
3089 /// Write the current basket to disk and return the number of bytes
3090 /// written to the file.
3091 
3093 {
3094  Int_t nevbuf = basket->GetNevBuf();
3095  if (fEntryOffsetLen > 10 && (4*nevbuf) < fEntryOffsetLen ) {
3096  // Make sure that the fEntryOffset array does not stay large unnecessarily.
3097  fEntryOffsetLen = nevbuf < 3 ? 10 : 4*nevbuf; // assume some fluctuations.
3098  } else if (fEntryOffsetLen && nevbuf > fEntryOffsetLen) {
3099  // Increase the array ...
3100  fEntryOffsetLen = 2*nevbuf; // assume some fluctuations.
3101  }
3102 
3103  // Note: captures `basket`, `where`, and `this` by value; modifies the TBranch and basket,
3104  // as we make a copy of the pointer. We cannot capture `basket` by reference as the pointer
3105  // itself might be modified after `WriteBasketImpl` exits.
3106  auto doUpdates = [=]() {
3107  Int_t nout = basket->WriteBuffer(); // Write buffer
3108  if (nout < 0) Error("TBranch::WriteBasketImpl", "basket's WriteBuffer failed.\n");
3109  fBasketBytes[where] = basket->GetNbytes();
3110  fBasketSeek[where] = basket->GetSeekKey();
3111  Int_t addbytes = basket->GetObjlen() + basket->GetKeylen();
3112  TBasket *reusebasket = 0;
3113  if (nout>0) {
3114  // The Basket was written so we can now safely reuse it.
3115  fBaskets[where] = 0;
3116 
3117  reusebasket = basket;
3118  reusebasket->WriteReset();
3119 
3120  fZipBytes += nout;
3121  fTotBytes += addbytes;
3122  fTree->AddTotBytes(addbytes);
3123  fTree->AddZipBytes(nout);
3124 #ifdef R__TRACK_BASKET_ALLOC_TIME
3125  fTree->AddAllocationTime(reusebasket->GetResetAllocationTime());
3126 #endif
3128  }
3129 
3130  if (where==fWriteBasket) {
3131  ++fWriteBasket;
3132  if (fWriteBasket >= fMaxBaskets) {
3134  }
3135  if (reusebasket && reusebasket == fCurrentBasket) {
3136  // The 'current' basket has Reset, so if we need it we will need
3137  // to reload it.
3138  fCurrentBasket = 0;
3139  fFirstBasketEntry = -1;
3140  fNextBasketEntry = -1;
3141  }
3142  fBaskets.AddAtAndExpand(reusebasket,fWriteBasket);
3144  } else {
3145  --fNBaskets;
3146  fBaskets[where] = 0;
3147  basket->DropBuffers();
3148  if (basket == fCurrentBasket) {
3149  fCurrentBasket = 0;
3150  fFirstBasketEntry = -1;
3151  fNextBasketEntry = -1;
3152  }
3153  delete basket;
3154  }
3155  return nout;
3156  };
3157  if (imtHelper) {
3158  imtHelper->Run(doUpdates);
3159  return 0;
3160  } else {
3161  return doUpdates();
3162  }
3163 }
3164 
3165 ////////////////////////////////////////////////////////////////////////////////
3166 ///set the first entry number (case of TBranchSTL)
3167 
3169 {
3170  fFirstEntry = entry;
3171  fEntries = 0;
3172  fEntryNumber = entry;
3173  if( fBasketEntry )
3174  fBasketEntry[0] = entry;
3175  for( Int_t i = 0; i < fBranches.GetEntriesFast(); ++i )
3176  ((TBranch*)fBranches[i])->SetFirstEntry( entry );
3177 }
3178 
3179 ////////////////////////////////////////////////////////////////////////////////
3180 /// If the branch address is not set, we set all addresses starting with
3181 /// the top level parent branch.
3182 
3184 {
3185  SetAddress(nullptr); // in some cases, this triggers setting of the address
3186 }
3187 
3188 ////////////////////////////////////////////////////////////////////////////////
3189 /// Refresh the value of fDirectory (i.e. where this branch writes/reads its buffers)
3190 /// with the current value of fTree->GetCurrentFile unless this branch has been
3191 /// redirected to a different file. Also update the sub-branches.
3192 
3194 {
3196  if (fFileName.Length() == 0) {
3197  fDirectory = file;
3198 
3199  // Apply to all existing baskets.
3200  TIter nextb(GetListOfBaskets());
3201  TBasket *basket;
3202  while ((basket = (TBasket*)nextb())) {
3203  basket->SetParent(file);
3204  }
3205  }
3206 
3207  // Apply to sub-branches as well.
3208  TIter next(GetListOfBranches());
3209  TBranch *branch;
3210  while ((branch = (TBranch*)next())) {
3211  branch->UpdateFile();
3212  }
3213 }
TBranch::ExpandBasketArrays
void ExpandBasketArrays()
Increase BasketEntry buffer of a minimum of 10 locations and a maximum of 50 per cent of current size...
Definition: TBranch.cxx:812
ROOT::Internal::TBranchIMTHelper::Run
void Run(const FN &lambda)
Definition: TBranchIMTHelper.h:33
TBranch::fNleaves
Int_t fNleaves
! Number of leaves
Definition: TBranch.h:124
TLeafC
A TLeaf for a variable length string.
Definition: TLeafC.h:26
TBuffer::GetMapCount
virtual Int_t GetMapCount() const =0
l
auto * l
Definition: textangle.C:4
TBranch::ResetAddress
virtual void ResetAddress()
Reset the address of the branch.
Definition: TBranch.cxx:2544
TBuffer::ReadString
virtual char * ReadString(char *s, Int_t max)=0
TBranch::fCacheInfo
CacheInfo_t fCacheInfo
! Hold info about which basket are in the cache and if they have been retrieved from the cache.
Definition: TBranch.h:154
TBranch::FillLeavesImpl
void FillLeavesImpl(TBuffer &b)
Loop on all leaves of this branch to fill Basket buffer.
Definition: TBranch.cxx:2389
TBranch::GetBasketAndFirst
Int_t GetBasketAndFirst(TBasket *&basket, Long64_t &first, TBuffer *user_buffer)
A helper function to locate the correct basket - and its first entry.
Definition: TBranch.cxx:1340
Compression.h
n
const Int_t n
Definition: legend1.C:16
TBasket::ReadBasketBuffers
Int_t ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:464
TFileMergeInfo
Definition: TFileMergeInfo.h:42
TBranch::fBasketSize
Int_t fBasketSize
Initial Size of Basket Buffer.
Definition: TBranch.h:114
TVirtualPerfStats.h
TBranch::fOffset
Int_t fOffset
Offset of this branch.
Definition: TBranch.h:120
TKey::GetKeylen
Int_t GetKeylen() const
Definition: TKey.h:85
first
Definition: first.py:1
TLeafL
A TLeaf for a 64 bit Integer data type.
Definition: TLeafL.h:27
TLeafD32.h
TBrowser
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TTree::TClusterIterator::GetStartEntry
Long64_t GetStartEntry()
Definition: TTree.h:298
TBasket::DisownBuffer
void DisownBuffer()
Disown all references to the internal buffer - some other object likely now owns it.
Definition: TBasket.cxx:713
TObjArray::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:356
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
TBranch::SetBufferAddress
virtual void SetBufferAddress(TBuffer *entryBuffer)
Set address of this branch directly from a TBuffer to avoid streaming.
Definition: TBranch.cxx:2638
Version_t
short Version_t
Definition: RtypesCore.h:65
TBranch::GetLeaf
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
Definition: TBranch.cxx:1963
TBranch::IsAutoDelete
Bool_t IsAutoDelete() const
Return kTRUE if an existing object in a TBranchObject must be deleted.
Definition: TBranch.cxx:2156
TTree::TClusterIterator::Previous
Long64_t Previous()
Move on to the previous cluster and return the starting entry of this previous cluster.
Definition: TTree.cxx:684
TLeafL.h
snprintf
#define snprintf
Definition: civetweb.c:1540
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
TBranchBrowsable.h
TBranch::fLeaves
TObjArray fLeaves
-> List of leaves of this branch
Definition: TBranch.h:135
kNewClassTag
const UInt_t kNewClassTag
Definition: TBufferFile.cxx:48
TBranch::FillEntryBuffer
Int_t FillEntryBuffer(TBasket *basket, TBuffer *buf, Int_t &lnew)
Copy the data from fEntryBuffer into the current basket.
Definition: TBranch.cxx:922
TBuffer::BufferSize
Int_t BufferSize() const
Definition: TBuffer.h:98
TBranch::FindBranch
virtual TBranch * FindBranch(const char *name)
Find the immediate sub-branch with passed name.
Definition: TBranch.cxx:1022
TBranch::GetZipBytes
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:2131
ROOT::RCompressionSetting::ELevel::kUseMin
@ kUseMin
Compression level reserved when we are not sure what to use (1 is for the fastest compression)
Definition: Compression.h:68
Option_t
const char Option_t
Definition: RtypesCore.h:66
TBranch::GetEntryExport
virtual Int_t GetEntryExport(Long64_t entry, Int_t getall, TClonesArray *list, Int_t n)
Read all leaves of an entry and export buffers to real objects in a TClonesArray list.
Definition: TBranch.cxx:1691
TBranch::GetEntriesSerialized
Int_t GetEntriesSerialized(Long64_t N, TBuffer &user_buf)
Definition: TBranch.h:181
TLeafObject.h
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
TBuffer::kRead
@ kRead
Definition: TBuffer.h:73
TBuffer::SetBuffer
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.
Definition: TBuffer.cxx:187
kNPOS
const Ssiz_t kNPOS
Definition: RtypesCore.h:115
TString::Prepend
TString & Prepend(const char *cs)
Definition: TString.h:661
TSystem::BaseName
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:933
TBranch::SetMakeClass
virtual Bool_t SetMakeClass(Bool_t decomposeObj=kTRUE)
Set the branch in a mode where the object are decomposed (Also known as MakeClass mode).
Definition: TBranch.cxx:2820
TString::Data
const char * Data() const
Definition: TString.h:369
TTree::IncrementTotalBuffers
virtual void IncrementTotalBuffers(Int_t nbytes)
Definition: TTree.h:541
TTree::CreateBasket
virtual TBasket * CreateBasket(TBranch *)
Create a basket for this tree and given branch.
Definition: TTree.cxx:3662
TBasket::SetNevBufSize
void SetNevBufSize(Int_t n)
Definition: TBasket.h:149
TSystem::IsAbsoluteFileName
virtual Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
Definition: TSystem.cxx:950
TBuffer::Expand
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
Definition: TBuffer.cxx:223
TBranch::fIOFeatures
TIOFeatures fIOFeatures
IO features for newly-created baskets.
Definition: TBranch.h:119
tree
Definition: tree.py:1
TLeafS.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
TBranch::GetIconName
const char * GetIconName() const
Return icon name depending on type of branch.
Definition: TBranch.cxx:1319
TObjArray::RemoveAt
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Definition: TObjArray.cxx:694
TBranch::fReadEntry
Long64_t fReadEntry
! Current entry number when reading
Definition: TBranch.h:126
tobuf
void tobuf(char *&buf, Bool_t x)
Definition: Bytes.h:55
TBranch::GetListOfBranches
TObjArray * GetListOfBranches()
Definition: TBranch.h:242
TBranch::fReadLeaves
ReadLeaves_t fReadLeaves
! Pointer to the ReadLeaves implementation to use.
Definition: TBranch.h:157
TTree::GetReadCache
TTreeCache * GetReadCache(TFile *file) const
Find and return the TTreeCache registered with the file and which may contain branches for us.
Definition: TTree.cxx:6227
TBranch::AddBasket
virtual void AddBasket(TBasket &b, Bool_t ondisk, Long64_t startEntry)
Add the basket to this branch.
Definition: TBranch.cxx:543
TTree::GetClusterPrefetch
virtual Bool_t GetClusterPrefetch() const
Definition: TTree.h:452
TBranch.h
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TBranch::GetMakeClass
virtual Bool_t GetMakeClass() const
Return whether this branch is in a mode where the object are decomposed or not (Also known as MakeCla...
Definition: TBranch.cxx:2025
TBranch::SetFirstEntry
virtual void SetFirstEntry(Long64_t entry)
set the first entry number (case of TBranchSTL)
Definition: TBranch.cxx:3168
TBranch::fZipBytes
Long64_t fZipBytes
Total number of bytes in all leaves after compression.
Definition: TBranch.h:133
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
TBranch::GetSubBranch
TBranch * GetSubBranch(const TBranch *br) const
Find the parent branch of child.
Definition: TBranch.cxx:2056
TBranch::fBranches
TObjArray fBranches
-> List of Branches of this branch
Definition: TBranch.h:134
TBasket::GetResetAllocationCount
Bool_t GetResetAllocationCount() const
Definition: TBasket.h:143
TBranch::GetTransientBuffer
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TBranch for reading/writing baskets.
Definition: TBranch.cxx:521
TBranch::SupportsBulkRead
Bool_t SupportsBulkRead() const
Returns true if this branch supports bulk IO, false otherwise.
Definition: TBranch.cxx:1418
TLeaf::GetTypeName
virtual const char * GetTypeName() const
Definition: TLeaf.h:138
TLeafF16
A TLeaf for a 24 bit truncated floating point data type.
Definition: TLeafF16.h:27
TBranch::GetListOfBaskets
TObjArray * GetListOfBaskets()
Definition: TBranch.h:241
TBranch::SetEntries
virtual void SetEntries(Long64_t entries)
Set the number of entries in this branch.
Definition: TBranch.cxx:2731
Float_t
float Float_t
Definition: RtypesCore.h:57
TLeafD
A TLeaf for a 64 bit floating point data type.
Definition: TLeafD.h:26
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TFile::Open
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3994
TBranch::fEntryOffsetLen
Int_t fEntryOffsetLen
Initial Length of fEntryOffset table in the basket buffers.
Definition: TBranch.h:115
TObject::Fatal
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:918
TUrl::SetAnchor
void SetAnchor(const char *anchor)
Definition: TUrl.h:86
TBranch::GetBrowsables
virtual TList * GetBrowsables()
Returns (and, if 0, creates) browsable objects for this branch See TVirtualBranchBrowsable::FillListO...
Definition: TBranch.cxx:1299
TKey::GetObjlen
Int_t GetObjlen() const
Definition: TKey.h:88
Int_t
int Int_t
Definition: RtypesCore.h:45
TTree::GetClusterIterator
virtual TClusterIterator GetClusterIterator(Long64_t firstentry)
Return an iterator over the cluster of baskets starting at firstentry.
Definition: TTree.cxx:5377
ROOT::Internal::TBranchCacheInfo::Print
void Print(const char *owner, Long64_t *entries) const
Definition: TBranchCacheInfo.h:141
N
#define N
TBrowser.h
TNamed::fName
TString fName
Definition: TNamed.h:32
TLeafO.h
TBranch::GetIOFeatures
TIOFeatures GetIOFeatures() const
Returns the IO settings currently in use for this branch.
Definition: TBranch.cxx:2148
TBuffer::Buffer
char * Buffer() const
Definition: TBuffer.h:96
TTree::AddZipBytes
virtual void AddZipBytes(Int_t zip)
Definition: TTree.h:328
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
R__LOCKGUARD_IMT
#define R__LOCKGUARD_IMT(mutex)
Definition: TVirtualMutex.h:111
TObjArray::GetEntries
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
TLeaf::SetAddress
virtual void SetAddress(void *add=0)
Definition: TLeaf.h:184
TDirectory::TContext
Small helper to keep current directory context.
Definition: TDirectory.h:47
TClass.h
TIOFeatures.hxx
TLeafD.h
R__likely
#define R__likely(expr)
Definition: RConfig.hxx:605
nentries
int nentries
Definition: THbookFile.cxx:91
kByteCountMask
const UInt_t kByteCountMask
Definition: TBufferFile.cxx:50
TMessage.h
TBranch::GetRealFileName
TString GetRealFileName() const
Get real file name.
Definition: TBranch.cxx:1976
TBranch::LoadBaskets
virtual Int_t LoadBaskets()
Baskets associated to this branch are forced to be in memory.
Definition: TBranch.cxx:2202
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
ROOT::TIOFeatures
TIOFeatures provides the end-user with the ability to change the IO behavior of data written via a TT...
Definition: TIOFeatures.hxx:69
TLeafI
A TLeaf for an Integer data type.
Definition: TLeafI.h:27
TKey::GetBufferRef
TBuffer * GetBufferRef() const
Definition: TKey.h:80
TObjArray::UncheckedAt
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:90
TBranch::kIsClone
@ kIsClone
Definition: TBranch.h:102
TBranch::ReadLeavesImpl
void ReadLeavesImpl(TBuffer &b)
Loop on all leaves of this branch to read Basket buffer.
Definition: TBranch.cxx:2354
TObjArray::At
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
TBranch::GetClassName
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
Definition: TBranch.cxx:1311
TBranch::IsFolder
Bool_t IsFolder() const
Return kTRUE if more than one leaf or browsables, kFALSE otherwise.
Definition: TBranch.cxx:2164
TTree.h
TLeaf::GetLenType
virtual Int_t GetLenType() const
Definition: TLeaf.h:132
TLeaf::GetOffset
virtual Int_t GetOffset() const
Definition: TLeaf.h:136
TBasket::GetNevBuf
Int_t GetNevBuf() const
Definition: TBasket.h:129
TString
Basic string class.
Definition: TString.h:136
TBranch::ReadLeaves1Impl
void ReadLeaves1Impl(TBuffer &b)
Read one leaf without the overhead of a loop.
Definition: TBranch.cxx:2372
TTree::GetAutoFlush
virtual Long64_t GetAutoFlush() const
Definition: TTree.h:442
TBuffer::SetBufferOffset
void SetBufferOffset(Int_t offset=0)
Definition: TBuffer.h:93
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
v
@ v
Definition: rootcling_impl.cxx:3635
TString::Clear
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1176
b
#define b(i)
Definition: RSha256.hxx:100
TFile.h
TBranchCacheInfo.h
TSystem::GetDirName
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1030
TBranch::fFileName
TString fFileName
Name of file where buffers are stored ("" if in same file as Tree header)
Definition: TBranch.h:145
bool
TClonesArray.h
TBranch::fParent
TBranch * fParent
! Pointer to parent branch.
Definition: TBranch.h:142
TVirtualBranchBrowsable::FillListOfBrowsables
static Int_t FillListOfBrowsables(TList &list, const TBranch *branch, const TVirtualBranchBrowsable *parent=0)
Askes all registered generators to fill their browsables into the list.
Definition: TBranchBrowsable.cxx:138
TObjArray::Add
void Add(TObject *obj)
Definition: TObjArray.h:74
TBranch::SetCompressionAlgorithm
void SetCompressionAlgorithm(Int_t algorithm=ROOT::RCompressionSetting::EAlgorithm::kUseGlobal)
Set compression algorithm.
Definition: TBranch.cxx:2656
TDirectory::IsWritable
virtual Bool_t IsWritable() const
Definition: TDirectory.h:181
TTree::GetListOfBranches
virtual TObjArray * GetListOfBranches()
Definition: TTree.h:483
TBranch::fgCount
static Int_t fgCount
! branch counter
Definition: TBranch.h:112
TBranch::GetTotBytes
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:2113
TBuffer::ResetMap
virtual void ResetMap()=0
TROOT.h
TBranch::kDoNotUseBufferMap
@ kDoNotUseBufferMap
Definition: TBranch.h:108
TBranch::kAutoDelete
@ kAutoDelete
Definition: TBranch.h:106
TBranch::KeepCircular
virtual void KeepCircular(Long64_t maxEntries)
keep a maximum of fMaxEntries in memory
Definition: TBranch.cxx:2176
TBasket::MoveEntries
virtual void MoveEntries(Int_t dentries)
Remove the first dentries of this basket, moving entries at dentries to the start of the buffer.
Definition: TBasket.cxx:310
TBranch::FlushBaskets
Int_t FlushBaskets()
Flush to disk all the baskets of this branch and any of subbranches.
Definition: TBranch.cxx:1123
TBasket::ReadBasketBytes
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:698
TBranch::fTransientBuffer
TBuffer * fTransientBuffer
! Pointer to the current transient buffer.
Definition: TBranch.h:147
TBasket::DropBuffers
virtual Int_t DropBuffers()
Drop buffers of this basket if it is not the current basket.
Definition: TBasket.cxx:173
TBranch::fEntries
Long64_t fEntries
Number of entries.
Definition: TBranch.h:130
TBranch::fCompress
Int_t fCompress
Compression level and algorithm.
Definition: TBranch.h:113
TBranch::Fill
Int_t Fill()
Definition: TBranch.h:201
TBuffer::GetCurrent
char * GetCurrent() const
Definition: TBuffer.h:97
TBranch
A TTree is a list of TBranches.
Definition: TBranch.h:89
TLeaf::SetBranch
virtual void SetBranch(TBranch *branch)
Definition: TLeaf.h:160
TStorage::ReAllocInt
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition: TStorage.cxx:295
TBranch::GetBulkEntries
Int_t GetBulkEntries(Long64_t, TBuffer &)
Read as many events as possible into the given buffer, using zero-copy mechanisms.
Definition: TBranch.cxx:1443
TBuffer::Length
Int_t Length() const
Definition: TBuffer.h:100
TTree::GetCurrentFile
TFile * GetCurrentFile() const
Return pointer to the current file.
Definition: TTree.cxx:5389
TBranch::fBaskets
TObjArray fBaskets
-> List of baskets of this branch
Definition: TBranch.h:136
TString::Form
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
TBranch::fNextBasketEntry
Long64_t fNextBasketEntry
! Next entry that will requires us to go to the next basket
Definition: TBranch.h:128
TBranch::Init
void Init(const char *name, const char *leaflist, Int_t compress)
Definition: TBranch.cxx:300
TBranch::GetExpectedType
virtual Int_t GetExpectedType(TClass *&clptr, EDataType &type)
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
Definition: TBranch.cxx:1763
TObjArray::GetLast
Int_t GetLast() const
Return index of last object in array.
Definition: TObjArray.cxx:577
TBuffer::GetBufferDisplacement
virtual Int_t GetBufferDisplacement() const =0
TLeafG.h
TTreeCache.h
TBranch::fFillLeaves
FillLeaves_t fFillLeaves
! Pointer to the FillLeaves implementation to use.
Definition: TBranch.h:159
TBranch::fTotBytes
Long64_t fTotBytes
Total number of bytes in all leaves before compression.
Definition: TBranch.h:132
TBuffer::SetReadMode
void SetReadMode()
Set buffer in read mode.
Definition: TBuffer.cxx:302
TBuffer.h
TBranch::fMaxBaskets
Int_t fMaxBaskets
Maximum number of Baskets so far.
Definition: TBranch.h:121
TBranch::GetFreshCluster
TBasket * GetFreshCluster()
Drops the cluster two behind the current cluster and returns a fresh basket by either reusing or crea...
Definition: TBranch.cxx:1882
TBranch::GetFile
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:1782
TLeaf.h
TLeaf::ReadBasketFast
virtual bool ReadBasketFast(TBuffer &, Long64_t)
Definition: TLeaf.h:153
TBranch::fWriteBasket
Int_t fWriteBasket
Last basket number written.
Definition: TBranch.h:116
ROOT::Internal::TBranchCacheInfo::SetUsed
void SetUsed(Int_t basketNumber)
Definition: TBranchCacheInfo.h:79
TObject::ResetBit
void ResetBit(UInt_t f)
Definition: TObject.h:171
TLeaf::FillBasket
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeaf.cxx:157
TTree::kCircular
@ kCircular
Definition: TTree.h:248
TSystem.h
TBranch::SetStatus
virtual void SetStatus(Bool_t status=1)
Set branch status to Process or DoNotProcess.
Definition: TBranch.cxx:2840
TBranch::GetBasketSeek
virtual Long64_t GetBasketSeek(Int_t basket) const
Return address of basket in the file.
Definition: TBranch.cxx:1289
TBufferIO::kNotDecompressed
@ kNotDecompressed
Definition: TBufferIO.h:66
TBranch::FindLeaf
virtual TLeaf * FindLeaf(const char *name)
Find the leaf corresponding to the name 'searchname'.
Definition: TBranch.cxx:1068
TLeaf::DeserializeType::kDestructive
@ kDestructive
TBranch::SetCompressionLevel
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
Set compression level.
Definition: TBranch.cxx:2676
TLeaf::GetDeserializeType
virtual DeserializeType GetDeserializeType() const
Definition: TLeaf.h:116
gROOTMutex
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:61
TBranch::fTree
TTree * fTree
! Pointer to Tree header
Definition: TBranch.h:140
TLeafI.h
TLeaf
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:57
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TBranch::ReadLeaves0Impl
void ReadLeaves0Impl(TBuffer &b)
Read zero leaves without the overhead of a loop.
Definition: TBranch.cxx:2365
TTree::TClusterIterator::GetNextEntry
Long64_t GetNextEntry()
Definition: TTree.h:303
TLeaf::GetLeafCount
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
Definition: TLeaf.h:120
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
TLeafF.h
TString::Remove
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
TTree::GetPerfStats
virtual TVirtualPerfStats * GetPerfStats() const
Definition: TTree.h:501
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TBasket::SetWriteMode
virtual void SetWriteMode()
Set write mode of basket.
Definition: TBasket.cxx:934
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TLeafS
A TLeaf for a 16 bit Integer data type.
Definition: TLeafS.h:26
TBranch::GetFreshBasket
TBasket * GetFreshBasket(Int_t basketnumber, TBuffer *user_buffer)
Return a fresh basket by either resusing an existing basket that needs to be drop (according to TTree...
Definition: TBranch.cxx:1823
TBuffer::WriteBuf
virtual void WriteBuf(const void *buf, Int_t max)=0
TLeafC.h
TString::First
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:499
TBranch::SetAutoDelete
virtual void SetAutoDelete(Bool_t autodel=kTRUE)
Set the automatic delete bit.
Definition: TBranch.cxx:2609
TBranch::GetEntry
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
Definition: TBranch.cxx:1635
TBranch::fBasketSeek
Long64_t * fBasketSeek
[fMaxBaskets] Addresses of baskets on file
Definition: TBranch.h:139
R__unlikely
#define R__unlikely(expr)
Definition: RConfig.hxx:604
TBranch::Refresh
virtual void Refresh(TBranch *b)
Refresh this branch using new information in b This function is called by TTree::Refresh.
Definition: TBranch.cxx:2401
TBuffer::kMinimalSize
@ kMinimalSize
Definition: TBuffer.h:78
TTree::Draw
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:427
TObjArray::AddAtAndExpand
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:235
TBuffer::kIsOwner
@ kIsOwner
Definition: TBuffer.h:75
R__LOCKGUARD
#define R__LOCKGUARD(mutex)
Definition: TVirtualMutex.h:104
TVirtualPad.h
TBuffer::SetBufferDisplacement
virtual void SetBufferDisplacement()=0
TBranch::ReadBasket
virtual void ReadBasket(TBuffer &b)
Loop on all leaves of this branch to read Basket buffer.
Definition: TBranch.cxx:2346
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TCollection::Browse
void Browse(TBrowser *b)
Browse this collection (called by TBrowser).
Definition: TCollection.cxx:248
TBranch::fDirectory
TDirectory * fDirectory
! Pointer to directory where this branch buffers are stored
Definition: TBranch.h:144
TBranch::SetupAddresses
virtual void SetupAddresses()
If the branch address is not set, we set all addresses starting with the top level parent branch.
Definition: TBranch.cxx:3183
TBasket::GetEntryOffset
Int_t * GetEntryOffset()
Definition: TBasket.h:124
TLeaf::ReadBasketSerialized
virtual bool ReadBasketSerialized(TBuffer &, Long64_t)
Definition: TLeaf.h:154
TBranch::FillImpl
virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *)
Loop on all leaves of this branch to fill Basket buffer.
Definition: TBranch.cxx:843
TObject::MakeZombie
void MakeZombie()
Definition: TObject.h:49
TBranch::ResetAfterMerge
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch.
Definition: TBranch.cxx:2491
TBranch::Print
virtual void Print(Option_t *option="") const
Print TBranch parameters.
Definition: TBranch.cxx:2234
TSystem::ExpandPathName
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1272
TBranch::GetTotalSize
Long64_t GetTotalSize(Option_t *option="") const
Return total number of bytes in the branch (including current buffer)
Definition: TBranch.cxx:2094
TBranch::SetAddress
virtual void SetAddress(void *add)
Set address of this branch.
Definition: TBranch.cxx:2575
TLeafB.h
TLeaf::SetOffset
virtual void SetOffset(Int_t offset=0)
Definition: TLeaf.h:163
TTree::TClusterIterator::Next
Long64_t Next()
Move on to the next cluster and return the starting entry of this next cluster.
Definition: TTree.cxx:640
TBranch::PrintCacheInfo
void PrintCacheInfo() const
Print the information we have about which basket is currently cached and whether they have been 'used...
Definition: TBranch.cxx:2338
TVirtualMutex.h
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
TUrl::GetUrl
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:389
TUrl
This class represents a WWW compatible URL.
Definition: TUrl.h:33
TLeafF
A TLeaf for a 32 bit floating point data type.
Definition: TLeafF.h:26
TBranch::fAddress
char * fAddress
! Address of 1st leaf (variable or object)
Definition: TBranch.h:143
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TBranch::SetFile
virtual void SetFile(TFile *file=0)
Set file where this branch writes/reads its buffers.
Definition: TBranch.cxx:2756
TBranch::fReadBasket
Int_t fReadBasket
! Current basket number when reading
Definition: TBranch.h:125
kOther_t
@ kOther_t
Definition: TDataType.h:32
unsigned int
TFileCacheRead
A cache when reading files over the network.
Definition: TFileCacheRead.h:22
TBranch::fEntryBuffer
TBuffer * fEntryBuffer
! Buffer used to directly pass the content without streaming
Definition: TBranch.h:146
TBranch::fBrowsables
TList * fBrowsables
! List of TVirtualBranchBrowsables used for Browse()
Definition: TBranch.h:148
TTree::GetDirectory
TDirectory * GetDirectory() const
Definition: TTree.h:457
TKey::SetParent
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
Definition: TKey.cxx:1294
TBasket::GetNevBufSize
Int_t GetNevBufSize() const
Definition: TBasket.h:130
TMath::BinarySearch
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMathBase.h:278
Printf
void Printf(const char *fmt,...)
TBasket::PrepareBasket
virtual void PrepareBasket(Long64_t)
Definition: TBasket.h:133
TBranch::ResetCount
static void ResetCount()
Static function resetting fgCount.
Definition: TBranch.cxx:2567
TObject::IsZombie
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:134
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TLeafO
A TLeaf for a bool data type.
Definition: TLeafO.h:26
TKey::GetSeekKey
virtual Long64_t GetSeekKey() const
Definition: TKey.h:90
TBasket::GetLast
Int_t GetLast() const
Definition: TBasket.h:131
TTree::TClusterIterator
Helper class to iterate over cluster of baskets.
Definition: TTree.h:266
TBranch::Reset
virtual void Reset(Option_t *option="")
Reset a Branch.
Definition: TBranch.cxx:2450
TLeaf::GetLen
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition: TLeaf.cxx:381
TObjArray::AddAt
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:254
TBasket::WriteBuffer
virtual Int_t WriteBuffer()
Write buffer of this basket on the current file.
Definition: TBasket.cxx:1131
TBuffer::IsReading
Bool_t IsReading() const
Definition: TBuffer.h:86
TBranch::UpdateFile
virtual void UpdateFile()
Refresh the value of fDirectory (i.e.
Definition: TBranch.cxx:3193
TTreeCacheUnzip.h
TBranch::GetMother
TBranch * GetMother() const
Get our top-level parent branch in the tree.
Definition: TBranch.cxx:2035
TLeaf::GetBranch
TBranch * GetBranch() const
Definition: TLeaf.h:115
TBasket
Manages buffers for branches of a Tree.
Definition: TBasket.h:34
TLeafD32
A TLeaf for a 24 bit truncated floating point data type.
Definition: TLeafD32.h:28
TBranch::ReadLeaves2Impl
void ReadLeaves2Impl(TBuffer &b)
Read two leaves without the overhead of a loop.
Definition: TBranch.cxx:2380
TBasket::GetBufferSize
Int_t GetBufferSize() const
Definition: TBasket.h:122
TBranch::BackFill
Int_t BackFill()
Loop on all leaves of this branch to back fill Basket buffer.
Definition: TBranch.cxx:667
TBranchIMTHelper.h
TBasket::SetReadMode
virtual void SetReadMode()
Set read mode of basket.
Definition: TBasket.cxx:925
TFileCacheRead::SetSkipZip
virtual void SetSkipZip(Bool_t=kTRUE)
Definition: TFileCacheRead.h:112
TBasket::GetDisplacement
Int_t * GetDisplacement() const
Definition: TBasket.h:123
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TLeaf::ReadBasketExport
virtual void ReadBasketExport(TBuffer &, TClonesArray *, Int_t)
Definition: TLeaf.h:152
TTree::AddAllocationCount
void AddAllocationCount(UInt_t count)
Definition: TTree.h:333
file
Definition: file.py:1
TObjArray::LowerBound
Int_t LowerBound() const
Definition: TObjArray.h:97
TBasket::ReadResetBuffer
virtual void ReadResetBuffer(Int_t basketnumber)
Reset the read basket TBuffer memory allocation if needed.
Definition: TBasket.cxx:733
EDataType
EDataType
Definition: TDataType.h:28
TUrl::GetAnchor
const char * GetAnchor() const
Definition: TUrl.h:70
TObjArray::Expand
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TObjArray.cxx:387
TBranch::fNBaskets
Int_t fNBaskets
! Number of baskets in memory
Definition: TBranch.h:122
TBasket::AdjustSize
virtual void AdjustSize(Int_t newsize)
Increase the size of the current fBuffer up to newsize.
Definition: TBasket.cxx:127
ROOT::Internal::TBranchIMTHelper
Definition: TBranchIMTHelper.h:26
TLeafB
A TLeaf for an 8 bit Integer data type.
Definition: TLeafB.h:26
TBufferFile.h
Bytes.h
TBranch::~TBranch
virtual ~TBranch()
Destructor.
Definition: TBranch.cxx:450
TDirectory::GetFile
virtual TFile * GetFile() const
Definition: TDirectory.h:165
TLeaf::ReadBasket
virtual void ReadBasket(TBuffer &)
Definition: TLeaf.h:151
TBranch::fFirstBasketEntry
Long64_t fFirstBasketEntry
! First entry in the current basket.
Definition: TBranch.h:127
name
char name[80]
Definition: TGX11.cxx:110
TBranch::fBasketBytes
Int_t * fBasketBytes
[fMaxBaskets] Length of baskets on file
Definition: TBranch.h:137
TBranch::AddLastBasket
virtual void AddLastBasket(Long64_t startEntry)
Add the start entry of the write basket (not yet created)
Definition: TBranch.cxx:609
TFile::GetCompressionSettings
Int_t GetCompressionSettings() const
Definition: TFile.h:399
TFileCacheRead::IsLearning
virtual Bool_t IsLearning() const
Definition: TFileCacheRead.h:102
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:40
ROOT::RCompressionSetting::EAlgorithm::kUndefined
@ kUndefined
Undefined compression algorithm (must be kept the last of the list in case a new algorithm is added).
Definition: Compression.h:100
gPad
#define gPad
Definition: TVirtualPad.h:287
TBranch::SetObject
virtual void SetObject(void *objadd)
Set object this branch is pointing to.
Definition: TBranch.cxx:2829
TBranch::fSkipZip
Bool_t fSkipZip
! After being read, the buffer will not be unzipped.
Definition: TBranch.h:151
TIter
Definition: TCollection.h:233
TBranch::fFirstEntry
Long64_t fFirstEntry
Number of the first entry in this branch.
Definition: TBranch.h:131
TBuffer::AutoExpand
void AutoExpand(Int_t size_needed)
Automatically calculate a new size and expand the buffer to fit at least size_needed.
Definition: TBuffer.cxx:158
TBuffer::SetWriteMode
void SetWriteMode()
Set buffer in write mode.
Definition: TBuffer.cxx:315
TLeafF16.h
TBranch::WriteBasket
Int_t WriteBasket(TBasket *basket, Int_t where)
Definition: TBranch.h:171
TBranch::DropBaskets
virtual void DropBaskets(Option_t *option="")
Loop on all branch baskets.
Definition: TBranch.cxx:744
TBranch::Browse
virtual void Browse(TBrowser *b)
Browser interface.
Definition: TBranch.cxx:686
TObjArray::SetLast
void SetLast(Int_t last)
Set index of last object in array, effectively truncating the array.
Definition: TObjArray.cxx:775
TLeafG
A TLeaf for a 64 bit Integer data type.
Definition: TLeafG.h:27
TBranch::FlushOneBasket
Int_t FlushOneBasket(UInt_t which)
If we have a write basket in memory and it contains some entries and has not yet been written to disk...
Definition: TBranch.cxx:1169
TAttFill
Fill Area Attributes class.
Definition: TAttFill.h:19
TStorage::ReAlloc
static void * ReAlloc(void *vp, size_t size)
Reallocate (i.e.
Definition: TStorage.cxx:183
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TBranch::GetFullName
virtual TString GetFullName() const
Return the 'full' name of the branch.
Definition: TBranch.cxx:1947
TBranch::WriteBasketImpl
Int_t WriteBasketImpl(TBasket *basket, Int_t where, ROOT::Internal::TBranchIMTHelper *)
Write the current basket to disk and return the number of bytes written to the file.
Definition: TBranch.cxx:3092
TBranch::kDoNotProcess
@ kDoNotProcess
Definition: TBranch.h:101
TCollection::RemoveAll
virtual void RemoveAll(TCollection *col)
Remove all objects in collection col from this collection.
Definition: TCollection.cxx:594
Stat_t
double Stat_t
Definition: RtypesCore.h:77
TBranch::fBasketEntry
Long64_t * fBasketEntry
[fMaxBaskets] Table of first entry in each basket
Definition: TBranch.h:138
TBasket::SetBranch
void SetBranch(TBranch *branch)
Definition: TBasket.h:148
TLeaf::SetUnsigned
virtual void SetUnsigned()
Definition: TLeaf.h:165
Class
void Class()
Definition: Class.C:29
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
TBranch::GetListOfLeaves
TObjArray * GetListOfLeaves()
Definition: TBranch.h:243
TBranch::GetTree
TTree * GetTree() const
Definition: TBranch.h:248
TBranch::GetBasket
TBasket * GetBasket(Int_t basket)
Definition: TBranch.h:209
TFileCacheRead::LearnBranch
virtual Int_t LearnBranch(TBranch *, Bool_t=kFALSE)
Definition: TFileCacheRead.h:103
TBasket::Update
void Update(Int_t newlast)
Definition: TBasket.h:152
TBranch::fExtraBasket
TBasket * fExtraBasket
! Allocated basket not currently holding any data.
Definition: TBranch.h:118
Char_t
char Char_t
Definition: RtypesCore.h:33
RooStats::HistFactory::Constraint::GetType
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
TBranch::fMother
TBranch * fMother
! Pointer to top-level parent branch in the tree.
Definition: TBranch.h:141
TTree::GetListOfLeaves
virtual TObjArray * GetListOfLeaves()
Definition: TTree.h:484
TClonesArray
An array of clone (identical) objects.
Definition: TClonesArray.h:29
TTree::GetMaxVirtualSize
virtual Long64_t GetMaxVirtualSize() const
Definition: TTree.h:495
TBranch::fSplitLevel
Int_t fSplitLevel
Branch split level.
Definition: TBranch.h:123
TBufferFile
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition: TBufferFile.h:47
TBranch::GetEntries
Long64_t GetEntries() const
Definition: TBranch.h:247
TBranch::DeleteBaskets
virtual void DeleteBaskets(Option_t *option="")
Loop on all branch baskets.
Definition: TBranch.cxx:713
TBasket::AdoptBuffer
void AdoptBuffer(TBuffer *user_buffer)
Adopt a buffer from an external entity.
Definition: TBasket.cxx:721
TBasket.h
TBranch::fCurrentBasket
TBasket * fCurrentBasket
! Pointer to the current basket.
Definition: TBranch.h:129
TLeaf::GetNdata
virtual Int_t GetNdata() const
Definition: TLeaf.h:135
TBranch::SetBasketSize
virtual void SetBasketSize(Int_t buffsize)
Set the basket size The function makes sure that the basket size is greater than fEntryOffsetlen.
Definition: TBranch.cxx:2622
TBranch::SetEntryOffsetLen
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...
Definition: TBranch.cxx:2714
TList
A doubly linked list.
Definition: TList.h:44
TBuffer::kWrite
@ kWrite
Definition: TBuffer.h:73
TTree::AddTotBytes
virtual void AddTotBytes(Int_t tot)
Definition: TTree.h:327
TBranch::GetRow
virtual Int_t GetRow(Int_t row)
Return all elements of one row unpacked in internal array fValues [Actually just returns 1 (?...
Definition: TBranch.cxx:2016
TMath.h
TBranch::fEntryNumber
Long64_t fEntryNumber
Current entry number (last one filled in this branch)
Definition: TBranch.h:117
TTree::kOnlyFlushAtCluster
@ kOnlyFlushAtCluster
If set, the branch's buffers will grow until an event cluster boundary is hit, guaranteeing a basket ...
Definition: TTree.h:252
gROOT
#define gROOT
Definition: TROOT.h:406
int
TBasket::WriteReset
virtual void WriteReset()
Reset the write basket to the starting state.
Definition: TBasket.cxx:806
TBranch::TBranch
TBranch()
Default constructor. Used for I/O by default.
Definition: TBranch.cxx:87
TBranch::SetCompressionSettings
void SetCompressionSettings(Int_t settings=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Set compression settings.
Definition: TBranch.cxx:2698
TKey::GetNbytes
Int_t GetNbytes() const
Definition: TKey.h:87
TVirtualPerfStats::SetUsed
virtual void SetUsed(TBranch *b, size_t basketNumber)=0
TBranch::GetBasketImpl
TBasket * GetBasketImpl(Int_t basket, TBuffer *user_buffer)
Return pointer to basket basketnumber in this Branch.
Definition: TBranch.cxx:1213