Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBranchElement.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Authors Rene Brun , Philippe Canal, Markus Frank 14/01/2001
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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/** \class TBranchElement
13\ingroup tree
14
15A Branch for the case of an object.
16*/
17
18#include "TBranchElement.h"
19
20#include "TBasket.h"
21#include "TBranchObject.h"
22#include "TBranchRef.h"
23#include "TBrowser.h"
24#include "TClass.h"
25#include "TClassEdit.h"
26#include "TClonesArray.h"
27#include "TDataMember.h"
28#include "TDataType.h"
29#include "TError.h"
30#include "TMath.h"
31#include "TFile.h"
32#include "TFolder.h"
33#include "TLeafElement.h"
34#include "TRealData.h"
35#include "TStreamerElement.h"
36#include "TStreamerInfo.h"
37#include "TTree.h"
40#include "TVirtualMutex.h"
41#include "TVirtualPad.h"
42#include "TBranchSTL.h"
43#include "TVirtualArray.h"
44#include "TBufferFile.h"
45#include "TInterpreter.h"
46#include "TROOT.h"
47
49#include "TSchemaRuleSet.h"
50
51
52////////////////////////////////////////////////////////////////////////////////
53
54namespace {
55 void RemovePrefix(TString& str, const TString &prefix) {
56 // -- Remove a prefix from a string.
57 // -- Require a '.' after the prefix.
58 if (prefix.Length() && prefix.Length() <= str.Length()
59 && (str.Data()[prefix.Length()] == '.' || (prefix[prefix.Length()-1]=='.')))
60 {
61 if (!str.Index(prefix))
62 str.Remove(0, prefix.Length());
63 }
64 }
65 struct R__PushCache {
67 TVirtualArray *fOnfileObject;
68
69 R__PushCache(TBuffer &b, TVirtualArray *in, UInt_t size) : fBuffer(b), fOnfileObject(in)
70 {
71 if (fOnfileObject) {
72 fOnfileObject->SetSize(size);
73 fBuffer.PushDataCache( fOnfileObject );
74 }
75 }
76 ~R__PushCache() {
77 if (fOnfileObject) fBuffer.PopDataCache();
78 }
79 };
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Check if a collection proxy represents an associative collection (e.g., std::map, std::set)
82 /// rather than a sequential collection (e.g., std::vector, std::list).
83 /// Both the version based on the fSTLtype integer and the one based on the TVirtualCollectionProxy
84 /// will return the same result about the 'currently' in memory collection attached to the branch.
85 /// The main difference is that the fSTLtype can be used without checking whether
86 /// fCollProxy is set or not but might (or might not) be a tad bit slower.
87 bool IsAssociativeContainer(Int_t stltype)
88 {
89 switch (stltype) {
90 case ROOT::kSTLset:
94 case ROOT::kSTLmap:
98 return true;
99 default:
100 return false;
101 }
102 }
103 bool IsAssociativeContainer(const TVirtualCollectionProxy &proxy)
104 {
106 }
107
108 void RecursiveResetReadEntry(TBranch *br)
109 {
110 br->ResetReadEntry();
111 for (auto sub : *br->GetListOfBranches())
112 RecursiveResetReadEntry(static_cast<TBranch *>(sub));
113 }
114
115 /// Find the counter branch `countname` of a variable-size array data member. The counter is created as a
116 /// sub-branch of the same parent, so look there first: if the top-level branch name has no trailing dot, the
117 /// sub-branches of two objects of the same class have identical names and a tree-wide search returns the counter
118 /// of the first object.
119 TBranchElement *FindBranchCount(TTree *tree, TBranch *parent, const TString &countname)
120 {
121 if (parent) {
122 if (auto counter = dynamic_cast<TBranchElement *>(parent->GetListOfBranches()->FindObject(countname.Data())))
123 return counter;
124 }
125 return static_cast<TBranchElement *>(tree->GetBranch(countname));
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Modify the container type of the branches
131
133 const Int_t nbranches = branches->GetEntriesFast();
134 for (Int_t i = 0; i < nbranches; ++i) {
135 TBranchElement* br = static_cast<TBranchElement*>(branches->At(i));
136 switch (br->GetType()) {
137 case 31: br->SetType(41); break;
138 case 41: {
139 br->SetType(31);
140 br->fCollProxy = nullptr;
141 break;
142 }
143 }
144 br->SetReadLeavesPtr();
145 br->SetFillLeavesPtr();
146 // Note: This is a tail recursion.
148 }
149}
150
151////////////////////////////////////////////////////////////////////////////////
152
153namespace {
154 bool CanSelfReference(TClass *cl) {
155 if (cl) {
156 if (cl->GetCollectionProxy()) {
157 TClass *inside = cl->GetCollectionProxy()->GetValueClass();
158 if (inside) {
159 return CanSelfReference(inside);
160 } else {
161 return false;
162 }
163 }
164 const static TClassRef stringClass("std::string");
165 if (cl == stringClass || cl == TString::Class()) {
166 return false;
167 }
168 // Here we could scan through the TStreamerInfo to see if there
169 // is any pointer anywhere and know whether this is a possibility
170 // of selfreference (but watch out for very indirect cases).
171 return true;
172 }
173 return false;
174 }
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Default and I/O constructor.
179
181: TBranch()
182, fClassName()
183, fParentName()
184, fClonesName()
185, fCollProxy(nullptr)
186, fCheckSum(0)
187, fClassVersion(0)
188, fID(0)
189, fType(0)
190, fStreamerType(-1)
191, fMaximum(0)
192, fSTLtype(ROOT::kNotSTL)
193, fNdata(1)
194, fBranchCount(nullptr)
195, fBranchCount2(nullptr)
196, fInfo(nullptr)
197, fObject(nullptr)
198, fOnfileObject(nullptr)
199, fInit(false)
200, fInInitInfo(false)
201, fInitOffsets(false)
202, fTargetClass()
203, fCurrentClass()
204, fParentClass()
205, fBranchClass()
206, fClonesClass()
207, fBranchOffset(nullptr)
208, fBranchID(-1)
209, fReadActionSequence(nullptr)
210, fFillActionSequence(nullptr)
211, fIterators(nullptr)
212, fWriteIterators(nullptr)
213, fPtrIterators(nullptr)
214{
215 fNleaves = 0;
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Constructor when the branch object is not a TClonesArray nor an STL container.
222///
223/// If splitlevel > 0 this branch in turn is split into sub-branches.
224
225TBranchElement::TBranchElement(TTree *tree, const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
226: TBranch()
227, fClassName(sinfo->GetName())
228, fParentName()
229, fClonesName()
230, fCollProxy(nullptr)
231, fCheckSum(sinfo->GetCheckSum())
232, fClassVersion(sinfo->GetClass()->GetClassVersion())
233, fID(id)
234, fType(0)
235, fStreamerType(-1)
236, fMaximum(0)
237, fSTLtype(ROOT::kNotSTL)
238, fNdata(1)
239, fBranchCount(nullptr)
240, fBranchCount2(nullptr)
241, fInfo(sinfo)
242, fObject(nullptr)
243, fOnfileObject(nullptr)
244, fInit(true)
245, fInInitInfo(false)
246, fInitOffsets(false)
247, fTargetClass(fClassName)
248, fCurrentClass()
249, fParentClass()
250, fBranchClass(sinfo->GetClass())
251, fClonesClass()
252, fBranchOffset(nullptr)
253, fBranchID(-1)
254, fReadActionSequence(nullptr)
255, fFillActionSequence(nullptr)
256, fIterators(nullptr)
257, fWriteIterators(nullptr)
258, fPtrIterators(nullptr)
259{
260 if (tree) {
261 ROOT::TIOFeatures features = tree->GetIOFeatures();
262 SetIOFeatures(features);
263 }
264 Init(tree, nullptr, bname,sinfo,id,pointer,basketsize,splitlevel,btype);
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Constructor when the branch object is not a TClonesArray nor an STL container.
269///
270/// If splitlevel > 0 this branch in turn is split into sub-branches.
271
272TBranchElement::TBranchElement(TBranch *parent, const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
273: TBranch()
274, fClassName(sinfo->GetName())
275, fParentName()
276, fClonesName()
277, fCollProxy(nullptr)
278, fCheckSum(sinfo->GetCheckSum())
279, fClassVersion(sinfo->GetClass()->GetClassVersion())
280, fID(id)
281, fType(0)
282, fStreamerType(-1)
283, fMaximum(0)
284, fSTLtype(ROOT::kNotSTL)
285, fNdata(1)
286, fBranchCount(nullptr)
287, fBranchCount2(nullptr)
288, fInfo(sinfo)
289, fObject(nullptr)
290, fOnfileObject(nullptr)
291, fInit(true)
292, fInInitInfo(false)
293, fInitOffsets(false)
294, fTargetClass( fClassName )
295, fCurrentClass()
296, fParentClass()
297, fBranchClass(sinfo->GetClass())
298, fClonesClass()
299, fBranchOffset(nullptr)
300, fBranchID(-1)
301, fReadActionSequence(nullptr)
302, fFillActionSequence(nullptr)
303, fIterators(nullptr)
304, fWriteIterators(nullptr)
305, fPtrIterators(nullptr)
306{
307 ROOT::TIOFeatures features = parent->GetIOFeatures();
308 SetIOFeatures(features);
309 Init(parent ? parent->GetTree() : nullptr, parent, bname,sinfo,id,pointer,basketsize,splitlevel,btype);
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Init when the branch object is not a TClonesArray nor an STL container.
314///
315/// If splitlevel > 0 this branch in turn is split into sub-branches.
316
317void TBranchElement::Init(TTree *tree, TBranch *parent,const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
318{
319 TString name(bname);
320
321 // Set our TNamed attributes.
322 SetName(name);
323 SetTitle(name);
324
325 // Set our TBranch attributes.
326 fSplitLevel = splitlevel;
327 fTree = tree;
328 if (fTree == nullptr) return;
329 fMother = parent ? parent->GetMother() : this;
330 fParent = parent;
332 fFileName = "";
333
334 // Clear the bit kAutoDelete to specify that when reading
335 // the object should not be deleted before calling Streamer.
336
337 SetAutoDelete(false);
338
341
342 //---------------------------------------------------------------------------
343 // Handling the splitting of the STL collections of pointers
344 /////////////////////////////////////////////////////////////////////////////
345
346 Int_t splitSTLP = splitlevel - (splitlevel%TTree::kSplitCollectionOfPointers);
348
349 fCompress = -1;
350 if (fTree->GetDirectory()) {
351 TFile* bfile = fTree->GetDirectory()->GetFile();
352 if (bfile) {
354 }
355 }
356
357 //
358 // Initialize streamer type and element.
359 //
360
361 if (id > -1) {
362 // We are *not* a top-level branch.
363 TStreamerElement* element = sinfo->GetElement(id);
364 fStreamerType = element->GetType();
365 }
366
367 //
368 // Handle varying-length datatypes by allocating an offsets array.
369 //
370 // The fBits part of a TObject is of varying length because the pidf
371 // is streamed only when the TObject is referenced by a TRef.
372 //
373
374 fEntryOffsetLen = 0;
377 }
378
379 //
380 // Make sure the basket is big enough to contain the
381 // entry offset array plus 100 bytes of data.
382 //
383
384 if (basketsize < (100 + fEntryOffsetLen)) {
385 basketsize = 100 + fEntryOffsetLen;
386 }
387 fBasketSize = basketsize;
388
389 //
390 // Allocate and initialize the basket control arrays.
391 //
392
396
397 for (Int_t i = 0; i < fMaxBaskets; ++i) {
398 fBasketBytes[i] = 0;
399 fBasketEntry[i] = 0;
400 fBasketSeek[i] = 0;
401 }
402
403 // We need to keep track of the counter branch if we have
404 // one, since we cannot set it until we have created our
405 // leaf, which we do last.
406 TBranchElement* brOfCounter = nullptr;
407
408 if (id < 0) {
409 // -- We are a top-level branch. Don't split a top-level branch, TTree::Bronch will do that work.
410 if (fBranchClass.GetClass()) {
411 bool hasCustomStreamer = false;
412 bool canSelfReference = CanSelfReference(fBranchClass);
414 if (canSelfReference) SetBit(kBranchObject);
416 } else {
417 if (canSelfReference) SetBit(kBranchAny);
419 }
420 if (hasCustomStreamer) {
421 fType = -1;
422 }
423 }
424 } else {
425 // -- We are a sub-branch of a split object.
426 TStreamerElement* element = sinfo->GetElement(id);
428 // -- If we are an object data member which inherits from TObject,
429 // flag it so that later during i/o we will register the object
430 // with the buffer so that pointers are handled correctly.
431 if (CanSelfReference(fBranchClass)) {
434 } else {
436 }
437 }
438 }
439 if (element->IsA() == TStreamerBasicPointer::Class()) {
440 // -- Fixup title with counter if we are a varying length array data member.
441 TStreamerBasicPointer *bp = dynamic_cast<TStreamerBasicPointer *>(element);
442 TString countname;
443 countname = bname;
444 Ssiz_t dot = countname.Last('.');
445 if (dot>=0) {
446 countname.Remove(dot+1);
447 } else {
448 countname = "";
449 }
450 countname += bp->GetCountName();
451 brOfCounter = FindBranchCount(fTree, fParent, countname);
452 countname.Form("%s[%s]",name.Data(),bp->GetCountName());
453 SetTitle(countname);
454
455 } else if (element->IsA() == TStreamerLoop::Class()) {
456 // -- Fixup title with counter if we are a varying length array data member.
457 TStreamerLoop *bp = static_cast<TStreamerLoop *>(element);
458 TString countname;
459 countname = bname;
460 Ssiz_t dot = countname.Last('.');
461 if (dot>=0) {
462 countname.Remove(dot+1);
463 } else {
464 countname = "";
465 }
466 countname += bp->GetCountName();
467 brOfCounter = FindBranchCount(fTree, fParent, countname);
468 countname.Form("%s[%s]",name.Data(),bp->GetCountName());
469 SetTitle(countname);
470
471 }
472
473 if (splitlevel > 0) {
474 // -- Create sub branches if requested by splitlevel.
475 const char* elemType = element->GetTypeName();
476 TClass *elementClass = element->GetClassPointer();
477 fSTLtype = elementClass ? elementClass->GetCollectionType() : ROOT::kNotSTL;
478 if (element->CannotSplit()) {
479 fSplitLevel = 0;
480 } else if (element->IsA() == TStreamerBase::Class()) {
481 // -- We are a base class element.
482 // Note: This does not include an STL container class which is
483 // being used as a base class because the streamer element
484 // in that case is not the base streamer element it is the
485 // STL streamer element.
486 fType = 1;
487 TClass* clOfElement = element->GetClassPointer();
488 Int_t nbranches = fBranches.GetEntriesFast();
489 // Note: The following code results in base class branches
490 // having two different cases for what their parent
491 // class will be, this is very annoying. It is also
492 // very annoying that the naming conventions for the
493 // sub-branch names are different as well.
494 if (!strcmp(name, clOfElement->GetName())) {
495 // -- If the branch's name is the same as the base class name,
496 // which happens when we are a child branch of a top-level
497 // branch whose name does not end in a dot and also has no
498 // internal dots, elide the branch name, and keep the branch
499 // hierarchy rooted at the ultimate parent, this keeps the base
500 // class part of the branch name from propagating downwards.
501 // FIXME: We are eliding the base class here, creating a break in the branch hierarchy.
502 // Note: We can use parent class (cltop) != branch class (elemClass) to detection elision.
503 Unroll("", fBranchClass.GetClass(), clOfElement, pointer, basketsize, splitlevel+splitSTLP, 0);
506 return;
507 }
508 // If the branch's name is not the same as the base class name,
509 // keep the branch name as a prefix (i.e., continue the branch
510 // hierarchy), but start a new class hierarchy at the base class.
511 //
512 // Note: If the parent branch was created by the branch constructor
513 // which takes a folder as a parameter, then this case will
514 // be used, because the branch name will be the same as the
515 // parent branch name.
516 // Note: This means that the sub-branches of a base class branch
517 // created by TTree::Bronch() have the base class name as
518 // as part of the branch name, while those created by
519 // Unroll() do not, ouch!!!
520 //
521 Unroll(name, clOfElement, clOfElement, pointer, basketsize, splitlevel+splitSTLP, 0);
522 if (strchr(bname, '.')) {
523 // Note: How can this happen?
524 // Answer: This is the case when using the new branch
525 // naming convention where the top-level branch ends in dot.
526 // Note: Well actually not entirely, we could also be a sub-branch
527 // of a split class, even when the top-level branch does not
528 // end in a dot.
529 // Note: Or the top-level branch could have been created by the
530 // branch constructor which takes a folder as input, in which
531 // case the top-level branch name will have internal dots
532 // representing the folder hierarchy.
535 return;
536 }
537 if (nbranches == fBranches.GetEntriesFast()) {
538 // -- We did not add any branches in the Unroll, finalize our name to be the base class name, because Unroll did not do it for us.
539 const auto bnamelen = strlen(bname);
540 if (bnamelen) {
541 name.Form("%s%s%s", bname, bname[bnamelen-1]=='.' ? "" : ".", clOfElement->GetName());
542 } else {
543 name.Form("%s", clOfElement->GetName());
544 }
545 SetName(name);
546 SetTitle(name);
547 }
550 return;
551 } else if (element->GetClassPointer() == TClonesArray::Class()) {
552 // -- We are a TClonesArray element.
553 bool ispointer = element->IsaPointer();
554 TClonesArray *clones;
555 if (ispointer) {
556 char **ppointer = reinterpret_cast<char**>(pointer);
557 clones = reinterpret_cast<TClonesArray*>(*ppointer);
558 } else {
559 clones = reinterpret_cast<TClonesArray*>(pointer);
560 }
561 // basket->DeleteEntryOffset(); //entryoffset not required for the clonesarray counter
562 fEntryOffsetLen = 0;
563 // ===> Create a leafcount
564 TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
565 fNleaves = 1;
566 fLeaves.Add(leaf);
567 fTree->GetListOfLeaves()->Add(leaf);
568 if (!clones) {
570 return;
571 }
572 TClass* clOfClones = clones->GetClass();
573 if (!clOfClones) {
576 return;
577 }
578 fType = 3;
579 // ===> create sub branches for each data member of a TClonesArray
580 //check that the contained objects class name is part of the element title
581 //This name is mandatory when reading the Tree later on and
582 //the parent class with the pointer to the TClonesArray is not available.
583 fClonesName = clOfClones->GetName();
584 fClonesClass = clOfClones;
585 TString aname;
586 aname.Form(" (%s)", clOfClones->GetName());
587 TString atitle = element->GetTitle();
588 if (!atitle.Contains(aname)) {
589 atitle += aname;
590 element->SetTitle(atitle.Data());
591 }
592 TString branchname( name );
593 if (branchname.EndsWith("."))
594 branchname.Remove(branchname.Length()-1);
595 branchname += "_";
596 SetTitle(branchname);
597 leaf->SetName(branchname);
598 leaf->SetTitle(branchname);
599 leaf->SetRange(true);
600 Unroll(name, clOfClones, clOfClones, pointer, basketsize, splitlevel+splitSTLP, 31);
604 return;
606 // -- We are an STL container element.
607 TClass* contCl = elementClass;
609 TClass* valueClass = GetCollectionProxy()->GetValueClass();
610 // Check to see if we can split the container.
611 bool cansplit = true;
612 if (!valueClass) {
613 cansplit = false;
614 } else if ((valueClass == TString::Class()) || (valueClass == TClass::GetClass("string"))) {
615 cansplit = false;
616 } else if (GetCollectionProxy()->HasPointers() && !splitSTLP ) {
617 cansplit = false;
618 } else if (!valueClass->CanSplit() && !(GetCollectionProxy()->HasPointers() && splitSTLP)) {
619 cansplit = false;
620 } else if (valueClass->GetCollectionProxy()) {
621 // -- A collection was stored in a collection, we choose not to split it.
622 // Note: Splitting it would require extending TTreeFormula
623 // to understand how to access it.
624 cansplit = false;
625 }
626 if (cansplit) {
627 // -- Do the splitting work if we are allowed to.
628 fType = 4;
629 // Create a leaf for the master branch (the counter).
630 TLeaf *leaf = new TLeafElement(this, name, fID, fStreamerType);
631 fNleaves = 1;
632 fLeaves.Add(leaf);
633 fTree->GetListOfLeaves()->Add(leaf);
634 // Check that the contained objects class name is part of the element title.
635 // This name is mandatory when reading the tree later on and
636 // the parent class with the pointer to the STL container is not available.
637 fClonesName = valueClass->GetName();
638 fClonesClass = valueClass;
639 TString aname;
640 aname.Form(" (%s)", valueClass->GetName());
641 TString atitle = element->GetTitle();
642 if (!atitle.Contains(aname)) {
643 atitle += aname;
644 element->SetTitle(atitle.Data());
645 }
646 TString branchname (name);
647 if (branchname.EndsWith("."))
648 branchname.Remove(branchname.Length()-1);
649 branchname += "_";
650 SetTitle(branchname);
651 leaf->SetName(branchname);
652 leaf->SetTitle(branchname);
653 leaf->SetRange(true);
654 // Create sub branches for each data member of an STL container.
655 Unroll(name, valueClass, valueClass, pointer, basketsize, splitlevel+splitSTLP, 41);
659 return;
660 }
661 } else if (!strchr(elemType, '*') && ((fStreamerType == TVirtualStreamerInfo::kObject) || (fStreamerType == TVirtualStreamerInfo::kAny))) {
662 // -- Create sub-branches for members that are classes.
663 //
664 // Note: This can only happen if we were called directly
665 // (usually by TClass::Bronch) because Unroll never
666 // calls us for an element of this type.
667 fType = 2;
668 TClass* clm = elementClass;
669 Int_t err = Unroll(name, clm, clm, pointer, basketsize, splitlevel+splitSTLP, 0);
670 if (err >= 0) {
671 // Return on success.
672 // FIXME: Why not on error too?
675 return;
676 }
677 }
678 }
679 }
680
681 //
682 // Create a leaf to represent this branch.
683 //
684
685 TLeaf* leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
686 leaf->SetTitle(GetTitle());
687 fNleaves = 1;
688 fLeaves.Add(leaf);
689 fTree->GetListOfLeaves()->Add(leaf);
690
691 //
692 // If we have a counter branch set it now that we have
693 // created our leaf, we cannot do it before then.
694 //
695
696 if (brOfCounter) {
697 SetBranchCount(brOfCounter);
698 }
699
702}
703
704////////////////////////////////////////////////////////////////////////////////
705/// Constructor when the branch object is a TClonesArray.
706///
707/// If splitlevel > 0 this branch in turn is split into sub branches.
708
709TBranchElement::TBranchElement(TTree *tree, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
710: TBranch()
711, fClassName("TClonesArray")
712, fParentName()
713, fInfo(static_cast<TStreamerInfo*>(TClonesArray::Class()->GetStreamerInfo()))
714, fInit(true)
715, fInInitInfo(false)
716, fInitOffsets(false)
717, fTargetClass( fClassName )
718, fCurrentClass()
719, fParentClass()
720, fBranchClass(TClonesArray::Class())
721, fBranchID(-1)
722, fReadActionSequence(nullptr)
723, fFillActionSequence(nullptr)
724, fIterators(nullptr)
725, fWriteIterators(nullptr)
726, fPtrIterators(nullptr)
727{
728 Init(tree, nullptr, bname, clones, basketsize, splitlevel, compress);
729}
730
731////////////////////////////////////////////////////////////////////////////////
732/// Constructor when the branch object is a TClonesArray.
733///
734/// If splitlevel > 0 this branch in turn is split into sub branches.
735
736TBranchElement::TBranchElement(TBranch *parent, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
737: TBranch()
738, fClassName("TClonesArray")
739, fParentName()
740, fInfo(static_cast<TStreamerInfo*>(TClonesArray::Class()->GetStreamerInfo()))
741, fInit(true)
742, fInInitInfo(false)
743, fInitOffsets(false)
744, fTargetClass( fClassName )
745, fCurrentClass()
746, fParentClass()
747, fBranchClass(TClonesArray::Class())
748, fBranchID(-1)
749, fReadActionSequence(nullptr)
750, fFillActionSequence(nullptr)
751, fIterators(nullptr)
752, fWriteIterators(nullptr)
753, fPtrIterators(nullptr)
754{
755 Init(parent ? parent->GetTree() : nullptr, parent, bname, clones, basketsize, splitlevel, compress);
756}
757
758////////////////////////////////////////////////////////////////////////////////
759/// Init when the branch object is a TClonesArray.
760///
761/// If splitlevel > 0 this branch in turn is split into sub branches.
762
763void TBranchElement::Init(TTree *tree, TBranch *parent, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
764{
765 fCollProxy = nullptr;
766 fSplitLevel = splitlevel;
767 fID = 0;
768 fInit = true;
769 fStreamerType = -1;
770 fType = 0;
773 fBranchCount = nullptr;
774 fBranchCount2 = nullptr;
775 fObject = nullptr;
776 fOnfileObject = nullptr;
777 fMaximum = 0;
778 fBranchOffset = nullptr;
780 fInitOffsets = false;
781
782 fTree = tree;
783 fMother = parent ? parent->GetMother() : this;
784 fParent = parent;
786 fFileName = "";
787
788 SetName(bname);
789 const char* name = GetName();
790
791 SetTitle(name);
792 //fClassName = fInfo->GetName();
793 fCompress = compress;
794 if (compress == -1 && fTree->GetDirectory()) {
795 TFile *bfile = fTree->GetDirectory()->GetFile();
796 if (bfile) fCompress = bfile->GetCompressionSettings();
797 }
798
799 if (basketsize < 100) basketsize = 100;
800 fBasketSize = basketsize;
804
805 for (Int_t i=0;i<fMaxBaskets;i++) {
806 fBasketBytes[i] = 0;
807 fBasketEntry[i] = 0;
808 fBasketSeek[i] = 0;
809 }
810
811 // Reset the bit kAutoDelete to specify that when reading
812 // the object should not be deleted before calling the streamer.
813 SetAutoDelete(false);
814
815 // create sub branches if requested by splitlevel
816 if (splitlevel%TTree::kSplitCollectionOfPointers > 0) {
817 TClass* clonesClass = clones->GetClass();
818 if (!clonesClass) {
819 Error("Init","Missing class object of the TClonesArray %s\n",clones->GetName());
820 return;
821 }
822 fType = 3;
823 // ===> Create a leafcount
824 TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
825 fNleaves = 1;
826 fLeaves.Add(leaf);
827 fTree->GetListOfLeaves()->Add(leaf);
828 // ===> create sub branches for each data member of a TClonesArray
829 fClonesName = clonesClass->GetName();
830 fClonesClass = clonesClass;
831 TString branchname( name );
832 if (branchname[branchname.Length()-1]=='.') {
833 branchname.Remove(branchname.Length()-1);
834 }
835 branchname += "_";
836 SetTitle(branchname);
837 leaf->SetName(branchname);
838 leaf->SetTitle(branchname);
839 Unroll(name, clonesClass, clonesClass, nullptr, basketsize, splitlevel, 31);
843 return;
844 }
845
846 if (!clones->GetClass() || CanSelfReference(clones->GetClass())) {
848 }
849 TLeaf *leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
850 leaf->SetTitle(GetTitle());
851 fNleaves = 1;
852 fLeaves.Add(leaf);
853 fTree->GetListOfLeaves()->Add(leaf);
854
857}
858
859////////////////////////////////////////////////////////////////////////////////
860/// Constructor when the branch object is an STL collection.
861///
862/// If splitlevel > 0 this branch in turn is split into sub branches.
863
864TBranchElement::TBranchElement(TTree *tree, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
865: TBranch()
866, fClassName(cont->GetCollectionClass()->GetName())
867, fParentName()
868, fInit(true)
869, fInInitInfo(false)
870, fInitOffsets(false)
871, fTargetClass( fClassName )
872, fCurrentClass()
873, fParentClass()
874, fBranchClass(cont->GetCollectionClass())
875, fBranchID(-1)
876, fReadActionSequence(nullptr)
877, fFillActionSequence(nullptr)
878, fIterators(nullptr)
879, fWriteIterators(nullptr)
880, fPtrIterators(nullptr)
881{
882 Init(tree, nullptr, bname, cont, basketsize, splitlevel, compress);
883}
884
885////////////////////////////////////////////////////////////////////////////////
886/// Constructor when the branch object is an STL collection.
887///
888/// If splitlevel > 0 this branch in turn is split into sub branches.
889
890TBranchElement::TBranchElement(TBranch *parent, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
891: TBranch()
892, fClassName(cont->GetCollectionClass()->GetName())
893, fParentName()
894, fInit(true)
895, fInInitInfo(false)
896, fInitOffsets(false)
897, fTargetClass( fClassName )
898, fCurrentClass()
899, fParentClass()
900, fBranchClass(cont->GetCollectionClass())
901, fBranchID(-1)
902, fReadActionSequence(nullptr)
903, fFillActionSequence(nullptr)
904, fIterators(nullptr)
905, fWriteIterators(nullptr)
906, fPtrIterators(nullptr)
907{
908 Init(parent ? parent->GetTree() : nullptr, parent, bname, cont, basketsize, splitlevel, compress);
909}
910
911////////////////////////////////////////////////////////////////////////////////
912/// Init when the branch object is an STL collection.
913///
914/// If splitlevel > 0 this branch in turn is split into sub branches.
915
916void TBranchElement::Init(TTree *tree, TBranch *parent, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
917{
918 fCollProxy = cont->Generate();
919 TString name( bname );
920 if (name[name.Length()-1]=='.') {
921 name.Remove(name.Length()-1);
922 }
923 fInitOffsets = false;
924 fSplitLevel = splitlevel;
925 fInfo = nullptr;
926 fID = -1;
927 fInit = true;
928 fStreamerType = -1; // TVirtualStreamerInfo::kSTLp;
929 fType = 0;
932 fBranchCount = nullptr;
933 fBranchCount2 = nullptr;
934 fObject = nullptr;
935 fOnfileObject = nullptr;
936 fMaximum = 0;
937 fBranchOffset = nullptr;
938
939 //Must be set here so that write actions will be properly matched to the ReadLeavesPtr
940 fSTLtype = cont->GetCollectionType();
941 if (fSTLtype < 0) {
943 }
944
945 fTree = tree;
946 fMother = parent ? parent->GetMother() : this;
947 fParent = parent;
949 fFileName = "";
950
951 SetName(name);
952 SetTitle(name);
953 //fClassName = fBranchClass.GetClass()->GetName();
954 fCompress = compress;
955 if ((compress == -1) && fTree->GetDirectory()) {
956 TFile* bfile = fTree->GetDirectory()->GetFile();
957 if (bfile) {
959 }
960 }
961
962 if (basketsize < 100) {
963 basketsize = 100;
964 }
965 fBasketSize = basketsize;
966
970
971 for (Int_t i = 0; i < fMaxBaskets; ++i) {
972 fBasketBytes[i] = 0;
973 fBasketEntry[i] = 0;
974 fBasketSeek[i] = 0;
975 }
976
977 // Reset the bit kAutoDelete to specify that, when reading,
978 // the object should not be deleted before calling the streamer.
979 SetAutoDelete(false);
980
981 // create sub branches if requested by splitlevel
983 (cont->HasPointers() && splitlevel > TTree::kSplitCollectionOfPointers && cont->GetValueClass() && cont->GetValueClass()->CanSplit() ) )
984 {
985 fType = 4;
986 // ===> Create a leafcount
987 TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
988 fNleaves = 1;
989 fLeaves.Add(leaf);
990 fTree->GetListOfLeaves()->Add(leaf);
991 // ===> create sub branches for each data member of an STL container value class
992 TClass* valueClass = cont->GetValueClass();
993 if (!valueClass) {
994 return;
995 }
996 fClonesName = valueClass->GetName();
997 fClonesClass = valueClass;
998 TString branchname( name );
999 branchname += "_";
1000 SetTitle(branchname);
1001 leaf->SetName(branchname);
1002 leaf->SetTitle(branchname);
1003 Unroll(name, valueClass, valueClass, nullptr, basketsize, splitlevel, 41);
1007 return;
1008 }
1009
1010 TLeaf *leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
1011 leaf->SetTitle(GetTitle());
1012 fNleaves = 1;
1013 fLeaves.Add(leaf);
1014 fTree->GetListOfLeaves()->Add(leaf);
1017}
1018
1019////////////////////////////////////////////////////////////////////////////////
1020/// Destructor.
1021
1023{
1024 // Release any allocated I/O buffers.
1026 delete fOnfileObject;
1027 fOnfileObject = nullptr;
1028 }
1029 ResetAddress();
1030
1031 delete[] fBranchOffset;
1032 fBranchOffset = nullptr;
1033
1034 fInfo = nullptr;
1035 fBranchCount2 = nullptr;
1036 fBranchCount = nullptr;
1037
1038 if (fType == 4 || fType == 0) {
1039 // Only the top level TBranchElement containing an STL container,
1040 // owns the collectionproxy.
1041 delete fCollProxy;
1042 }
1043 fCollProxy = nullptr;
1044
1045 delete fReadActionSequence;
1046 delete fFillActionSequence;
1047 delete fIterators;
1048 delete fWriteIterators;
1049 delete fPtrIterators;
1050}
1051
1052//
1053// This function is located here to allow inlining by the optimizer.
1054//
1055////////////////////////////////////////////////////////////////////////////////
1056/// Get streamer info for the branch class.
1057
1059{
1060 // Note: we need to find a way to reduce the complexity of
1061 // this often executed condition.
1062 if (!fInfo || (fInfo && (!fInit || !fInfo->IsCompiled()))) {
1063 const_cast<TBranchElement*>(this)->InitInfo();
1064 }
1065 return fInfo;
1066}
1067
1068////////////////////////////////////////////////////////////////////////////////
1069/// Get streamer info for the branch class.
1070
1072{
1073 return GetInfoImp();
1074}
1075
1076////////////////////////////////////////////////////////////////////////////////
1077/// Browse the branch content.
1078
1080{
1081 Int_t nbranches = fBranches.GetEntriesFast();
1082 if (nbranches > 0) {
1083 TList persistentBranches;
1084 TBranch* branch=nullptr;
1085 TIter iB(&fBranches);
1086 while((branch=static_cast<TBranch*>(iB()))) {
1087 if (branch->IsFolder()) persistentBranches.Add(branch);
1088 else {
1089 // only show branches corresponding to persistent members
1090 TClass* cl=nullptr;
1091 if (strlen(GetClonesName()))
1092 // this works both for top level branches and for sub-branches,
1093 // as GetClonesName() is properly updated for sub-branches
1094 cl=fClonesClass;
1095 else {
1097
1098 // check if we're in a sub-branch of this class
1099 // we can only find out asking the streamer given our ID
1100 TStreamerElement *element=nullptr;
1101 TClass* clsub=nullptr;
1102 auto info = (fID >= 0) ? GetInfoImp() : nullptr;
1103 if (info
1104 && info->IsCompiled()
1105 && ((element=info->GetElement(fID)))
1106 && ((clsub=element->GetClassPointer())))
1107 cl=clsub;
1108 }
1109 if (cl) {
1110 TString strMember=branch->GetName();
1111 Size_t mempos=strMember.Last('.');
1112 if (mempos!=kNPOS)
1113 strMember.Remove(0, (Int_t)mempos+1);
1114 mempos=strMember.First('[');
1115 if (mempos!=kNPOS)
1116 strMember.Remove((Int_t)mempos);
1117 TDataMember* m=cl->GetDataMember(strMember);
1118 if (!m || m->IsPersistent()) persistentBranches.Add(branch);
1119 } else persistentBranches.Add(branch);
1120 } // branch if not a folder
1121 }
1122 persistentBranches.Browse(b);
1123 // add all public const methods without params
1124 if (GetBrowsables() && GetBrowsables()->GetSize())
1126 } else {
1127 if (GetBrowsables() && GetBrowsables()->GetSize()) {
1129 return;
1130 }
1131 // Get the name and strip any extra brackets
1132 // in order to get the full arrays.
1133 TString slash("/");
1134 TString escapedSlash("\\/");
1135 TString name = GetName();
1136 Int_t pos = name.First('[');
1137 if (pos != kNPOS) {
1138 name.Remove(pos);
1139 }
1140 TString mothername;
1141 if (GetMother()) {
1142 mothername = GetMother()->GetName();
1143 pos = mothername.First('[');
1144 if (pos != kNPOS) {
1145 mothername.Remove(pos);
1146 }
1147 Int_t len = mothername.Length();
1148 if (len) {
1149 if (mothername(len-1) != '.') {
1150 // We do not know for sure whether the mother's name is
1151 // already preprended. So we need to check:
1152 // a) it is prepended
1153 // b) it is NOT the name of a daughter (i.e. mothername.mothername exist)
1154 TString doublename = mothername;
1155 doublename.Append(".");
1156 Int_t isthere = (name.Index(doublename) == 0);
1157 if (!isthere) {
1158 name.Prepend(doublename);
1159 } else {
1160 if (GetMother()->FindBranch(mothername)) {
1161 doublename.Append(mothername);
1162 isthere = (name.Index(doublename) == 0);
1163 if (!isthere) {
1164 mothername.Append(".");
1165 name.Prepend(mothername);
1166 }
1167 } else {
1168 // Nothing to do because the mother's name is
1169 // already in the name.
1170 }
1171 }
1172 } else {
1173 // If the mother's name end with a dot then
1174 // the daughter probably already contains the mother's name
1175 if (name.Index(mothername) == kNPOS) {
1176 name.Prepend(mothername);
1177 }
1178 }
1179 }
1180 }
1181 name.ReplaceAll(slash, escapedSlash);
1182 GetTree()->Draw(name, "", b ? b->GetDrawOption() : "");
1183 if (gPad) {
1184 gPad->Update();
1185 }
1186 }
1187}
1188
1189////////////////////////////////////////////////////////////////////////////////
1190/// Set branch and leaf name and title in the case of a container sub-branch.
1191
1193{
1194 TString branchname;
1195
1196 Int_t nbranches = fBranches.GetEntriesFast();
1197
1198 TString indexname(name);
1199 if (indexname[indexname.Length()-1]=='.') {
1200 indexname.Remove(indexname.Length()-1);
1201 }
1202 indexname += "_";
1203
1204 for (Int_t i = 0; i < nbranches; ++i) {
1205 TBranchElement* bre = static_cast<TBranchElement*>(fBranches.At(i));
1206 if (!bre)
1207 continue;
1208 if (fType == 3) {
1209 bre->SetType(31);
1210 } else if (fType == 4) {
1211 bre->SetType(41);
1212 } else {
1213 Error("BuildTitle", "This cannot happen, fType of parent is not 3 or 4!");
1214 }
1216 bre->BuildTitle(name);
1217 const char* fin = strrchr(bre->GetTitle(), '.');
1218 if (fin == nullptr) {
1219 continue;
1220 }
1221 // The branch counter for a sub-branch of a container is the container master branch.
1222 bre->SetBranchCount(this);
1223 TLeafElement* lf = static_cast<TLeafElement*>(bre->GetListOfLeaves()->At(0));
1224 // If branch name is of the form fTracks.fCovar[3][4], then
1225 // set the title to fCovar[fTracks_].
1226 branchname = fin+1;
1227 Ssiz_t dim = branchname.First('[');
1228 if (dim>=0) {
1229 branchname.Remove(dim);
1230 }
1231 branchname += TString::Format("[%s]", indexname.Data());
1232 bre->SetTitle(branchname);
1233 if (lf) {
1234 lf->SetTitle(branchname);
1235 }
1236 // Is there a secondary branchcount?
1237 //
1238 // fBranchCount2 points to the secondary branchcount
1239 // in case a TClonesArray element itself has a branchcount.
1240 //
1241 // Example: In Event class with TClonesArray fTracks of Track objects.
1242 // if the Track object has two members
1243 // Int_t fNpoint;
1244 // Float_t *fPoints; //[fNpoint]
1245 // In this case the TBranchElement fTracks.fPoints has
1246 // -its primary branchcount pointing to the branch fTracks
1247 // -its secondary branchcount pointing to fTracks.fNpoint
1248 Int_t stype = bre->GetStreamerType();
1249 // FIXME: Should 60 be included here?
1250 if ((stype > 40) && (stype < 61)) {
1251 TString name2 (bre->GetName());
1252 Ssiz_t bn = name2.Last('.');
1253 if (bn<0) {
1254 continue;
1255 }
1256 TStreamerBasicPointer *el = dynamic_cast<TStreamerBasicPointer*>(bre->GetInfoImp()->GetElements()->FindObject(name2.Data()+bn+1));
1257 name2.Remove(bn+1);
1258 if (el) name2 += el->GetCountName();
1259 TBranchElement *bc2 = static_cast<TBranchElement*>(fBranches.FindObject(name2));
1260 bre->SetBranchCount2(bc2);
1261 }
1262 bre->SetReadLeavesPtr();
1263 bre->SetFillLeavesPtr();
1264 }
1265}
1266
1267////////////////////////////////////////////////////////////////////////////////
1268/// Loop on all leaves of this branch to fill the basket buffer.
1269///
1270/// The function returns the number of bytes committed to the
1271/// individual branches. If a write error occurs, the number of
1272/// bytes returned is -1. If no data are written, because, e.g.,
1273/// the branch is disabled, the number of bytes returned is 0.
1274///
1275/// Note: We not not use any member functions from TLeafElement!
1276
1278{
1279 Int_t nbytes = 0;
1280 Int_t nwrite = 0;
1281 Int_t nerror = 0;
1282 Int_t nbranches = fBranches.GetEntriesFast();
1283
1285
1286 //
1287 // If we are a top-level branch, update addresses.
1288 //
1289
1290 if (fID < 0) {
1291 if (!fObject) {
1292 Error("Fill", "attempt to fill branch %s while address is not set", GetName());
1293 return 0;
1294 }
1295 }
1296
1297 //
1298 // If the tree has a TRefTable, set the current branch if
1299 // branch is not a basic type.
1300 //
1301
1302 // FIXME: This test probably needs to be extended past 10.
1303 if ((fType >= -1) && (fType < 10)) {
1304 TBranchRef* bref = fTree->GetBranchRef();
1305 if (bref) {
1306 fBranchID = bref->SetParent(this, fBranchID);
1307 }
1308 }
1309
1310 if (!nbranches) {
1311 // No sub-branches.
1312 if (!TestBit(kDoNotProcess)) {
1313 nwrite = TBranch::FillImpl(imtHelper);
1314 if (nwrite < 0) {
1315 Error("Fill", "Failed filling branch:%s, nbytes=%d", GetName(), nwrite);
1316 ++nerror;
1317 } else {
1318 nbytes += nwrite;
1319 }
1320 }
1321 } else {
1322 // We have sub-branches.
1323 if (fType == 3 || fType == 4) {
1324 // TClonesArray or STL container counter
1325 nwrite = TBranch::FillImpl(imtHelper);
1326 if (nwrite < 0) {
1327 Error("Fill", "Failed filling branch:%s, nbytes=%d", GetName(), nwrite);
1328 ++nerror;
1329 } else {
1330 nbytes += nwrite;
1331 }
1332 } else {
1333 ++fEntries;
1334 }
1335 for (Int_t i = 0; i < nbranches; ++i) {
1336 TBranchElement* branch = static_cast<TBranchElement*>(fBranches[i]);
1337 if (!branch->TestBit(kDoNotProcess)) {
1338 nwrite = branch->FillImpl(imtHelper);
1339 if (nwrite < 0) {
1340 Error("Fill", "Failed filling branch:%s.%s, nbytes=%d", GetName(), branch->GetName(), nwrite);
1341 nerror++;
1342 } else {
1343 nbytes += nwrite;
1344 }
1345 }
1346 }
1347 }
1348
1349 if (fTree->Debug() > 0) {
1350 // Debugging.
1351 Long64_t entry = fEntries;
1352 if ((entry >= fTree->GetDebugMin()) && (entry <= fTree->GetDebugMax())) {
1353 printf("Fill: %lld, branch=%s, nbytes=%d\n", entry, GetName(), nbytes);
1354 }
1355 }
1356
1357 if (nerror != 0) {
1358 return -1;
1359 }
1360
1361 return nbytes;
1362}
1363
1364////////////////////////////////////////////////////////////////////////////////
1365/// Write leaves into i/o buffers for this branch.
1366/// For the case where the branch is set in MakeClass mode (decomposed object).
1367
1369{
1371
1372 //
1373 // Silently do nothing if we have no user i/o buffer.
1374 //
1375
1376 if (!fObject) {
1377 return;
1378 }
1379
1380 // -- TClonesArray top-level branch. Write out number of entries, sub-branch writes the entries themselves.
1381 if(fType == 3) {
1382 // fClonesClass can not be zero since we are of type 3, see TBranchElement::Init
1384 if (!si) {
1385 Error("FillLeaves", "Cannot get streamer info for branch '%s' class '%s'", GetName(), fClonesClass->GetName());
1386 return;
1387 }
1388 b.ForceWriteInfo(si,false);
1389 Int_t* nptr = reinterpret_cast<Int_t*>(fAddress);
1390 b << *nptr;
1391 } else if (fType == 31) {
1392 // -- TClonesArray sub-branch. Write out the entries in the TClonesArray.
1393 // -- A MakeClass() tree, we must use fAddress instead of fObject.
1394 if (!fAddress) {
1395 // FIXME: Enable this message.
1396 //Error("FillLeaves", "Branch address not set for branch '%s'!", GetName());
1397 return;
1398 }
1399 Int_t atype = fStreamerType;
1400 if (atype > 54) {
1401 // Note: We are not supporting kObjectp, kAny, kObjectp,
1402 // kObjectP, kTString, kTObject, kTNamed, kAnyp,
1403 // kAnyP, kSTLp, kSTL, kSTLstring, kStreamer,
1404 // kStreamLoop here, nor pointers to varying length
1405 // arrays of them either.
1406 // Nor do we support pointers to varying length
1407 // arrays of kBits, kLong64, kULong64, nor kBool.
1408 return;
1409 }
1410 Int_t* nn = reinterpret_cast<Int_t*>(fBranchCount->GetAddress());
1411 if (!nn) {
1412 Error("FillLeaves", "The branch counter address was zero!");
1413 return;
1414 }
1415 Int_t n = *nn;
1416 if (atype > 40) {
1417 // Note: We are not supporting pointer to varying length array.
1418 Error("FillLeaves", "Clonesa: %s, n=%d, sorry not supported yet", GetName(), n);
1419 return;
1420 }
1421 if (atype > 20) {
1422 atype -= 20;
1423 TLeafElement* leaf = static_cast<TLeafElement*>(fLeaves.UncheckedAt(0));
1424 n = n * leaf->GetLenStatic();
1425 }
1426 switch (atype) {
1427 // Note: Type 0 is a base class and cannot happen here, see Unroll().
1428 case TVirtualStreamerInfo::kChar /* 1 */: { b.WriteFastArray(reinterpret_cast<Char_t*>(fAddress), n); break; }
1429 case TVirtualStreamerInfo::kShort /* 2 */: { b.WriteFastArray(reinterpret_cast<Short_t*>(fAddress), n); break; }
1430 case TVirtualStreamerInfo::kInt /* 3 */: { b.WriteFastArray(reinterpret_cast<Int_t*>(fAddress), n); break; }
1431 case TVirtualStreamerInfo::kLong /* 4 */: { b.WriteFastArray(reinterpret_cast<Long_t*>(fAddress), n); break; }
1432 case TVirtualStreamerInfo::kFloat /* 5 */: { b.WriteFastArray(reinterpret_cast<Float_t*>(fAddress), n); break; }
1433 case TVirtualStreamerInfo::kCounter /* 6 */: { b.WriteFastArray(reinterpret_cast<Int_t*>(fAddress), n); break; }
1434 // FIXME: We do nothing with type 7 (TVirtualStreamerInfo::kCharStar, char*) here!
1435 case TVirtualStreamerInfo::kDouble /* 8 */: { b.WriteFastArray(reinterpret_cast<Double_t*>(fAddress), n); break; }
1436 case TVirtualStreamerInfo::kDouble32 /* 9 */: {
1438 // coverity[returned_null] structurally si->fComp (used in GetElem) can not be null.
1439 TStreamerElement* se = si->GetElement(fID);
1440 Double_t* xx = reinterpret_cast<Double_t*>(fAddress);
1441 for (Int_t ii = 0; ii < n; ++ii) {
1442 b.WriteDouble32(&(xx[ii]),se);
1443 }
1444 break;
1445 }
1446 case TVirtualStreamerInfo::kFloat16 /* 19 */: {
1448 // coverity[dereference] structurally si can not be null.
1449 TStreamerElement* se = static_cast<TStreamerElement*>(si->GetElement(fID));
1450 Float_t* xx = reinterpret_cast<Float_t*>(fAddress);
1451 for (Int_t ii = 0; ii < n; ++ii) {
1452 b.WriteFloat16(&(xx[ii]),se);
1453 }
1454 break;
1455 }
1456 // Note: Type 10 is unused for now.
1457 case TVirtualStreamerInfo::kUChar /* 11 */: { b.WriteFastArray(reinterpret_cast<UChar_t*>(fAddress), n); break; }
1458 case TVirtualStreamerInfo::kUShort /* 12 */: { b.WriteFastArray(reinterpret_cast<UShort_t*>(fAddress), n); break; }
1459 case TVirtualStreamerInfo::kUInt /* 13 */: { b.WriteFastArray(reinterpret_cast<UInt_t*>(fAddress), n); break; }
1460 case TVirtualStreamerInfo::kULong /* 14 */: { b.WriteFastArray(reinterpret_cast<ULong_t*>(fAddress), n); break; }
1461 // FIXME: This is wrong!!! TVirtualStreamerInfo::kBits is a variable length type.
1462 case TVirtualStreamerInfo::kBits /* 15 */: { b.WriteFastArray(reinterpret_cast<UInt_t*>(fAddress), n); break; }
1463 case TVirtualStreamerInfo::kLong64 /* 16 */: { b.WriteFastArray(reinterpret_cast<Long64_t*>(fAddress), n); break; }
1464 case TVirtualStreamerInfo::kULong64 /* 17 */: { b.WriteFastArray(reinterpret_cast<ULong64_t*>(fAddress), n); break; }
1465 case TVirtualStreamerInfo::kBool /* 18 */: { b.WriteFastArray(reinterpret_cast<bool*>(fAddress), n); break; }
1466 }
1467 }
1468}
1469
1470////////////////////////////////////////////////////////////////////////////////
1471/// Write leaves into i/o buffers for this branch.
1472/// Case of a collection (fType == 4).
1473
1475{
1476 // -- STL container top-level branch. Write out number of entries, sub-branch writes the entries themselves.
1478
1479 //
1480 // Silently do nothing if we have no user i/o buffer.
1481 //
1482
1483 if (!fObject) {
1484 return;
1485 }
1486
1488 Int_t n = 0;
1489 // We are in a block so the helper pops as soon as possible.
1491 n = proxy->Size();
1492
1493 if (n > fMaximum) {
1494 fMaximum = n;
1495 }
1496 b << n;
1497
1500 } else {
1501 //NOTE: this does not work for not vectors since the CreateIterators expects a TGenCollectionProxy::TStaging as its argument!
1502 //NOTE: and those not work in general yet, since the TStaging object is neither created nor passed.
1503 // We need to review how to avoid the need for a TStaging during the writing.
1504 if (IsAssociativeContainer(*proxy)) {
1506 } else {
1508 }
1509 }
1510
1511}
1512
1513////////////////////////////////////////////////////////////////////////////////
1514/// Write leaves into i/o buffers for this branch.
1515/// Case of a data member within a collection (fType == 41).
1516
1518{
1520
1521 //
1522 // Silently do nothing if we have no user i/o buffer.
1523 //
1524
1525 if (!fObject) {
1526 return;
1527 }
1528
1529 // FIXME: This wont work if a pointer to vector is split!
1531 // Note: We cannot pop the proxy here because we need it for the i/o.
1532 TStreamerInfo* si = static_cast<TStreamerInfo*>(GetInfoImp());
1533 if (!si) {
1534 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1535 return;
1536 }
1537
1539 R__ASSERT(nullptr!=iter);
1540 b.ApplySequenceVecPtr(*fFillActionSequence,iter->fBegin,iter->fEnd);
1541}
1542
1543////////////////////////////////////////////////////////////////////////////////
1544/// Write leaves into i/o buffers for this branch.
1545/// Case of a data member within a collection (fType == 41).
1546
1548{
1550
1551 //
1552 // Silently do nothing if we have no user i/o buffer.
1553 //
1554
1555 if (!fObject) {
1556 return;
1557 }
1558
1559 // FIXME: This wont work if a pointer to vector is split!
1561
1562 // Note: We cannot pop the proxy here because we need it for the i/o.
1563 TStreamerInfo* si = static_cast<TStreamerInfo*>(GetInfoImp());
1564 if (!si) {
1565 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1566 return;
1567 }
1568
1570 b.ApplySequence(*fFillActionSequence,iter->fBegin,iter->fEnd);
1571
1572}
1573
1574////////////////////////////////////////////////////////////////////////////////
1575/// Write leaves into i/o buffers for this branch.
1576/// Case of a data member within a collection (fType == 41).
1577
1579{
1581
1582 //
1583 // Silently do nothing if we have no user i/o buffer.
1584 //
1585
1586 if (!fObject) {
1587 return;
1588 }
1589
1590 // FIXME: This wont work if a pointer to vector is split!
1592 // Note: We cannot pop the proxy here because we need it for the i/o.
1593 TStreamerInfo* si = static_cast<TStreamerInfo*>(GetInfoImp());
1594 if (!si) {
1595 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1596 return;
1597 }
1598
1600 R__ASSERT(nullptr!=iter);
1601 b.ApplySequence(*fFillActionSequence,iter->fBegin,iter->fEnd);
1602
1603}
1604
1605////////////////////////////////////////////////////////////////////////////////
1606/// Write leaves into i/o buffers for this branch.
1607/// Case of a data member within a collection (fType == 41).
1608
1610{
1612
1613 //
1614 // Silently do nothing if we have no user i/o buffer.
1615 //
1616
1617 if (!fObject) {
1618 return;
1619 }
1620
1621 // FIXME: This wont work if a pointer to vector is split!
1623 // Note: We cannot pop the proxy here because we need it for the i/o.
1624 TStreamerInfo* si = static_cast<TStreamerInfo*>(GetInfoImp());
1625 if (!si) {
1626 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1627 return;
1628 }
1629
1631 R__ASSERT(nullptr!=iter);
1632 b.ApplySequence(*fFillActionSequence,iter->fBegin,iter->fEnd);
1633
1634}
1635
1636////////////////////////////////////////////////////////////////////////////////
1637/// Write leaves into i/o buffers for this branch.
1638/// Case of a TClonesArray (fType == 3).
1639
1641{
1642 // -- TClonesArray top-level branch. Write out number of entries, sub-branch writes the entries themselves.
1644
1645 //
1646 // Silently do nothing if we have no user i/o buffer.
1647 //
1648
1649 if (!fObject) {
1650 return;
1651 }
1652
1653 TClonesArray* clones = reinterpret_cast<TClonesArray*>(fObject);
1654 Int_t n = clones->GetEntriesFast();
1655 if (n > fMaximum) {
1656 fMaximum = n;
1657 }
1658 b << n;
1659}
1660
1661////////////////////////////////////////////////////////////////////////////////
1662/// Write leaves into i/o buffers for this branch.
1663/// Case of a data member within a TClonesArray (fType == 31).
1664
1666{
1668
1669 //
1670 // Silently do nothing if we have no user i/o buffer.
1671 //
1672
1673 if (!fObject) {
1674 return;
1675 }
1676
1677 TClonesArray* clones = reinterpret_cast<TClonesArray*>(fObject);
1678 Int_t n = clones->GetEntriesFast();
1679 TStreamerInfo* si = static_cast<TStreamerInfo*>(GetInfoImp());
1680 if (!si) {
1681 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1682 return;
1683 }
1684
1685 char **arr = reinterpret_cast<char **>(clones->GetObjectRef(nullptr));
1686 char **end = arr + n;
1687 b.ApplySequenceVecPtr(*fFillActionSequence,arr,end);
1688}
1689
1690////////////////////////////////////////////////////////////////////////////////
1691/// Write leaves into i/o buffers for this branch.
1692/// Case of a non TObject, non collection class with a custom streamer
1693
1695{
1697
1698 //
1699 // Silently do nothing if we have no user i/o buffer.
1700 //
1701
1702 if (!fObject) {
1703 return;
1704 }
1705
1706 //
1707 // Remember tobjects written to the buffer so that
1708 // pointers are handled correctly later.
1709
1710 if (TestBit(kBranchObject)) {
1711 b.MapObject(reinterpret_cast<TObject*>(fObject));
1712 } else if (TestBit(kBranchAny)) {
1713 b.MapObject(fObject, fBranchClass);
1714 }
1715
1717}
1718
1719////////////////////////////////////////////////////////////////////////////////
1720/// Write leaves into i/o buffers for this branch.
1721/// For split-class branch, base class branch, data member branch, or top-level branch.
1722/// which do have a branch count and are not a counter.
1723
1725{
1727 /*
1728 ValidateAddress();
1729
1730 //
1731 // Silently do nothing if we have no user i/o buffer.
1732 //
1733
1734 if (!fObject) {
1735 return;
1736 }
1737 */
1738}
1739
1740////////////////////////////////////////////////////////////////////////////////
1741/// Write leaves into i/o buffers for this branch.
1742/// For split-class branch, base class branch, data member branch, or top-level branch.
1743/// which do not have a branch count and are a counter.
1744
1746{
1748
1749 //
1750 // Silently do nothing if we have no user i/o buffer.
1751 //
1752
1753 if (!fObject) {
1754 return;
1755 }
1756 // -- Top-level, data member, base class, or split class branch.
1757 // A non-split top-level branch (0, and fID == -1)), a non-split object (0, and fID > -1), or a base class (1), or a split (non-TClonesArray, non-STL container) object (2). Write out the object.
1758 // Note: A split top-level branch (0, and fID == -2) should not happen here, see Fill().
1759 // FIXME: What happens with a split base class branch,
1760 // or a split class branch???
1761 TStreamerInfo* si = GetInfoImp();
1762 if (!si) {
1763 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1764 return;
1765 }
1766 // Since info is not null, fFillActionSequence is not null either.
1767 b.ApplySequence(*fFillActionSequence, fObject);
1768 // Int_t n = si->WriteBufferAux(b, &fObject, fID, 1, 0, 0);
1769
1770 Int_t n = *reinterpret_cast<Int_t*>(fObject + si->TStreamerInfo::GetElementOffset(fID)); // or GetInfoImp()->GetTypedValue<Int_t>(&fObject, fID, j, -1);
1771 if (n > fMaximum) {
1772 fMaximum = n;
1773 }
1774
1775}
1776
1777////////////////////////////////////////////////////////////////////////////////
1778/// Write leaves into i/o buffers for this branch.
1779/// For split-class branch, base class branch, data member branch, or top-level branch.
1780/// which do not have a branch count and are not a counter.
1781
1783{
1785
1786 //
1787 // Silently do nothing if we have no user i/o buffer.
1788 //
1789
1790 if (!fObject) {
1791 return;
1792 }
1793
1794 if (TestBit(kBranchObject)) {
1795 b.MapObject(reinterpret_cast<TObject*>(fObject));
1796 } else if (TestBit(kBranchAny)) {
1797 b.MapObject(fObject, fBranchClass);
1798 }
1799
1800 // -- Top-level, data member, base class, or split class branch.
1801 // A non-split top-level branch (0, and fID == -1)), a non-split object (0, and fID > -1), or a base class (1), or a split (non-TClonesArray, non-STL container) object (2). Write out the object.
1802 // Note: A split top-level branch (0, and fID == -2) should not happen here, see Fill().
1803 // FIXME: What happens with a split base class branch,
1804 // or a split class branch???
1805 TStreamerInfo* si = GetInfoImp();
1806 if (!si) {
1807 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1808 return;
1809 }
1810 // Since info is not null, fFillActionSequence is not null either.
1811 b.ApplySequence(*fFillActionSequence, fObject);
1812
1813}
1814
1815////////////////////////////////////////////////////////////////////////////////
1816/// Remove trailing dimensions and make sure
1817/// there is a trailing dot.
1818
1819static void R__CleanName(std::string &name)
1820{
1821 if (name[name.length()-1]==']') {
1822 std::size_t dim = name.find_first_of('[');
1823 if (dim != std::string::npos) {
1824 name.erase(dim);
1825 }
1826 }
1827 if (name[name.size()-1] != '.') {
1828 name += '.';
1829 }
1830}
1831
1832////////////////////////////////////////////////////////////////////////////////
1833/// Find the immediate sub-branch with passed name.
1834
1836{
1837 // The default behavior of TBranch::FindBranch is sometimes
1838 // incorrect if this branch represent a base class, since
1839 // the base class name might or might not be in the name
1840 // of the sub-branches and might or might not be in the
1841 // name being passed.
1842
1843 if (fID >= 0) {
1845 TStreamerElement* se = si->GetElement(fID);
1846 if (se && se->IsBase()) {
1847 // We allow the user to pass only the last dotted component of the name.
1848 UInt_t len = strlen(name);
1849 std::string longnm;
1850 longnm.reserve(fName.Length()+len+3); // Enough space of fName + name + dots
1851 longnm = fName.Data();
1852 R__CleanName(longnm);
1853 longnm += name;
1854 std::string longnm_parent;
1855 longnm_parent.reserve(fName.Length()+len+3);
1856 longnm_parent = (GetMother()->GetSubBranch(this)->GetName());
1857 R__CleanName(longnm_parent);
1858 longnm_parent += name; // Name without the base class name
1859
1860 UInt_t namelen = strlen(name);
1861
1862 TBranch* branch = nullptr;
1863 Int_t nbranches = fBranches.GetEntries();
1864 for(Int_t i = 0; i < nbranches; ++i) {
1865 branch = static_cast<TBranch*>(fBranches.UncheckedAt(i));
1866
1867 const char *brname = branch->GetName();
1868 UInt_t brlen = strlen(brname);
1869 if (brname[brlen-1]==']') {
1870 const char *dim = strchr(brname,'[');
1871 if (dim) {
1872 brlen = dim - brname;
1873 }
1874 }
1875 if (namelen == brlen /* same effective size */
1876 && strncmp(name,brname,brlen) == 0) {
1877 return branch;
1878 }
1879 if (brlen == longnm.length()
1880 && strncmp(longnm.c_str(),brname,brlen) == 0) {
1881 return branch;
1882 }
1883 // This check is specific to base class
1884 if (brlen == longnm_parent.length()
1885 && strncmp(longnm_parent.c_str(),brname,brlen) == 0) {
1886 return branch;
1887 }
1888
1889 if (namelen>brlen && name[brlen]=='.' && strncmp(name,brname,brlen)==0) {
1890 // The prefix subbranch name match the branch name.
1891 return branch->FindBranch(name+brlen+1);
1892 }
1893 }
1894 }
1895 }
1897 if (!result) {
1898 // Look in base classes if any
1899 Int_t nbranches = fBranches.GetEntries();
1900 for(Int_t i = 0; i < nbranches; ++i) {
1901 TObject *obj = fBranches.UncheckedAt(i);
1902 if(obj->IsA() != TBranchElement :: Class() )
1903 continue;
1904 TBranchElement *br = static_cast<TBranchElement*>(obj);
1905 TVirtualStreamerInfo* si = br->GetInfoImp();
1906 if (si && br->GetID() >= 0) {
1907 TStreamerElement* se = si->GetElement(br->GetID());
1908 if (se && se->IsBase()) {
1909 result = br->FindBranch(name);
1910 }
1911 }
1912 }
1913 }
1914 return result;
1915}
1916
1917////////////////////////////////////////////////////////////////////////////////
1918/// Find the leaf corresponding to the name 'searchname'.
1919
1921{
1922 TLeaf *leaf = TBranch::FindLeaf(name);
1923
1924 if (leaf==nullptr && GetListOfLeaves()->GetEntries()==1) {
1925 TBranch *br = GetMother()->GetSubBranch( this );
1926 if( br->IsA() != TBranchElement::Class() )
1927 return nullptr;
1928
1929 TBranchElement *parent = static_cast<TBranchElement*>(br);
1930 if (parent==this || parent->GetID()<0 ) return nullptr;
1931
1932 TVirtualStreamerInfo* si = parent->GetInfoImp();
1933 TStreamerElement* se = si->GetElement(parent->GetID());
1934
1935 if (! se->IsBase() ) return nullptr;
1936
1937 br = GetMother()->GetSubBranch( parent );
1938 if( br->IsA() != TBranchElement::Class() )
1939 return nullptr;
1940
1941 TBranchElement *grand_parent = static_cast<TBranchElement*>(br);
1942
1943 std::string longname( grand_parent->GetName() );
1944 R__CleanName(longname);
1945 longname += name;
1946
1947 std::string leafname( GetListOfLeaves()->At(0)->GetName() );
1948
1949 if ( longname == leafname ) {
1950 return static_cast<TLeaf*>(GetListOfLeaves()->At(0));
1951 }
1952 }
1953 return leaf;
1954}
1955
1956////////////////////////////////////////////////////////////////////////////////
1957/// Get the branch address.
1958///
1959/// If we are *not* owned by a MakeClass() tree:
1960///
1961/// - If we are a top-level branch, return a pointer
1962/// - to the pointer to our object.
1963///
1964/// If we are *not* a top-level branch, return a pointer
1965/// to our object.
1966///
1967/// If we are owned by a MakeClass() tree:
1968///
1969/// - Return a pointer to our object.
1970
1972{
1974 return fAddress;
1975}
1976
1977
1978// For a mother branch of type 3 or 4, find the 'correct' StreamerInfo for the
1979// content of the collection by find a sub-branch corresponding to a direct data member
1980// of the containee class (valueClass)
1981// Default to the current StreamerInfo if none are found.
1983{
1984 TVirtualStreamerInfo *localInfo = nullptr;
1985
1986 // Search for the correct version.
1987 for(auto subbe : TRangeDynCast<TBranchElement>( branches )) {
1988 if (!subbe->fInfo)
1989 subbe->SetupInfo();
1990 if (valueClass == subbe->fInfo->GetClass()) { // Use GetInfo to provoke its creation.
1991 localInfo = subbe->fInfo;
1992 break;
1993 }
1994 }
1995 if (!localInfo) {
1996 // This is likely sub-optimal as we really should call GetFile but it is non-const.
1997 auto file = fDirectory ? fDirectory->GetFile() : nullptr;
1998 if (file && file->GetSeekInfo()) {
1999 localInfo = static_cast<TStreamerInfo*>(file->GetStreamerInfoCache()->FindObject(valueClass->GetName()));
2000 if (localInfo) {
2001 if (valueClass->IsVersioned()) {
2002 localInfo = valueClass->GetStreamerInfo(localInfo->GetClassVersion());
2003 } else {
2004 localInfo = valueClass->FindStreamerInfo(localInfo->GetCheckSum());
2005 if (localInfo) {
2006 // Now that we found it, we need to make sure it is initialize (Find does not initialize the StreamerInfo).
2007 localInfo = valueClass->GetStreamerInfo(localInfo->GetClassVersion());
2008 }
2009 }
2010 }
2011 }
2012 }
2013 if (!localInfo)
2014 localInfo = valueClass->GetStreamerInfo();
2015
2016 if (localInfo) {
2017 // See if we need any conversion.
2018 TClass *targetValueClass = fInfo->GetClass()->GetCollectionProxy()
2020 : nullptr;
2021 // For TClonesArray, the rest of the code probably does not support change in
2022 // value class, but if it does, we would have to look up the target value class
2023 // in the TClonesArray instance.
2024 // if (type == 3 && instance) targetValueClass = (reinterpret_cast<TClonesArray*>(instance))->GetClass();
2025
2026 if (targetValueClass && localInfo->GetClass() != targetValueClass) {
2027 localInfo = targetValueClass->GetConversionStreamerInfo(localInfo->GetClass(),
2028 localInfo->GetClassVersion());
2029 }
2030 }
2031 return static_cast<TStreamerInfo*>(localInfo);
2032}
2033
2034namespace {
2035void GatherArtificialElements(const TObjArray &branches, TStreamerInfoActions::TIDs &ids, TString prefix, TStreamerInfo *info, Int_t offset) {
2036 size_t ndata = info->GetNelement();
2037 for (size_t i =0; i < ndata; ++i) {
2038 TStreamerElement *nextel = info->GetElement(i);
2039
2040 if (nextel->GetType() == TStreamerInfo::kCacheDelete
2041 || nextel->GetType() == TStreamerInfo::kCacheNew) {
2042 continue;
2043 }
2044
2045 TString ename = prefix + nextel->GetName();
2046
2047 if (ename[0]=='*')
2048 ename.Remove(0,1);
2049
2050 Ssiz_t pos;
2051 while ((pos = ename.Last('[')) != TString::kNPOS) {
2052 ename = ename.Remove(pos);
2053 }
2054
2055 TBranchElement *be = static_cast<TBranchElement*>(branches.FindObject(ename));
2056 if (nextel->IsA() == TStreamerArtificial::Class()
2057 && be == nullptr) {
2058
2059 ids.push_back(i);
2060 ids.back().fElement = nextel;
2061 ids.back().fInfo = info;
2062 }
2063
2064 if (nextel->CannotSplit() || nextel->IsTransient() || nextel->GetOffset() == TStreamerInfo::kMissing)
2065 continue;
2066
2067 if (!be && nextel->IsBase()) {
2068 // We could be in the case of a branch created from a Folder or
2069 // a top level branch with a non-trailing dot in its name (case inadvertently confused with the folder case).
2070 // In those case, the name of the base class is *not* used to create the corresponding branch.
2071 TString subprefix(prefix);
2072 if (subprefix.Length() && subprefix[subprefix.Length()-1] == '.')
2073 subprefix.Remove(subprefix.Length()-1);
2074
2075 be = static_cast<TBranchElement*>(branches.FindObject(subprefix));
2076 if (be) {
2077 // There is at least 'one' base class branch all with the same name, so let's find the
2078 // right one.
2079 TClass *expectedClass = nullptr;
2080 EDataType expectedType;
2081 if (0 != be->GetExpectedType(expectedClass,expectedType)
2082 || expectedClass != nextel->GetClassPointer())
2083 {
2084 be = nullptr;
2085 Int_t nbranches = branches.GetEntriesFast();
2086 for (Int_t bi = 0; bi < nbranches; ++bi) {
2087 TBranchElement* branch = static_cast<TBranchElement*>(branches[bi]);
2088 if (subprefix != branch->GetName())
2089 continue;
2090 if (0 == branch->GetExpectedType(expectedClass,expectedType)
2091 && expectedClass == nextel->GetClassPointer())
2092 {
2093 be = branch;
2094 break;
2095 }
2096 }
2097 } // else we have already found the right branch.
2098 }
2099 }
2100
2101 TClass *elementClass = nextel->GetClassPointer();
2102 if (elementClass && (!be || be->GetType() == -2)) {
2103 // Recurse on sub-objects.
2104 TStreamerInfo *nextinfo = nullptr;
2105
2106 // nextinfo_version = ....
2107 auto search = be ? be->GetListOfBranches() : &branches;
2108 TVirtualArray *onfileObject = nullptr;
2109
2110 TString subprefix;
2111 if (prefix.Length() && nextel->IsA() == TStreamerBase::Class()) {
2112 // We skip the name of the base class if there is already a prefix.
2113 // See TBranchElement::Unroll
2114 subprefix = prefix;
2115 } else {
2116 subprefix = ename + ".";
2117 }
2118 auto nbranches = search->GetEntriesFast();
2119 bool foundRelatedSplit = false;
2120 for (Int_t bi = 0; bi < nbranches; ++bi) {
2121 TBranchElement* subbe = static_cast<TBranchElement*>(search->At(bi));
2122 bool matchSubPrefix = strncmp(subbe->GetFullName(), subprefix.Data(), subprefix.Length()) == 0;
2123 if (!foundRelatedSplit)
2124 foundRelatedSplit = matchSubPrefix;
2125 if (elementClass == subbe->GetInfo()->GetClass() // Use GetInfo to provoke its creation.
2126 && subbe->GetOnfileObject()
2127 && matchSubPrefix)
2128 {
2129 nextinfo = subbe->GetInfo();
2130 onfileObject = subbe->GetOnfileObject();
2131 break;
2132 }
2133 }
2134
2135 if (!foundRelatedSplit) {
2136 continue;
2137 }
2138
2139 if (!nextinfo) {
2140 nextinfo = static_cast<TStreamerInfo *>(elementClass->GetStreamerInfo());
2141 if (elementClass->GetCollectionProxy() && elementClass->GetCollectionProxy()->GetValueClass()) {
2142 nextinfo = static_cast<TStreamerInfo *>(elementClass->GetCollectionProxy()->GetValueClass()->GetStreamerInfo()); // NOTE: need to find the right version
2143 }
2144 }
2145 ids.emplace_back(nextinfo, offset + nextel->GetOffset());
2146 if (!onfileObject && nextinfo && nextinfo->GetNelement() && nextinfo->GetElement(0)->GetType() == TStreamerInfo::kCacheNew) {
2147 onfileObject = new TVirtualArray( info->GetElement(0)->GetClassPointer(), 1 /* is that always right? */ );
2148 ids.back().fNestedIDs->fOwnOnfileObject = true;
2149 }
2150 ids.back().fNestedIDs->fOnfileObject = onfileObject;
2151 GatherArtificialElements(branches, ids.back().fNestedIDs->fIDs, subprefix, nextinfo, offset + nextel->GetOffset());
2152 if (ids.back().fNestedIDs->fIDs.empty())
2153 ids.pop_back();
2154 }
2155 }
2156};
2157} // Anonymous namespace.
2158
2159
2160////////////////////////////////////////////////////////////////////////////////
2161/// Set the value of fInfo. This is part one of InitInfo.
2162/// To be used as:
2163/// if (!fInfo)
2164/// SetupInfo();
2165/// It would only be used within InitInfo (and its callees)
2166
2168{
2169 // We did not already have streamer info, so now we must find it.
2171
2172 //------------------------------------------------------------------------
2173 // Check if we're dealing with the name change
2174 //////////////////////////////////////////////////////////////////////////
2175
2176 TClass* targetClass = nullptr;
2177 if( fTargetClass.GetClassName()[0] ) {
2178 targetClass = fTargetClass;
2179 if (!targetClass && GetCollectionProxy()) {
2180 // We are in the case where the branch holds a custom collection
2181 // proxy but the dictionary is not loaded, calling
2182 // GetCollectionProxy had the side effect of creating the TClass
2183 // corresponding to this emulated collection.
2184 targetClass = fTargetClass;
2185 }
2186 if ( !targetClass ) {
2187 Error("InitInfo", "Branch '%s': missing dictionary for target class '%s'!",
2189 return;
2190 }
2191 } else {
2192 targetClass = cl;
2193 }
2194 if (cl) {
2195 //---------------------------------------------------------------------
2196 // Get the streamer info for given version
2197 ///////////////////////////////////////////////////////////////////////
2198
2199 {
2200 if ( (cl->Property() & kIsAbstract) && cl == targetClass) {
2201 TBranchElement *parent = static_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
2202 if (parent && parent != this && !parent->GetClass()->IsLoaded() ) {
2203 // Our parent's class is emulated and we represent an abstract class.
2204 // and the target class has not been set explicitly.
2205 TString target = cl->GetName();
2206 target += "@@emulated";
2208
2209 if (!fTargetClass) {
2211 }
2212 targetClass = fTargetClass;
2213 }
2214 }
2215 if( targetClass != cl ) {
2216 fInfo = static_cast<TStreamerInfo*>(targetClass->GetConversionStreamerInfo( cl, fClassVersion ));
2217 } else {
2218 fInfo = static_cast<TStreamerInfo*>(cl->GetStreamerInfo(fClassVersion));
2219 }
2220 }
2221
2222 // FIXME: Check that the found streamer info checksum matches our branch class checksum here.
2223 // Check to see if the class code was unloaded/reloaded
2224 // since we were created.
2226 if (fCheckSum && (cl->IsForeign() || (!cl->IsLoaded() && (fClassVersion == 1) && cl->GetStreamerInfos()->At(1) && (fCheckSum != static_cast<TVirtualStreamerInfo*>(cl->GetStreamerInfos()->At(1))->GetCheckSum())))) {
2227 // Try to compensate for a class that got unloaded on us.
2228 // Search through the streamer infos by checksum
2229 // and take the first match.
2230
2231 TStreamerInfo* info;
2232 if( targetClass != cl )
2233 info = static_cast<TStreamerInfo*>(targetClass->FindConversionStreamerInfo( cl, fCheckSum ));
2234 else {
2235 info = static_cast<TStreamerInfo*>(cl->FindStreamerInfo( fCheckSum ));
2236 if (info) {
2237 // Now that we found it, we need to make sure it is initialize (Find does not initialize the StreamerInfo).
2238 info = static_cast<TStreamerInfo*>(cl->GetStreamerInfo(info->GetClassVersion()));
2239 }
2240 }
2241 if( info ) {
2242 fInfo = info;
2243 // We no longer reset the class version so that in case the user is passing us later
2244 // the address of a class that require (another) Conversion we can find the proper
2245 // StreamerInfo.
2246 // fClassVersion = fInfo->GetClassVersion();
2247 }
2248 }
2249 }
2250}
2251
2252
2253////////////////////////////////////////////////////////////////////////////////
2254/// Init the streamer info for the branch class, try to compensate for class
2255/// code unload/reload and schema evolution.
2256
2258{
2259 if (!fInfo)
2260 SetupInfo();
2261
2262 //
2263 // Fixup cached streamer info if necessary.
2264 //
2265 // FIXME: What if the class code was unloaded/reloaded since we were cached?
2266
2267 if (fInfo) {
2268
2269 if (!fInfo->IsCompiled()) {
2270 // Streamer info has not yet been compiled.
2271
2272 Error("InitInfo","StreamerInfo is not compiled.");
2273 }
2274 // return immediately if we are called recursively.
2275 if (fInInitInfo)
2276 return;
2277 fInInitInfo = true;
2278 if (!fInit) {
2279 // We were read in from a file, figure out what our fID should be,
2280 // schema evolution must be considered.
2281 //
2282 // Force our fID to be the id of the first streamer element that matches our name.
2283 //
2284 auto SetOnfileObject = [this](TStreamerInfo *info) {
2285 Int_t arrlen = 1;
2286 if (fType==31 || fType==41) {
2287 TLeaf *leaf = static_cast<TLeaf*>(fLeaves.At(0));
2288 if (leaf) {
2289 arrlen = leaf->GetMaximum();
2290 }
2291 }
2292 bool toplevel = (fType == 3 || fType == 4 || (fType == 0 && fID == -2));
2293 bool seenExisting = false;
2294
2295 fOnfileObject = new TVirtualArray( info->GetElement(0)->GetClassPointer(), arrlen );
2296 // Propagate this to all the other branches belonging to the same object.
2297 TObjArray *branches = toplevel ? GetListOfBranches() : GetMother()->GetSubBranch(this)->GetListOfBranches();
2298 Int_t nbranches = branches->GetEntriesFast();
2299 TBranchElement *lastbranch = this;
2300
2301 TClass *currentClass = fBranchClass;
2302 auto currentVersion = fClassVersion;
2303 if (toplevel) {
2304 // Note: Fragile/wrong when using conversion StreamerInfo?
2305 currentClass = info->GetClass();
2306 currentVersion = info->GetClassVersion();
2307 }
2308
2309 // First find the first branch corresponding to the same class as 'this'
2310 // branch
2311 Int_t index = branches->IndexOf(this);
2312 Int_t firstindex = 0;
2313 Int_t lastindex = nbranches - 1;
2314 if (index >= 0) {
2315 TString fullname( GetFullName() );
2316 Ssiz_t lastdot = fullname.Last('.');
2317 if (lastdot == TString::kNPOS) {
2318 // No prefix or index, thus this is a first level branch
2319 TBranchElement* subbranch = static_cast<TBranchElement*>(branches->At(0));
2320 if (!subbranch->fInfo)
2321 subbranch->SetupInfo();
2322 } else {
2323 TString &thisprefix = fullname.Remove(lastdot + 1); // Mod fullname and 'rename' the variable.
2324 for(Int_t i = index - 1; i >= 0; --i) {
2325 TBranchElement* subbranch = static_cast<TBranchElement*>(branches->At(i));
2326 TString subbranch_name(subbranch->GetFullName());
2327 if ( ! subbranch_name.BeginsWith(thisprefix)) {
2328 // We moved to another data member (of the enclosing class)
2329 firstindex = i + 1;
2330 break;
2331 }
2332 if (!subbranch->fInfo)
2333 subbranch->SetupInfo();
2334 }
2335 for(Int_t i = index; i < nbranches; ++i) {
2336 TBranchElement* subbranch = static_cast<TBranchElement*>(branches->At(i));
2337 TString subbranch_name(subbranch->GetFullName());
2338 if ( ! subbranch_name.BeginsWith(thisprefix)) {
2339 lastindex = i - 1;
2340 break;
2341 }
2342 }
2343 }
2344 } else {
2345 // Case of a top level branch or 'empty node' (object marker for split sub-object)
2346 TString fullname( GetFullName() );
2347 Ssiz_t lastdot = fullname.Last('.');
2348 if (lastdot != TString::kNPOS) {
2349 TString &thisprefix = fullname.Remove(lastdot + 1); // Mod fullname and 'rename' the variable.
2350 for(Int_t i = 0; i < nbranches; ++i) {
2351 TBranchElement* subbranch = static_cast<TBranchElement*>(branches->At(i));
2352 TString subbranch_name(subbranch->GetFullName());
2353 if ( ! subbranch_name.BeginsWith(thisprefix)) {
2354 lastindex = i - 1;
2355 break;
2356 }
2357 }
2358 }
2359 }
2360 for (Int_t i = firstindex; i <= lastindex; ++i) {
2361 TBranchElement* subbranch = static_cast<TBranchElement*>(branches->At(i));
2362 bool match = false;
2363 if (this != subbranch) {
2364
2365 if (!subbranch->fInfo)
2366 subbranch->SetupInfo();
2367
2368 // We previously checked for subbranch->fInfo == info. However, this fails for split collections
2369 // where the value class was renamed. Eventually, the subbranch will get its target class properly
2370 // set and use the conversion streamer info. However, we hit the current code path from the collection
2371 // parent's TBranchElement::SetAddressImpl() _before_ we fix up the target class of the child branch.
2372 // So the previous call to subbranch->SetupInfo() doesn't return the conversion streamer info but
2373 // streamer info of the old class.
2374 if (strcmp(subbranch->fInfo->GetName(), info->GetName()) == 0 &&
2375 subbranch->fInfo->GetClassVersion() == info->GetClassVersion()) {
2376 match = true;
2377 } else if (subbranch->fInfo == nullptr && subbranch->fBranchClass == currentClass) {
2378 if (!toplevel) {
2379 if (subbranch->fCheckSum == fCheckSum)
2380 match = true;
2381 } else {
2382 if (!subbranch->fBranchClass->IsForeign() && subbranch->fClassVersion == currentVersion)
2383 match = true;
2384 else if (subbranch->fCheckSum == info->GetCheckSum()) {
2385 match = true;
2386 }
2387 }
2388 }
2389 }
2390 if (match) {
2391 if (subbranch->fOnfileObject && subbranch->fOnfileObject != fOnfileObject) {
2392 if (seenExisting) {
2393 Error("SetOnfileObject (lambda)", "2 distincts fOnfileObject are in the hierarchy of %s for type %s",
2394 toplevel ? GetName() : GetMother()->GetSubBranch(this)->GetName(), info->GetName());
2395 } else {
2396 delete fOnfileObject;
2397 fOnfileObject = subbranch->fOnfileObject;
2398 seenExisting = true;
2399 }
2400 }
2401 subbranch->fOnfileObject = fOnfileObject;
2402 lastbranch = subbranch;
2403 }
2404 }
2405 if (toplevel) {
2407 if (lastbranch != this)
2408 lastbranch->ResetBit(kOwnOnfileObj);
2409 } else {
2410 lastbranch->SetBit(kOwnOnfileObj);
2411 }
2412 };
2413 if (GetID() > -1) {
2414 // We are *not* a top-level branch.
2415 std::string s(GetName());
2416 size_t pos = s.rfind('.');
2417 if (pos != std::string::npos) {
2418 s = s.substr(pos+1);
2419 }
2420 while ((pos = s.rfind('[')) != std::string::npos) {
2421 s = s.substr(0, pos);
2422 }
2423 int offset = 0;
2424 TStreamerElement* elt = fInfo->GetStreamerElement(s.c_str(), offset);
2425 if (elt && offset!=TStreamerInfo::kMissing) {
2426 size_t ndata = fInfo->GetNelement();
2427 fNewIDs.clear();
2428 for (size_t i = 0; i < ndata; ++i) {
2429 if (fInfo->GetElement(i) == elt) {
2431 && (i+1) < ndata
2432 && s == fInfo->GetElement(i)->GetName())
2433 {
2434 // If the TStreamerElement we found is storing the information in the
2435 // cache and is a repeater, we need to use the real one (the next one).
2436 // (At least until the cache/repeat mechanism is properly handle by
2437 // ReadLeaves).
2438 // fID = i+1;
2439 fID = i;
2440 if (fType != 2) {
2442 fNewIDs.push_back(fID+1);
2443 fNewIDs.back().fElement = fInfo->GetElement(i+1);
2444 fNewIDs.back().fInfo = fInfo;
2445 } else if (fInfo->GetElement(i+1)->TestBit(TStreamerElement::kWrite)) {
2446 fNewIDs.push_back(fID+1);
2447 fNewIDs.back().fElement = fInfo->GetElement(i+1);
2448 fNewIDs.back().fInfo = fInfo;
2449 }
2450 }
2451 } else {
2452 fID = i;
2453 }
2454 if (elt->TestBit (TStreamerElement::kCache)) {
2456 }
2457 break;
2458 }
2459 }
2460 for (size_t i = fID+1+(fNewIDs.size()); i < ndata; ++i) {
2461 TStreamerElement *nextel = fInfo->GetElement(i);
2462
2463 std::string ename = nextel->GetName();
2464 if (ename[0] == '*')
2465 ename = ename.substr(1);
2466
2467 while ((pos = ename.rfind('[')) != std::string::npos) {
2468 ename = ename.substr(0, pos);
2469 }
2470
2471 if (s != ename) {
2472 // We moved on to the next set
2473 break;
2474 }
2475 // Add all (and only) the Artificial Elements that follows this StreamerInfo.
2476 // fprintf(stderr,"%s/%d[%zu] passing through %zu %s\n",GetName(),fID,fIDs.size(),i,nextel->GetName());
2477 if (fType==31||fType==41) {
2478 // The nested objects are unfolded and their branch can not be used to
2479 // execute StreamerElements of this StreamerInfo.
2480 if ((nextel->GetType() == TStreamerInfo::kObject
2481 || nextel->GetType() == TStreamerInfo::kAny)
2482 && nextel->GetClassPointer()->CanSplit())
2483 {
2484 continue;
2485 }
2486 }
2487 if (nextel->GetOffset() == TStreamerInfo::kMissing) {
2488 // This element will be 'skipped', it's TBranchElement's fObject will null
2489 // and thus can not be used to execute the artificial StreamerElements
2490 continue;
2491 }
2492 if (nextel->IsA() != TStreamerArtificial::Class()
2493 || nextel->GetType() == TStreamerInfo::kCacheDelete ) {
2494 continue;
2495 }
2496 // NOTE: We should verify that the rule's source are 'before'
2497 // or 'at' this branch.
2498 // fprintf(stderr,"%s/%d[%zu] pushd %zu %s\n",GetName(),fID,fIDs.size(),i,nextel->GetName());
2499 fNewIDs.push_back(i);
2500 fNewIDs.back().fElement = nextel;
2501 fNewIDs.back().fInfo = fInfo;
2502 }
2503 } else if (elt && offset==TStreamerInfo::kMissing) {
2504 // Still re-assign fID properly.
2505 fNewIDs.clear();
2506 size_t ndata = fInfo->GetNelement();
2507 for (size_t i = 0; i < ndata; ++i) {
2508 if (fInfo->GetElement(i) == elt) {
2509 fID = i;
2510 break;
2511 }
2512 }
2513 } else {
2514 // We have not even found the element .. this is strange :(
2515 // fNewIDs.clear();
2516 // fID = -3;
2517 // SetBit(kDoNotProcess);
2518 }
2519 if (fOnfileObject==nullptr && (fType==31 || fType==41 || (0 <= fType && fType <=2) ) && fInfo->GetNelement()
2521 {
2522 SetOnfileObject(fInfo);
2523 }
2524 }
2525 if (fType == 3 || fType == 4 || (fType == 0 && fID == -2) || fType == 2) {
2526 // Need to add the rule targeting transient members.
2527 TStreamerInfo *localInfo = fInfo;
2528 if (fType == 3 || fType == 4) {
2529 // Don't we have real version information?
2530 // Not unless there is a subbranch with a non-split element of the class.
2531 // Search for the correct version.
2533 }
2534
2535 TString prefix(GetFullName());
2536 if (fType == 2 && fID >= 0) {
2537 auto start = prefix.Length();
2538 if (prefix[start - 1] == '.')
2539 --start;
2540 std::string_view view(prefix.Data(), start);
2541 auto cutoff = view.find_last_of('.');
2542 if (cutoff != std::string::npos) {
2543 prefix.Remove(cutoff + 1);
2544 }
2545 }
2546 if (prefix[prefix.Length()-1] != '.') {
2547 if (fType == 3 || fType == 4 || prefix.Index('.') != TString::kNPOS) {
2548 prefix += ".";
2549 } else {
2550 prefix = "";
2551 }
2552 }
2553 fNewIDs.clear();
2554
2555 GatherArtificialElements(fBranches, fNewIDs, prefix, localInfo, 0);
2556
2557 if (!fNewIDs.empty() && fOnfileObject == nullptr && localInfo->GetElement(0)->GetType() == TStreamerInfo::kCacheNew)
2558 {
2559 SetOnfileObject(localInfo);
2560 }
2561
2562 }
2563 fInit = true;
2564
2565 // Get the action sequence we need to copy for reading.
2568 } else if (!fReadActionSequence) {
2569 // Get the action sequence we need to copy for reading.
2572 }
2575 fInInitInfo = false;
2576 }
2577}
2578
2579////////////////////////////////////////////////////////////////////////////////
2580/// Return the collection proxy describing the branch content, if any.
2581
2583{
2584 if (fCollProxy) {
2585 return fCollProxy;
2586 }
2587 TBranchElement* thiscast = const_cast<TBranchElement*>(this);
2588 if (fType == 4) {
2589 // STL container top-level branch.
2590 const char* className = nullptr;
2591 TClass* cl = nullptr;
2592 if (fID < 0) {
2593 // We are a top-level branch.
2594 if (fBranchClass.GetClass()) {
2595 cl = fBranchClass.GetClass();
2596 }
2597 } else {
2598 // We are not a top-level branch.
2599 TVirtualStreamerInfo* si = thiscast->GetInfoImp();
2600 if (fCollProxy) {
2601 // The GetInfo set fProxy for us, let's not
2602 // redo it; the value of fCollProxy is possibly
2603 // used/recorded is the actions sequences, so
2604 // if we change it here, we would need to propagate
2605 // the change.
2606 return fCollProxy;
2607 }
2608 TStreamerElement* se = si->GetElement(fID);
2609 cl = se->GetClassPointer();
2610 }
2611 if (!cl) {
2612 // The TClass was not created but we do know (since it
2613 // is used as a collection) that it 'className' was a
2614 // class, so let's create it by hand!.
2615
2616 if (fID < 0) {
2618 className = cl->GetName();
2619 } else {
2620 cl = new TClass(className, fClassVersion);
2621 className = cl->GetName();
2622 }
2623 }
2625 if (!proxy) {
2626 // humm, we must have an older file with a custom collection
2627 // let's try to work-around it.
2628 TString equiv;
2629 equiv.Form("vector<%s>",fClonesName.Data());
2630 TClass *clequiv = TClass::GetClass(equiv);
2631 proxy = clequiv->GetCollectionProxy();
2632 if (!proxy) {
2633 Fatal("GetCollectionProxy",
2634 "Can not create a Collection Proxy of any kind for the class \"%s\" needed by the branch \"%s\" of the TTree \"%s\"!",
2635 className, GetName(), GetTree()->GetName());
2636 }
2637 if (gDebug > 0) Info("GetCollectionProxy",
2638 "Fixing the collection proxy of the class \"%s\" \n"
2639 "\tneeded by the branch \"%s\" of the TTree \"%s\" to be similar to \"%s\".",
2640 className, GetName(), GetTree()->GetName(),equiv.Data());
2641 cl->CopyCollectionProxy( *proxy );
2642 }
2643 fCollProxy = proxy->Generate();
2644 fSTLtype = proxy->GetCollectionType();
2645 } else if (fType == 41) {
2646 // STL container sub-branch.
2648 }
2649 return fCollProxy;
2650}
2651
2652////////////////////////////////////////////////////////////////////////////////
2653/// Return a pointer to the current type of the data member corresponding to branch element.
2654
2656{
2657 TClass* cl = fCurrentClass;
2658 if (cl) {
2659 return cl;
2660 }
2661
2662 TStreamerInfo* brInfo = static_cast<TStreamerInfo*>(GetInfoImp());
2663 if (!brInfo) {
2665 R__ASSERT(cl && cl->GetCollectionProxy());
2666 fCurrentClass = cl;
2667 return cl;
2668 }
2669 TClass* motherCl = brInfo->GetClass();
2670 if (motherCl->GetCollectionProxy()) {
2671 cl = motherCl->GetCollectionProxy()->GetCollectionClass();
2672 if (cl) {
2673 fCurrentClass = cl;
2674 }
2675 return cl;
2676 }
2677 if (GetID() < 0 || GetID()>=brInfo->GetNelement()) {
2678 return nullptr;
2679 }
2680 TStreamerElement* currentStreamerElement = brInfo->GetElement(GetID());
2681 TDataMember* dm = static_cast<TDataMember*>(motherCl->GetListOfDataMembers()->FindObject(currentStreamerElement->GetName()));
2682
2683 TString newType;
2684 if (!dm) {
2685 // Either the class is not loaded or the data member is gone
2686 if (!motherCl->IsLoaded()) {
2687 TVirtualStreamerInfo* newInfo = motherCl->GetStreamerInfo();
2688 if (newInfo != brInfo) {
2689 TStreamerElement* newElems = static_cast<TStreamerElement*>(newInfo->GetElements()->FindObject(currentStreamerElement->GetName()));
2690 if (newElems) {
2691 if (newElems->GetClassPointer())
2692 newType = newElems->GetClassPointer()->GetName();
2693 else
2694 newType = newElems->GetTypeName();
2695 }
2696 }
2697 if (newType.Length()==0) {
2698 if (currentStreamerElement->GetClassPointer())
2699 newType = currentStreamerElement->GetClassPointer()->GetName();
2700 else
2701 newType = currentStreamerElement->GetTypeName();
2702 }
2703 }
2704 } else {
2705 newType = dm->GetTypeName();
2706 }
2707 cl = TClass::GetClass(newType);
2708 if (cl) {
2709 fCurrentClass = cl;
2710 }
2711 return cl;
2712}
2713
2714////////////////////////////////////////////////////////////////////////////////
2715/// Read all branches of a BranchElement and return total number of bytes.
2716///
2717/// - If entry = 0, then use current entry number + 1.
2718/// - If entry < 0, then reset entry number to 0.
2719///
2720/// Returns the number of bytes read from the input buffer.
2721/// - If entry does not exist, then returns 0.
2722/// - If an I/O error occurs, then returns -1.
2723///
2724/// See IMPORTANT REMARKS in TTree::GetEntry.
2725
2727{
2728 // Remember which entry we are reading.
2729 auto prevEntry = fReadEntry;
2730 fReadEntry = entry;
2731
2732 // If our tree has a branch ref, make it remember the entry and
2733 // this branch. This allows a TRef::GetObject() call done during
2734 // the following I/O operation, for example in a custom streamer,
2735 // to search for the referenced object in the proper element of the
2736 // proper branch.
2737 TBranchRef* bref = fTree->GetBranchRef();
2738 if (R__unlikely(bref)) {
2739 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
2740 fBranchID = bref->SetParent(this, fBranchID);
2741 bref->SetRequestedEntry(entry);
2742 }
2743
2744 Int_t nbytes = 0;
2745
2746 if (R__unlikely(IsAutoDelete())) {
2749 } else {
2751 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
2753 }
2754 }
2755
2756 Int_t nbranches = fBranches.GetEntriesFast();
2757 if (nbranches) {
2758 // -- Branch has daughters.
2759 // One must always read the branch counter.
2760 // In the case when one reads consecutively twice the same entry,
2761 // the user may have cleared the TClonesArray between the GetEntry calls.
2762 if ((fType == 3) || (fType == 4)) {
2763 Int_t nb = TBranch::GetEntry(entry, getall);
2764 if (nb < 0) {
2765 return nb;
2766 }
2767 nbytes += nb;
2768 }
2769 if (!IsAssociativeContainer(fSTLtype)) {
2770 ValidateAddress(); // There is no ReadLeave for the node of a top level split object, so we need to do the
2771 // validation here.
2772 for (Int_t i = 0; i < nbranches; ++i) {
2773 TBranch* branch = static_cast<TBranch*>(fBranches.UncheckedAt(i));
2774 Int_t nb = branch->GetEntry(entry, getall);
2775 if (nb < 0) {
2776 return nb;
2777 }
2778 nbytes += nb;
2779 }
2780 }
2782 if (fType == 3) {
2783 // Apply the unattached rules; by definition they do not need any
2784 // input from a buffer.
2786
2787 auto ndata = GetNdata();
2788
2789 TClonesArray* clones = reinterpret_cast<TClonesArray*>(fObject);
2790 if (clones->IsZombie()) {
2791 return -1;
2792 }
2793 R__PushCache onfileObject(b, fOnfileObject, ndata);
2794
2795 char **arr = reinterpret_cast<char **>(clones->GetObjectRef());
2796 char **end = arr + fNdata;
2797
2798 b.ApplySequenceVecPtr(*fReadActionSequence,arr,end);
2799 } else if (fType == 4) {
2800 // Apply the unattached rules; by definition they do not need any
2801 // input from a buffer.
2803
2804 auto ndata = GetNdata();
2805
2806 R__PushCache onfileObject(b, fOnfileObject, ndata);
2809
2811 b.ApplySequence(*fReadActionSequence,iter->fBegin,iter->fEnd);
2812 } else {
2813 // Apply the unattached rules; by definition they do not need any
2814 // input from a buffer.
2816 R__PushCache onfileObject(b, fOnfileObject, fNdata);
2817 b.ApplySequence(*fReadActionSequence, fObject);
2818 }
2819 }
2820 } else {
2821 // -- Terminal branch.
2822
2823 if (fBranchCount && (fBranchCount->GetReadEntry() != entry)) {
2824 Int_t nb = fBranchCount->TBranch::GetEntry(entry, getall);
2825 if (nb < 0)
2826 return nb;
2827 nbytes += nb;
2828 }
2829 // For associative containers, the count branch is actually
2830 // reading the subbranches (including this one) and in the case
2831 // of a compiled proxy the necessary staging area is only available
2832 // during the call to the count branch GetEntry.
2833 // We detect this code path by checking the position of the cursor,
2834 // which is explicitly reset by the count branch's GetEntry.
2835 // One down-side, if the user call twice GetEntry on the same entry,
2836 // the second call will not re-read the sub-branches (unlike all the other
2837 // types of branches).
2838 if (!fBranchCount || (prevEntry != entry) || !IsAssociativeContainer(fBranchCount->fSTLtype)) {
2839 Int_t nb = TBranch::GetEntry(entry, getall);
2840 if (nb < 0) {
2841 return nb;
2842 }
2843 nbytes += nb;
2844 }
2845 }
2846
2847 if (R__unlikely(fTree->Debug() > 0)) {
2848 if ((entry >= fTree->GetDebugMin()) && (entry <= fTree->GetDebugMax())) {
2849 Info("GetEntry", "%lld, branch=%s, nbytes=%d", entry, GetName(), nbytes);
2850 }
2851 }
2852 return nbytes;
2853}
2854
2855////////////////////////////////////////////////////////////////////////////////
2856/// Fill expectedClass and expectedType with information on the data type of the
2857/// object/values contained in this branch (and thus the type of pointers
2858/// expected to be passed to Set[Branch]Address
2859/// return 0 in case of success and > 0 in case of failure.
2860
2862{
2863 expectedClass = nullptr;
2864 expectedType = kOther_t;
2865
2867 if ((type == -1) || (fID == -1)) {
2868 expectedClass = fBranchClass;
2869 } else {
2870 // Case of an object data member. Here we allow for the
2871 // variable name to be omitted. Eg, for Event.root with split
2872 // level 1 or above Draw("GetXaxis") is the same as Draw("fH.GetXaxis()")
2874 if (element) {
2875 expectedClass = element->GetClassPointer();
2876 if (!expectedClass) {
2877 TDataType* data = gROOT->GetType(element->GetTypeNameBasic());
2878 if (!data) {
2879 Error("GetExpectedType", "Did not find the type number for %s", element->GetTypeNameBasic());
2880 return 1;
2881 } else {
2882 expectedType = (EDataType) data->GetType();
2883 }
2884 }
2885 } else {
2886 Error("GetExpectedType", "Did not find the type for %s",GetName());
2887 return 2;
2888 }
2889 }
2890 return 0;
2891}
2892
2893////////////////////////////////////////////////////////////////////////////////
2894/// Return the 'full' name of the branch. In particular prefix the mother's name
2895/// when it does not end in a trailing dot and thus is not part of the branch name
2897{
2898 TBranchElement* mother = static_cast<TBranchElement*>(GetMother());
2899 if (!mother || mother==this || mother->GetType() == 3 || mother->GetType() == 4) {
2900 // The parent's name is already included in the name for split TClonesArray and STL collections
2901 return fName;
2902 }
2903
2904 return TBranch::GetFullName();
2905}
2906
2907////////////////////////////////////////////////////////////////////////////////
2908/// Return icon name depending on type of branch element.
2909
2911{
2912 if (IsFolder()) {
2913 return "TBranchElement-folder";
2914 } else {
2915 return "TBranchElement-leaf";
2916 }
2917}
2918
2919////////////////////////////////////////////////////////////////////////////////
2920/// Return whether this branch is in a mode where the object are decomposed
2921/// or not (Also known as MakeClass mode).
2922
2924{
2925 return TestBit(kDecomposedObj); // Same as TestBit(kMakeClass)
2926}
2927
2928////////////////////////////////////////////////////////////////////////////////
2929/// Return maximum count value of the branchcount if any.
2930
2932{
2933 if (fBranchCount) {
2934 return fBranchCount->GetMaximum();
2935 }
2936 return fMaximum;
2937}
2938
2939////////////////////////////////////////////////////////////////////////////////
2940/// Return a pointer to our object.
2941
2943{
2945 return fObject;
2946}
2947
2948////////////////////////////////////////////////////////////////////////////////
2949/// Return a pointer to the parent class of the branch element.
2950
2955
2956////////////////////////////////////////////////////////////////////////////////
2957/// Return type name of element in the branch.
2958
2960{
2961 if (fType == 3 || fType == 4) {
2962 return "Int_t";
2963 }
2964 // FIXME: Use symbolic constants here.
2965 if ((fStreamerType < 1) || (fStreamerType > 59)) {
2966 if (fBranchClass.GetClass()) {
2967 if (fID>=0) {
2968 return GetInfoImp()->GetElement(fID)->GetTypeName();
2969 } else {
2970 return fBranchClass.GetClass()->GetName();
2971 }
2972 } else {
2973 return nullptr;
2974 }
2975 }
2976 const char *types[20] = {
2977 "",
2978 "Char_t",
2979 "Short_t",
2980 "Int_t",
2981 "Long_t",
2982 "Float_t",
2983 "Int_t",
2984 "char*",
2985 "Double_t",
2986 "Double32_t",
2987 "",
2988 "UChar_t",
2989 "UShort_t",
2990 "UInt_t",
2991 "ULong_t",
2992 "UInt_t",
2993 "Long64_t",
2994 "ULong64_t",
2995 "Bool_t",
2996 "Float16_t"
2997 };
2998 Int_t itype = fStreamerType % 20;
2999 return types[itype];
3000}
3001
3002////////////////////////////////////////////////////////////////////////////////
3003
3004template Double_t TBranchElement::GetTypedValue(Int_t j, Int_t len, bool subarr) const;
3005template Long64_t TBranchElement::GetTypedValue(Int_t j, Int_t len, bool subarr) const;
3006template LongDouble_t TBranchElement::GetTypedValue(Int_t j, Int_t len, bool subarr) const;
3007
3008template <typename T>
3010{
3011 // -- Returns the branch value.
3012 //
3013 // If the leaf is an array, j is the index in the array.
3014 //
3015 // If leaf is an array inside a TClonesArray, len should be the length
3016 // of the array.
3017 //
3018 // If subarr is true, then len is actually the index within the sub-array.
3019 //
3020
3022
3023 Int_t prID = fID;
3024 char *object = fObject;
3025 if (TestBit(kCache)) {
3026 if (GetInfoImp()->GetElements()->At(fID)->TestBit(TStreamerElement::kRepeat)) {
3027 prID = fID+1;
3028 } else if (fOnfileObject) {
3029 object = fOnfileObject->GetObjectAt(0);
3030 }
3031 }
3032
3033 if (!j && fBranchCount) {
3034 Long64_t entry = fTree->GetReadEntry();
3035 // Since reloading the index, will reset the ClonesArray, let's
3036 // skip the load if we already read this entry.
3037 if (entry != fBranchCount->GetReadEntry()) {
3038 fBranchCount->TBranch::GetEntry(entry);
3039 }
3040 if (fBranchCount2 && entry != fBranchCount2->GetReadEntry()) {
3041 fBranchCount2->TBranch::GetEntry(entry);
3042 }
3043 }
3044
3045 if (TestBit(kDecomposedObj)) {
3046 if (!fAddress) {
3047 return 0;
3048 }
3049 if ((fType == 3) || (fType == 4)) {
3050 // Top-level branch of a TClonesArray.
3051 return fNdata;
3052 } else if ((fType == 31) || (fType == 41)) {
3053 // sub branch of a TClonesArray
3054 Int_t atype = fStreamerType;
3055 if (atype < 20) {
3056 atype += 20;
3057 }
3058 return GetInfoImp()->GetTypedValue<T>(fAddress, atype, j, 1);
3059 } else if (fType <= 2) {
3060 // branch in split mode
3061 // FIXME: This should probably be < 60 instead!
3062 if ((fStreamerType > 40) && (fStreamerType < 55)) {
3063 Int_t atype = fStreamerType - 20;
3064 return GetInfoImp()->GetTypedValue<T>(fAddress, atype, j, 1);
3065 } else {
3066 return GetInfoImp()->GetTypedValue<T>(object, prID, j, -1);
3067 }
3068 }
3069 }
3070
3071 if (object == nullptr)
3072 {
3073 // We have nowhere to read the data from (probably because the data member was
3074 // 'dropped' from the current schema).
3075 return 0;
3076 }
3077
3078 if (fType == 31) {
3079 TClonesArray* clones = reinterpret_cast<TClonesArray*>(object);
3080 if (subarr) {
3081 return GetInfoImp()->GetTypedValueClones<T>(clones, prID, j, len, fOffset);
3082 }
3083 return GetInfoImp()->GetTypedValueClones<T>(clones, prID, j/len, j%len, fOffset);
3084 } else if (fType == 41) {
3085 TVirtualCollectionProxy::TPushPop helper(const_cast<TBranchElement*>(this)->GetCollectionProxy(), object);
3087 {
3088 if (subarr)
3089 return GetInfoImp()->GetTypedValueSTL<T>(const_cast<TBranchElement*>(this)->GetCollectionProxy(), prID, j, len, fOffset);
3090
3091 return GetInfoImp()->GetTypedValueSTL<T>(const_cast<TBranchElement*>(this)->GetCollectionProxy(), prID, j/len, j%len, fOffset);
3092 }
3093 else
3094 {
3095 if (subarr)
3096 return GetInfoImp()->GetTypedValueSTLP<T>(const_cast<TBranchElement*>(this)->GetCollectionProxy(), prID, j, len, fOffset);
3097 return GetInfoImp()->GetTypedValueSTLP<T>(const_cast<TBranchElement*>(this)->GetCollectionProxy(), prID, j/len, j%len, fOffset);
3098 }
3099 } else {
3100 auto info = GetInfoImp();
3101 if (info) {
3102 return info->GetTypedValue<T>(object, prID, j, -1);
3103 }
3104 return 0;
3105 }
3106}
3107
3108////////////////////////////////////////////////////////////////////////////////
3109/// Returns pointer to first data element of this branch.
3110/// Currently used only for members of type character.
3111
3113{
3115
3116 TStreamerInfo *info = nullptr;
3117 Int_t prID = fID;
3118 char *object = fObject;
3119 if (TestBit(kCache)) {
3120 info = GetInfoImp();
3122 prID = fID+1;
3123 } else if (fOnfileObject) {
3124 object = fOnfileObject->GetObjectAt(0);
3125 }
3126 }
3127
3128 if (fBranchCount) {
3129 Long64_t entry = fTree->GetReadEntry();
3130 fBranchCount->TBranch::GetEntry(entry);
3131 if (fBranchCount2) fBranchCount2->TBranch::GetEntry(entry);
3132 }
3133 if (TestBit(kDecomposedObj)) {
3134 if (!fAddress) {
3135 return nullptr;
3136 }
3137 if (fType == 3) { //top level branch of a TClonesArray
3138 //return &fNdata;
3139 return nullptr;
3140 } else if (fType == 4) { //top level branch of a TClonesArray
3141 //return &fNdata;
3142 return nullptr;
3143 } else if (fType == 31) { // sub branch of a TClonesArray
3144 //Int_t atype = fStreamerType;
3145 //if (atype < 20) atype += 20;
3146 //return GetInfoImp()->GetValue(fAddress, atype, j, 1);
3147 return nullptr;
3148 } else if (fType == 41) { // sub branch of a TClonesArray
3149 //Int_t atype = fStreamerType;
3150 //if (atype < 20) atype += 20;
3151 //return GetInfoImp()->GetValue(fAddress, atype, j, 1);
3152 return nullptr;
3153 } else if (fType <= 2) { // branch in split mode
3154 // FIXME: This should probably be < 60 instead!
3155 if (fStreamerType > 40 && fStreamerType < 55) {
3156 //Int_t atype = fStreamerType - 20;
3157 //return GetInfoImp()->GetValue(fAddress, atype, j, 1);
3158 return nullptr;
3159 } else {
3160 //return GetInfoImp()->GetValue(object, fID, j, -1);
3161 return nullptr;
3162 }
3163 }
3164 }
3165
3166 if (fType == 31) {
3167 return nullptr;
3168 } else if (fType == 41) {
3169 return nullptr;
3170 } else if (prID < 0) {
3171 return object;
3172 } else {
3173 //return GetInfoImp()->GetValue(object,fID,j,-1);
3174 if (!info)
3175 info = GetInfoImp();
3176 if (!info || !object) return nullptr;
3177 char **val = reinterpret_cast<char **>(object+info->TStreamerInfo::GetElementOffset(prID));
3178 return *val;
3179 }
3180}
3181
3182////////////////////////////////////////////////////////////////////////////////
3183/// Initialize the base class subobjects offsets of our sub-branches and set fOffset if we are a container sub-branch.
3184///
3185/// Note: The offsets are zero for data members so that when
3186/// SetAddress recursively sets their address, they will get the
3187/// same address as their containing class because i/o is based
3188/// on streamer info offsets from the address of the containing
3189/// class.
3190///
3191/// Offsets are non-zero for base-class sub-branches that are
3192/// not the leftmost direct base class. They are laid out in
3193/// memory sequentially and only the leftmost direct base class
3194/// has the same address as the derived class. The streamer
3195/// offsets need to be added to the address of the base class
3196/// subobject which is not the same as the address of the
3197/// derived class for the non-leftmost direct base classes.
3198
3200{
3201 Int_t nbranches = fBranches.GetEntriesFast();
3202
3203 // See https://sft.its.cern.ch/jira/browse/ROOT-8742
3204 // and https://sft.its.cern.ch/jira/browse/ROOT-9253
3205 // As of commit e21b4f1a3b, removing this lock lead to a failure
3206 // in the test testSetAddress[Loop].
3207 // As of commit 4f8b237849, removing this lock does not lead to
3208 // a visible failure in test. This might be due to the underlying
3209 // problem (missing lock or ?) being solved somewhere else or some
3210 // other perturbation reducing the failure rate.
3211 // Having the lock here is not too costly as InitializeOffsets is
3212 // one called once in the lifetime of the TBranch.
3214
3215 if (fID < 0) {
3216 // -- We are a top-level branch. Let's mark whether we need to use MapObject.
3217 if (CanSelfReference(fBranchClass)) {
3218 if (fBranchClass.GetClass()->IsTObject()) {
3220 } else {
3222 }
3223 }
3224 }
3225 if (nbranches) {
3226 // Allocate space for the new sub-branch offsets.
3227 delete[] fBranchOffset;
3228 fBranchOffset = nullptr;
3229 fBranchOffset = new Int_t[nbranches];
3230 // Make sure we can instantiate our class meta info.
3231 if (!fBranchClass.GetClass()) {
3232 Warning("InitializeOffsets", "No branch class set for branch: %s", GetName());
3233 fInitOffsets = true;
3234 return;
3235 }
3236 // Make sure we can instantiate our class streamer info.
3237 TStreamerInfo *info = GetInfoImp();
3238 if (!info) {
3239 Warning("InitializeOffsets", "No streamer info available for branch: %s of class: %s", GetName(), fBranchClass.GetClass()->GetName());
3240 fInitOffsets = true;
3241 return;
3242 }
3243
3244 // Get the class we are a member of now (which is the
3245 // type of our containing subobject) and get our offset
3246 // inside of our containing subobject (our local offset).
3247 // Note: branchElem stays zero if we are a top-level branch,
3248 // we have to be careful about this later.
3249 TStreamerElement* branchElem = nullptr;
3250 Int_t localOffset = 0;
3251 TClass* branchClass = fBranchClass.GetClass();
3252 bool renamed = false;
3253 if (fID > -1) {
3254 // -- Branch is *not* a top-level branch.
3255 // Instead of the streamer info class, we want the class of our
3256 // specific element in the streamer info. We could be a data
3257 // member of a base class or a split class, in which case our
3258 // streamer info will be for our containing sub-object, while
3259 // we are actually a different type.
3260 // Note: We tested to make sure the streamer info was available previously.
3261 if (!info->IsCompiled()) {
3262 Warning("InitializeOffsets", "Streamer info for branch: %s has no elements array!", GetName());
3263 fInitOffsets = true;
3264 return;
3265 }
3266 // FIXME: Check that fID is in range.
3267 branchElem = info->GetElement(fID);
3268 if (!branchElem) {
3269 Warning("InitializeOffsets", "Cannot get streamer element for branch: %s!", GetName());
3270 fInitOffsets = true;
3271 return;
3272 } else if (branchElem->TestBit(TStreamerElement::kRepeat)) {
3273 // If we have a repeating streamerElement, use the next
3274 // one as it actually hold the 'real' data member('s offset)
3275 if (info->GetElement(fID+1)) {
3276 branchElem = info->GetElement(fID+1);
3277 }
3278 }
3279 localOffset = branchElem->GetOffset();
3280 branchClass = branchElem->GetClassPointer();
3281 if (localOffset == TStreamerInfo::kMissing) {
3282 fObject = nullptr;
3283 } else {
3284 renamed = branchClass && branchElem->GetNewClass() && (branchClass != branchElem->GetNewClass());
3285 }
3286 } else {
3287 renamed = fTargetClass != fBranchClass;
3288 }
3289 if (!branchClass) {
3290 Error("InitializeOffsets", "Could not find class for branch: %s", GetName());
3291 fInitOffsets = true;
3292 return;
3293 }
3294
3295 //------------------------------------------------------------------------
3296 // Extract the name of the STL branch in case it has been split.
3297 //////////////////////////////////////////////////////////////////////////
3298
3299 TString stlParentName;
3300 bool stlParentNameUpdated = false;
3301 if( fType == 4 )
3302 {
3303 TBranch *br = GetMother()->GetSubBranch( this );
3304 stlParentName = br->GetName();
3305 stlParentName = stlParentName.Strip( TString::kTrailing, '.' );
3306
3307 // We may ourself contain the 'Mother' branch name.
3308 // To avoid code duplication, we delegate the removal
3309 // of the mother's name to the first sub-branch loop.
3310 }
3311
3312 // Loop over our sub-branches and compute their offsets.
3313 for (Int_t subBranchIdx = 0; subBranchIdx < nbranches; ++subBranchIdx) {
3314 bool alternateElement = false;
3315
3316 fBranchOffset[subBranchIdx] = 0;
3317 TBranchElement* subBranch = dynamic_cast<TBranchElement*> (fBranches[subBranchIdx]);
3318 if (subBranch == nullptr) {
3319 // -- Skip sub-branches that are not TBranchElements.
3320 continue;
3321 }
3322
3323 if (renamed) {
3324 if (subBranch->fBranchClass == branchClass) {
3325 if (branchElem) subBranch->SetTargetClass(branchElem->GetNewClass()->GetName());
3326 else subBranch->SetTargetClass(fTargetClass->GetName());
3327 }
3328 }
3329
3330 TVirtualStreamerInfo* sinfo = subBranch->GetInfoImp();
3331 if (!sinfo) {
3332 Warning("InitializeOffsets", "No streamer info for branch: %s subbranch: %s", GetName(), subBranch->GetName());
3333 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3334 continue;
3335 }
3336 if (!sinfo->IsCompiled()) {
3337 Warning("InitializeOffsets", "No elements array for branch: %s subbranch: %s", GetName(), subBranch->GetName());
3338 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3339 continue;
3340 }
3341 // FIXME: Make sure subBranch->fID is in range.
3342 TStreamerElement* subBranchElement = sinfo->GetElement(subBranch->fID);
3343 if (!subBranchElement) {
3344 Warning("InitializeOffsets", "No streamer element for branch: %s subbranch: %s", GetName(), subBranch->GetName());
3345 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3346 continue;
3347 } else if (subBranchElement->TestBit(TStreamerElement::kRepeat)) {
3348 // If we have a repeating streamerElement, use the next
3349 // one as it actually hold the 'real' data member('s offset)
3350 if (sinfo->GetElement(subBranch->fID+1)) {
3351 subBranchElement = sinfo->GetElement(subBranch->fID+1);
3352 }
3353 } else if (subBranchElement->TestBit(TStreamerElement::kCache)) {
3354 // We have a cached item which is not a repeated but we might still
3355 // have some Actions triggered by a rule that affect real
3356 // data member(s).
3357 if (subBranch->fReadActionSequence && subBranch->fReadActionSequence->fActions.size() > 1) {
3358 typedef TStreamerInfoActions::ActionContainer_t::iterator iterator;
3359 iterator end = subBranch->fReadActionSequence->fActions.end();
3360 for(iterator iter = subBranch->fReadActionSequence->fActions.begin();
3361 iter != end; ++iter) {
3362 TStreamerInfoActions::TConfiguration *config = iter->fConfiguration;
3363 UInt_t id = config->fElemId;
3364 TStreamerElement *e = static_cast<TStreamerElement*>(config->fInfo->GetElements()->At(id));
3365 if (e && !e->TestBit(TStreamerElement::kCache)) {
3366 subBranchElement = e;
3367 alternateElement = true;
3368 break;
3369 }
3370 }
3371 }
3372 }
3373
3374 localOffset = subBranchElement->GetOffset();
3375 if (localOffset == TStreamerInfo::kMissing) {
3376 subBranch->fObject = nullptr;
3377 }
3378 {
3379 Int_t streamerType = subBranchElement->GetType();
3380 if (streamerType > TStreamerInfo::kObject
3381 && subBranch->GetListOfBranches()->GetEntriesFast()==0
3382 && CanSelfReference(subBranchElement->GetClass()))
3383 {
3384 subBranch->SetBit(kBranchAny);
3385 } else {
3386 subBranch->ResetBit(kBranchAny);
3387 }
3388 }
3389
3390 if (subBranchElement->GetNewType()<0) {
3391 subBranch->ResetBit(kBranchAny);
3392 subBranch->ResetBit(kBranchObject);
3393 }
3394
3395 // Note: This call is expensive, do it only once.
3396 TBranch* mother = GetMother();
3397 if (!mother) {
3398 Warning("InitializeOffsets", "Branch '%s' has no mother!", GetName());
3399 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3400 continue;
3401 }
3402 TString motherName(mother->GetName());
3403 bool motherDot = false;
3404 if (motherName.Length() && strchr(motherName.Data(), '.')) {
3405 motherDot = true;
3406 }
3407 bool motherDotAtEnd = false;
3408 if (motherName.Length() && (motherName[motherName.Length()-1] == '.')) {
3409 motherDotAtEnd = true;
3410 }
3411
3412 bool isBaseSubBranch = false;
3413 if ((subBranch->fType == 1) || (subBranchElement && subBranchElement->IsBase())) {
3414 // -- Base class sub-branch (1).
3415 //
3416 // Note: Our type will not be 1, even though we are
3417 // a base class branch, if we are not split (see the
3418 // constructor), or if we are an STL container master
3419 // branch and a base class branch at the same time
3420 // or an std::string.
3421 isBaseSubBranch = true;
3422 }
3423
3424 bool isContDataMember = false;
3425 if ((subBranch->fType == 31) || (subBranch->fType == 41)) {
3426 // -- Container data member sub-branch (31 or 41).
3427 isContDataMember = true;
3428 }
3429
3430 // I am either a data member sub-branch (0), or a base class
3431 // sub-branch (1), or TClonesArray master sub-branch (3),
3432 // or an STL container master sub-branch (4), or TClonesArray
3433 // data member sub-branch (31), or an STL container data member
3434 // sub-branch (41).
3435 //
3436 // My parent branch is either a top-level branch ((0), fID==(-2,-1)),
3437 // or a base class sub-branch (1), or a split-class branch (2),
3438 // or a TClonesArray master branch (3), or an STL container
3439 // master branch (4).
3440 //
3441
3442 //
3443 // We need to extract from our name the name
3444 // of the data member which contains us, so
3445 // that we may then do a by-name lookup in the
3446 // dictionary meta info of our parent class to
3447 // get our offset in our parent class.
3448 //
3449
3450 // Get our name.
3451 TString dataName(subBranch->GetName());
3452 if (motherDotAtEnd) {
3453 // -- Remove the top-level branch name from our name.
3454 dataName.Remove(0, motherName.Length());
3455 // stlParentNameUpdated is false the first time in this loop.
3456 if (!stlParentNameUpdated && stlParentName.Length()) {
3457 stlParentName.Remove(0, motherName.Length());
3458 stlParentNameUpdated = true;
3459 }
3460 } else if (fType == 4) {
3461 // This is a top-level branch of type STL collection. In this current
3462 // iteration, we are trying to calculate the offset of one of the
3463 // base classes of the element type of the STL collection. The
3464 // dataName string in this case will be akin to
3465 // "nameOfBranch.BaseClassName". Later logic in this function will
3466 // try to get the TRealData relative to "BaseClassName". But if the
3467 // base class is not splittable (i.e. it has a custom streamer), that
3468 // will not work anyway. The treatment of base classes follows a
3469 // different path: we remove the leading name of the branch, so only
3470 // the name of the base class is left. This will be later detected
3471 // and dataName will be stripped from the name of the base class,
3472 // leaving the string completely empty. Since the dataName string
3473 // will be empty, the logic of this function skips the part related
3474 // to finding the TRealData and directly computes the base class
3475 // offset.
3476 // Only perform the modification of the string if it looks as we
3477 // expect
3478 if (dataName == (motherName + '.' + subBranchElement->GetName()))
3479 dataName = subBranchElement->GetName();
3480 } else if (motherDot) {
3481 // -- Remove the top-level branch name from our name, folder case.
3482 //
3483 // Note: We are in the case where our mother was created
3484 // by the branch constructor which takes a folder
3485 // as an argument. The mother branch has internal
3486 // dots in its name to represent the folder hierarchy.
3487 // The TTree::Bronch() routine has handled us as a
3488 // special case, we must compensate.
3489 if ((fID < 0) && (subBranchElement->IsA() == TStreamerBase::Class())) {
3490 // -- Our name is the mother name, remove it.
3491 // Note: The test is our parent is a top-level branch
3492 // and our streamer is the base class streamer,
3493 // this matches the exact test in TTree::Bronch().
3494 if (dataName.Length() == motherName.Length()) {
3495 dataName.Remove(0, motherName.Length());
3496 // stlParentNameUpdated is false the first time in this loop.
3497 if (!stlParentNameUpdated && stlParentName.Length()) {
3498 stlParentName.Remove(0, motherName.Length());
3499 }
3500 }
3501 } else {
3502 // -- Remove the mother name and the dot.
3503 if (dataName.Length() > motherName.Length()) {
3504 dataName.Remove(0, motherName.Length() + 1);
3505 if (!stlParentNameUpdated && stlParentName.Length()) {
3506 stlParentName.Remove(0, motherName.Length());
3507 }
3508 }
3509 }
3510 }
3511 stlParentNameUpdated = true;
3512 if (isBaseSubBranch) {
3513 // -- Remove the base class name suffix from our name.
3514 // Note: The pattern is the name of the base class.
3515 TString pattern(subBranchElement->GetName());
3516 if (pattern.Length() <= dataName.Length()) {
3517 if (!strcmp(dataName.Data() + (dataName.Length() - pattern.Length()), pattern.Data())) {
3518 // The branch name contains the name of the base class in it.
3519 // This name is not reproduced in the sub-branches, so we need to
3520 // remove it.
3521 dataName.Remove(dataName.Length() - pattern.Length());
3522 }
3523 }
3524 // Remove any leading dot.
3525 if (dataName.Length()) {
3526 if (dataName[0] == '.') {
3527 dataName.Remove(0, 1);
3528 }
3529 }
3530 // Note: We intentionally leave any trailing dot
3531 // in our modified name here.
3532 }
3533
3534 // Get our parent branch's name.
3535 TString parentName(GetName());
3536 if (motherDotAtEnd) {
3537 // -- Remove the top-level branch name from our parent's name.
3538 parentName.Remove(0, motherName.Length());
3539 } else if (motherDot) {
3540 // -- Remove the top-level branch name from our parent's name, folder case.
3541 //
3542 // Note: We are in the case where our mother was created
3543 // by the branch constructor which takes a folder
3544 // as an argument. The mother branch has internal
3545 // dots in its name to represent the folder hierarchy.
3546 // The TTree::Bronch() routine has handled us as a
3547 // special case, we must compensate.
3548 if ((fID > -1) && (mother == mother->GetSubBranch(this)) && (branchElem->IsA() == TStreamerBase::Class())) {
3549 // -- Our parent's name is the mother name, remove it.
3550 // Note: The test is our parent's parent is a top-level branch
3551 // and our parent's streamer is the base class streamer,
3552 // this matches the exact test in TTree::Bronch().
3553 if (parentName.Length() == motherName.Length()) {
3554 parentName.Remove(0, motherName.Length());
3555 }
3556 } else {
3557 // -- Remove the mother name and the dot.
3558 if (parentName.Length() > motherName.Length()) {
3559 parentName.Remove(0, motherName.Length() + 1);
3560 }
3561 }
3562 }
3563 // FIXME: Do we need to use the other tests for a base class here?
3564 if (fType == 1) {
3565 // -- Our parent is a base class sub-branch, remove the base class name suffix from its name.
3566 if (mother != mother->GetSubBranch(this)) {
3567 // -- My parent's parent is not a top-level branch.
3568 // Remove the base class name suffix from the parent name.
3569 // Note: The pattern is the name of the base class.
3570 // coverity[var_deref_model] branchElem is non zero here since fType==1 and thus fID > -1
3571 TString pattern(branchElem->GetName());
3572 if (pattern.Length() <= parentName.Length()) {
3573 if (!strcmp(parentName.Data() + (parentName.Length() - pattern.Length()), pattern.Data())) {
3574 // The branch name contains the name of the base class in it.
3575 // This name is not reproduced in the sub-branches, so we need to
3576 // remove it.
3577 parentName.Remove(parentName.Length() - pattern.Length());
3578 }
3579 }
3580 }
3581 // Note: We intentionally leave any trailing dots
3582 // in the modified parent name here.
3583 }
3584
3585 // Remove the parent branch name part from our name,
3586 // but only if the parent branch is not a top-level branch.
3587 // FIXME: We should not assume parent name does not have length 0.
3588 if (fID > -1) {
3589 RemovePrefix(dataName, parentName);
3590 }
3591
3592 // Remove any leading dot.
3593 if (dataName.Length()) {
3594 if (dataName[0] == '.') {
3595 dataName.Remove(0, 1);
3596 }
3597 }
3598
3599 // Remove any trailing dot.
3600 if (dataName.Length()) {
3601 if (dataName[dataName.Length()-1] == '.') {
3602 dataName.Remove(dataName.Length() - 1, 1);
3603 }
3604 }
3605
3606 //
3607 // Now that we have our data member name, find our offset
3608 // in our parent class.
3609 //
3610 // Note: Our data member name can have many dots in it
3611 // if branches were elided between our parent branch
3612 // and us by Unroll().
3613 //
3614 // FIXME: This may not work if our member name is ambiguous.
3615 //
3616
3617 Int_t offset = 0;
3618 if (dataName.Length()) {
3619 // -- We have our data member name, do a lookup in the dictionary meta info of our parent class.
3620 // Get our parent class.
3621 TClass* pClass = nullptr;
3622 // First check whether this sub-branch is part of the 'cache' (because the data member it
3623 // represents is no longer in the current class layout.
3624 TStreamerInfo *subInfo = subBranch->GetInfoImp();
3625 //if (subInfo && subBranch->TestBit(kCache)) { // subInfo->GetElements()->At(subBranch->GetID())->TestBit(TStreamerElement::kCache)) {
3626 if (subBranchElement->TestBit(TStreamerElement::kCache)) {
3627 pClass = static_cast<TStreamerElement*>(subInfo->GetElements()->At(0))->GetClassPointer();
3628 }
3629 // FIXME: Do we need the other base class tests here?
3630 if (!pClass) {
3631 if (fType == 1) {
3632 // -- Parent branch is a base class branch.
3633 // FIXME: Is using branchElem here the right thing?
3634 pClass = branchElem->GetClassPointer();
3635 if (pClass->Property() & kIsAbstract) {
3636 // the class is abstract, let see if the
3637
3638 TBranchElement *parent = static_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
3639 if (parent && parent != this && !parent->GetClass()->IsLoaded() ) {
3640 // Our parent's class is emulated and we represent an abstract class.
3641 // and the target class has not been set explicitly.
3642 TString target = pClass->GetName();
3643 target += "@@emulated";
3644
3645 pClass = TClass::GetClass(target);
3646 }
3647 }
3648 } else {
3649 // -- Parent branch is *not* a base class branch.
3650 // FIXME: This sometimes returns a null pointer.
3651 pClass = subBranch->GetParentClass();
3652 }
3653 }
3654 if (!pClass) {
3655 // -- No parent class, fix it.
3656 // FIXME: This is probably wrong!
3657 // Assume parent class is our parent branch's clones class or value class.
3658 if (GetClonesName() && strlen(GetClonesName())) {
3659 pClass = fClonesClass;
3660 if (!pClass) {
3661 Warning("InitializeOffsets", "subBranch: '%s' has no parent class, and cannot get class for clones class: '%s'!", subBranch->GetName(), GetClonesName());
3662 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3663 continue;
3664 }
3665 Warning("InitializeOffsets", "subBranch: '%s' has no parent class! Assuming parent class is: '%s'.", subBranch->GetName(), pClass->GetName());
3666 }
3669 Warning("InitializeOffsets", "subBranch: '%s' has no parent class! Assuming parent class is: '%s'.", subBranch->GetName(), pClass ? pClass->GetName() : "unknown class");
3670 }
3671 if (!pClass) {
3672 // -- Still no parent class, assume our parent class is our parent branch's class.
3673 // FIXME: This is probably wrong!
3674 pClass = branchClass;
3675 // FIXME: Enable this warning!
3676 //Warning("InitializeOffsets", "subBranch: '%s' has no parent class! Assuming parent class is: '%s'.", subBranch->GetName(), pClass->GetName());
3677 }
3678 }
3679 if (renamed && pClass) {
3680 if (pClass == branchClass) {
3681 pClass = branchElem->GetNewClass();
3682 } else if (fCollProxy && pClass == branchClass->GetCollectionProxy()->GetValueClass()) {
3683 pClass = fCollProxy->GetValueClass();
3684 }
3685 }
3686
3687 //------------------------------------------------------------------
3688 // If we have the are the sub-branch of the TBranchSTL, we need
3689 // to remove it's name to get the correct real data offsets
3690 ////////////////////////////////////////////////////////////////////
3691
3692 const bool isToplevelCollection = (this == GetMother() && (fType == 3 || fType == 4));
3693 if( stlParentName.Length() && (dynamic_cast<TBranchSTL*>(fParent) || isToplevelCollection))
3694 {
3695 if( !strncmp( stlParentName.Data(), dataName.Data(), stlParentName.Length()-1 )
3696 && dataName[ stlParentName.Length() ] == '.' )
3697 dataName.Remove( 0, stlParentName.Length()+1 );
3698 }
3699
3700 // Find our offset in our parent class using
3701 // a lookup by name in the dictionary meta info
3702 // for our parent class.
3703
3704 if (alternateElement) {
3705 Ssiz_t dotpos = dataName.Last('.');
3706 Ssiz_t endpos = dataName.Length();
3707 if (dotpos != kNPOS) ++dotpos; else dotpos = 0;
3708 dataName.Replace(dotpos,endpos-dotpos,subBranchElement->GetFullName());
3709 }
3710 TRealData* rd = pClass->GetRealData(dataName);
3711 if (rd && (!rd->TestBit(TRealData::kTransient) || alternateElement)) {
3712 // -- Data member exists in the dictionary meta info, get the offset.
3713 // If we are using an alternateElement, it is the target of a rule
3714 // and might be indeed transient.
3715 offset = rd->GetThisOffset();
3716 } else if (subBranchElement->TestBit(TStreamerElement::kWholeObject)) {
3717 // We are a rule with no specific target, it applies to the whole
3718 // object, let's set the offset to zero
3719 offset = 0;
3720 } else {
3721 // -- No dictionary meta info for this data member, it must no
3722 // longer exist
3723 if (fEntries == 0) {
3724 // ... unless we creating the branch in which case
3725 // we have an internal error.
3726 if (pClass->GetListOfRealData()->GetEntries() == 0) {
3727 // We are probably missing the ShowMember, let's
3728 // just issue an error.
3729 Error("InitializeOffsets",
3730 "Could not find the real data member '%s' when constructing the branch '%s' [Likely missing ShowMember].",
3731 dataName.Data(),GetName());
3732 } else if (subInfo && subInfo->GetClassVersion()!=subInfo->GetClass()->GetClassVersion()) {
3733 // In the case where we are cloning a TTree that was created with an older version of the layout, we may not
3734 // able to find all the members
3735 Info("InitializeOffsets",
3736 "TTree created with an older schema, some data might not be copied in 'slow-cloning' mode; fast-cloning should have the correct result. '%s' is missing when constructing the branch '%s'. ",
3737 dataName.Data(),GetName());
3738 } else {
3739 // Something really bad happen.
3740 Fatal("InitializeOffsets",
3741 "Could not find the real data member '%s' when constructing the branch '%s' [Likely an internal error, please report to the developers].",
3742 dataName.Data(),GetName());
3743 }
3744 }
3745 localOffset = TStreamerInfo::kMissing;
3746 }
3747 } else {
3748 // -- We have no data member name, ok for a base class, not good otherwise.
3749 if (isBaseSubBranch) {
3750 // I am a direct base class of my parent class, my local offset is enough.
3751 } else {
3752 Warning("InitializeOffsets", "Could not find the data member name for branch '%s' with parent branch '%s', assuming offset is zero!", subBranch->GetName(), GetName());
3753 }
3754 }
3755
3756 //
3757 // Ok, do final calculations for fOffset and fBranchOffset.
3758 //
3759
3760 if (isContDataMember) {
3761 // -- Container data members set fOffset instead of fBranchOffset.
3762 // The fOffset is what should be added to the start of the entry
3763 // in the collection (i.e., its current absolute address) to find
3764 // the beginning of the data member described by the current branch.
3765 //
3766 // Compensate for the i/o routines adding our local offset later.
3767 if (subBranch->fObject == nullptr && localOffset == TStreamerInfo::kMissing) {
3768 subBranch->SetMissing();
3769 // We stil need to set fBranchOffset in the case of a missing
3770 // element so that SetAddress is (as expected) not called
3771 // recursively in this case.
3772 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3773 } else {
3774 if (isBaseSubBranch) {
3775 // The value of 'offset' for a base class does not include its
3776 // 'localOffset'.
3777 subBranch->SetOffset(offset);
3778 } else {
3779 // The value of 'offset' for a regular data member does include its
3780 // 'localOffset', we need to remove it explicitly.
3781 subBranch->SetOffset(offset - localOffset);
3782 }
3783 }
3784 } else {
3785 // -- Set fBranchOffset for sub-branch.
3786 Int_t isSplit = 0 != subBranch->GetListOfBranches()->GetEntriesFast();
3787 if (subBranch->fObject == nullptr && localOffset == TStreamerInfo::kMissing) {
3788 // The branch is missing
3789 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3790
3791 } else if (isSplit) {
3792 if (isBaseSubBranch) {
3793 // We are split, so we need to add in our local offset
3794 // to get our absolute address for our children.
3795 fBranchOffset[subBranchIdx] = offset + localOffset;
3796 } else {
3797 // We are split so our offset will never be
3798 // used in an i/o, so we do not have to subtract
3799 // off our local offset like below.
3800 fBranchOffset[subBranchIdx] = offset;
3801 }
3802 } else {
3803 if (isBaseSubBranch) {
3804 // We are not split, so our local offset will be
3805 // added later by the i/o routines.
3806 fBranchOffset[subBranchIdx] = offset;
3807 } else {
3808 // Compensate for the fact that the i/o routines
3809 // are going to add my local offset later.
3810 fBranchOffset[subBranchIdx] = offset - localOffset;
3811 }
3812 }
3813 }
3814 }
3815 }
3816 else {
3817 if (fID > -1) {
3818 // Branch is *not* a top-level branch.
3819 // Let's check if the target member is still present in memory
3821 fObject = nullptr;
3822 }
3823 }
3824 }
3825 const bool isSplitNode = (fType == 2 || fType == 1 || (fType == 0 && fID == -2)) && !fBranches.IsEmpty();
3826 if (fReadActionSequence && isSplitNode) {
3827 TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
3828 auto index = parent->fBranches.IndexOf(this);
3829 if (index >= 0) {
3831 }
3832 }
3833
3834 fInitOffsets = true;
3835}
3836
3837////////////////////////////////////////////////////////////////////////////////
3838/// Return true if more than one leaf, false otherwise.
3839
3841{
3842 Int_t nbranches = fBranches.GetEntriesFast();
3843 if (nbranches >= 1) {
3844 return true;
3845 }
3846 TList* browsables = const_cast<TBranchElement*>(this)->GetBrowsables();
3847 return browsables && browsables->GetSize();
3848}
3849
3850////////////////////////////////////////////////////////////////////////////////
3851/// Detect a collection written using a zero pointer in old versions of root.
3852/// In versions of ROOT older than 4.00/03, if a collection (TClonesArray
3853/// or STL container) was split but the pointer to the collection was zeroed
3854/// out, nothing was saved. Hence there is no __easy__ way to detect the
3855/// case. In newer versions, a zero is written so that a 'missing' collection
3856/// appears to be an empty collection.
3857
3859{
3860 bool ismissing = false;
3861 TBasket* basket = static_cast<TBasket*>(fBaskets.UncheckedAt(fReadBasket));
3862 if (basket && fTree) {
3863 Long64_t entry = fTree->GetReadEntry();
3865 Long64_t last;
3866 if (fReadBasket == fWriteBasket) {
3867 last = fEntryNumber - 1;
3868 } else {
3869 last = fBasketEntry[fReadBasket+1] - 1;
3870 }
3871 Int_t* entryOffset = basket->GetEntryOffset();
3872 Int_t bufbegin;
3873 Int_t bufnext;
3874 if (entryOffset) {
3875 bufbegin = entryOffset[entry-first];
3876
3877 if (entry < last) {
3878 bufnext = entryOffset[entry+1-first];
3879 } else {
3880 bufnext = basket->GetLast();
3881 }
3882 if (bufnext == bufbegin) {
3883 ismissing = true;
3884 } else {
3885 // fixed length buffer so this is not the case here.
3886 if (basket->GetNevBufSize() == 0) {
3887 ismissing = true;
3888 }
3889 }
3890 }
3891 }
3892 return ismissing;
3893}
3894
3895////////////////////////////////////////////////////////////////////////////////
3896/// Print branch parameters.
3897
3898static void PrintElements(const TStreamerInfo *info, const TStreamerInfoActions::TIDs &ids)
3899{
3900 for(auto &cursor : ids) {
3901 auto id = cursor.fElemID;
3902 if (id >= 0) {
3903 auto el = info->GetElement(id);
3904 if (el)
3905 el->ls();
3906 else {
3907 Error("TBranchElement::Print", "Element for id #%d not found in StreamerInfo for %s",
3908 id, info->GetName());
3909 info->ls();
3910 }
3911 } else if (cursor.fNestedIDs) {
3912 Printf(" Within subobject of type %s offset = %d", cursor.fNestedIDs->fInfo->GetName(), cursor.fNestedIDs->fOffset);
3913 PrintElements(cursor.fNestedIDs->fInfo, cursor.fNestedIDs->fIDs);
3914 }
3915 }
3916}
3917
3919{
3920 constexpr auto length = std::char_traits<char>::length;
3921 Int_t nbranches = fBranches.GetEntriesFast();
3922 if (strncmp(option,"debugAddress",length("debugAddress"))==0) {
3923 if (strlen(option)==length("debugAddress")) {
3924 Printf("%-24s %-16s %2s %4s %-16s %-16s %8s %8s %s %s\n",
3925 "Branch Name", "Streamer Class", "ID", "Type", "Class", "Parent", "pOffset", "fOffset", "fObject", "fOnfileObject");
3926 }
3927 if (strlen(GetName())>24) Printf("%-24s\n%-24s ", GetName(),"");
3928 else Printf("%-24s ", GetName());
3929
3930 TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
3931 Int_t ind = parent ? parent->GetListOfBranches()->IndexOf(this) : -1;
3932 TVirtualStreamerInfo *info = const_cast<TBranchElement*>(this)->GetInfoImp();
3933
3934 Printf("%-16s %2d %4d %-16s %-16s %8x %8x %p %p%s\n",
3935 info ? info->GetName() : "StreamerInfo unavailable", GetID(), GetType(),
3937 (fBranchOffset&&parent && ind>=0) ? parent->fBranchOffset[ind] : 0,
3938 GetOffset(), GetObject(), fOnfileObject, TestBit(kOwnOnfileObj) ? " (owned)" : "");
3939 for (Int_t i = 0; i < nbranches; ++i) {
3940 TBranchElement* subbranch = static_cast<TBranchElement*>(fBranches.At(i));
3941 subbranch->Print("debugAddressSub");
3942 }
3943 return;
3944 }
3945 if (strncmp(option,"debugInfo",length("debugInfo"))==0) {
3946 Printf("Branch %s uses:",GetName());
3947 TStreamerInfo *localInfo = GetInfoImp();
3948 if (fID>= 0) {
3949 // GetInfoImp()->GetElement(fID)->ls();
3950 // for(UInt_t i=0; i< fIDs.size(); ++i) {
3951 // GetInfoImp()->GetElement(fIDs[i])->ls();
3952 // }
3953 if (fType == 3 || fType == 4) {
3954 // Search for the correct version.
3956 }
3957 Printf(" With elements:");
3958 if (fType != 3 && fType != 4)
3959 localInfo->GetElement(fID)->ls();
3960 PrintElements(localInfo, fNewIDs);
3961 Printf(" with read actions:");
3963 Printf(" with write actions:");
3965 } else if (!fNewIDs.empty() && localInfo) {
3966 if (fType == 3 || fType == 4) {
3967 // Search for the correct version.
3969 }
3970 PrintElements(localInfo, fNewIDs);
3971 Printf(" with read actions:");
3973 Printf(" with write actions:");
3975 }
3976 TString suboption = "debugInfoSub";
3977 suboption += (option+length("debugInfo"));
3978 for (Int_t i = 0; i < nbranches; ++i) {
3979 TBranchElement* subbranch = static_cast<TBranchElement*>(fBranches.At(i));
3980 subbranch->Print(suboption);
3981 }
3982 Printf(" ");
3983 return;
3984 }
3985 if (nbranches) {
3986 if (fID == -2) {
3987 if (strcmp(GetName(),GetTitle()) == 0) {
3988 Printf("*Branch :%-66s *",GetName());
3989 } else {
3990 Printf("*Branch :%-9s : %-54s *",GetName(),GetTitle());
3991 }
3992 Printf("*Entries : %8d : BranchElement (see below) *",Int_t(fEntries));
3993 Printf("*............................................................................*");
3994 }
3995 if (fType >= 2) {
3997 }
3998 for (Int_t i=0;i<nbranches;i++) {
3999 TBranch *branch = static_cast<TBranch*>(fBranches.At(i));
4000 branch->Print(option);
4001 }
4002 } else {
4004 }
4005}
4006
4007////////////////////////////////////////////////////////////////////////////////
4008/// Prints values of leaves.
4009
4011{
4013
4014 TStreamerInfo *info = GetInfoImp();
4015 Int_t prID = fID;
4016 char *object = fObject;
4017 if (TestBit(kCache)) {
4019 prID = fID+1;
4020 } else if (fOnfileObject) {
4021 object = fOnfileObject->GetObjectAt(0);
4022 }
4023 }
4024
4025 if (TestBit(kDecomposedObj)) {
4026 if (!fAddress) {
4027 return;
4028 }
4029 if (fType == 3 || fType == 4) {
4030 // TClonesArray or STL container top-level branch.
4031 printf(" %-15s = %d\n", GetName(), fNdata);
4032 return;
4033 } else if (fType == 31 || fType == 41) {
4034 // TClonesArray or STL container sub-branch.
4035 Int_t n = TMath::Min(10, fNdata);
4038 // TVirtualStreamerInfo::kOffsetL + TVirtualStreamerInfo::kChar is
4039 // printed as a string and could print weird characters.
4040 // So we print an unsigned char instead (not perfect, but better).
4042 }
4043 if (atype > 54) {
4044 // FIXME: More logic required here (like in ReadLeaves)
4045 printf(" %-15s = %d\n", GetName(), fNdata);
4046 return;
4047 }
4048 if (fStreamerType > 20) {
4049 atype -= 20;
4050 TLeafElement* leaf = static_cast<TLeafElement*>(fLeaves.UncheckedAt(0));
4051 n = n * leaf->GetLenStatic();
4052 }
4053 if (info) {
4054 info->PrintValue(GetName(), fAddress, atype, n, lenmax);
4055 }
4056 return;
4057 } else if (fType <= 2) {
4058 // Branch in split mode.
4059 // FIXME: This should probably be < 60 instead.
4060 if ((fStreamerType > 40) && (fStreamerType < 55)) {
4061 Int_t atype = fStreamerType - 20;
4062 TBranchElement* counterElement = static_cast<TBranchElement*>(fBranchCount);
4063 Int_t n = (Int_t) counterElement->GetValue(0, 0);
4064 if (info) {
4065 info->PrintValue(GetName(), fAddress, atype, n, lenmax);
4066 }
4067 } else {
4068 if (info) {
4069 info->PrintValue(GetName(), object, prID, -1, lenmax);
4070 }
4071 }
4072 return;
4073 }
4074 } else if (fType == 3) {
4075 printf(" %-15s = %d\n", GetName(), fNdata);
4076 } else if (fType == 31) {
4077 TClonesArray* clones = reinterpret_cast<TClonesArray*>(object);
4078 if (info) {
4079 info->PrintValueClones(GetName(), clones, prID, fOffset, lenmax);
4080 }
4081 } else if (fType == 41) {
4082 TVirtualCollectionProxy::TPushPop helper(const_cast<TBranchElement*>(this)->GetCollectionProxy(), object);
4083 if (info) {
4084 info->PrintValueSTL(GetName(), const_cast<TBranchElement*>(this)->GetCollectionProxy(), prID, fOffset, lenmax);
4085 }
4086 } else {
4087 if (info) {
4088 info->PrintValue(GetName(), object, prID, -1, lenmax);
4089 }
4090 }
4091}
4092
4093////////////////////////////////////////////////////////////////////////////////
4094/// Unconfiguration Read Leave function.
4095
4097{
4098 Fatal("ReadLeaves","The ReadLeaves function has not been configured for %s",GetName());
4099}
4100
4101////////////////////////////////////////////////////////////////////////////////
4102/// Read leaves into i/o buffers for this branch.
4103/// For the case where the branch is set in MakeClass mode (decomposed object).
4104
4106{
4108
4109 if (fType == 3 || fType == 4) {
4110 // Top level branch of a TClonesArray.
4111 Int_t *n = reinterpret_cast<Int_t*>(fAddress);
4112 b >> n[0];
4113 if ((n[0] < 0) || (n[0] > fMaximum)) {
4114 if (IsMissingCollection()) {
4115 n[0] = 0;
4116 b.SetBufferOffset(b.Length() - sizeof(n));
4117 } else {
4118 Error("ReadLeaves", "Incorrect size read for the container in %s\nThe size read is %d when the maximum is %d\nThe size is reset to 0 for this entry (%lld)", GetName(), n[0], fMaximum, GetReadEntry());
4119 n[0] = 0;
4120 }
4121 }
4122 fNdata = n[0];
4123 if (fType == 4 && IsAssociativeContainer(fSTLtype)) {
4124 Int_t nbranches = fBranches.GetEntriesFast();
4125 for (Int_t i=0; i<nbranches; i++) {
4126 TBranch *branch = static_cast<TBranch*>(fBranches[i]);
4127 Int_t nb = branch->GetEntry(GetReadEntry(), 1);
4128 if (nb < 0) {
4129 break;
4130 }
4131 }
4132 }
4133 return;
4134 } else if (fType == 31 || fType == 41) { // sub branch of a TClonesArray
4136 Int_t atype = fStreamerType;
4137 // FIXME: This should probably be > 59 instead.
4138 if (atype > 54) return;
4139 if (!fAddress) {
4140 return;
4141 }
4142 Int_t n = fNdata;
4143 if (atype>40) {
4144 atype -= 40;
4145 if (!fBranchCount2) return;
4146 const char *len_where = fBranchCount2->fAddress;
4147 if (!len_where) return;
4148 Int_t len_atype = fBranchCount2->fStreamerType;
4149 Int_t length;
4150 Int_t k;
4151 Char_t isArray;
4152 for( k=0; k<n; k++) {
4153 char **where = &((reinterpret_cast<char**>(fAddress))[k]);
4154 delete [] *where;
4155 *where = nullptr;
4156 switch(len_atype) {
4157 case 1: {length = (reinterpret_cast<const Char_t* >(len_where))[k]; break;}
4158 case 2: {length = (reinterpret_cast<const Short_t* >(len_where))[k]; break;}
4159 case 3: {length = (reinterpret_cast<const Int_t* >(len_where))[k]; break;}
4160 case 4: {length = (reinterpret_cast<const Long_t* >(len_where))[k]; break;}
4161 //case 5: {length = (reinterpret_cast<Float_t*>(len_where))[k]; break;}
4162 case 6: {length = (reinterpret_cast<const Int_t* >(len_where))[k]; break;}
4163 //case 8: {length = (reinterpret_cast<Double_t*>(len_where))[k]; break;}
4164 case 11: {length = (reinterpret_cast<const UChar_t* >(len_where))[k]; break;}
4165 case 12: {length = (reinterpret_cast<const UShort_t* >(len_where))[k]; break;}
4166 case 13: {length = (reinterpret_cast<const UInt_t* >(len_where))[k]; break;}
4167 case 14: {length = (reinterpret_cast<const ULong_t* >(len_where))[k]; break;}
4168 case 15: {length = (reinterpret_cast<const ULong64_t*>(len_where))[k]; break;}
4169 case 16: {length = (reinterpret_cast<const Long64_t* >(len_where))[k]; break;}
4170 case 17: {length = (reinterpret_cast<const ULong64_t*>(len_where))[k]; break;}
4171 case 18: {length = (reinterpret_cast<const bool* >(len_where))[k]; break;}
4172 default: continue;
4173 }
4174 b >> isArray;
4175 if (length <= 0) continue;
4176 if (isArray == 0) continue;
4177 switch (atype) {
4178 case 1: {*where=new char[sizeof(Char_t)*length]; b.ReadFastArray(reinterpret_cast<Char_t*>(*where), length); break;}
4179 case 2: {*where=new char[sizeof(Short_t)*length]; b.ReadFastArray(reinterpret_cast<Short_t*>(*where), length); break;}
4180 case 3: {*where=new char[sizeof(Int_t)*length]; b.ReadFastArray(reinterpret_cast<Int_t*>(*where), length); break;}
4181 case 4: {*where=new char[sizeof(Long_t)*length]; b.ReadFastArray(reinterpret_cast<Long_t*>(*where), length); break;}
4182 case 5: {*where=new char[sizeof(Float_t)*length]; b.ReadFastArray(reinterpret_cast<Float_t*>(*where), length); break;}
4183 case 6: {*where=new char[sizeof(Int_t)*length]; b.ReadFastArray(reinterpret_cast<Int_t*>(*where), length); break;}
4184 case 8: {*where=new char[sizeof(Double_t)*length]; b.ReadFastArray(reinterpret_cast<Double_t*>(*where), length); break;}
4185 case 11: {*where=new char[sizeof(UChar_t)*length]; b.ReadFastArray(reinterpret_cast<UChar_t*>(*where), length); break;}
4186 case 12: {*where=new char[sizeof(UShort_t)*length]; b.ReadFastArray(reinterpret_cast<UShort_t*>(*where), length); break;}
4187 case 13: {*where=new char[sizeof(UInt_t)*length]; b.ReadFastArray(reinterpret_cast<UInt_t*>(*where), length); break;}
4188 case 14: {*where=new char[sizeof(ULong_t)*length]; b.ReadFastArray(reinterpret_cast<ULong_t*>(*where), length); break;}
4189 case 15: {*where=new char[sizeof(UInt_t)*length]; b.ReadFastArray(reinterpret_cast<UInt_t*>(*where), length); break;}
4190 case 16: {*where=new char[sizeof(Long64_t)*length]; b.ReadFastArray(reinterpret_cast<Long64_t*>(*where), length); break;}
4191 case 17: {*where=new char[sizeof(ULong64_t)*length]; b.ReadFastArray(reinterpret_cast<ULong64_t*>(*where), length); break;}
4192 case 18: {*where=new char[sizeof(bool)*length]; b.ReadFastArray(reinterpret_cast<bool*>(*where), length); break;}
4193 }
4194 }
4195 return;
4196 }
4197 if (atype > 20) {
4198 atype -= 20;
4199 TLeafElement *leaf = static_cast<TLeafElement*>(fLeaves.UncheckedAt(0));
4200 n *= leaf->GetLenStatic();
4201 }
4202 switch (atype) {
4203 case 1: {b.ReadFastArray(reinterpret_cast<Char_t*>(fAddress), n); break;}
4204 case 2: {b.ReadFastArray(reinterpret_cast<Short_t*>(fAddress), n); break;}
4205 case 3: {b.ReadFastArray(reinterpret_cast<Int_t*>(fAddress), n); break;}
4206 case 4: {b.ReadFastArray(reinterpret_cast<Long_t*>(fAddress), n); break;}
4207 case 5: {b.ReadFastArray(reinterpret_cast<Float_t*>(fAddress), n); break;}
4208 case 6: {b.ReadFastArray(reinterpret_cast<Int_t*>(fAddress), n); break;}
4209 case 8: {b.ReadFastArray(reinterpret_cast<Double_t*>(fAddress), n); break;}
4210 case 11: {b.ReadFastArray(reinterpret_cast<UChar_t*>(fAddress), n); break;}
4211 case 12: {b.ReadFastArray(reinterpret_cast<UShort_t*>(fAddress), n); break;}
4212 case 13: {b.ReadFastArray(reinterpret_cast<UInt_t*>(fAddress), n); break;}
4213 case 14: {b.ReadFastArray(reinterpret_cast<ULong_t*>(fAddress), n); break;}
4214 case 15: {b.ReadFastArray(reinterpret_cast<UInt_t*>(fAddress), n); break;}
4215 case 16: {b.ReadFastArray(reinterpret_cast<Long64_t*>(fAddress), n); break;}
4216 case 17: {b.ReadFastArray(reinterpret_cast<ULong64_t*>(fAddress), n); break;}
4217 case 18: {b.ReadFastArray(reinterpret_cast<bool*>(fAddress), n); break;}
4218 case 9: {
4220 TStreamerElement* se = static_cast<TStreamerElement*>(si->GetElement(fID));
4221 Double_t *xx = reinterpret_cast<Double_t*>(fAddress);
4222 for (Int_t ii=0;ii<n;ii++) {
4223 b.ReadDouble32(&(xx[ii]),se);
4224 }
4225 break;
4226 }
4227 case 19: {
4229 TStreamerElement* se = static_cast<TStreamerElement*>(si->GetElement(fID));
4230 Float_t *xx = reinterpret_cast<Float_t*>(fAddress);
4231 for (Int_t ii=0;ii<n;ii++) {
4232 b.ReadFloat16(&(xx[ii]),se);
4233 }
4234 break;
4235 }
4236 }
4237 return;
4238 } else if (fType <= 2) { // branch in split mode
4239 // FIXME: This should probably be < 60 instead.
4240 if (fStreamerType > 40 && fStreamerType < 55) {
4241 Int_t atype = fStreamerType - 40;
4242 Int_t n;
4243 if (fBranchCount==nullptr) {
4244 // Missing fBranchCount. let's attempts to recover.
4245
4246 TString countname( GetName() );
4247 Ssiz_t dot = countname.Last('.');
4248 if (dot>=0) {
4249 countname.Remove(dot+1);
4250 } else {
4251 countname = "";
4252 }
4253 TString counter( GetTitle() );
4254 Ssiz_t loc = counter.Last('[');
4255 if (loc>=0) {
4256 counter.Remove(0,loc+1);
4257 }
4258 loc = counter.Last(']');
4259 if (loc>=0) {
4260 counter.Remove(loc);
4261 }
4262 countname += counter;
4263 SetBranchCount(FindBranchCount(fTree, fParent, countname));
4264 }
4265 if (fBranchCount) {
4266 n = (Int_t)fBranchCount->GetValue(0,0);
4267 } else {
4268 Warning("ReadLeaves","Missing fBranchCount for %s. Data will not be read correctly by the MakeClass mode.",GetName());
4269 n = 0;
4270 }
4271 fNdata = n;
4272 Char_t isArray;
4273 b >> isArray;
4274 switch (atype) {
4275 case 1: {b.ReadFastArray(reinterpret_cast<Char_t*>(fAddress), n); break;}
4276 case 2: {b.ReadFastArray(reinterpret_cast<Short_t*>(fAddress), n); break;}
4277 case 3: {b.ReadFastArray(reinterpret_cast<Int_t*>(fAddress), n); break;}
4278 case 4: {b.ReadFastArray(reinterpret_cast<Long_t*>(fAddress), n); break;}
4279 case 5: {b.ReadFastArray(reinterpret_cast<Float_t*>(fAddress), n); break;}
4280 case 6: {b.ReadFastArray(reinterpret_cast<Int_t*>(fAddress), n); break;}
4281 case 8: {b.ReadFastArray(reinterpret_cast<Double_t*>(fAddress), n); break;}
4282 case 11: {b.ReadFastArray(reinterpret_cast<UChar_t*>(fAddress), n); break;}
4283 case 12: {b.ReadFastArray(reinterpret_cast<UShort_t*>(fAddress), n); break;}
4284 case 13: {b.ReadFastArray(reinterpret_cast<UInt_t*>(fAddress), n); break;}
4285 case 14: {b.ReadFastArray(reinterpret_cast<ULong_t*>(fAddress), n); break;}
4286 case 15: {b.ReadFastArray(reinterpret_cast<UInt_t*>(fAddress), n); break;}
4287 case 16: {b.ReadFastArray(reinterpret_cast<Long64_t*>(fAddress), n); break;}
4288 case 17: {b.ReadFastArray(reinterpret_cast<ULong64_t*>(fAddress), n); break;}
4289 case 18: {b.ReadFastArray(reinterpret_cast<bool*>(fAddress), n); break;}
4290 case 9: {
4292 TStreamerElement* se = si->GetElement(fID);
4293 Double_t *xx = reinterpret_cast<Double_t*>(fAddress);
4294 for (Int_t ii=0;ii<n;ii++) {
4295 b.ReadDouble32(&(xx[ii]),se);
4296 }
4297 break;
4298 }
4299 case 19: {
4301 TStreamerElement* se = si->GetElement(fID);
4302 Float_t *xx = reinterpret_cast<Float_t*>(fAddress);
4303 for (Int_t ii=0;ii<n;ii++) {
4304 b.ReadFloat16(&(xx[ii]),se);
4305 }
4306 break;
4307 }
4308 }
4309 } else {
4310 fNdata = 1;
4311 if (fAddress) {
4312 if (fType<0) {
4313 // Non TObject, Non collection classes with a custom streamer.
4314
4315 // if (fObject)
4317 } else {
4318 TStreamerInfo *info = GetInfoImp();
4319 if (!info) {
4320 return;
4321 }
4322 // Since info is not null, fReadActionSequence is not null either.
4323 b.ApplySequence(*fReadActionSequence, fObject);
4324 }
4326 fNdata = (Int_t) GetValue(0, 0);
4327 }
4328 } else {
4329 fNdata = 0;
4330 }
4331 }
4332 return;
4333 }
4334}
4335
4336////////////////////////////////////////////////////////////////////////////////
4337/// Read leaves into i/o buffers for this branch.
4338/// Case of a collection (fType == 4).
4339
4341{
4343 if (fObject == nullptr)
4344 {
4345 // We have nowhere to copy the data (probably because the data member was
4346 // 'dropped' from the current schema) so let's no copy it in a random place.
4347 return;
4348 }
4349
4350 // STL container master branch (has only the number of elements).
4351 Int_t n;
4352 b >> n;
4353 if ((n < 0) || (n > fMaximum)) {
4354 if (IsMissingCollection()) {
4355 n = 0;
4356 b.SetBufferOffset(b.Length()-sizeof(n));
4357 } else {
4358 Error("ReadLeaves", "Incorrect size read for the container in %s\n\tThe size read is %d while the maximum is %d\n\tThe size is reset to 0 for this entry (%lld)", GetName(), n, fMaximum, GetReadEntry());
4359 n = 0;
4360 }
4361 }
4362 fNdata = n;
4363
4364 R__PushCache onfileObject(b, fOnfileObject, 1);
4365
4366 // Note: Proxy-helper needs to "embrace" the entire
4367 // streaming of this STL container if the container
4368 // is a set/multiset/map/multimap (what we do not
4369 // know here).
4370 // For vector/list/deque Allocate == Resize
4371 // and Commit == noop.
4372 // TODO: Exception safety a la TPushPop
4375 void* alternate = proxy->Allocate(fNdata, true);
4377 fPtrIterators->CreateIterators(alternate, proxy);
4378 } else {
4379 fIterators->CreateIterators(alternate, proxy);
4380 }
4381
4382 if (IsAssociativeContainer(*proxy)) {
4383
4384 Int_t nbranches = fBranches.GetEntriesFast();
4385 for (Int_t i = 0; i < nbranches; ++i) {
4386 TBranch *branch = static_cast<TBranch*>(fBranches[i]);
4387 // To ensure that the sub-branches are read, we need
4388 // reset their entry cursor.
4389 RecursiveResetReadEntry(branch);
4390 Int_t nb = branch->GetEntry(GetReadEntry(), 1);
4391 if (nb < 0) {
4392 // Give up on i/o failure.
4393 // FIXME: We need an error message here.
4394 break;
4395 }
4396 }
4397 }
4398 //------------------------------------------------------------------------
4399 // We have split this stuff, so we need to create the pointers
4400 /////////////////////////////////////////////////////////////////////////////
4401
4403 {
4404 TClass *elClass = proxy->GetValueClass();
4405
4406 //--------------------------------------------------------------------
4407 // The allocation is done in this strange way because ReadLeaves
4408 // is being called many times by TTreeFormula!!!
4409 //////////////////////////////////////////////////////////////////////////
4410
4411 Int_t i = 0;
4412 // coverity[returned_null] the fNdata is check enough to prevent the use of null value of At(0)
4413 if( !fNdata || *reinterpret_cast<void**>(proxy->At( 0 )) != nullptr )
4414 i = fNdata;
4415
4416 for( ; i < fNdata; ++i )
4417 {
4418 void **el = reinterpret_cast<void**>(proxy->At( i ));
4419 // coverity[dereference] since this is a member streaming action by definition the collection contains objects and elClass is not null.
4420 *el = elClass->New();
4421 }
4422 }
4423
4424 proxy->Commit(alternate);
4425}
4426
4427////////////////////////////////////////////////////////////////////////////////
4428/// Read leaves into i/o buffers for this branch.
4429/// Case of a data member within a collection (fType == 41).
4430
4432{
4434 if (fObject == nullptr)
4435 {
4436 // We have nowhere to copy the data (probably because the data member was
4437 // 'dropped' from the current schema) so let's no copy it in a random place.
4438 return;
4439 }
4440
4441 // STL container sub-branch (contains the elements).
4443 if (!fNdata) {
4444 return;
4445 }
4446
4447 R__PushCache onfileObject(b, fOnfileObject, fNdata);
4448
4449 TStreamerInfo *info = GetInfoImp();
4450 if (info == nullptr) return;
4451
4454
4455 // R__ASSERT(0);
4457 b.ApplySequence(*fReadActionSequence,iter->fBegin,iter->fEnd);
4458}
4459
4460////////////////////////////////////////////////////////////////////////////////
4461/// Read leaves into i/o buffers for this branch.
4462/// Case of a data member within a collection (fType == 41).
4463
4465{
4467 if (fObject == nullptr)
4468 {
4469 // We have nowhere to copy the data (probably because the data member was
4470 // 'dropped' from the current schema) so let's no copy it in a random place.
4471 return;
4472 }
4473
4474 // STL container sub-branch (contains the elements).
4476 if (!fNdata) {
4477 return;
4478 }
4479 R__PushCache onfileObject(b, fOnfileObject, fNdata);
4480
4481 TStreamerInfo *info = GetInfoImp();
4482 if (info == nullptr) return;
4483
4486
4488 b.ApplySequenceVecPtr(*fReadActionSequence,iter->fBegin,iter->fEnd);
4489}
4490
4491////////////////////////////////////////////////////////////////////////////////
4492/// Read leaves into i/o buffers for this branch.
4493/// Case of a data member within a collection (fType == 41).
4494
4496{
4498 if (fObject == nullptr)
4499 {
4500 // We have nowhere to copy the data (probably because the data member was
4501 // 'dropped' from the current schema) so let's no copy it in a random place.
4502 return;
4503 }
4504
4505 // STL container sub-branch (contains the elements).
4507 if (!fNdata) {
4508 return;
4509 }
4510 R__PushCache onfileObject(b, fOnfileObject, fNdata);
4511
4512 TStreamerInfo *info = GetInfoImp();
4513 if (info == nullptr) return;
4514 // Since info is not null, fReadActionSequence is not null either.
4515
4516 // Still calling PushPop for the legacy entries.
4519
4521 b.ApplySequence(*fReadActionSequence,iter->fBegin,iter->fEnd);
4522}
4523
4524////////////////////////////////////////////////////////////////////////////////
4525/// Read leaves into i/o buffers for this branch.
4526/// Case of a TClonesArray (fType == 3).
4527
4529{
4531 if (fObject == nullptr)
4532 {
4533 // We have nowhere to copy the data (probably because the data member was
4534 // 'dropped' from the current schema) so let's no copy it in a random place.
4535 return;
4536 }
4537
4538 // TClonesArray master branch (has only the number of elements).
4539 Int_t n;
4540 b >> n;
4541 if ((n < 0) || (n > fMaximum)) {
4542 if (IsMissingCollection()) {
4543 n = 0;
4544 b.SetBufferOffset(b.Length()-sizeof(n));
4545 } else {
4546 Error("ReadLeaves", "Incorrect size read for the container in %s\n\tThe size read is %d while the maximum is %d\n\tThe size is reset to 0 for this entry (%lld)", GetName(), n, fMaximum, GetReadEntry());
4547 n = 0;
4548 }
4549 }
4550 fNdata = n;
4551 TClonesArray* clones = reinterpret_cast<TClonesArray*>(fObject);
4552 if (clones->IsZombie()) {
4553 return;
4554 }
4555 // The salient part of Clear is now 'duplicated in ExpandCreateFast (i.e. the
4556 // setting to zero of the unused slots), so we no longer need to call Clear explicitly
4557 // clones->Clear();
4558 clones->ExpandCreateFast(fNdata);
4559}
4560
4561////////////////////////////////////////////////////////////////////////////////
4562/// Read leaves into i/o buffers for this branch.
4563/// Case of a data member within a TClonesArray (fType == 31).
4564
4566{
4567 // No need to validate the address here, if we are a member of a split ClonesArray,
4568 // fID is positive
4569 // ValidateAddress();
4570
4571 if (fObject == nullptr)
4572 {
4573 // We have nowhere to copy the data (probably because the data member was
4574 // 'dropped' from the current schema) so let's no copy it in a random place.
4575 return;
4576 }
4577
4578 // TClonesArray sub-branch (contains the elements).
4580 TClonesArray* clones = reinterpret_cast<TClonesArray*>(fObject);
4581 if (clones->IsZombie()) {
4582 return;
4583 }
4584 TStreamerInfo *info = GetInfoImp();
4585 if (info==nullptr) return;
4586 // Since info is not null, fReadActionSequence is not null either.
4587
4588 // Note, we could (possibly) save some more, by configuring the action
4589 // based on the value of fOnfileObject rather than pushing in on a stack.
4590 R__PushCache onfileObject(b, fOnfileObject, fNdata);
4591
4592 char **arr = reinterpret_cast<char **>(clones->GetObjectRef());
4593 char **end = arr + fNdata;
4594 b.ApplySequenceVecPtr(*fReadActionSequence,arr,end);
4595}
4596
4597////////////////////////////////////////////////////////////////////////////////
4598/// Read leaves into i/o buffers for this branch.
4599/// For split-class branch, base class branch, data member branch, or top-level branch.
4600/// which do not have a branch count and are not a counter.
4601
4603{
4604 R__ASSERT(fBranchCount==nullptr);
4606
4608 if (fObject == nullptr)
4609 {
4610 // We have nowhere to copy the data (probably because the data member was
4611 // 'dropped' from the current schema) so let's no copy it in a random place.
4612 return;
4613 }
4614
4615 R__PushCache onfileObject(b, fOnfileObject, 1);
4616 // If not a TClonesArray or STL container master branch
4617 // or sub-branch and branch inherits from tobject,
4618 // then register with the buffer so that pointers are
4619 // handled properly.
4620 if (TestBit(kBranchObject)) {
4621 b.MapObject(reinterpret_cast<TObject*>(fObject));
4622 } else if (TestBit(kBranchAny)) {
4623 b.MapObject(fObject, fBranchClass);
4624 }
4625
4626 fNdata = 1;
4627 TStreamerInfo *info = GetInfoImp();
4628 if (!info) {
4629 return;
4630 }
4631 // Since info is not null, fReadActionSequence is not null either.
4632 b.ApplySequence(*fReadActionSequence, fObject);
4633}
4634
4635////////////////////////////////////////////////////////////////////////////////
4636/// Read leaves into i/o buffers for this branch.
4637/// For split-class branch, base class branch, data member branch, or top-level branch.
4638/// which do have a branch count and are not a counter.
4639
4641{
4643
4645 if (fObject == nullptr)
4646 {
4647 // We have nowhere to copy the data (probably because the data member was
4648 // 'dropped' from the current schema) so let's no copy it in a random place.
4649 return;
4650 }
4651
4652 // If not a TClonesArray or STL container master branch
4653 // or sub-branch and branch inherits from tobject,
4654 // then register with the buffer so that pointers are
4655 // handled properly.
4656 if (TestBit(kBranchObject)) {
4657 b.MapObject(reinterpret_cast<TObject*>(fObject));
4658 } else if (TestBit(kBranchAny)) {
4659 b.MapObject(fObject, fBranchClass);
4660 }
4661
4662 fNdata = (Int_t) fBranchCount->GetValue(0, 0);
4663 TStreamerInfo *info = GetInfoImp();
4664 if (!info) {
4665 return;
4666 }
4667 R__PushCache onfileObject(b, fOnfileObject,
4668 1); // Here we have a single object that contains a variable size C-style array.
4669 // Since info is not null, fReadActionSequence is not null either.
4670 b.ApplySequence(*fReadActionSequence, fObject);
4671}
4672
4673////////////////////////////////////////////////////////////////////////////////
4674/// Read leaves into i/o buffers for this branch.
4675/// For split-class branch, base class branch, data member branch, or top-level branch.
4676/// which do not have a branch count and are a counter.
4677
4679{
4681 if (fObject == nullptr)
4682 {
4683 // We have nowhere to copy the data (probably because the data member was
4684 // 'dropped' from the current schema) so let's no copy it in a random place.
4685 return;
4686 }
4687
4688 // If not a TClonesArray or STL container master branch
4689 // or sub-branch and branch inherits from tobject,
4690 // then register with the buffer so that pointers are
4691 // handled properly.
4692 if (TestBit(kBranchObject)) {
4693 b.MapObject(reinterpret_cast<TObject*>(fObject));
4694 } else if (TestBit(kBranchAny)) {
4695 b.MapObject(fObject, fBranchClass);
4696 }
4697
4698 TStreamerInfo *info = GetInfoImp();
4699 if (!info) {
4700 return;
4701 }
4702
4703 R__PushCache onfileObject(b, fOnfileObject, 1);
4704
4705 // Since info is not null, fReadActionSequence is not null either.
4706 b.ApplySequence(*fReadActionSequence, fObject);
4707 fNdata = (Int_t) GetValue(0, 0);
4708}
4709
4710////////////////////////////////////////////////////////////////////////////////
4711/// Read leaves into i/o buffers for this branch.
4712/// Non TObject, Non collection classes with a custom streamer.
4713
4715{
4717 if (fObject == nullptr)
4718 {
4719 // We have nowhere to copy the data (probably because the data member was
4720 // 'dropped' from the current schema) so let's no copy it in a random place.
4721 return;
4722 }
4723
4724 R__PushCache onfileObject(b, fOnfileObject, 1);
4726}
4727
4728////////////////////////////////////////////////////////////////////////////////
4729/// Unconfiguration Fill Leave function.
4730
4732{
4733 Fatal("FillLeaves","The FillLeaves function has not been configured for %s",GetName());
4734}
4735
4736////////////////////////////////////////////////////////////////////////////////
4737/// Delete any object we may have allocated on a previous call to SetAddress.
4738
4740{
4741 if (fObject && TestBit(kDeleteObject)) {
4742 if (IsAutoDelete() && fAddress != reinterpret_cast<char*>(&fObject)) {
4743 *(reinterpret_cast<char**>(fAddress)) = nullptr;
4744 }
4746 if (fType == 3) {
4747 // -- We are a TClonesArray master branch.
4749 fObject = nullptr;
4752 // -- We are a pointer to a TClonesArray.
4753 // We must zero the pointer in the object.
4754 *(reinterpret_cast<char**>(fAddress)) = nullptr;
4755 }
4756 } else if (fType == 4) {
4757 // -- We are an STL container master branch.
4759
4760 if (!proxy) {
4761 Warning("ReleaseObject", "Cannot delete allocated STL container because I do not have a proxy! branch: %s", GetName());
4762 fObject = nullptr;
4763 } else {
4764 bool needDelete = proxy->GetProperties()&TVirtualCollectionProxy::kNeedDelete;
4765 if (needDelete && fID >= 0) {
4767 TStreamerElement* se = si->GetElement(fID);
4768 needDelete = !se->TestBit(TStreamerElement::kDoNotDelete);
4769 }
4770 if (needDelete) {
4772 proxy->Clear("force");
4773 }
4774 proxy->Destructor(fObject);
4775 fObject = nullptr;
4776 }
4778 // -- We are a pointer to an STL container.
4779 // We must zero the pointer in the object.
4780 *(reinterpret_cast<char**>(fAddress)) = nullptr;
4781 }
4782 } else {
4783 // We are *not* a TClonesArray master branch and we are *not* an STL container master branch.
4785 if (!cl) {
4786 Warning("ReleaseObject", "Cannot delete allocated object because I cannot instantiate a TClass object for its class! branch: '%s' class: '%s'", GetName(), fBranchClass.GetClassName());
4787 fObject = nullptr;
4788 } else {
4790
4791 if (proxy) {
4792 if (fID >= 0) {
4794 TStreamerElement* se = si->GetElement(fID);
4797 proxy->Clear("force");
4798 }
4801 proxy->Clear("force");
4802 }
4803
4804 }
4805 cl->Destructor(fObject);
4806 fObject = nullptr;
4807 }
4808 }
4809 }
4810}
4811
4812////////////////////////////////////////////////////////////////////////////////
4813/// Reset a Branch.
4814///
4815/// Existing i/o buffers are deleted.
4816/// Entries, max and min are reset.
4817///
4818
4820{
4821 Int_t nbranches = fBranches.GetEntriesFast();
4822 for (Int_t i = 0; i < nbranches; ++i) {
4823 TBranch* branch = static_cast<TBranch*>(fBranches[i]);
4824 branch->Reset(option);
4825 }
4826 fBranchID = -1;
4828}
4829
4830////////////////////////////////////////////////////////////////////////////////
4831/// Reset a Branch after a Merge operation (drop data but keep customizations)
4832///
4833
4835{
4836 Int_t nbranches = fBranches.GetEntriesFast();
4837 for (Int_t i = 0; i < nbranches; ++i) {
4838 TBranch* branch = static_cast<TBranch*>(fBranches[i]);
4839 branch->ResetAfterMerge(info);
4840 }
4842}
4843
4844////////////////////////////////////////////////////////////////////////////////
4845/// Set branch address to zero and free all allocated memory.
4846
4848{
4849 for (Int_t i = 0; i < fNleaves; ++i) {
4850 TLeaf* leaf = static_cast<TLeaf*>(fLeaves.UncheckedAt(i));
4851 //if (leaf) leaf->SetAddress(0);
4852 leaf->SetAddress(nullptr);
4853 }
4854
4855 // Note: We *must* do the sub-branches first, otherwise
4856 // we may delete the object containing the sub-branches
4857 // before giving them a chance to cleanup.
4858 Int_t nbranches = fBranches.GetEntriesFast();
4859 for (Int_t i = 0; i < nbranches; ++i) {
4860 TBranch* br = static_cast<TBranch*>(fBranches[i]);
4861 if (br) br->ResetAddress();
4862 }
4863
4864 //
4865 // SetAddress may have allocated an object.
4866 //
4867
4868 ReleaseObject();
4869
4871 fAddress = nullptr;
4872 fObject = nullptr;
4873}
4874
4875////////////////////////////////////////////////////////////////////////////////
4876/// Release ownership of any allocated objects.
4877///
4878/// Note: This interface was added so that clone trees could
4879/// be told they do not own the allocated objects.
4880
4882{
4885 for (Int_t i = 0; i < nb; ++i) {
4886 TBranch* br = static_cast<TBranch*>(fBranches[i]);
4888 static_cast<TBranchElement*>(br)->ResetDeleteObject();
4889 }
4890 }
4891}
4892
4893////////////////////////////////////////////////////////////////////////////////
4894/// \brief Reset offset and StreamerInfo information from this branch.
4895/// \param[in] recurse When true call ResetInitInfo on all subbranches.
4896///
4897
4899{
4900 fInfo = nullptr;
4901 fInit = false;
4902 fInitOffsets = false;
4903 fCurrentClass = nullptr;
4904 delete fReadActionSequence;
4905 fReadActionSequence = nullptr;
4906 delete fFillActionSequence;
4907 fFillActionSequence = nullptr;
4908
4909 if (recurse) {
4910 Int_t nbranches = fBranches.GetEntriesFast();
4911 for (Int_t i = 0; i < nbranches; ++i) {
4912 TBranchElement *sub = static_cast<TBranchElement*>(fBranches[i]);
4913 sub->ResetInitInfo(true);
4914 }
4915 }
4916}
4917
4918////////////////////////////////////////////////////////////////////////////////
4919/// Point this branch at an object.
4920///
4921/// For a sub-branch, addr is a pointer to the branch object.
4922///
4923/// For a top-level branch the meaning of addr is as follows:
4924///
4925/// If addr is zero, then we allocate a branch object
4926/// internally and the branch is the owner of the allocated
4927/// object, not the caller. However the caller may obtain
4928/// a pointer to the branch object with GetObject().
4929/// The pointer is reset to zero (nullptr) when the relevant
4930/// branch object is destroyed.
4931///
4932/// Example:
4933/// ~~~ {.cpp}
4934/// branch->SetAddress(0);
4935/// Event* event = branch->GetObject();
4936/// ... Do some work.
4937/// ~~~
4938/// If addr is not zero, but the pointer addr points at is
4939/// zero, then we allocate a branch object and set the passed
4940/// pointer to point at the allocated object. The caller
4941/// owns the allocated object and is responsible for deleting
4942/// it when it is no longer needed.
4943///
4944/// Example:
4945/// ~~~ {.cpp}
4946/// Event* event = 0;
4947/// branch->SetAddress(&event);
4948/// ... Do some work.
4949/// delete event;
4950/// event = 0;
4951/// ~~~
4952/// If addr is not zero and the pointer addr points at is
4953/// also not zero, then the caller has allocated a branch
4954/// object and is asking us to use it. The caller owns it
4955/// and must delete it when it is no longer needed.
4956///
4957/// Example:
4958/// ~~~ {.cpp}
4959/// Event* event = new Event();
4960/// branch->SetAddress(&event);
4961/// ... Do some work.
4962/// delete event;
4963/// event = 0;
4964/// ~~~
4965/// These rules affect users of TTree::Branch(),
4966/// TTree::SetBranchAddress(), and TChain::SetBranchAddress()
4967/// as well because those routines call this one.
4968///
4969/// An example of a tree with branches with objects allocated
4970/// and owned by us:
4971/// ~~~ {.cpp}
4972/// TFile* f1 = new TFile("myfile_original.root");
4973/// TTree* t1 = f1->Get<TTree>("MyTree");
4974/// TFile* f2 = new TFile("myfile_copy.root", "recreate");
4975/// TTree* t2 = t1->Clone(0);
4976/// for (Int_t i = 0; i < 10; ++i) {
4977/// t1->GetEntry(i);
4978/// t2->Fill();
4979/// }
4980/// t2->Write()
4981/// delete f2;
4982/// f2 = 0;
4983/// delete f1;
4984/// f1 = 0;
4985/// ~~~
4986/// An example of a branch with an object allocated by us,
4987/// but owned by the caller:
4988/// ~~~ {.cpp}
4989/// TFile* f = new TFile("myfile.root", "recreate");
4990/// TTree* t = new TTree("t", "A test tree.")
4991/// Event* event = 0;
4992/// TBranchElement* br = t->Branch("event.", &event);
4993/// for (Int_t i = 0; i < 10; ++i) {
4994/// ... Fill event with meaningful data in some way.
4995/// t->Fill();
4996/// }
4997/// t->Write();
4998/// delete event;
4999/// event = 0;
5000/// delete f;
5001/// f = 0;
5002/// ~~~
5003/// Notice that the only difference between this example
5004/// and the following example is that the event pointer
5005/// is zero when the branch is created.
5006///
5007/// An example of a branch with an object allocated and
5008/// owned by the caller:
5009/// ~~~ {.cpp}
5010/// TFile* f = new TFile("myfile.root", "recreate");
5011/// TTree* t = new TTree("t", "A test tree.")
5012/// Event* event = new Event();
5013/// TBranchElement* br = t->Branch("event.", &event);
5014/// for (Int_t i = 0; i < 10; ++i) {
5015/// ... Fill event with meaningful data in some way.
5016/// t->Fill();
5017/// }
5018/// t->Write();
5019/// delete event;
5020/// event = 0;
5021/// delete f;
5022/// f = 0;
5023/// ~~~
5024/// If AutoDelete is on (see TBranch::SetAutoDelete),
5025/// the top level objet will be deleted and recreate
5026/// each time an entry is read, whether or not the
5027/// TTree owns the object.
5028
5030{
5031 SetAddressImpl(addr, (addr == nullptr), 0);
5032}
5033
5034/// See TBranchElement::SetAddress.
5035/// If implied is true, we do not over-ride existing address for
5036/// sub-branches.
5037/// The `offset` is the offset of the sub-object within its parent,
5038/// it is already included in the addr but is still needed to be added
5039/// the OnfileObject address when/if we need to use that address.
5040void TBranchElement::SetAddressImpl(void* addr, bool implied, Int_t offset)
5041{
5042 //
5043 // Don't bother if we are disabled.
5044 //
5045
5046 if (TestBit(kDoNotProcess)) {
5047 return;
5048 }
5049
5050 //
5051 // FIXME: When would this happen?
5052 //
5053
5054 if (fType < -1) {
5055 return;
5056 }
5057
5058 //
5059 // Special case when called from code generated by TTree::MakeClass.
5060 //
5061
5062 if (Longptr_t(addr) == -1) {
5063 // FIXME: Do we have to release an object here?
5064 // ReleaseObject();
5065 fAddress = reinterpret_cast<char*>(-1);
5066 fObject = reinterpret_cast<char*>(-1);
5069 return;
5070 }
5071
5072 //
5073 // Reset last read entry number, we have a new user object now.
5074 //
5075
5076 fReadEntry = -1;
5077
5078 //
5079 // Make sure our branch class is instantiated.
5080 //
5081 TClass* clOfBranch = fBranchClass.GetClass();
5082 if( fTargetClass.GetClassName()[0] ) {
5083 clOfBranch = fTargetClass;
5084 }
5085
5086 //
5087 // Try to build the streamer info.
5088 //
5089
5090 TStreamerInfo *info = GetInfoImp();
5091
5092 // FIXME: Warn about failure to get the streamer info here?
5093
5094 //
5095 // We may have allocated an object last time we were called.
5096 //
5097
5098 if (fObject && TestBit(kDeleteObject)){
5099 ReleaseObject();
5100 }
5101
5102 //
5103 // Remember the pointer to the pointer to our object.
5104 //
5105
5106 fAddress = reinterpret_cast<char*>(addr);
5107 if (fAddress != reinterpret_cast<char*>(&fObject)) {
5108 fObject = nullptr;
5109 }
5112
5113 //
5114 // Do special stuff if we got called from a MakeClass class.
5115 // Allow sub-branches to have independently set addresses.
5116 //
5117
5118 if (TestBit(kDecomposedObj)) {
5119 if (fID > -1) {
5120 // We are *not* a top-level branch.
5121 if (!info) {
5122 // No streamer info, give up.
5123 // FIXME: We should have an error message here.
5124 fObject = fAddress;
5125 } else {
5126 // Compensate for the fact that the i/o routines
5127 // will add the streamer offset to the address.
5128 fObject = fAddress - info->TStreamerInfo::GetElementOffset(fID);
5129 }
5130 return;
5131 }
5132 }
5133
5134 //
5135 // Check whether the container type is still the same
5136 // to support schema evolution; what is written on the file
5137 // may no longer match the class code which is loaded.
5138 //
5139
5140 if (fType == 3) {
5141 // split TClonesArray, counter/master branch.
5142 TClass* clm = fClonesClass;
5143 if (clm) {
5144 // In case clm derives from an abstract class.
5145 clm->BuildRealData();
5146 clm->GetStreamerInfo();
5147 }
5148 TClass* newType = GetCurrentClass();
5149 if (newType && (newType != TClonesArray::Class())) {
5150 // The data type of the container has changed.
5151 //
5152 // Let's check if it is a compatible type:
5153 bool matched = false;
5154 if (newType->GetCollectionProxy()) {
5155 TClass *content = newType->GetCollectionProxy()->GetValueClass();
5156 if (clm == content) {
5157 matched = true;
5158 } else {
5159 Warning("SetAddress", "The type of %s was changed from TClonesArray to %s but the content do not match (was %s)!", GetName(), newType->GetName(), GetClonesName());
5160 }
5161 } else {
5162 Warning("SetAddress", "The type of the %s was changed from TClonesArray to %s but we do not have a TVirtualCollectionProxy for that container type!", GetName(), newType->GetName());
5163 }
5164 if (matched) {
5165 // Change from 3/31 to 4/41
5166 SetType(4);
5167 // Set the proxy.
5168 fSTLtype = newType->GetCollectionType();
5169 fCollProxy = newType->GetCollectionProxy()->Generate();
5170
5174
5177 } else if (IsAssociativeContainer(*fCollProxy)) {
5180 } else {
5182 }
5183 } else {
5184 // FIXME: Must maintain fObject here as well.
5185 fAddress = nullptr;
5187 }
5188 }
5189 } else if (fType == 4) {
5190 // split STL container, counter/master branch.
5191 TClass* newType = GetCurrentClass();
5192 if (newType && (newType != GetCollectionProxy()->GetCollectionClass())) {
5193 // Let's check if it is a compatible type:
5194 TVirtualCollectionProxy* newProxy = newType->GetCollectionProxy();
5196 if (newProxy && (oldProxy->GetValueClass() == newProxy->GetValueClass()) && ((!oldProxy->GetValueClass() && (oldProxy->GetType() == newProxy->GetType())) || (oldProxy->GetValueClass() && (oldProxy->HasPointers() == newProxy->HasPointers())))) {
5197 delete fCollProxy;
5198 Int_t nbranches = GetListOfBranches()->GetEntries();
5199 fCollProxy = newType->GetCollectionProxy()->Generate();
5201 for (Int_t i = 0; i < nbranches; ++i) {
5203 br->fCollProxy = nullptr;
5204 if (br->fReadActionSequence) {
5206 }
5207 if (br->fFillActionSequence) {
5209 }
5210 }
5215 delete fIterators;
5216 delete fPtrIterators;
5219 } else if (IsAssociativeContainer(*fCollProxy)) {
5222 } else {
5224 }
5225 }
5226 else if (newProxy && (oldProxy->HasPointers() == newProxy->HasPointers()) && (oldProxy->GetValueClass()!=nullptr) && (newProxy->GetValueClass()!=nullptr)) {
5227 // Let see if there is a rule to convert the content of the collection into each other.
5228 if (newType->GetSchemaRules()->HasRuleWithSourceClass( oldProxy->GetCollectionClass()->GetName())) {
5229 TClass *oldValueClass = oldProxy->GetValueClass();
5230 delete fCollProxy;
5231 Int_t nbranches = GetListOfBranches()->GetEntries();
5232 fCollProxy = newType->GetCollectionProxy()->Generate();
5234 for (Int_t i = 0; i < nbranches; ++i) {
5236 br->fCollProxy = nullptr;
5237 if (br->fBranchClass == oldValueClass) {
5239 }
5240 if (br->fReadActionSequence) {
5242 }
5243 if (br->fFillActionSequence) {
5245 }
5246 }
5251 delete fIterators;
5252 delete fPtrIterators;
5255 } else if (IsAssociativeContainer(*fCollProxy)) {
5258 } else {
5260 }
5261 } else {
5262 Error("SetAddress","For %s, we can not convert %s into %s\n",
5263 GetName(),oldProxy->GetCollectionClass()->GetName(),newType->GetName());
5264 fAddress = nullptr;
5265 fObject = nullptr;
5267 return;
5268 }
5269 }
5270 else if ((newType == TClonesArray::Class()) && (oldProxy->GetValueClass() && !oldProxy->HasPointers() && oldProxy->GetValueClass()->IsTObject()))
5271 {
5272 // The new collection and the old collection are not compatible,
5273 // we cannot use the new collection to read the data.
5274 // Actually we could check if the new collection is a
5275 // compatible ROOT collection.
5276
5277 // We cannot insure that the TClonesArray is set for the
5278 // proper class (oldProxy->GetValueClass()), so we assume that
5279 // the transformation was done properly by the class designer.
5280
5281 // Change from 4/41 to 3/31
5282 SetType(3);
5283 // Reset the proxy.
5284 fSTLtype = kNone;
5285 switch(fStreamerType) {
5289 break;
5293 break;
5296 break;
5297 }
5298 fClonesClass = oldProxy->GetValueClass();
5300 delete fCollProxy;
5301 fCollProxy = nullptr;
5302 TClass* clm = fClonesClass;
5303 if (clm) {
5304 clm->BuildRealData(); //just in case clm derives from an abstract class
5305 clm->GetStreamerInfo();
5306 }
5310 delete fIterators;
5311 fIterators = nullptr;
5312 delete fPtrIterators;
5313 fPtrIterators =nullptr;
5314 } else {
5315 // FIXME: We must maintain fObject here as well.
5316 Error("SetAddress","For %s can not convert %s into %s\n",GetName(),GetCurrentClass()->GetName(),newType->GetName());
5317 fAddress = nullptr;
5319 return;
5320 }
5321 } else {
5322 if (!fIterators && !fPtrIterators) {
5325 } else if (IsAssociativeContainer(*fCollProxy)) {
5328 } else {
5330 }
5331 }
5332 }
5333 }
5334
5335 //
5336 // Establish the semantics of fObject and fAddress.
5337 //
5338 // Top-level branch:
5339 // fObject is a ptr to the object,
5340 // fAddress is a ptr to a pointer to the object.
5341 //
5342 // Sub-branch:
5343 // fObject is a ptr to the object,
5344 // fAddress is the same as fObject.
5345 //
5346 //
5347 // There are special cases for TClonesArray and STL containers.
5348 // If there is no user-provided object, we allocate one. We must
5349 // also initialize any STL container proxy.
5350 //
5351
5352 if (fType == 3) {
5353 // -- We are a TClonesArray master branch.
5354 if (fAddress) {
5355 // -- We have been given a non-zero address, allocate if necessary.
5357 // -- We are *not* a top-level branch and we are *not* a pointer to a TClonesArray.
5358 // Case of an embedded TClonesArray.
5359 fObject = fAddress;
5360 // Check if it has already been properly built.
5361 TClonesArray* clones = reinterpret_cast<TClonesArray*>(fObject);
5362 if (!clones->GetClass()) {
5364 }
5365 } else {
5366 // -- We are either a top-level branch or we are a subbranch which is a pointer to a TClonesArray.
5367 // Streamer type should be -1 (for a top-level branch) or kObject(p|P) here.
5368 if ((fStreamerType != -1) &&
5371 Error("SetAddress", "TClonesArray with fStreamerType: %d", fStreamerType);
5372 } else if (fStreamerType == -1) {
5373 // -- We are a top-level branch.
5374 TClonesArray** pp = reinterpret_cast<TClonesArray**>(fAddress);
5375 if (!*pp) {
5376 // -- Caller wants us to allocate the clones array, but they will own it.
5377 *pp = new TClonesArray(fClonesClass);
5378 }
5379 fObject = reinterpret_cast<char*>(*pp);
5380 } else {
5381 // -- We are a pointer to a TClonesArray.
5382 // Note: We do this so that the default constructor,
5383 // or the i/o constructor can be lazy.
5384 TClonesArray** pp = reinterpret_cast<TClonesArray**>(fAddress);
5385 if (!*pp) {
5386 // -- Caller wants us to allocate the clones array, but they will own it.
5387 *pp = new TClonesArray(fClonesClass);
5388 }
5389 fObject = reinterpret_cast<char*>(*pp);
5390 }
5391 }
5392 } else {
5393 // -- We have been given a zero address, allocate for top-level only.
5395 // -- We are *not* a top-level branch and we are *not* a pointer to a TClonesArray.
5396 // Case of an embedded TClonesArray.
5397 Error("SetAddress", "Embedded TClonesArray given a zero address for branch '%s'", GetName());
5398 } else {
5399 // -- We are either a top-level branch or we are a subbranch which is a pointer to a TClonesArray.
5400 // Streamer type should be -1 (for a top-level branch) or kObject(p|P) here.
5401 if ((fStreamerType != -1) &&
5404 Error("SetAddress", "TClonesArray with fStreamerType: %d", fStreamerType);
5405 } else if (fStreamerType == -1) {
5406 // -- We are a top-level branch.
5407 // Idea: Consider making a zero address not allocate.
5409 fObject = reinterpret_cast<char*>(new TClonesArray(fClonesClass));
5410 fAddress = reinterpret_cast<char*>(&fObject);
5411 } else {
5412 // -- We are a sub-branch which is a pointer to a TClonesArray.
5413 Error("SetAddress", "Embedded pointer to a TClonesArray given a zero address for branch '%s'", GetName());
5414 }
5415 }
5416 }
5417 } else if (fType == 4) {
5418 // -- We are an STL container master branch.
5419 //
5420 // Initialize fCollProxy.
5422 if (fAddress) {
5423 // -- We have been given a non-zero address, allocate if necessary.
5427 // We are *not* a top-level branch and we are *not* a pointer to an STL container.
5428 // Case of an embedded STL container.
5429 // Note: We test for the kObject and kAny types to support
5430 // the (unwise) choice of inheriting from an STL container.
5431 fObject = fAddress;
5432 } else {
5433 // We are either a top-level branch or subbranch which is a pointer to an STL container.
5434 // Streamer type should be -1 (for a top-level branch) or kSTLp here.
5436 Error("SetAddress",
5437 "Branch %s is a split STL container (fStreamerType is: %d), the address can not be set directly.",
5439 } else if (fStreamerType == -1) {
5440 // -- We are a top-level branch.
5441 void** pp = reinterpret_cast<void**>(fAddress);
5442 if (!*pp) {
5443 // -- Caller wants us to allocate the STL container, but they will own it.
5444 *pp = proxy->New();
5445 if (!(*pp)) {
5446 Error("SetAddress", "Failed to allocate STL container for branch '%s'", GetName());
5447 // FIXME: Should we do this? Lots of other code wants
5448 // fAddress to be zero if no fObject, but is
5449 // that a good thing?
5450 fAddress = nullptr;
5452 }
5453 }
5454 fObject = reinterpret_cast<char*>(*pp);
5455 } else {
5456 // -- We are a pointer to an STL container.
5457 // Note: We do this so that the default constructor,
5458 // or the i/o constructor can be lazy.
5459 void** pp = reinterpret_cast<void**>(fAddress);
5460 if (!*pp) {
5461 // -- Caller wants us to allocate the STL container, but they will own it.
5462 *pp = proxy->New();
5463 if (!(*pp)) {
5464 Error("SetAddress", "Failed to allocate STL container for branch '%s'", GetName());
5465 // FIXME: Should we do this? Lots of other code wants
5466 // fAddress to be zero if no fObject, but is
5467 // that a good thing?
5468 fAddress = nullptr;
5470 }
5471 }
5472 fObject = reinterpret_cast<char*>(*pp);
5473 }
5474 }
5475 } else {
5476 // -- We have been given a zero address, allocate for top-level only.
5480 // We are *not* a top-level branch and we are *not* a pointer to an STL container.
5481 // Case of an embedded STL container.
5482 // Note: We test for the kObject and kAny types to support
5483 // the (unwise) choice of inheriting from an STL container.
5484 Error("SetAddress", "Embedded STL container given a zero address for branch '%s'", GetName());
5485 } else {
5486 // We are either a top-level branch or sub-branch which is a pointer to an STL container.
5487 // Streamer type should be -1 (for a top-level branch) or kSTLp here.
5489 Error("SetAddress",
5490 "Branch %s is a split STL container (fStreamerType is: %d), the address can not be set directly.",
5492 } else if (fStreamerType == -1) {
5493 // -- We are a top-level branch, allocate.
5495 fObject = reinterpret_cast<char*>(proxy->New());
5496 if (fObject) {
5497 fAddress = reinterpret_cast<char*>(&fObject);
5498 } else {
5499 Error("SetAddress", "Failed to allocate STL container for branch '%s'", GetName());
5500 // FIXME: Should we do this? Lots of other code wants
5501 // fAddress to be zero if no fObject, but is
5502 // that a good thing?
5503 fAddress = nullptr;
5505 }
5506 } else {
5507 // -- We are a sub-branch which is a pointer to an STL container.
5508 Error("SetAddress", "Embedded pointer to an STL container given a zero address for branch '%s'", GetName());
5509 }
5510 }
5511 }
5512 } else if (fType == 41) {
5513 // -- We are an STL container sub-branch.
5514 // Initialize fCollProxy.
5516 // We are not at top-level branch.
5517 fObject = fAddress;
5518 } else if (fID < 0) {
5519 // -- We are a top-level branch.
5520 char** pp = reinterpret_cast<char**>(fAddress);
5521 if (pp && *pp) {
5522 // -- Caller provided an i/o buffer for us to use.
5523 fObject = *pp;
5524 } else {
5525 // -- Caller did not provide an i/o buffer for us to use, we must make one for ourselves.
5526 if (clOfBranch) {
5527 if (!pp) {
5528 // -- Caller wants us to own the object.
5530 }
5531 fObject = reinterpret_cast<char*>(clOfBranch->New());
5532 if (pp) {
5533 *pp = fObject;
5534 } else {
5535 fAddress = reinterpret_cast<char*>(&fObject);
5536 }
5537 } else {
5538 Error("SetAddress", "I have no TClass for branch %s, so I cannot allocate an I/O buffer!", GetName());
5539 if (pp) {
5540 fObject = nullptr;
5541 *pp = nullptr;
5542 }
5543 }
5544 }
5545 } else {
5546 // -- We are *not* a top-level branch.
5547 fObject = fAddress;
5548 }
5549
5550 if (!info) {
5551 // FIXME: We need and error message here, no streamer info, so cannot set offsets.
5552 return;
5553 }
5554
5555 // We do this only once because it depends only on
5556 // the type of our object, not on its address.
5557 if (!fInitOffsets) {
5559 }
5560
5561 // We are split, recurse down to our sub-branches.
5562 //
5563 // FIXME: This is a tail recursion, we burn stack.
5564 Int_t nbranches = fBranches.GetEntriesFast();
5565 char *localObject = fObject;
5566 if (fOnfileObject && this != GetMother()) {
5567 localObject = fOnfileObject->GetObjectAt(0) + offset;
5568 }
5569 for (Int_t i = 0; i < nbranches; ++i) {
5570 TBranch *abranch = static_cast<TBranch*>(fBranches.UncheckedAt(i));
5571 // FIXME: This is a tail recursion!
5572 if (fBranchOffset[i] != TStreamerInfo::kMissing && !(implied && abranch->TestBit(kAddressSet))) {
5573 abranch->SetAddressImpl(localObject + fBranchOffset[i], implied, fBranchOffset[i]);
5574 abranch->SetBit(kAddressSet);
5575 if (TestBit(kDecomposedObj) != abranch->TestBit(kDecomposedObj))
5577 } else {
5578 // When the member is missing, just leave the address alone
5579 // (since setting explicitly to 0 would trigger error/warning
5580 // messages).
5581 // abranch->SetAddress(0);
5582 abranch->SetBit(kAddressSet);
5583 }
5584 }
5585}
5586
5587////////////////////////////////////////////////////////////////////////////////
5588/// Reset the basket size for all sub-branches of this branch element.
5589
5591{
5592 TBranch::SetBasketSize(bufsize);
5593 Int_t nbranches = fBranches.GetEntriesFast();
5594 for (Int_t i = 0; i < nbranches; ++i) {
5595 TBranch* branch = static_cast<TBranch*>(fBranches[i]);
5596 branch->SetBasketSize(fBasketSize);
5597 }
5598}
5599
5600////////////////////////////////////////////////////////////////////////////////
5601/// Set the branch counter for this branch.
5602
5604{
5605 fBranchCount = brOfCounter;
5606 if (fBranchCount==nullptr) return;
5607
5608 TLeafElement* leafOfCounter = static_cast<TLeafElement*>(brOfCounter->GetListOfLeaves()->At(0));
5609 TLeafElement* leaf = static_cast<TLeafElement*>(GetListOfLeaves()->At(0));
5610 if (leafOfCounter && leaf) {
5611 leaf->SetLeafCount(leafOfCounter);
5612 } else {
5613 if (!leafOfCounter) {
5614 Warning("SetBranchCount", "Counter branch %s for branch %s has no leaves!", brOfCounter->GetName(), GetName());
5615 }
5616 if (!leaf) {
5617 Warning("SetBranchCount", "Branch %s has no leaves!", GetName());
5618 }
5619 }
5620}
5621
5622////////////////////////////////////////////////////////////////////////////////
5623/// Set the branch in a mode where the object are decomposed
5624/// (Also known as MakeClass mode).
5625/// Return whether the setting was possible (it is not possible for
5626/// TBranch and TBranchObject).
5627
5628bool TBranchElement::SetMakeClass(bool decomposeObj)
5629{
5630 if (decomposeObj)
5631 SetBit(kDecomposedObj); // Same as SetBit(kMakeClass)
5632 else
5634
5635 Int_t nbranches = fBranches.GetEntriesFast();
5636 for (Int_t i = 0; i < nbranches; ++i) {
5637 TBranchElement* branch = static_cast<TBranchElement*>(fBranches[i]);
5638 branch->SetMakeClass(decomposeObj);
5639 }
5642
5643 return true;
5644}
5645
5646////////////////////////////////////////////////////////////////////////////////
5647/// Set object this branch is pointing to.
5648
5650{
5651 if (TestBit(kDoNotProcess)) {
5652 return;
5653 }
5654 fObject = reinterpret_cast<char*>(obj);
5655 SetAddress( &fObject );
5656}
5657
5658////////////////////////////////////////////////////////////////////////////////
5659/// Set offset of the object (to which the data member represented by this
5660/// branch belongs) inside its containing object (if any).
5661
5663{
5664 // We need to make sure that the Read and Write action's configuration
5665 // properly reflect this value.
5666
5668 SetMissing();
5669 return;
5670 }
5671
5672 if (fReadActionSequence) {
5674 }
5675 if (fFillActionSequence) {
5677 }
5678 fOffset = offset;
5679}
5680
5681////////////////////////////////////////////////////////////////////////////////
5682/// Set offset of the object (to which the data member represented by this
5683/// branch belongs) inside its containing object (if any) to mark it as missing.
5684
5686{
5687 // We need to make sure that the Read and Write action's configuration
5688 // properly reflect this value.
5689
5690 if (fReadActionSequence) {
5692 }
5693 if (fFillActionSequence) {
5695 }
5697}
5698
5699
5700////////////////////////////////////////////////////////////////////////////////
5701/// Set the sequence of actions needed to read the data out of the buffer.
5703{
5704 // A 'split' node does not store data itself (it has not associated baskets)
5705 const bool isSplitNode = (fType == 3 || fType == 4 || fType == 2 || fType == 1 || (fType == 0 && fID == -2)) && !fBranches.IsEmpty();
5706
5707 if (!isSplitNode) {
5708 fNewIDs.insert(fNewIDs.begin(),fID); // Include the main element in the sequence.
5709 }
5710
5711 if (actionSequence) delete actionSequence;
5712 auto original = create(localInfo, GetCollectionProxy(), originalClass);
5713
5714 actionSequence = original->CreateSubSequence(fNewIDs, fOffset, create);
5715
5716 if (!isSplitNode)
5717 fNewIDs.erase(fNewIDs.begin());
5718
5719 else if (fInitOffsets && fType != 3 && fType != 4) {
5720 // fObject has the address of the sub-object but the streamer action have
5721 // offset relative to the parent.
5722
5723 // Note: We skipped this for the top node of split collection because the
5724 // sequence is about the content, we need to review what happens where an
5725 // action related to the collection itself will land.
5726 TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
5727
5728 auto index = parent->fBranches.IndexOf(this);
5729 if (index >= 0) {
5730 actionSequence->AddToOffset( - parent->fBranchOffset[index] );
5731 }
5732 } // else it will be done by InitOffsets
5733}
5734
5735////////////////////////////////////////////////////////////////////////////////
5736/// Set the sequence of actions needed to read the data out of the buffer.
5738{
5739 if (fInfo == nullptr) {
5740 // We are called too soon. We will be called again by InitInfo
5741 return;
5742 }
5743
5745 TClass *originalClass = nullptr;
5746 TStreamerInfo *localInfo = fInfo;
5747 if (fType == 41) {
5750 } else {
5752 if (GetParentClass() == info->GetClass()) {
5754 originalClass = fBranchClass;
5756 } else {
5758 }
5759 } else if (GetCollectionProxy()) {
5760 // Base class and embedded objects.
5762 }
5763 }
5764 } else if (fType == 31) {
5766 } else if (0<=fType && fType<=2) {
5767 // Note: this still requires the ObjectWise sequence to not be optimized!
5769 } else if ( fType == 4 && !fNewIDs.empty()) {
5772 } else if ( fType == 3 && !fNewIDs.empty()) {
5775 }
5776
5777 if (create) {
5778 SetActionSequence(originalClass, localInfo, create, fReadActionSequence);
5779 }
5780}
5781
5782////////////////////////////////////////////////////////////////////////////////
5783/// Set the ReadLeaves pointer to execute the expected operations.
5784
5786{
5787 if (TestBit(kDecomposedObj)) {
5789 } else if (fType == 4) {
5791 } else if (fType == 41) {
5795 } else {
5797 }
5798 } else {
5800 }
5801 } else if (fType == 3) {
5803 } else if (fType == 31) {
5805 } else if (fType < 0) {
5807 } else if (fType == 0 && fID == -1) {
5808 // top-level branch.
5810 if (hasCustomStreamer) {
5811 // We are in the case where the object did *not* have a custom
5812 // Streamer when the TTree was written but now *does* have a custom
5813 // Streamer thus we must use it.
5815 } else {
5817 }
5818 } else if (fType <= 2) {
5819 // split-class branch, base class branch or data member branch.
5820 if (fBranchCount) {
5824 } else {
5826 }
5827 } else {
5828 Fatal("SetReadLeavePtr","Unexpected branch type %d for %s",fType,GetName());
5829 }
5830
5832}
5833
5834////////////////////////////////////////////////////////////////////////////////
5835/// Set the sequence of actions needed to write the data out from the buffer.
5836
5838{
5839 if (fInfo == nullptr) {
5840 // We are called too soon. We will be called again by InitInfo
5841 return;
5842 }
5843
5845 TClass *originalClass = nullptr;
5846 TStreamerInfo *localInfo = fInfo;
5847 if (fType == 41) {
5850 } else {
5852 if (GetParentClass() == info->GetClass()) {
5853 // if( fTargetClass.GetClassName()[0] && fBranchClass != fTargetClass ) {
5854 // originalClass = fBranchClass;
5855 // create = TStreamerInfoActions::TActionSequence::ConversionWriteMemberWiseActionsViaProxyGetter;
5856 // } else {
5858 // }
5859 } else if (GetCollectionProxy()) {
5860 // Base class and embedded objects.
5862 }
5863 }
5864 } else if (fType == 31) {
5866 } else if (0<=fType && fType<=2) {
5867 // Note: this still requires the ObjectWise sequence to not be optimized!
5869 } else if ( fType == 4 && !fNewIDs.empty()) {
5872 } else if ( fType == 3 && !fNewIDs.empty()) {
5875 }
5876
5877 if (create) {
5878 SetActionSequence(originalClass, localInfo, create, fFillActionSequence);
5879 }
5880}
5881
5882////////////////////////////////////////////////////////////////////////////////
5883/// Set the FillLeaves pointer to execute the expected operations.
5884
5886{
5887 if (TestBit(kDecomposedObj) && ((fType==3)||(fType==31))) {
5889 } else if (fType == 4) {
5891 } else if (fType == 41) {
5895 } else {
5897 }
5898 } else if (IsAssociativeContainer(*GetCollectionProxy())) {
5900 } else {
5902 }
5903 } else if (fType == 3) {
5905 } else if (fType == 31) {
5907 } else if (fType < 0) {
5909 } else if (fType <=2) {
5910 //split-class branch, base class branch, data member branch, or top-level branch.
5911 if (fBranchCount) {
5915 } else {
5917 }
5918 } else {
5919 Fatal("SetFillLeavePtr","Unexpected branch type %d for %s",fType,GetName());
5920 }
5921
5923}
5924
5925////////////////////////////////////////////////////////////////////////////////
5926/// Set the name of the class of the in-memory object into which the data will
5927/// loaded.
5928
5930{
5931 if (name == nullptr) return;
5932
5933 if (strcmp(fTargetClass.GetClassName(),name) != 0 )
5934 {
5935 // We are changing target class, let's reset the meta information and
5936 // the sub-branches.
5937
5938 ResetInitInfo(/*recurse=*/ false);
5939
5940 Int_t nbranches = fBranches.GetEntriesFast();
5941 for (Int_t i = 0; i < nbranches; ++i) {
5942 TBranchElement *sub = static_cast<TBranchElement*>(fBranches[i]);
5943
5944 if (sub->fTargetClass == fTargetClass ) {
5945 sub->SetTargetClass(name);
5946 } else {
5947 // Since the top level changes, the StreamerInfo (in particular for split collection)
5948 // may still need to change (and the info might be updated else (see for example SetAddress for the
5949 // the case fType 4/41)
5950 sub->ResetInitInfo(true);
5951 }
5952 if (sub->fParentClass == fTargetClass ) {
5954 }
5955 }
5957 }
5958
5959}
5960
5961////////////////////////////////////////////////////////////////////////////////
5962/// If the branch address is not set, we set all addresses starting with
5963/// the top level parent branch. This is required to be done in order for
5964/// GetOffset to be correct and for GetEntry to run.
5965
5967{
5968 // Check to see if the user changed the branch address on us.
5970
5972 // -- Do nothing if already setup or if we are a MakeClass branch.
5973 return;
5974 }
5976}
5977
5978////////////////////////////////////////////////////////////////////////////////
5979/// If the branch address is not set, we set all addresses starting with
5980/// the top level parent branch. This is required to be done in order for
5981/// GetOffset to be correct and for GetEntry to run.
5982
5984{
5985 if (TestBit((long)kDoNotProcess|(long)kAddressSet)) {
5986 // -- Do nothing if we have been told not to.
5987 // Or the data member in this branch is not longer part of the
5988 // parent's layout.
5989 return;
5990 }
5991
5992 //--------------------------------------------------------------------------
5993 // Check if we are splited STL collection of pointers
5994 /////////////////////////////////////////////////////////////////////////////
5995
5997 {
5998 TBranchElement *parent = static_cast<TBranchElement*>(GetMother()->GetSubBranch( this ));
5999
6000 // Make sure the StreamerInfo is loaded and initialized.
6001 GetInfoImp();
6002
6003 if( !parent->GetAddress() )
6004 parent->SetAddress( nullptr );
6005 return;
6006 }
6007
6008 //--------------------------------------------------------------------------
6009 // Any other case
6010 /////////////////////////////////////////////////////////////////////////////
6011
6012 TBranchElement* mother = static_cast<TBranchElement*>(GetMother());
6013 if (!mother) {
6014 return;
6015 }
6016 TClass* cl = TClass::GetClass(mother->GetClassName());
6017
6018 // Make sure the StreamerInfo is loaded and initialized.
6019 GetInfoImp();
6020
6021 if (!cl) {
6022 return;
6023 }
6024
6025 if (!mother->GetAddress()) {
6026 // -- Our top-level branch has no address.
6027 bool motherStatus = mother->TestBit(kDoNotProcess);
6028 mother->ResetBit(kDoNotProcess);
6029 // Note: This will allocate an object.
6030 mother->SetAddress(nullptr);
6031 mother->SetBit(kDoNotProcess, motherStatus);
6032 }
6033}
6034
6035////////////////////////////////////////////////////////////////////////////////
6036/// Stream an object of class TBranchElement.
6037
6039{
6040 if (R__b.IsReading()) {
6046 // The fAddress and fObject data members are not persistent,
6047 // therefore we do not own anything.
6048 // Also clear the bit possibly set by the schema evolution.
6050 // Fixup a case where the TLeafElement was missing
6051 if ((fType == 0) && (fLeaves.GetEntriesFast() == 0)) {
6052 TLeaf* leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
6053 leaf->SetTitle(GetTitle());
6054 fNleaves = 1;
6055 fLeaves.Add(leaf);
6056 fTree->GetListOfLeaves()->Add(leaf);
6057 }
6058
6059 // SetReadLeavesPtr();
6060 }
6061 else {
6062 TDirectory* dirsav = fDirectory;
6063 fDirectory = nullptr; // to avoid recursive calls
6064 {
6065 // Save class version.
6066 Int_t classVersion = fClassVersion;
6067 // Record only positive 'version number'
6068 if (fClassVersion < 0) {
6070 }
6071 // TODO: Should we clear the kDeleteObject bit before writing?
6072 // If we did we would have to remember the old value and
6073 // put it back, we wouldn't want to forget that we owned
6074 // something just because we got written to disk.
6076 // Restore class version.
6077 fClassVersion = classVersion;
6078 }
6079 //
6080 // Mark all streamer infos used by this branch element
6081 // to be written to our output file.
6082 //
6083 {
6084 R__b.ForceWriteInfo(GetInfoImp(), true);
6085 }
6086 //
6087 // If we are a clones array master branch, or an
6088 // STL container master branch, we must also mark
6089 // the streamer infos used by the value class to
6090 // be written to our output file.
6091 //
6092 if (fType == 3) {
6093 // -- TClonesArray, counter/master branch
6094 //
6095 // We must mark the streamer info for the
6096 // value class to be written to the file.
6097 //
6098 TClass* cl = fClonesClass;
6099 if (cl) {
6100 R__b.ForceWriteInfo(cl->GetStreamerInfo(), true);
6101 }
6102 }
6103 else if (fType == 4) {
6104 // -- STL container, counter/master branch
6105 //
6106 // We must mark the streamer info for the
6107 // value class to be written to the file.
6108 //
6110 if (cp) {
6111 TClass* cl = cp->GetValueClass();
6112 if (cl) {
6113 R__b.ForceWriteInfo(cl->GetStreamerInfo(), true);
6114 }
6115 }
6116 }
6117 // If we are in a separate file, then save
6118 // ourselves as an independent key.
6119 if (!dirsav) {
6120 // Note: No need to restore fDirectory, it was already zero.
6121 return;
6122 }
6123 if (!dirsav->IsWritable()) {
6124 fDirectory = dirsav;
6125 return;
6126 }
6127 TDirectory* pdirectory = fTree->GetDirectory();
6128 if (!pdirectory) {
6129 fDirectory = dirsav;
6130 return;
6131 }
6132 const char* treeFileName = pdirectory->GetFile()->GetName();
6133 TBranch* mother = GetMother();
6134 const char* motherFileName = treeFileName;
6135 if (mother && (mother != this)) {
6136 motherFileName = mother->GetFileName();
6137 }
6138 if ((fFileName.Length() > 0) && strcmp(motherFileName, fFileName.Data())) {
6139 dirsav->WriteTObject(this);
6140 }
6141 fDirectory = dirsav;
6142 }
6143}
6144
6145
6146////////////////////////////////////////////////////////////////////////////////
6147/// Split class cl into sub-branches of this branch.
6148///
6149/// This version of Unroll was formerly embedded in TTree::BronchExec
6150/// It is moved here so we can make sure to call SetReadActionSequence.
6151
6152void TBranchElement::Unroll(const char *name, TClass *cl, TStreamerInfo *sinfo, char* objptr, Int_t bufsize, Int_t splitlevel)
6153{
6154 //
6155 // Do we have a final dot in our name?
6156 //
6157
6158 // Note: The branch constructor which takes a folder as input
6159 // creates top-level branch names with dots in them to
6160 // indicate the folder hierarchy.
6161 const char* dot = strchr(name, '.');
6162 Int_t nch = strlen(name);
6163 bool dotlast = false;
6164 if (nch && (name[nch-1] == '.')) {
6165 dotlast = true;
6166 }
6167
6168 // Loop on all public data members of the class and its base classes and create branches for each one.
6169 TObjArray* blist = this->GetListOfBranches();
6170 TIter next(sinfo->GetElements());
6171 TStreamerElement* element = nullptr;
6172 TString bname;
6173 for (Int_t id = 0; (element = static_cast<TStreamerElement*>(next())); ++id) {
6174 if (element->IsA() == TStreamerArtificial::Class()) {
6175 continue;
6176 }
6177 if (element->TestBit(TStreamerElement::kRepeat)) {
6178 continue;
6179 }
6181 continue;
6182 }
6183 char* pointer = (objptr + element->GetOffset());
6184 // FIXME: This is not good enough, an STL container can be
6185 // a base, and the test will fail.
6186 // See TBranchElement::InitializeOffsets() for the
6187 // correct test.
6188 bool isBase = (element->IsA() == TStreamerBase::Class());
6189 if (isBase) {
6190 TClass* clbase = element->GetClassPointer();
6191 if ((clbase == TObject::Class()) && cl->CanIgnoreTObjectStreamer()) {
6192 // Note: TStreamerInfo::Compile() leaves this element
6193 // out of the optimized info, although it does
6194 // exists in the non-compiled and non-optimized info.
6195 // FIXME: The test that TStreamerInfo::Compile() uses
6196 // is element->GetType() < 0, so that is what
6197 // we should do as well.
6198 continue;
6199 }
6200 if (clbase->GetListOfRealData()->GetSize() == 0) {
6201 // Do not create a branch for empty bases.
6202 continue;
6203 }
6204 }
6205 if (dot) {
6206 if (dotlast) {
6207 bname.Form("%s%s", name, element->GetFullName());
6208 } else {
6209 // FIXME: We are in the case where we have a top-level
6210 // branch name that was created by the branch
6211 // constructor which takes a folder as input.
6212 // The internal dots in the name are in place of
6213 // of the original slashes and represent the
6214 // folder hierarchy.
6215 if (isBase) {
6216 // FIXME: This is very strange, this is the only case where
6217 // we create a branch for a base class that does
6218 // not have the base class name in the branch name.
6219 // FIXME: This is also quite bad since classes with two
6220 // or more base classes end up with sub-branches
6221 // that have the same name.
6222 bname = name;
6223 } else {
6224 bname.Form("%s.%s", name, element->GetFullName());
6225 }
6226 }
6227 } else {
6228 // Note: For a base class element, this results in the branchname
6229 // being the name of the base class.
6230 bname.Form("%s", element->GetFullName());
6231 }
6232
6233 if( splitlevel > TTree::kSplitCollectionOfPointers && element->GetClass() &&
6234 element->GetClass()->GetCollectionProxy() &&
6235 element->GetClass()->GetCollectionProxy()->HasPointers() )
6236 {
6237 TBranchSTL* brSTL = new TBranchSTL(this, bname, element->GetClass()->GetCollectionProxy(), bufsize, splitlevel-1, sinfo, id );
6238 blist->Add(brSTL);
6239 }
6240 else
6241 {
6242 TBranchElement* bre = new TBranchElement(this, bname, sinfo, id, pointer, bufsize, splitlevel - 1);
6243 bre->SetParentClass(cl);
6244 blist->Add(bre);
6245 }
6246 }
6247 // Now that we know that this branch is split, let's redo the actions.
6250}
6251
6252////////////////////////////////////////////////////////////////////////////////
6253/// Split class cl into sub-branches of this branch.
6254///
6255/// Create a sub-branch of this branch for each non-empty,
6256/// non-abstract base class of cl (unless we are a sub-branch
6257/// of a TClonesArray or an STL container, in which case we
6258/// do *not* create a sub-branch), and for each non-split data
6259/// member of cl.
6260///
6261/// Note: We do *not* create sub-branches for base classes of cl
6262/// if we are a sub-branch of a TClonesArray or an STL container.
6263///
6264/// Note: We do *not* create sub-branches for data members which
6265/// have a class type and which we are splitting.
6266///
6267/// Note: The above rules imply that the branch hierarchy increases
6268/// in depth only for base classes of cl (unless we are inside
6269/// of a TClonesArray or STL container, in which case the depth
6270/// does *not* increase, the base class is elided) and for
6271/// TClonesArray or STL container data members (which have one
6272/// additional level of sub-branches). The only other way the
6273/// depth increases is when the top-level branch has a split
6274/// class data member, in that case the constructor will create
6275/// a sub-branch for it. In other words, the interior nodes of
6276/// the branch tree are all either: base class nodes; split
6277/// class nodes which are direct sub-branches of top-level nodes
6278/// (created by TClass::Bronch usually); or TClonesArray or STL
6279/// container master nodes.
6280///
6281/// Note: The exception to the above is for the top-level branches,
6282/// Tree::Bronch creates nodes for everything in that case,
6283/// except for a TObject base class of a class which has the
6284/// can ignore tobject streamer flag set.
6285
6286Int_t TBranchElement::Unroll(const char* name, TClass* clParent, TClass* cl, char* ptr, Int_t basketsize, Int_t splitlevel, Int_t btype)
6287{
6288 //----------------------------------------------------------------------------
6289 // Handling the case of STL collections of pointers
6290 /////////////////////////////////////////////////////////////////////////////
6291
6292 Int_t splitSTLP = splitlevel - (splitlevel%TTree::kSplitCollectionOfPointers);
6294
6295 TString branchname;
6296
6297 if ((cl == TObject::Class()) && clParent->CanIgnoreTObjectStreamer()) {
6298 return 0;
6299 }
6300
6302
6303 //
6304 // Do nothing if we couldn't build the streamer info for cl.
6305 //
6306
6307 if (!sinfo) {
6308 return 0;
6309 }
6310
6311 const auto namelen = strlen(name);
6312 bool dotlast = (namelen && (name[namelen-1] == '.'));
6313
6314 Int_t ndata = sinfo->GetNelement();
6315
6316 if ((ndata == 1) && cl->GetCollectionProxy() && !strcmp(sinfo->GetElement(0)->GetName(), "This")) {
6317 // -- Class cl is an STL collection, refuse to split it.
6318 // Question: Why? We certainly could by switching to the value class.
6319 // Partial Answer: Only the branch element constructor can split STL containers.
6320 return 1;
6321 }
6322
6323 for (Int_t elemID = 0; elemID < ndata; ++elemID) {
6324 // -- Loop over all the streamer elements and create sub-branches as needed.
6325 TStreamerElement* elem = sinfo->GetElement(elemID);
6326 if (elem->IsA() == TStreamerArtificial::Class()) {
6327 continue;
6328 }
6330 continue;
6331 }
6333 continue;
6334 }
6335 Int_t offset = elem->GetOffset();
6336 // FIXME: An STL container as a base class gets TStreamerSTL as its class, so this test is not enough.
6337 // See InitializeOffsets() for the proper test.
6338 if (elem->IsA() == TStreamerBase::Class()) {
6339 // -- This is a base class of cl.
6340 TClass* clOfBase = elem->GetClassPointer();
6341 if (!clOfBase || ((clOfBase->Property() & kIsAbstract) && cl->InheritsFrom(TCollection::Class()))) {
6342 // -- Do nothing if we are one of the abstract collection (we know they have no data).
6343 return -1;
6344 }
6345 if ((btype == 31) || (btype == 41)) {
6346 // -- Elide the base-class sub-branches of a split TClonesArray or STL container.
6347 //
6348 // Note: We are eliding the base class here, that is, we never
6349 // create a branch for it, so the branch hierarchy is not
6350 // complete.
6351 // Note: The clParent parameter is the value class of the
6352 // container which we are splitting. It does not
6353 // appear in the branch hierarchy either.
6354 // Note: We can use parent class (clParent) != branch class (elemClass) to detection elision.
6355 Int_t unroll = -1;
6356 if (!elem->CannotSplit() || clOfBase == TObject::Class()) {
6357 unroll = Unroll(name, clParent, clOfBase, ptr + offset, basketsize, splitlevel+splitSTLP, btype);
6358 }
6359 if (unroll < 0) {
6360 // FIXME: We could not split because we are abstract, should we be doing this?
6361 if (namelen) {
6362 branchname.Form("%s%s%s", name, dotlast ? "" : ".", elem->GetFullName());
6363 } else {
6364 branchname.Form("%s", elem->GetFullName());
6365 }
6366 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, nullptr, basketsize, 0, btype);
6367 branch->SetParentClass(clParent);
6368 fBranches.Add(branch);
6369 }
6370 } else if (clOfBase->GetListOfRealData()->GetSize()) {
6371 // -- Create a branch for a non-empty base class.
6372 if (namelen) {
6373 branchname.Form("%s%s%s", name, dotlast ? "" : ".", elem->GetFullName());
6374 // Elide the base class name when creating the sub-branches.
6375 // Note: The branch names for sub-branches of a base class branch
6376 // do not represent the full class hierarchy because we do
6377 // this, however it does keep the branch names for the
6378 // inherited data members simple.
6379 TBranchElement* branch = new TBranchElement(this, name, sinfo, elemID, ptr + offset, basketsize, splitlevel+splitSTLP, btype);
6380 // Then reset it to the proper name.
6381 branch->SetName(branchname);
6382 branch->SetTitle(branchname);
6383 branch->SetParentClass(clParent);
6384 fBranches.Add(branch);
6385 } else {
6386 branchname.Form("%s", elem->GetFullName());
6387 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, splitlevel+splitSTLP, btype);
6388 branch->SetParentClass(clParent);
6389 fBranches.Add(branch);
6390 }
6391 }
6392 } else {
6393 // -- This is a data member of cl.
6394 if (namelen) {
6395 branchname.Form("%s%s%s", name, dotlast ? "" : ".", elem->GetFullName());
6396 } else {
6397 branchname.Form("%s", elem->GetFullName());
6398 }
6399 if ((splitlevel > 1) && ((elem->IsA() == TStreamerObject::Class()) || (elem->IsA() == TStreamerObjectAny::Class()))) {
6400 // -- We are splitting a non-TClonesArray (may inherit from TClonesArray though), non-STL container object.
6401 //
6402 // Ignore an abstract class.
6403 // FIXME: How could an abstract class get here?
6404 // Partial answer: It is a base class. But this is a data member!
6405 TClass* elemClass = elem->GetClassPointer();
6406 if (!elemClass || elemClass->Property() & kIsAbstract) {
6407 return -1;
6408 }
6409 if (elem->CannotSplit()) {
6410 // We are not splitting.
6411 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, 0, btype);
6412 branch->SetParentClass(clParent);
6413 fBranches.Add(branch);
6414 } else if (elemClass->InheritsFrom(TClonesArray::Class())) {
6415 // Splitting something derived from TClonesArray.
6416 Int_t subSplitlevel = splitlevel-1;
6417 if (btype == 31 || btype == 41 || elem->CannotSplit()) {
6418 // -- We split the sub-branches of a TClonesArray or an STL container only once.
6419 subSplitlevel = 0;
6420 }
6421 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, subSplitlevel, btype);
6422 branch->SetParentClass(clParent);
6423 fBranches.Add(branch);
6424 } else {
6425 // Splitting a normal class.
6426 // FIXME: We are eliding the class we are splitting here,
6427 // i.e., we do not create a branch for it, so the
6428 // branch hierarchy does not match the class hierarchy.
6429 // Note: clParent is the class which contains a data member of
6430 // the class type which we are splitting.
6431 // Note: We can use parent class (clParent) != branch class (elemClass) to detection elision.
6432 Int_t unroll = Unroll(branchname, clParent, elemClass, ptr + offset, basketsize, splitlevel-1+splitSTLP, btype);
6433 if (unroll < 0) {
6434 // FIXME: We could not split because we are abstract, should we be doing this?
6435 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, 0, btype);
6436 branch->SetParentClass(clParent);
6437 fBranches.Add(branch);
6438 }
6439 }
6440 }
6441 else if( elem->GetClassPointer() &&
6444 splitSTLP && fType != 4 )
6445 {
6446
6447 TBranchSTL* branch = new TBranchSTL( this, branchname,
6449 basketsize, splitlevel - 1+splitSTLP, sinfo, elemID );
6450 branch->SetAddress( ptr+offset );
6451 fBranches.Add( branch );
6452 }
6453 else if ((elem->IsA() == TStreamerSTL::Class()) && !elem->IsaPointer()) {
6454 // -- We have an STL container.
6455 // Question: What if splitlevel == 0 here?
6456 // Answer: then we should not be here.
6457 Int_t subSplitlevel = splitlevel - 1;
6458 if ((btype == 31) || (btype == 41) || elem->CannotSplit()) {
6459 // -- We split the sub-branches of a TClonesArray or an STL container only once.
6460 subSplitlevel = 0;
6461 }
6462 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, subSplitlevel+splitSTLP, btype);
6463 branch->SetParentClass(clParent);
6464 fBranches.Add(branch);
6465 } else if (((btype != 31) && (btype != 41)) && ptr && ((elem->GetClassPointer() == TClonesArray::Class()) || ((elem->IsA() == TStreamerSTL::Class()) && !elem->CannotSplit()))) {
6466 // -- We have a TClonesArray.
6467 // FIXME: We could get a ptr to a TClonesArray here by mistake.
6468 // Question: What if splitlevel == 0 here?
6469 // Answer: then we should not be here.
6470 // Note: ptr may be null in case of a TClonesArray inside another
6471 // TClonesArray or STL container, see the else clause.
6472 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, splitlevel-1+splitSTLP, btype);
6473 branch->SetParentClass(clParent);
6474 fBranches.Add(branch);
6475 } else {
6476 // -- We are not going to split this element any farther.
6477 TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, nullptr, basketsize, splitSTLP, btype);
6478 branch->SetType(btype);
6479 branch->SetParentClass(clParent);
6480 fBranches.Add(branch);
6481 }
6482 }
6483 }
6484
6485 if (!fBranches.IsEmpty()) {
6486 // Refresh this branch's action now that we know whether it is split or not.
6489 }
6490 return 1;
6491}
6492
6493////////////////////////////////////////////////////////////////////////////////
6494/// Refresh the value of fDirectory (i.e. where this branch writes/reads its buffers)
6495/// with the current value of fTree->GetCurrentFile unless this branch has been
6496/// redirected to a different file. Also update the sub-branches.
6497
6499{
6500 // The BranchCount and BranchCount2 are part of higher level branches' list of
6501 // branches.
6502 // if (fBranchCount) fBranchCount->UpdateFile();
6503 // if (fBranchCount2) fBranchCount2->UpdateFile();
6505}
static void unroll(cpyrt_PyArgs_t packed_args, cpyrt_PyArgs_t unrolled, Py_ssize_t nArgs)
fBuffer
const Handle_t kNone
Definition GuiTypes.h:89
#define R__unlikely(expr)
Definition RConfig.hxx:568
#define b(i)
Definition RSha256.hxx:100
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
Definition RtypesCore.h:55
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
float Size_t
Attribute size (float)
Definition RtypesCore.h:104
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:90
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:53
int Ssiz_t
String size (currently int)
Definition RtypesCore.h:82
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:52
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:70
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:54
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
long double LongDouble_t
Long Double (not portable)
Definition RtypesCore.h:76
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:132
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:85
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
static void PrintElements(const TStreamerInfo *info, const TStreamerInfoActions::TIDs &ids)
Print branch parameters.
static void R__CleanName(std::string &name)
Remove trailing dimensions and make sure there is a trailing dot.
EDataType
Definition TDataType.h:28
@ kOther_t
Definition TDataType.h:32
@ kIsAbstract
Definition TDictionary.h:71
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:139
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
R__EXTERN TVirtualMutex * gInterpreterMutex
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:792
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:417
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2585
#define R__LOCKGUARD_IMT(mutex)
#define R__LOCKGUARD(mutex)
#define gPad
Bool_t HasRuleWithSourceClass(const TString &source) const
Return True if we have any rule whose source class is 'source'.
A helper class for managing IMT work during TTree:Fill operations.
TIOFeatures provides the end-user with the ability to change the IO behavior of data written via a TT...
Manages buffers for branches of a Tree.
Definition TBasket.h:34
Int_t GetNevBufSize() const
Definition TBasket.h:130
Int_t * GetEntryOffset()
Definition TBasket.h:124
Int_t GetLast() const
Definition TBasket.h:131
A Branch for the case of an object.
void ReadLeavesClonesMember(TBuffer &b)
Read leaves into i/o buffers for this branch.
void SetActionSequence(TClass *originalClass, TStreamerInfo *localInfo, TStreamerInfoActions::TActionSequence::SequenceGetter_t create, TStreamerInfoActions::TActionSequence *&actionSequence)
Set the sequence of actions needed to read the data out of the buffer.
char * fObject
! Pointer to object at *fAddress
TStreamerInfo * fInfo
! Pointer to StreamerInfo
Int_t fSTLtype
! STL container type
void ReadLeavesCustomStreamer(TBuffer &b)
Read leaves into i/o buffers for this branch.
void Reset(Option_t *option="") override
Reset a Branch.
void SetParentClass(TClass *clparent)
TBranchElement * fBranchCount2
pointer to secondary branchcount branch
static TClass * Class()
Int_t fNdata
! Number of data in this branch
~TBranchElement() override
Destructor.
void SetOffset(Int_t offset) override
Set offset of the object (to which the data member represented by this branch belongs) inside its con...
void FillLeavesCollectionMember(TBuffer &b)
Write leaves into i/o buffers for this branch.
TString fClassName
Class name of referenced object.
TStreamerInfoActions::TActionSequence * fFillActionSequence
! Set of actions to be executed to write the data to the basket.
void Print(Option_t *option="") const override
Print TBranch parameters.
void SetAddressImpl(void *addr, bool implied, Int_t offset) override
See TBranchElement::SetAddress.
Int_t GetID() const
const char * GetClassName() const override
Return the name of the user class whose content is stored in this branch, if any.
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
void ReadLeavesCollection(TBuffer &b)
Read leaves into i/o buffers for this branch.
void SetupAddresses() override
If the branch address is not set, we set all addresses starting with the top level parent branch.
void ResetAddress() override
Set branch address to zero and free all allocated memory.
virtual void SetType(Int_t btype)
void FillLeavesMember(TBuffer &b)
Write leaves into i/o buffers for this branch.
void SetBranchCount(TBranchElement *bre)
Set the branch counter for this branch.
static void SwitchContainer(TObjArray *)
Modify the container type of the branches.
void SetReadActionSequence()
Set the sequence of actions needed to read the data out of the buffer.
bool IsMissingCollection() const
Detect a collection written using a zero pointer in old versions of root.
Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *) override
Loop on all leaves of this branch to fill the basket buffer.
TVirtualCollectionProxy * GetCollectionProxy()
Return the collection proxy describing the branch content, if any.
@ kOwnOnfileObj
We are the owner of fOnfileObject.
@ kAddressSet
The addressing set have been called for this branch.
@ kDecomposedObj
More explicit alias for kMakeClass.
@ kDeleteObject
We are the owner of fObject.
@ kCache
Need to pushd/pop fOnfileObject.
void SetupAddressesImpl()
If the branch address is not set, we set all addresses starting with the top level parent branch.
void SetBasketSize(Int_t bufsize) override
Reset the basket size for all sub-branches of this branch element.
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Read all branches of a BranchElement and return total number of bytes.
TClassRef fParentClass
! Reference to class definition in fParentName
Double_t GetValue(Int_t i, Int_t len, bool subarr=false) const
bool fInInitInfo
! True during the 2nd part of InitInfo (cut recursion).
void BuildTitle(const char *name)
Set branch and leaf name and title in the case of a container sub-branch.
virtual Int_t GetMaximum() const
Return maximum count value of the branchcount if any.
TString fParentName
Name of parent class.
void ReadLeavesCollectionSplitPtrMember(TBuffer &b)
Read leaves into i/o buffers for this branch.
TClassRef fBranchClass
! Reference to class definition in fClassName
TStreamerInfoActions::TIDs fNewIDs
! Nested List of the serial number of all the StreamerInfo to be used.
Int_t GetStreamerType() const
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
UInt_t fCheckSum
CheckSum of class.
void ResetAfterMerge(TFileMergeInfo *) override
Reset a Branch after a Merge operation (drop data but keep customizations)
TStreamerInfoActions::TActionSequence * fReadActionSequence
! Set of actions to be executed to extract the data from the basket.
void FillLeavesClones(TBuffer &b)
Write leaves into i/o buffers for this branch.
void ReadLeavesMemberBranchCount(TBuffer &b)
Read leaves into i/o buffers for this branch.
void SetReadLeavesPtr()
Set the ReadLeaves pointer to execute the expected operations.
Int_t Unroll(const char *name, TClass *cltop, TClass *cl, char *ptr, Int_t basketsize, Int_t splitlevel, Int_t btype)
Split class cl into sub-branches of this branch.
void FillLeavesMakeClass(TBuffer &b)
Write leaves into i/o buffers for this branch.
void FillLeavesCollectionSplitVectorPtrMember(TBuffer &b)
Write leaves into i/o buffers for this branch.
void FillLeavesCollection(TBuffer &b)
Write leaves into i/o buffers for this branch.
Int_t fID
element serial number in fInfo
char * GetAddress() const override
Get the branch address.
void FillLeavesMemberCounter(TBuffer &b)
Write leaves into i/o buffers for this branch.
void SetBranchCount2(TBranchElement *bre)
void FillLeavesCollectionSplitPtrMember(TBuffer &b)
Write leaves into i/o buffers for this branch.
void SetAddress(void *addobj) override
Point this branch at an object.
TStreamerInfo * GetInfoImp() const
Get streamer info for the branch class.
virtual void SetTargetClass(const char *name)
Set the name of the class of the in-memory object into which the data will loaded.
virtual void ResetDeleteObject()
Release ownership of any allocated objects.
virtual const char * GetParentName() const
void ValidateAddress() const
TVirtualArray * GetOnfileObject() const
TVirtualCollectionIterators * fWriteIterators
! holds the read (non-staging) iterators when the branch is of fType==4 and associative containers.
void PrintValue(Int_t i) const
Prints values of leaves.
TVirtualArray * fOnfileObject
! Place holder for the onfile representation of data members.
virtual const char * GetTypeName() const
Return type name of element in the branch.
void FillLeavesAssociativeCollectionMember(TBuffer &b)
Write leaves into i/o buffers for this branch.
void Init(TTree *tree, TBranch *parent, const char *name, TStreamerInfo *sinfo, Int_t id, char *pointer, Int_t basketsize=32000, Int_t splitlevel=0, Int_t btype=0)
Init when the branch object is not a TClonesArray nor an STL container.
T GetTypedValue(Int_t i, Int_t len, bool subarr=false) const
TClassRef fClonesClass
! Reference to class definition in fClonesName
virtual void * GetValuePointer() const
Returns pointer to first data element of this branch.
void ReadLeavesImpl(TBuffer &b)
Unconfiguration Read Leave function.
bool fInitOffsets
! Initialization flag to not endlessly recalculate offsets
void SetupInfo()
Set the value of fInfo.
void FillLeavesImpl(TBuffer &b)
Unconfiguration Fill Leave function.
void FillLeavesClonesMember(TBuffer &b)
Write leaves into i/o buffers for this branch.
TClassRef fCurrentClass
! Reference to current (transient) class definition
char * GetObject() const
Return a pointer to our object.
void UpdateFile() override
Refresh the value of fDirectory (i.e.
TStreamerInfo * FindOnfileInfo(TClass *valueClass, const TObjArray &branches) const
bool SetMakeClass(bool decomposeObj=true) override
Set the branch in a mode where the object are decomposed (Also known as MakeClass mode).
void ReadLeavesClones(TBuffer &b)
Read leaves into i/o buffers for this branch.
Int_t * fBranchOffset
! Sub-Branch offsets with respect to current transient class
Int_t fType
Branch type.
virtual void ResetInitInfo(bool recurse)
Reset offset and StreamerInfo information from this branch.
friend class TLeafElement
TString GetFullName() const override
Return the 'full' name of the branch.
void ReadLeavesMakeClass(TBuffer &b)
Read leaves into i/o buffers for this branch.
TBranchElement()
Default and I/O constructor.
void FillLeavesCustomStreamer(TBuffer &b)
Write leaves into i/o buffers for this branch.
virtual const char * GetClonesName() const
virtual TClass * GetClass() const
Int_t fMaximum
Maximum entries for a TClonesArray or variable array.
void ReadLeavesMemberCounter(TBuffer &b)
Read leaves into i/o buffers for this branch.
Int_t fBranchID
! ID number assigned by a TRefTable.
TLeaf * FindLeaf(const char *name) override
Find the leaf corresponding to the name 'searchname'.
TVirtualCollectionIterators * fIterators
! holds the iterators when the branch is of fType==4.
void ReleaseObject()
Delete any object we may have allocated on a previous call to SetAddress.
TClassRef fTargetClass
! Reference to the target in-memory class
void Browse(TBrowser *b) override
Browse the branch content.
void FillLeavesMemberBranchCount(TBuffer &b)
Write leaves into i/o buffers for this branch.
bool IsFolder() const override
Return true if more than one leaf, false otherwise.
virtual void SetMissing()
Set offset of the object (to which the data member represented by this branch belongs) inside its con...
TString fClonesName
Name of class in TClonesArray or (STL) collection (if any)
TBranchElement * fBranchCount
pointer to primary branchcount branch
Int_t GetType() const
void ReadLeavesMember(TBuffer &b)
Read leaves into i/o buffers for this branch.
Version_t fClassVersion
Version number of class.
TVirtualCollectionPtrIterators * fPtrIterators
! holds the iterators when the branch is of fType==4 and it is a split collection of pointers.
TBranch * FindBranch(const char *name) override
Find the immediate sub-branch with passed name.
void Streamer(TBuffer &) override
Stream an object of class TBranchElement.
virtual void InitInfo()
Init the streamer info for the branch class, try to compensate for class code unload/reload and schem...
virtual void InitializeOffsets()
Initialize the base class subobjects offsets of our sub-branches and set fOffset if we are a containe...
const char * GetIconName() const override
Return icon name depending on type of branch element.
TClass * GetParentClass()
Return a pointer to the parent class of the branch element.
Int_t GetNdata() const
Int_t GetExpectedType(TClass *&clptr, EDataType &type) override
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
bool fInit
! Initialization flag for branch assignment
TVirtualCollectionProxy * fCollProxy
! collection interface (if any)
void SetFillActionSequence()
Set the sequence of actions needed to write the data out from the buffer.
void SetObject(void *objadd) override
Set object this branch is pointing to.
Int_t fStreamerType
branch streamer type
void ReadLeavesCollectionSplitVectorPtrMember(TBuffer &b)
Read leaves into i/o buffers for this branch.
bool GetMakeClass() const override
Return whether this branch is in a mode where the object are decomposed or not (Also known as MakeCla...
void SetFillLeavesPtr()
Set the FillLeaves pointer to execute the expected operations.
void ReadLeavesCollectionMember(TBuffer &b)
Read leaves into i/o buffers for this branch.
A branch containing and managing a TRefTable for TRef autoloading.
Definition TBranchRef.h:34
virtual void SetRequestedEntry(Long64_t entry)
Definition TBranchRef.h:55
virtual Int_t SetParent(const TObject *obj, Int_t branchID)
Set the current parent branch.
A Branch handling STL collection of pointers (vectors, lists, queues, sets and multisets) while stori...
Definition TBranchSTL.h:22
void SetAddress(void *addr) override
Set Address.
A TTree is a list of TBranches.
Definition TBranch.h:93
virtual void ResetAddress()
Reset the address of the branch.
Definition TBranch.cxx:2649
TString fFileName
Name of file where buffers are stored ("" if in same file as Tree header)
Definition TBranch.h:158
Int_t fEntryOffsetLen
Initial Length of fEntryOffset table in the basket buffers.
Definition TBranch.h:128
Int_t fMaxBaskets
Maximum number of Baskets so far.
Definition TBranch.h:134
TTree * GetTree() const
Definition TBranch.h:261
FillLeaves_t fFillLeaves
! Pointer to the FillLeaves implementation to use.
Definition TBranch.h:172
virtual TString GetFullName() const
Return the 'full' name of the branch.
Definition TBranch.cxx:2029
void(TBranch::* ReadLeaves_t)(TBuffer &b)
Definition TBranch.h:169
@ kBranchAny
Branch is an object*.
Definition TBranch.h:114
@ kBranchObject
Branch is a TObject*.
Definition TBranch.h:113
@ kDoNotProcess
Active bit for branches.
Definition TBranch.h:111
TObjArray fLeaves
-> List of leaves of this branch
Definition TBranch.h:148
char * fAddress
! Address of 1st leaf (variable or object)
Definition TBranch.h:156
TObjArray * GetListOfBranches()
Definition TBranch.h:255
virtual TList * GetBrowsables()
Returns (and, if 0, creates) browsable objects for this branch See TVirtualBranchBrowsable::FillListO...
Definition TBranch.cxx:1310
Int_t fOffset
Offset of this branch.
Definition TBranch.h:133
Long64_t * fBasketEntry
[fMaxBaskets] Table of first entry in each basket
Definition TBranch.h:151
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:1704
const char * GetFileName() const
Definition TBranch.h:243
TIOFeatures GetIOFeatures() const
Returns the IO settings currently in use for this branch.
Definition TBranch.cxx:2253
TClass * IsA() const override
Definition TBranch.h:304
Long64_t fReadEntry
! Current entry number when reading
Definition TBranch.h:139
void Print(Option_t *option="") const override
Print TBranch parameters.
Definition TBranch.cxx:2339
TBranch * GetSubBranch(const TBranch *br) const
Find the parent branch of child.
Definition TBranch.cxx:2162
ReadLeaves_t fReadLeaves
! Pointer to the ReadLeaves implementation to use.
Definition TBranch.h:170
void(TBranch::* FillLeaves_t)(TBuffer &b)
Definition TBranch.h:171
virtual void SetAutoDelete(bool autodel=true)
Set the automatic delete bit.
Definition TBranch.cxx:2727
Int_t GetOffset() const
Definition TBranch.h:244
virtual TLeaf * FindLeaf(const char *name)
Find the leaf corresponding to the name 'searchname'.
Definition TBranch.cxx:1079
Long64_t GetReadEntry() const
Definition TBranch.h:246
Long64_t GetEntries() const
Definition TBranch.h:260
Int_t fNleaves
! Number of leaves
Definition TBranch.h:137
Int_t fSplitLevel
Branch split level.
Definition TBranch.h:136
virtual void UpdateFile()
Refresh the value of fDirectory (i.e.
Definition TBranch.cxx:3323
Int_t * fBasketBytes
[fMaxBaskets] Length of baskets on file
Definition TBranch.h:150
bool IsAutoDelete() const
Return true if an existing object in a TBranchObject must be deleted.
Definition TBranch.cxx:2261
TObjArray fBranches
-> List of Branches of this branch
Definition TBranch.h:147
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch.
Definition TBranch.cxx:2596
virtual void ResetReadEntry()
Definition TBranch.h:278
virtual TBranch * FindBranch(const char *name)
Find the immediate sub-branch with passed name.
Definition TBranch.cxx:1033
TDirectory * fDirectory
! Pointer to directory where this branch buffers are stored
Definition TBranch.h:157
TObjArray fBaskets
-> List of baskets of this branch
Definition TBranch.h:149
void SetIOFeatures(TIOFeatures &features)
Definition TBranch.h:292
TBranch * fMother
! Pointer to top-level parent branch in the tree.
Definition TBranch.h:154
TBranch * fParent
! Pointer to parent branch.
Definition TBranch.h:155
bool IsFolder() const override
Return true if more than one leaf or browsables, false otherwise.
Definition TBranch.cxx:2269
virtual bool SetMakeClass(bool decomposeObj=true)
Set the branch in a mode where the object are decomposed (Also known as MakeClass mode).
Definition TBranch.cxx:2938
Int_t fWriteBasket
Last basket number written.
Definition TBranch.h:129
Long64_t * fBasketSeek
[fMaxBaskets] Addresses of baskets on file
Definition TBranch.h:152
TObjArray * GetListOfLeaves()
Definition TBranch.h:256
Int_t fReadBasket
! Current basket number when reading
Definition TBranch.h:138
Int_t fBasketSize
Initial Size of Basket Buffer.
Definition TBranch.h:127
virtual void Reset(Option_t *option="")
Reset a Branch.
Definition TBranch.cxx:2555
virtual void SetBasketSize(Int_t bufsize)
Set the basket size The function makes sure that the basket size is greater than fEntryOffsetlen.
Definition TBranch.cxx:2740
Long64_t fEntryNumber
Current entry number (last one filled in this branch)
Definition TBranch.h:130
TBranch * GetMother() const
Get our top-level parent branch in the tree.
Definition TBranch.cxx:2125
Int_t fCompress
Compression level and algorithm.
Definition TBranch.h:126
virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *)
Loop on all leaves of this branch to fill Basket buffer.
Definition TBranch.cxx:854
Long64_t fEntries
Number of entries.
Definition TBranch.h:143
virtual void SetAddressImpl(void *addr, bool, Int_t)
Definition TBranch.h:188
TTree * fTree
! Pointer to Tree header
Definition TBranch.h:153
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
Buffer base class used for serializing objects.
Definition TBuffer.h:43
@ kRead
Definition TBuffer.h:73
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TClassRef is used to implement a permanent reference to a TClass object.
Definition TClassRef.h:29
void SetName(const char *new_name)
Definition TClassRef.h:62
TClass * GetClass() const
Definition TClassRef.h:67
const char * GetClassName()
Definition TClassRef.h:66
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
UInt_t GetCheckSum(ECheckSum code=kCurrentCheckSum) const
Call GetCheckSum with validity check.
Definition TClass.cxx:6693
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=nullptr) const
Definition TClass.h:627
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name "datamember".
Definition TClass.cxx:3506
Bool_t CanSplit() const
Return true if the data member of this TClass can be saved separately.
Definition TClass.cxx:2331
ROOT::ESTLType GetCollectionType() const
Return the 'type' of the STL the TClass is representing.
Definition TClass.cxx:2912
TVirtualStreamerInfo * GetStreamerInfoAbstractEmulated(Int_t version=0) const
For the case where the requestor class is emulated and this class is abstract, returns a pointer to t...
Definition TClass.cxx:4826
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5107
void CopyCollectionProxy(const TVirtualCollectionProxy &)
Replaces the collection proxy for this class.
Definition TClass.cxx:2482
Bool_t HasCustomStreamerMember() const
The class has a Streamer method and it is implemented by the user or an older (not StreamerInfo based...
Definition TClass.h:524
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5529
TClassStreamer * GetStreamer() const
Return the Streamer Class allowing streaming (if any).
Definition TClass.cxx:2940
void BuildRealData(void *pointer=nullptr, Bool_t isTransient=kFALSE)
Build a full list of persistent data members.
Definition TClass.cxx:2043
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3833
TList * GetListOfRealData() const
Definition TClass.h:468
Bool_t CanIgnoreTObjectStreamer()
Definition TClass.h:406
const ROOT::Detail::TSchemaRuleSet * GetSchemaRules() const
Return the set of the schema rules if any.
Definition TClass.cxx:1939
const TObjArray * GetStreamerInfos() const
Definition TClass.h:508
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition TClass.cxx:6088
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:6114
Bool_t IsForeign() const
Return kTRUE is the class is Foreign (the class does not have a Streamer method).
Definition TClass.cxx:6123
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Definition TClass.cxx:4716
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4991
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2923
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6268
TVirtualStreamerInfo * GetConversionStreamerInfo(const char *onfile_classname, Int_t version) const
Return a Conversion StreamerInfo from the class 'classname' for version number 'version' to this clas...
Definition TClass.cxx:7286
TVirtualStreamerInfo * FindConversionStreamerInfo(const char *onfile_classname, UInt_t checksum) const
Return a Conversion StreamerInfo from the class 'classname' for the layout represented by 'checksum' ...
Definition TClass.cxx:7393
Bool_t IsVersioned() const
Definition TClass.h:539
TVirtualStreamerInfo * FindStreamerInfo(TObjArray *arr, UInt_t checksum) const
Find the TVirtualStreamerInfo in the StreamerInfos corresponding to checksum.
Definition TClass.cxx:7266
Version_t GetClassVersion() const
Definition TClass.h:434
TRealData * GetRealData(const char *name) const
Return pointer to TRealData element with name "name".
Definition TClass.cxx:3570
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2999
An array of clone (identical) objects.
virtual void ExpandCreateFast(Int_t n)
Expand or shrink the array to n elements and create the clone objects by calling their default ctor.
TClass * GetClass() const
static TClass * Class()
static TClass * Class()
const char * GetName() const override
Return name of this collection.
virtual Int_t GetEntries() const
void Browse(TBrowser *b) override
Browse this collection (called by TBrowser).
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
const char * GetTypeName() const
Get the decayed type name of this data member, removing const and volatile qualifiers,...
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Describe directory structure in memory.
Definition TDirectory.h:45
virtual Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *="", Int_t=0)
Write an object with proper type checking.
virtual TFile * GetFile() const
Definition TDirectory.h:221
virtual Bool_t IsWritable() const
Definition TDirectory.h:238
A class to pass information from the TFileMerger to the objects being merged.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Int_t GetCompressionSettings() const
Definition TFile.h:491
A TLeaf for the general case when using the branches created via a TStreamerInfo (i....
void SetLeafCount(TLeaf *leaf) override
Set the leaf count of this leaf.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual Int_t GetMaximum() const
Definition TLeaf.h:137
virtual void SetAddress(void *add=nullptr)
Definition TLeaf.h:188
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
Definition TLeaf.h:135
virtual void SetRange(bool range=true)
Definition TLeaf.h:168
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
void Add(TObject *obj) override
Definition TList.h:81
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
TString fName
Definition TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntriesFast() const
Definition TObjArray.h:58
Int_t IndexOf(const TObject *obj) const override
TObject ** GetObjectRef() const
Definition TObjArray.h:63
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:170
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:90
Bool_t IsEmpty() const override
Definition TObjArray.h:65
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
void Add(TObject *obj) override
Definition TObjArray.h:68
Mother of all ROOT objects.
Definition TObject.h:42
friend class TClonesArray
Definition TObject.h:245
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
static TClass * Class()
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:161
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:548
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1124
virtual TClass * IsA() const
Definition TObject.h:248
void ResetBit(UInt_t f)
Definition TObject.h:203
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1070
The TRealData class manages the effective list of all data members for a given class.
Definition TRealData.h:30
Long_t GetThisOffset() const
Definition TRealData.h:55
static TClass * Class()
static TClass * Class()
static TClass * Class()
const char * GetCountName() const
Describe one element (data member) to be Streamed.
Int_t GetNewType() const
Int_t GetType() const
virtual const char * GetFullName() const
Return element name including dimensions, if any Note that this function stores the name into a stati...
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element and updates fClassObject.
TClass * GetNewClass() const
void ls(Option_t *option="") const override
Print the content of the element.
virtual Bool_t IsTransient() const
Return kTRUE if the element represent an entity that is not written to the disk (transient members,...
virtual Bool_t IsaPointer() const
const char * GetTypeName() const
virtual Bool_t CannotSplit() const
Returns true if the element cannot be split, false otherwise.
TClass * GetClass() const
TClass * IsA() const override
Int_t GetOffset() const
const char * GetTypeNameBasic() const
Return type name of this element in case the type name is not a standard basic type,...
virtual Bool_t IsBase() const
Return kTRUE if the element represent a base class.
static SequencePtr WriteMemberWiseActionsViaProxyGetter(TStreamerInfo *, TVirtualCollectionProxy *collectionProxy, TClass *)
static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
static SequencePtr ConversionReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass)
void Print(Option_t *="") const override
This method must be overridden when a class wants to print itself.
static SequencePtr WriteMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
static SequencePtr ReadMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass) SequenceGetter_t
static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
TActionSequence * CreateSubSequence(const std::vector< Int_t > &element_ids, size_t offset)
static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
Base class of the Configurations.
TVirtualStreamerInfo * fInfo
TStreamerInfo form which the action is derived.
UInt_t fElemId
Identifier of the TStreamerElement.
Describes a persistent version of a class.
Int_t GetClassVersion() const override
TStreamerElement * GetElement(Int_t id) const override
T GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const
Return value of element i in object at pointer.
void ls(Option_t *option="") const override
List the TStreamerElement list and also the precomputed tables if option contains the string "incOrig...
Int_t GetNelement() const
void PrintValue(const char *name, char *pointer, Int_t i, Int_t len, Int_t lenmax=1000) const
print value of element i in object at pointer The function may be called in two ways: -method1 len < ...
T GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const
Return value of element i in object number j in a pointer to STL container and eventually element k i...
T GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const
Return value of element i in object number j in an STL container and eventually element k in a sub-ar...
TClass * GetClass() const override
T GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const
void PrintValueSTL(const char *name, TVirtualCollectionProxy *cont, Int_t i, Int_t eoffset, Int_t lenmax=1000) const
Print value of element i in an STL container.
TObjArray * GetElements() const override
TStreamerElement * GetStreamerElement(const char *datamember, Int_t &offset) const override
Return the StreamerElement of "datamember" inside our class or any of its base classes.
UInt_t GetCheckSum() const override
void PrintValueClones(const char *name, TClonesArray *clones, Int_t i, Int_t eoffset, Int_t lenmax=1000) const
Print value of element i in a TClonesArray.
const char * GetCountName() const
static TClass * Class()
static TClass * Class()
static TClass * Class()
static TClass * Class()
Basic string class.
Definition TString.h:137
Ssiz_t Length() const
Definition TString.h:426
static constexpr Ssiz_t kNPOS
Definition TString.h:285
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2325
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1171
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:704
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:546
const char * Data() const
Definition TString.h:385
@ kTrailing
Definition TString.h:283
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:939
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:633
TString & Remove(Ssiz_t pos)
Definition TString.h:695
TString & Append(const char *cs)
Definition TString.h:582
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
static TClass * Class()
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:661
A TTree represents a columnar dataset.
Definition TTree.h:95
TStreamerInfo * BuildStreamerInfo(TClass *cl, void *pointer=nullptr, bool canOptimize=true)
Build StreamerInfo for class cl.
Definition TTree.cxx:2683
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5459
Int_t GetDefaultEntryOffsetLen() const
Definition TTree.h:520
virtual TObjArray * GetListOfLeaves()
Definition TTree.h:590
void Draw(Option_t *opt) override
Default Draw method for all objects.
Definition TTree.h:492
TDirectory * GetDirectory() const
Definition TTree.h:523
Int_t Debug() const
Definition TTree.h:490
virtual TBranchRef * GetBranchRef() const
Definition TTree.h:511
@ kSplitCollectionOfPointers
Definition TTree.h:324
virtual Long64_t GetReadEntry() const
Definition TTree.h:610
Long64_t GetDebugMin() const
Definition TTree.h:522
ROOT::TIOFeatures GetIOFeatures() const
Returns the current set of IO settings.
Definition TTree.cxx:6214
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
char * GetObjectAt(UInt_t ind) const
void SetSize(UInt_t size)
Small helper class to generically acquire and release iterators.
void CreateIterators(void *collection, TVirtualCollectionProxy *proxy)
RAII helper class that ensures that PushProxy() / PopProxy() are called when entering / leaving a C++...
Defines a common interface to inspect/change the contents of an object that represents a collection.
virtual Int_t GetProperties() const
Return miscallenous properties of the proxy (see TVirtualCollectionProxy::EProperty)
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
Execute the container destructor.
virtual EDataType GetType() const =0
If the value type is a fundamental data type, return its type (see enumeration EDataType).
@ kNeedDelete
The collection contains directly or indirectly (via other collection) some pointers that need explici...
virtual void Clear(const char *opt="")=0
Clear the container.
virtual void * New() const
Construct a new container object and return its address.
virtual TClass * GetValueClass() const =0
If the value type is a user-defined class, return a pointer to the TClass representing the value type...
virtual void Commit(void *)=0
Commits pending elements in a staging area (see Allocate() for more information).
virtual void * At(UInt_t idx)=0
Return the address of the value at index idx
virtual Int_t GetCollectionType() const =0
Return the type of the proxied collection (see enumeration TClassEdit::ESTLType)
virtual UInt_t Size() const =0
Return the current number of elements in the container.
virtual TVirtualCollectionProxy * Generate() const =0
Returns a clean object of the actual class that derives from TVirtualCollectionProxy.
virtual void * Allocate(UInt_t n, Bool_t forceDelete)=0
Allocates space for storing at least n elements.
virtual Bool_t HasPointers() const =0
Return true if the content is of type 'pointer to'.
virtual TClass * GetCollectionClass() const
Return a pointer to the TClass representing the proxied container class.
void CreateIterators(void *collection, TVirtualCollectionProxy *proxy)
Abstract Interface class describing Streamer information for one class.
virtual UInt_t GetCheckSum() const =0
@ kUChar
Equal to TDataType's kchar.
virtual TStreamerElement * GetElement(Int_t id) const =0
virtual TObjArray * GetElements() const =0
virtual Int_t GetClassVersion() const =0
virtual TClass * GetClass() const =0
const Int_t n
Definition legend1.C:16
@ kSTLmap
Definition ESTLType.h:33
@ kSTLunorderedmultiset
Definition ESTLType.h:43
@ kSTLend
Definition ESTLType.h:47
@ kSTLset
Definition ESTLType.h:35
@ kSTLmultiset
Definition ESTLType.h:36
@ kSTLvector
Definition ESTLType.h:30
@ kSTLunorderedmultimap
Definition ESTLType.h:45
@ kSTLunorderedset
Definition ESTLType.h:42
@ kSTLunorderedmap
Definition ESTLType.h:44
@ kNotSTL
Definition ESTLType.h:29
@ kSTLmultimap
Definition ESTLType.h:34
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
std::vector< TIDNode > TIDs
TCanvas * slash()
Definition slash.C:1
TMarker m
Definition textangle.C:8