Logo ROOT  
Reference Guide
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
52
53////////////////////////////////////////////////////////////////////////////////
54
55namespace {
56 void RemovePrefix(TString& str, const TString &prefix) {
57 // -- Remove a prefix from a string.
58 // -- Require a '.' after the prefix.
59 if (prefix.Length() && prefix.Length() <= str.Length()
60 && (str.Data()[prefix.Length()] == '.' || (prefix[prefix.Length()-1]=='.')))
61 {
62 if (!str.Index(prefix))
63 str.Remove(0, prefix.Length());
64 }
65 }
66 struct R__PushCache {
68 TVirtualArray *fOnfileObject;
69
70 R__PushCache(TBufferFile &b, TVirtualArray *in, UInt_t size) : fBuffer(b), fOnfileObject(in) {
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
82////////////////////////////////////////////////////////////////////////////////
83/// Modify the container type of the branches
84
86 const Int_t nbranches = branches->GetEntriesFast();
87 for (Int_t i = 0; i < nbranches; ++i) {
88 TBranchElement* br = (TBranchElement*) branches->At(i);
89 switch (br->GetType()) {
90 case 31: br->SetType(41); break;
91 case 41: {
92 br->SetType(31);
93 br->fCollProxy = 0;
94 break;
95 }
96 }
97 br->SetReadLeavesPtr();
98 br->SetFillLeavesPtr();
99 // Note: This is a tail recursion.
101 }
102}
103
104////////////////////////////////////////////////////////////////////////////////
105
106namespace {
107 Bool_t CanSelfReference(TClass *cl) {
108 if (cl) {
109 if (cl->GetCollectionProxy()) {
110 TClass *inside = cl->GetCollectionProxy()->GetValueClass();
111 if (inside) {
112 return CanSelfReference(inside);
113 } else {
114 return kFALSE;
115 }
116 }
117 const static TClassRef stringClass("std::string");
118 if (cl == stringClass || cl == TString::Class()) {
119 return kFALSE;
120 }
121 // Here we could scan through the TStreamerInfo to see if there
122 // is any pointer anywhere and know whether this is a possibility
123 // of selfreference (but watch out for very indirect cases).
124 return kTRUE;
125 }
126 return kFALSE;
127 }
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Default and I/O constructor.
132
134: TBranch()
135, fClassName()
136, fParentName()
137, fClonesName()
138, fCollProxy(0)
139, fCheckSum(0)
140, fClassVersion(0)
141, fID(0)
142, fType(0)
143, fStreamerType(-1)
144, fMaximum(0)
145, fSTLtype(ROOT::kNotSTL)
146, fNdata(1)
147, fBranchCount(0)
148, fBranchCount2(0)
149, fInfo(0)
150, fObject(0)
151, fOnfileObject(0)
152, fInit(kFALSE)
153, fInInitInfo(kFALSE)
154, fInitOffsets(kFALSE)
155, fTargetClass()
156, fCurrentClass()
157, fParentClass()
158, fBranchClass()
159, fClonesClass()
160, fBranchOffset(0)
161, fBranchID(-1)
162, fReadActionSequence(0)
163, fFillActionSequence(0)
164, fIterators(0)
165, fWriteIterators(0)
166, fPtrIterators(0)
167{
168 fNleaves = 0;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Constructor when the branch object is not a TClonesArray nor an STL container.
175///
176/// If splitlevel > 0 this branch in turn is split into sub-branches.
177
178TBranchElement::TBranchElement(TTree *tree, const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
179: TBranch()
180, fClassName(sinfo->GetName())
181, fParentName()
182, fClonesName()
183, fCollProxy(0)
184, fCheckSum(sinfo->GetCheckSum())
185, fClassVersion(sinfo->GetClass()->GetClassVersion())
186, fID(id)
187, fType(0)
188, fStreamerType(-1)
189, fMaximum(0)
190, fSTLtype(ROOT::kNotSTL)
191, fNdata(1)
192, fBranchCount(0)
193, fBranchCount2(0)
194, fInfo(sinfo)
195, fObject(0)
196, fOnfileObject(0)
197, fInit(kTRUE)
198, fInInitInfo(kFALSE)
199, fInitOffsets(kFALSE)
200, fTargetClass(fClassName)
201, fCurrentClass()
202, fParentClass()
203, fBranchClass(sinfo->GetClass())
204, fClonesClass()
205, fBranchOffset(0)
206, fBranchID(-1)
207, fReadActionSequence(0)
208, fFillActionSequence(0)
209, fIterators(0)
210, fWriteIterators(0)
211, fPtrIterators(0)
212{
213 if (tree) {
214 ROOT::TIOFeatures features = tree->GetIOFeatures();
215 SetIOFeatures(features);
216 }
217 Init(tree, 0, bname,sinfo,id,pointer,basketsize,splitlevel,btype);
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(TBranch *parent, 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(0)
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(0)
240, fBranchCount2(0)
241, fInfo(sinfo)
242, fObject(0)
243, fOnfileObject(0)
244, fInit(kTRUE)
245, fInInitInfo(kFALSE)
246, fInitOffsets(kFALSE)
247, fTargetClass( fClassName )
248, fCurrentClass()
249, fParentClass()
250, fBranchClass(sinfo->GetClass())
251, fClonesClass()
252, fBranchOffset(0)
253, fBranchID(-1)
254, fReadActionSequence(0)
255, fFillActionSequence(0)
256, fIterators(0)
257, fWriteIterators(0)
258, fPtrIterators(0)
259{
260 ROOT::TIOFeatures features = parent->GetIOFeatures();
261 SetIOFeatures(features);
262 Init(parent ? parent->GetTree() : 0, parent, bname,sinfo,id,pointer,basketsize,splitlevel,btype);
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Init when the branch object is not a TClonesArray nor an STL container.
267///
268/// If splitlevel > 0 this branch in turn is split into sub-branches.
269
270void 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)
271{
272 TString name(bname);
273
274 // Set our TNamed attributes.
275 SetName(name);
276 SetTitle(name);
277
278 // Set our TBranch attributes.
279 fSplitLevel = splitlevel;
280 fTree = tree;
281 if (fTree == 0) return;
282 fMother = parent ? parent->GetMother() : this;
283 fParent = parent;
285 fFileName = "";
286
287 // Clear the bit kAutoDelete to specify that when reading
288 // the object should not be deleted before calling Streamer.
289
291
294
295 //---------------------------------------------------------------------------
296 // Handling the splitting of the STL collections of pointers
297 /////////////////////////////////////////////////////////////////////////////
298
299 Int_t splitSTLP = splitlevel - (splitlevel%TTree::kSplitCollectionOfPointers);
301
302 fCompress = -1;
303 if (fTree->GetDirectory()) {
304 TFile* bfile = fTree->GetDirectory()->GetFile();
305 if (bfile) {
307 }
308 }
309
310 //
311 // Initialize streamer type and element.
312 //
313
314 if (id > -1) {
315 // We are *not* a top-level branch.
316 TStreamerElement* element = sinfo->GetElement(id);
317 fStreamerType = element->GetType();
318 }
319
320 //
321 // Handle varying-length datatypes by allocating an offsets array.
322 //
323 // The fBits part of a TObject is of varying length because the pidf
324 // is streamed only when the TObject is referenced by a TRef.
325 //
326
327 fEntryOffsetLen = 0;
330 }
331
332 //
333 // Make sure the basket is big enough to contain the
334 // entry offset array plus 100 bytes of data.
335 //
336
337 if (basketsize < (100 + fEntryOffsetLen)) {
338 basketsize = 100 + fEntryOffsetLen;
339 }
340 fBasketSize = basketsize;
341
342 //
343 // Allocate and initialize the basket control arrays.
344 //
345
349
350 for (Int_t i = 0; i < fMaxBaskets; ++i) {
351 fBasketBytes[i] = 0;
352 fBasketEntry[i] = 0;
353 fBasketSeek[i] = 0;
354 }
355
356 // We need to keep track of the counter branch if we have
357 // one, since we cannot set it until we have created our
358 // leaf, which we do last.
359 TBranchElement* brOfCounter = 0;
360
361 if (id < 0) {
362 // -- We are a top-level branch. Don't split a top-level branch, TTree::Bronch will do that work.
363 if (fBranchClass.GetClass()) {
364 Bool_t hasCustomStreamer = kFALSE;
365 Bool_t canSelfReference = CanSelfReference(fBranchClass);
367 if (canSelfReference) SetBit(kBranchObject);
369 } else {
370 if (canSelfReference) SetBit(kBranchAny);
372 }
373 if (hasCustomStreamer) {
374 fType = -1;
375 }
376 }
377 } else {
378 // -- We are a sub-branch of a split object.
379 TStreamerElement* element = sinfo->GetElement(id);
381 // -- If we are an object data member which inherits from TObject,
382 // flag it so that later during i/o we will register the object
383 // with the buffer so that pointers are handled correctly.
384 if (CanSelfReference(fBranchClass)) {
387 } else {
389 }
390 }
391 }
392 if (element->IsA() == TStreamerBasicPointer::Class()) {
393 // -- Fixup title with counter if we are a varying length array data member.
395 TString countname;
396 countname = bname;
397 Ssiz_t dot = countname.Last('.');
398 if (dot>=0) {
399 countname.Remove(dot+1);
400 } else {
401 countname = "";
402 }
403 countname += bp->GetCountName();
404 brOfCounter = (TBranchElement *)fTree->GetBranch(countname);
405 countname.Form("%s[%s]",name.Data(),bp->GetCountName());
406 SetTitle(countname);
407
408 } else if (element->IsA() == TStreamerLoop::Class()) {
409 // -- Fixup title with counter if we are a varying length array data member.
410 TStreamerLoop *bp = (TStreamerLoop *)element;
411 TString countname;
412 countname = bname;
413 Ssiz_t dot = countname.Last('.');
414 if (dot>=0) {
415 countname.Remove(dot+1);
416 } else {
417 countname = "";
418 }
419 countname += bp->GetCountName();
420 brOfCounter = (TBranchElement *)fTree->GetBranch(countname);
421 countname.Form("%s[%s]",name.Data(),bp->GetCountName());
422 SetTitle(countname);
423
424 }
425
426 if (splitlevel > 0) {
427 // -- Create sub branches if requested by splitlevel.
428 const char* elemType = element->GetTypeName();
429 TClass *elementClass = element->GetClassPointer();
430 fSTLtype = elementClass ? elementClass->GetCollectionType() : ROOT::kNotSTL;
431 if (element->CannotSplit()) {
432 fSplitLevel = 0;
433 } else if (element->IsA() == TStreamerBase::Class()) {
434 // -- We are a base class element.
435 // Note: This does not include an STL container class which is
436 // being used as a base class because the streamer element
437 // in that case is not the base streamer element it is the
438 // STL streamer element.
439 fType = 1;
440 TClass* clOfElement = element->GetClassPointer();
441 Int_t nbranches = fBranches.GetEntriesFast();
442 // Note: The following code results in base class branches
443 // having two different cases for what their parent
444 // class will be, this is very annoying. It is also
445 // very annoying that the naming conventions for the
446 // sub-branch names are different as well.
447 if (!strcmp(name, clOfElement->GetName())) {
448 // -- If the branch's name is the same as the base class name,
449 // which happens when we are a child branch of a top-level
450 // branch whose name does not end in a dot and also has no
451 // internal dots, elide the branch name, and keep the branch
452 // hierarchy rooted at the ultimate parent, this keeps the base
453 // class part of the branch name from propagating downwards.
454 // FIXME: We are eliding the base class here, creating a break in the branch hierarchy.
455 // Note: We can use parent class (cltop) != branch class (elemClass) to detection elision.
456 Unroll("", fBranchClass.GetClass(), clOfElement, pointer, basketsize, splitlevel+splitSTLP, 0);
459 return;
460 }
461 // If the branch's name is not the same as the base class name,
462 // keep the branch name as a prefix (i.e., continue the branch
463 // hierarchy), but start a new class hierarchy at the base class.
464 //
465 // Note: If the parent branch was created by the branch constructor
466 // which takes a folder as a parameter, then this case will
467 // be used, because the branch name will be the same as the
468 // parent branch name.
469 // Note: This means that the sub-branches of a base class branch
470 // created by TTree::Bronch() have the base class name as
471 // as part of the branch name, while those created by
472 // Unroll() do not, ouch!!!
473 //
474 Unroll(name, clOfElement, clOfElement, pointer, basketsize, splitlevel+splitSTLP, 0);
475 if (strchr(bname, '.')) {
476 // Note: How can this happen?
477 // Answer: This is the case when using the new branch
478 // naming convention where the top-level branch ends in dot.
479 // Note: Well actually not entirely, we could also be a sub-branch
480 // of a split class, even when the top-level branch does not
481 // end in a dot.
482 // Note: Or the top-level branch could have been created by the
483 // branch constructor which takes a folder as input, in which
484 // case the top-level branch name will have internal dots
485 // representing the folder hierarchy.
488 return;
489 }
490 if (nbranches == fBranches.GetEntriesFast()) {
491 // -- 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.
492 const auto bnamelen = strlen(bname);
493 if (bnamelen) {
494 name.Form("%s%s%s", bname, bname[bnamelen-1]=='.' ? "" : ".", clOfElement->GetName());
495 } else {
496 name.Form("%s", clOfElement->GetName());
497 }
498 SetName(name);
499 SetTitle(name);
500 }
503 return;
504 } else if (element->GetClassPointer() == TClonesArray::Class()) {
505 // -- We are a TClonesArray element.
506 Bool_t ispointer = element->IsaPointer();
507 TClonesArray *clones;
508 if (ispointer) {
509 char **ppointer = (char**)(pointer);
510 clones = (TClonesArray*)(*ppointer);
511 } else {
512 clones = (TClonesArray*)pointer;
513 }
514 // basket->DeleteEntryOffset(); //entryoffset not required for the clonesarray counter
515 fEntryOffsetLen = 0;
516 // ===> Create a leafcount
517 TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
518 fNleaves = 1;
519 fLeaves.Add(leaf);
520 fTree->GetListOfLeaves()->Add(leaf);
521 if (!clones) {
523 return;
524 }
525 TClass* clOfClones = clones->GetClass();
526 if (!clOfClones) {
529 return;
530 }
531 fType = 3;
532 // ===> create sub branches for each data member of a TClonesArray
533 //check that the contained objects class name is part of the element title
534 //This name is mandatory when reading the Tree later on and
535 //the parent class with the pointer to the TClonesArray is not available.
536 fClonesName = clOfClones->GetName();
537 fClonesClass = clOfClones;
538 TString aname;
539 aname.Form(" (%s)", clOfClones->GetName());
540 TString atitle = element->GetTitle();
541 if (!atitle.Contains(aname)) {
542 atitle += aname;
543 element->SetTitle(atitle.Data());
544 }
545 TString branchname( name );
546 if (branchname.EndsWith("."))
547 branchname.Remove(branchname.Length()-1);
548 branchname += "_";
549 SetTitle(branchname);
550 leaf->SetName(branchname);
551 leaf->SetTitle(branchname);
552 leaf->SetRange(kTRUE);
553 Unroll(name, clOfClones, clOfClones, pointer, basketsize, splitlevel+splitSTLP, 31);
557 return;
559 // -- We are an STL container element.
560 TClass* contCl = elementClass;
562 TClass* valueClass = GetCollectionProxy()->GetValueClass();
563 // Check to see if we can split the container.
564 Bool_t cansplit = kTRUE;
565 if (!valueClass) {
566 cansplit = kFALSE;
567 } else if ((valueClass == TString::Class()) || (valueClass == TClass::GetClass("string"))) {
568 cansplit = kFALSE;
569 } else if (GetCollectionProxy()->HasPointers() && !splitSTLP ) {
570 cansplit = kFALSE;
571 } else if (!valueClass->CanSplit() && !(GetCollectionProxy()->HasPointers() && splitSTLP)) {
572 cansplit = kFALSE;
573 } else if (valueClass->GetCollectionProxy()) {
574 // -- A collection was stored in a collection, we choose not to split it.
575 // Note: Splitting it would require extending TTreeFormula
576 // to understand how to access it.
577 cansplit = kFALSE;
578 }
579 if (cansplit) {
580 // -- Do the splitting work if we are allowed to.
581 fType = 4;
582 // Create a leaf for the master branch (the counter).
583 TLeaf *leaf = new TLeafElement(this, name, fID, fStreamerType);
584 fNleaves = 1;
585 fLeaves.Add(leaf);
586 fTree->GetListOfLeaves()->Add(leaf);
587 // Check that the contained objects class name is part of the element title.
588 // This name is mandatory when reading the tree later on and
589 // the parent class with the pointer to the STL container is not available.
590 fClonesName = valueClass->GetName();
591 fClonesClass = valueClass;
592 TString aname;
593 aname.Form(" (%s)", valueClass->GetName());
594 TString atitle = element->GetTitle();
595 if (!atitle.Contains(aname)) {
596 atitle += aname;
597 element->SetTitle(atitle.Data());
598 }
599 TString branchname (name);
600 if (branchname.EndsWith("."))
601 branchname.Remove(branchname.Length()-1);
602 branchname += "_";
603 SetTitle(branchname);
604 leaf->SetName(branchname);
605 leaf->SetTitle(branchname);
606 leaf->SetRange(kTRUE);
607 // Create sub branches for each data member of an STL container.
608 Unroll(name, valueClass, valueClass, pointer, basketsize, splitlevel+splitSTLP, 41);
612 return;
613 }
614 } else if (!strchr(elemType, '*') && ((fStreamerType == TVirtualStreamerInfo::kObject) || (fStreamerType == TVirtualStreamerInfo::kAny))) {
615 // -- Create sub-branches for members that are classes.
616 //
617 // Note: This can only happen if we were called directly
618 // (usually by TClass::Bronch) because Unroll never
619 // calls us for an element of this type.
620 fType = 2;
621 TClass* clm = elementClass;
622 Int_t err = Unroll(name, clm, clm, pointer, basketsize, splitlevel+splitSTLP, 0);
623 if (err >= 0) {
624 // Return on success.
625 // FIXME: Why not on error too?
628 return;
629 }
630 }
631 }
632 }
633
634 //
635 // Create a leaf to represent this branch.
636 //
637
638 TLeaf* leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
639 leaf->SetTitle(GetTitle());
640 fNleaves = 1;
641 fLeaves.Add(leaf);
642 fTree->GetListOfLeaves()->Add(leaf);
643
644 //
645 // If we have a counter branch set it now that we have
646 // created our leaf, we cannot do it before then.
647 //
648
649 if (brOfCounter) {
650 SetBranchCount(brOfCounter);
651 }
652
655}
656
657////////////////////////////////////////////////////////////////////////////////
658/// Constructor when the branch object is a TClonesArray.
659///
660/// If splitlevel > 0 this branch in turn is split into sub branches.
661
662TBranchElement::TBranchElement(TTree *tree, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
663: TBranch()
664, fClassName("TClonesArray")
665, fParentName()
666, fInfo((TStreamerInfo*)TClonesArray::Class()->GetStreamerInfo())
667, fInit(kTRUE)
668, fInInitInfo(kFALSE)
669, fInitOffsets(kFALSE)
670, fTargetClass( fClassName )
671, fCurrentClass()
672, fParentClass()
673, fBranchClass(TClonesArray::Class())
674, fBranchID(-1)
675, fReadActionSequence(0)
676, fFillActionSequence(0)
677, fIterators(0)
678, fWriteIterators(0)
679, fPtrIterators(0)
680{
681 Init(tree, 0, bname, clones, basketsize, splitlevel, compress);
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Constructor when the branch object is a TClonesArray.
686///
687/// If splitlevel > 0 this branch in turn is split into sub branches.
688
689TBranchElement::TBranchElement(TBranch *parent, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
690: TBranch()
691, fClassName("TClonesArray")
692, fParentName()
693, fInfo((TStreamerInfo*)TClonesArray::Class()->GetStreamerInfo())
694, fInit(kTRUE)
695, fInInitInfo(kFALSE)
696, fInitOffsets(kFALSE)
697, fTargetClass( fClassName )
698, fCurrentClass()
699, fParentClass()
700, fBranchClass(TClonesArray::Class())
701, fBranchID(-1)
702, fReadActionSequence(0)
703, fFillActionSequence(0)
704, fIterators(0)
705, fWriteIterators(0)
706, fPtrIterators(0)
707{
708 Init(parent ? parent->GetTree() : 0, parent, bname, clones, basketsize, splitlevel, compress);
709}
710
711////////////////////////////////////////////////////////////////////////////////
712/// Init when the branch object is a TClonesArray.
713///
714/// If splitlevel > 0 this branch in turn is split into sub branches.
715
716void TBranchElement::Init(TTree *tree, TBranch *parent, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
717{
718 fCollProxy = 0;
719 fSplitLevel = splitlevel;
720 fID = 0;
721 fInit = kTRUE;
722 fStreamerType = -1;
723 fType = 0;
724 fClassVersion = TClonesArray::Class()->GetClassVersion();
726 fBranchCount = 0;
727 fBranchCount2 = 0;
728 fObject = 0;
729 fOnfileObject = 0;
730 fMaximum = 0;
731 fBranchOffset = 0;
734
735 fTree = tree;
736 fMother = parent ? parent->GetMother() : this;
737 fParent = parent;
739 fFileName = "";
740
741 SetName(bname);
742 const char* name = GetName();
743
744 SetTitle(name);
745 //fClassName = fInfo->GetName();
746 fCompress = compress;
747 if (compress == -1 && fTree->GetDirectory()) {
748 TFile *bfile = fTree->GetDirectory()->GetFile();
749 if (bfile) fCompress = bfile->GetCompressionSettings();
750 }
751
752 if (basketsize < 100) basketsize = 100;
753 fBasketSize = basketsize;
757
758 for (Int_t i=0;i<fMaxBaskets;i++) {
759 fBasketBytes[i] = 0;
760 fBasketEntry[i] = 0;
761 fBasketSeek[i] = 0;
762 }
763
764 // Reset the bit kAutoDelete to specify that when reading
765 // the object should not be deleted before calling the streamer.
767
768 // create sub branches if requested by splitlevel
769 if (splitlevel%TTree::kSplitCollectionOfPointers > 0) {
770 TClass* clonesClass = clones->GetClass();
771 if (!clonesClass) {
772 Error("Init","Missing class object of the TClonesArray %s\n",clones->GetName());
773 return;
774 }
775 fType = 3;
776 // ===> Create a leafcount
777 TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
778 fNleaves = 1;
779 fLeaves.Add(leaf);
780 fTree->GetListOfLeaves()->Add(leaf);
781 // ===> create sub branches for each data member of a TClonesArray
782 fClonesName = clonesClass->GetName();
783 fClonesClass = clonesClass;
784 TString branchname( name );
785 if (branchname[branchname.Length()-1]=='.') {
786 branchname.Remove(branchname.Length()-1);
787 }
788 branchname += "_";
789 SetTitle(branchname);
790 leaf->SetName(branchname);
791 leaf->SetTitle(branchname);
792 Unroll(name, clonesClass, clonesClass, 0, basketsize, splitlevel, 31);
796 return;
797 }
798
799 if (!clones->GetClass() || CanSelfReference(clones->GetClass())) {
801 }
802 TLeaf *leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
803 leaf->SetTitle(GetTitle());
804 fNleaves = 1;
805 fLeaves.Add(leaf);
806 fTree->GetListOfLeaves()->Add(leaf);
807
810}
811
812////////////////////////////////////////////////////////////////////////////////
813/// Constructor when the branch object is an STL collection.
814///
815/// If splitlevel > 0 this branch in turn is split into sub branches.
816
817TBranchElement::TBranchElement(TTree *tree, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
818: TBranch()
819, fClassName(cont->GetCollectionClass()->GetName())
820, fParentName()
821, fInit(kTRUE)
822, fInInitInfo(kFALSE)
823, fInitOffsets(kFALSE)
824, fTargetClass( fClassName )
825, fCurrentClass()
826, fParentClass()
827, fBranchClass(cont->GetCollectionClass())
828, fBranchID(-1)
829, fReadActionSequence(0)
830, fFillActionSequence(0)
831, fIterators(0)
832, fWriteIterators(0)
833, fPtrIterators(0)
834{
835 Init(tree, 0, bname, cont, basketsize, splitlevel, compress);
836}
837
838////////////////////////////////////////////////////////////////////////////////
839/// Constructor when the branch object is an STL collection.
840///
841/// If splitlevel > 0 this branch in turn is split into sub branches.
842
843TBranchElement::TBranchElement(TBranch *parent, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
844: TBranch()
845, fClassName(cont->GetCollectionClass()->GetName())
846, fParentName()
847, fInit(kTRUE)
848, fInInitInfo(kFALSE)
849, fInitOffsets(kFALSE)
850, fTargetClass( fClassName )
851, fCurrentClass()
852, fParentClass()
853, fBranchClass(cont->GetCollectionClass())
854, fBranchID(-1)
855, fReadActionSequence(0)
856, fFillActionSequence(0)
857, fIterators(0)
858, fWriteIterators(0)
859, fPtrIterators(0)
860{
861 Init(parent ? parent->GetTree() : 0, parent, bname, cont, basketsize, splitlevel, compress);
862}
863
864////////////////////////////////////////////////////////////////////////////////
865/// Init when the branch object is an STL collection.
866///
867/// If splitlevel > 0 this branch in turn is split into sub branches.
868
869void TBranchElement::Init(TTree *tree, TBranch *parent, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
870{
871 fCollProxy = cont->Generate();
872 TString name( bname );
873 if (name[name.Length()-1]=='.') {
874 name.Remove(name.Length()-1);
875 }
877 fSplitLevel = splitlevel;
878 fInfo = 0;
879 fID = -1;
880 fInit = kTRUE;
881 fStreamerType = -1; // TVirtualStreamerInfo::kSTLp;
882 fType = 0;
885 fBranchCount = 0;
886 fBranchCount2 = 0;
887 fObject = 0;
888 fOnfileObject = 0;
889 fMaximum = 0;
890 fBranchOffset = 0;
891
892 //Must be set here so that write actions will be properly matched to the ReadLeavesPtr
893 fSTLtype = cont->GetCollectionType();
894 if (fSTLtype < 0) {
896 }
897
898 fTree = tree;
899 fMother = parent ? parent->GetMother() : this;
900 fParent = parent;
902 fFileName = "";
903
904 SetName(name);
905 SetTitle(name);
906 //fClassName = fBranchClass.GetClass()->GetName();
907 fCompress = compress;
908 if ((compress == -1) && fTree->GetDirectory()) {
909 TFile* bfile = fTree->GetDirectory()->GetFile();
910 if (bfile) {
912 }
913 }
914
915 if (basketsize < 100) {
916 basketsize = 100;
917 }
918 fBasketSize = basketsize;
919
923
924 for (Int_t i = 0; i < fMaxBaskets; ++i) {
925 fBasketBytes[i] = 0;
926 fBasketEntry[i] = 0;
927 fBasketSeek[i] = 0;
928 }
929
930 // Reset the bit kAutoDelete to specify that, when reading,
931 // the object should not be deleted before calling the streamer.
933
934 // create sub branches if requested by splitlevel
936 (cont->HasPointers() && splitlevel > TTree::kSplitCollectionOfPointers && cont->GetValueClass() && cont->GetValueClass()->CanSplit() ) )
937 {
938 fType = 4;
939 // ===> Create a leafcount
940 TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
941 fNleaves = 1;
942 fLeaves.Add(leaf);
943 fTree->GetListOfLeaves()->Add(leaf);
944 // ===> create sub branches for each data member of an STL container value class
945 TClass* valueClass = cont->GetValueClass();
946 if (!valueClass) {
947 return;
948 }
949 fClonesName = valueClass->GetName();
950 fClonesClass = valueClass;
951 TString branchname( name );
952 branchname += "_";
953 SetTitle(branchname);
954 leaf->SetName(branchname);
955 leaf->SetTitle(branchname);
956 Unroll(name, valueClass, valueClass, 0, basketsize, splitlevel, 41);
960 return;
961 }
962
963 TLeaf *leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
964 leaf->SetTitle(GetTitle());
965 fNleaves = 1;
966 fLeaves.Add(leaf);
967 fTree->GetListOfLeaves()->Add(leaf);
970}
971
972////////////////////////////////////////////////////////////////////////////////
973/// Destructor.
974
976{
977 // Release any allocated I/O buffers.
979 delete fOnfileObject;
980 fOnfileObject = 0;
981 }
982 ResetAddress();
983
984 delete[] fBranchOffset;
985 fBranchOffset = 0;
986
987 fInfo = 0;
988 fBranchCount2 = 0;
989 fBranchCount = 0;
990
991 if (fType == 4 || fType == 0) {
992 // Only the top level TBranchElement containing an STL container,
993 // owns the collectionproxy.
994 delete fCollProxy;
995 }
996 fCollProxy = 0;
997
998 delete fReadActionSequence;
999 delete fFillActionSequence;
1000 delete fIterators;
1001 delete fWriteIterators;
1002 delete fPtrIterators;
1003}
1004
1005//
1006// This function is located here to allow inlining by the optimizer.
1007//
1008////////////////////////////////////////////////////////////////////////////////
1009/// Get streamer info for the branch class.
1010
1012{
1013 // Note: we need to find a way to reduce the complexity of
1014 // this often executed condition.
1015 if (!fInfo || (fInfo && (!fInit || !fInfo->IsCompiled()))) {
1016 const_cast<TBranchElement*>(this)->InitInfo();
1017 }
1018 return fInfo;
1019}
1020
1021////////////////////////////////////////////////////////////////////////////////
1022/// Get streamer info for the branch class.
1023
1025{
1026 return GetInfoImp();
1027}
1028
1029////////////////////////////////////////////////////////////////////////////////
1030/// Browse the branch content.
1031
1033{
1034 Int_t nbranches = fBranches.GetEntriesFast();
1035 if (nbranches > 0) {
1036 TList persistentBranches;
1037 TBranch* branch=0;
1038 TIter iB(&fBranches);
1039 while((branch=(TBranch*)iB())) {
1040 if (branch->IsFolder()) persistentBranches.Add(branch);
1041 else {
1042 // only show branches corresponding to persistent members
1043 TClass* cl=0;
1044 if (strlen(GetClonesName()))
1045 // this works both for top level branches and for sub-branches,
1046 // as GetClonesName() is properly updated for sub-branches
1047 cl=fClonesClass;
1048 else {
1050
1051 // check if we're in a sub-branch of this class
1052 // we can only find out asking the streamer given our ID
1053 TStreamerElement *element=0;
1054 TClass* clsub=0;
1055 if (fID>=0 && GetInfoImp()
1056 && GetInfoImp()->IsCompiled()
1057 && ((element=GetInfoImp()->GetElement(fID)))
1058 && ((clsub=element->GetClassPointer())))
1059 cl=clsub;
1060 }
1061 if (cl) {
1062 TString strMember=branch->GetName();
1063 Size_t mempos=strMember.Last('.');
1064 if (mempos!=kNPOS)
1065 strMember.Remove(0, (Int_t)mempos+1);
1066 mempos=strMember.First('[');
1067 if (mempos!=kNPOS)
1068 strMember.Remove((Int_t)mempos);
1069 TDataMember* m=cl->GetDataMember(strMember);
1070 if (!m || m->IsPersistent()) persistentBranches.Add(branch);
1071 } else persistentBranches.Add(branch);
1072 } // branch if not a folder
1073 }
1074 persistentBranches.Browse(b);
1075 // add all public const methods without params
1076 if (GetBrowsables() && GetBrowsables()->GetSize())
1078 } else {
1079 if (GetBrowsables() && GetBrowsables()->GetSize()) {
1081 return;
1082 }
1083 // Get the name and strip any extra brackets
1084 // in order to get the full arrays.
1085 TString slash("/");
1086 TString escapedSlash("\\/");
1087 TString name = GetName();
1088 Int_t pos = name.First('[');
1089 if (pos != kNPOS) {
1090 name.Remove(pos);
1091 }
1092 TString mothername;
1093 if (GetMother()) {
1094 mothername = GetMother()->GetName();
1095 pos = mothername.First('[');
1096 if (pos != kNPOS) {
1097 mothername.Remove(pos);
1098 }
1099 Int_t len = mothername.Length();
1100 if (len) {
1101 if (mothername(len-1) != '.') {
1102 // We do not know for sure whether the mother's name is
1103 // already preprended. So we need to check:
1104 // a) it is prepended
1105 // b) it is NOT the name of a daughter (i.e. mothername.mothername exist)
1106 TString doublename = mothername;
1107 doublename.Append(".");
1108 Int_t isthere = (name.Index(doublename) == 0);
1109 if (!isthere) {
1110 name.Prepend(doublename);
1111 } else {
1112 if (GetMother()->FindBranch(mothername)) {
1113 doublename.Append(mothername);
1114 isthere = (name.Index(doublename) == 0);
1115 if (!isthere) {
1116 mothername.Append(".");
1117 name.Prepend(mothername);
1118 }
1119 } else {
1120 // Nothing to do because the mother's name is
1121 // already in the name.
1122 }
1123 }
1124 } else {
1125 // If the mother's name end with a dot then
1126 // the daughter probably already contains the mother's name
1127 if (name.Index(mothername) == kNPOS) {
1128 name.Prepend(mothername);
1129 }
1130 }
1131 }
1132 }
1133 name.ReplaceAll(slash, escapedSlash);
1134 GetTree()->Draw(name, "", b ? b->GetDrawOption() : "");
1135 if (gPad) {
1136 gPad->Update();
1137 }
1138 }
1139}
1140
1141////////////////////////////////////////////////////////////////////////////////
1142/// Set branch and leaf name and title in the case of a container sub-branch.
1143
1145{
1146 TString branchname;
1147
1148 Int_t nbranches = fBranches.GetEntriesFast();
1149
1150 TString indexname(name);
1151 if (indexname[indexname.Length()-1]=='.') {
1152 indexname.Remove(indexname.Length()-1);
1153 }
1154 indexname += "_";
1155
1156 for (Int_t i = 0; i < nbranches; ++i) {
1158 if (!bre)
1159 continue;
1160 if (fType == 3) {
1161 bre->SetType(31);
1162 } else if (fType == 4) {
1163 bre->SetType(41);
1164 } else {
1165 Error("BuildTitle", "This cannot happen, fType of parent is not 3 or 4!");
1166 }
1168 bre->BuildTitle(name);
1169 const char* fin = strrchr(bre->GetTitle(), '.');
1170 if (fin == 0) {
1171 continue;
1172 }
1173 // The branch counter for a sub-branch of a container is the container master branch.
1174 bre->SetBranchCount(this);
1175 TLeafElement* lf = (TLeafElement*) bre->GetListOfLeaves()->At(0);
1176 // If branch name is of the form fTracks.fCovar[3][4], then
1177 // set the title to fCovar[fTracks_].
1178 branchname = fin+1;
1179 Ssiz_t dim = branchname.First('[');
1180 if (dim>=0) {
1181 branchname.Remove(dim);
1182 }
1183 branchname += TString::Format("[%s]", indexname.Data());
1184 bre->SetTitle(branchname);
1185 if (lf) {
1186 lf->SetTitle(branchname);
1187 }
1188 // Is there a secondary branchcount?
1189 //
1190 // fBranchCount2 points to the secondary branchcount
1191 // in case a TClonesArray element itself has a branchcount.
1192 //
1193 // Example: In Event class with TClonesArray fTracks of Track objects.
1194 // if the Track object has two members
1195 // Int_t fNpoint;
1196 // Float_t *fPoints; //[fNpoint]
1197 // In this case the TBranchElement fTracks.fPoints has
1198 // -its primary branchcount pointing to the branch fTracks
1199 // -its secondary branchcount pointing to fTracks.fNpoint
1200 Int_t stype = bre->GetStreamerType();
1201 // FIXME: Should 60 be included here?
1202 if ((stype > 40) && (stype < 61)) {
1203 TString name2 (bre->GetName());
1204 Ssiz_t bn = name2.Last('.');
1205 if (bn<0) {
1206 continue;
1207 }
1209 name2.Remove(bn+1);
1210 if (el) name2 += el->GetCountName();
1212 bre->SetBranchCount2(bc2);
1213 }
1214 bre->SetReadLeavesPtr();
1215 bre->SetFillLeavesPtr();
1216 }
1217}
1218
1219////////////////////////////////////////////////////////////////////////////////
1220/// Loop on all leaves of this branch to fill the basket buffer.
1221///
1222/// The function returns the number of bytes committed to the
1223/// individual branches. If a write error occurs, the number of
1224/// bytes returned is -1. If no data are written, because, e.g.,
1225/// the branch is disabled, the number of bytes returned is 0.
1226///
1227/// Note: We not not use any member functions from TLeafElement!
1228
1230{
1231 Int_t nbytes = 0;
1232 Int_t nwrite = 0;
1233 Int_t nerror = 0;
1234 Int_t nbranches = fBranches.GetEntriesFast();
1235
1237
1238 //
1239 // If we are a top-level branch, update addresses.
1240 //
1241
1242 if (fID < 0) {
1243 if (!fObject) {
1244 Error("Fill", "attempt to fill branch %s while address is not set", GetName());
1245 return 0;
1246 }
1247 }
1248
1249 //
1250 // If the tree has a TRefTable, set the current branch if
1251 // branch is not a basic type.
1252 //
1253
1254 // FIXME: This test probably needs to be extended past 10.
1255 if ((fType >= -1) && (fType < 10)) {
1256 TBranchRef* bref = fTree->GetBranchRef();
1257 if (bref) {
1258 fBranchID = bref->SetParent(this, fBranchID);
1259 }
1260 }
1261
1262 if (!nbranches) {
1263 // No sub-branches.
1264 if (!TestBit(kDoNotProcess)) {
1265 nwrite = TBranch::FillImpl(imtHelper);
1266 if (nwrite < 0) {
1267 Error("Fill", "Failed filling branch:%s, nbytes=%d", GetName(), nwrite);
1268 ++nerror;
1269 } else {
1270 nbytes += nwrite;
1271 }
1272 }
1273 } else {
1274 // We have sub-branches.
1275 if (fType == 3 || fType == 4) {
1276 // TClonesArray or STL container counter
1277 nwrite = TBranch::FillImpl(imtHelper);
1278 if (nwrite < 0) {
1279 Error("Fill", "Failed filling branch:%s, nbytes=%d", GetName(), nwrite);
1280 ++nerror;
1281 } else {
1282 nbytes += nwrite;
1283 }
1284 } else {
1285 ++fEntries;
1286 }
1287 for (Int_t i = 0; i < nbranches; ++i) {
1288 TBranchElement* branch = (TBranchElement*) fBranches[i];
1289 if (!branch->TestBit(kDoNotProcess)) {
1290 nwrite = branch->FillImpl(imtHelper);
1291 if (nwrite < 0) {
1292 Error("Fill", "Failed filling branch:%s.%s, nbytes=%d", GetName(), branch->GetName(), nwrite);
1293 nerror++;
1294 } else {
1295 nbytes += nwrite;
1296 }
1297 }
1298 }
1299 }
1300
1301 if (fTree->Debug() > 0) {
1302 // Debugging.
1303 Long64_t entry = fEntries;
1304 if ((entry >= fTree->GetDebugMin()) && (entry <= fTree->GetDebugMax())) {
1305 printf("Fill: %lld, branch=%s, nbytes=%d\n", entry, GetName(), nbytes);
1306 }
1307 }
1308
1309 if (nerror != 0) {
1310 return -1;
1311 }
1312
1313 return nbytes;
1314}
1315
1316////////////////////////////////////////////////////////////////////////////////
1317/// Write leaves into i/o buffers for this branch.
1318/// For the case where the branch is set in MakeClass mode (decomposed object).
1319
1321{
1323
1324 //
1325 // Silently do nothing if we have no user i/o buffer.
1326 //
1327
1328 if (!fObject) {
1329 return;
1330 }
1331
1332 // -- TClonesArray top-level branch. Write out number of entries, sub-branch writes the entries themselves.
1333 if(fType == 3) {
1334 // fClonesClass can not be zero since we are of type 3, see TBranchElement::Init
1336 if (!si) {
1337 Error("FillLeaves", "Cannot get streamer info for branch '%s' class '%s'", GetName(), fClonesClass->GetName());
1338 return;
1339 }
1340 b.ForceWriteInfo(si,kFALSE);
1341 Int_t* nptr = (Int_t*) fAddress;
1342 b << *nptr;
1343 } else if (fType == 31) {
1344 // -- TClonesArray sub-branch. Write out the entries in the TClonesArray.
1345 // -- A MakeClass() tree, we must use fAddress instead of fObject.
1346 if (!fAddress) {
1347 // FIXME: Enable this message.
1348 //Error("FillLeaves", "Branch address not set for branch '%s'!", GetName());
1349 return;
1350 }
1351 Int_t atype = fStreamerType;
1352 if (atype > 54) {
1353 // Note: We are not supporting kObjectp, kAny, kObjectp,
1354 // kObjectP, kTString, kTObject, kTNamed, kAnyp,
1355 // kAnyP, kSTLp, kSTL, kSTLstring, kStreamer,
1356 // kStreamLoop here, nor pointers to varying length
1357 // arrays of them either.
1358 // Nor do we support pointers to varying length
1359 // arrays of kBits, kLong64, kULong64, nor kBool.
1360 return;
1361 }
1362 Int_t* nn = (Int_t*) fBranchCount->GetAddress();
1363 if (!nn) {
1364 Error("FillLeaves", "The branch counter address was zero!");
1365 return;
1366 }
1367 Int_t n = *nn;
1368 if (atype > 40) {
1369 // Note: We are not supporting pointer to varying length array.
1370 Error("FillLeaves", "Clonesa: %s, n=%d, sorry not supported yet", GetName(), n);
1371 return;
1372 }
1373 if (atype > 20) {
1374 atype -= 20;
1376 n = n * leaf->GetLenStatic();
1377 }
1378 switch (atype) {
1379 // Note: Type 0 is a base class and cannot happen here, see Unroll().
1380 case TVirtualStreamerInfo::kChar /* 1 */: { b.WriteFastArray((Char_t*) fAddress, n); break; }
1381 case TVirtualStreamerInfo::kShort /* 2 */: { b.WriteFastArray((Short_t*) fAddress, n); break; }
1382 case TVirtualStreamerInfo::kInt /* 3 */: { b.WriteFastArray((Int_t*) fAddress, n); break; }
1383 case TVirtualStreamerInfo::kLong /* 4 */: { b.WriteFastArray((Long_t*) fAddress, n); break; }
1384 case TVirtualStreamerInfo::kFloat /* 5 */: { b.WriteFastArray((Float_t*) fAddress, n); break; }
1385 case TVirtualStreamerInfo::kCounter /* 6 */: { b.WriteFastArray((Int_t*) fAddress, n); break; }
1386 // FIXME: We do nothing with type 7 (TVirtualStreamerInfo::kCharStar, char*) here!
1387 case TVirtualStreamerInfo::kDouble /* 8 */: { b.WriteFastArray((Double_t*) fAddress, n); break; }
1388 case TVirtualStreamerInfo::kDouble32 /* 9 */: {
1390 // coverity[returned_null] structurally si->fComp (used in GetElem) can not be null.
1391 TStreamerElement* se = si->GetElement(fID);
1392 Double_t* xx = (Double_t*) fAddress;
1393 for (Int_t ii = 0; ii < n; ++ii) {
1394 b.WriteDouble32(&(xx[ii]),se);
1395 }
1396 break;
1397 }
1398 case TVirtualStreamerInfo::kFloat16 /* 19 */: {
1400 // coverity[dereference] structurally si can not be null.
1402 Float_t* xx = (Float_t*) fAddress;
1403 for (Int_t ii = 0; ii < n; ++ii) {
1404 b.WriteFloat16(&(xx[ii]),se);
1405 }
1406 break;
1407 }
1408 // Note: Type 10 is unused for now.
1409 case TVirtualStreamerInfo::kUChar /* 11 */: { b.WriteFastArray((UChar_t*) fAddress, n); break; }
1410 case TVirtualStreamerInfo::kUShort /* 12 */: { b.WriteFastArray((UShort_t*) fAddress, n); break; }
1411 case TVirtualStreamerInfo::kUInt /* 13 */: { b.WriteFastArray((UInt_t*) fAddress, n); break; }
1412 case TVirtualStreamerInfo::kULong /* 14 */: { b.WriteFastArray((ULong_t*) fAddress, n); break; }
1413 // FIXME: This is wrong!!! TVirtualStreamerInfo::kBits is a variable length type.
1414 case TVirtualStreamerInfo::kBits /* 15 */: { b.WriteFastArray((UInt_t*) fAddress, n); break; }
1415 case TVirtualStreamerInfo::kLong64 /* 16 */: { b.WriteFastArray((Long64_t*) fAddress, n); break; }
1416 case TVirtualStreamerInfo::kULong64 /* 17 */: { b.WriteFastArray((ULong64_t*) fAddress, n); break; }
1417 case TVirtualStreamerInfo::kBool /* 18 */: { b.WriteFastArray((Bool_t*) fAddress, n); break; }
1418 }
1419 }
1420}
1421
1422////////////////////////////////////////////////////////////////////////////////
1423/// Write leaves into i/o buffers for this branch.
1424/// Case of a collection (fType == 4).
1425
1427{
1428 // -- STL container top-level branch. Write out number of entries, sub-branch writes the entries themselves.
1430
1431 //
1432 // Silently do nothing if we have no user i/o buffer.
1433 //
1434
1435 if (!fObject) {
1436 return;
1437 }
1438
1440 Int_t n = 0;
1441 // We are in a block so the helper pops as soon as possible.
1443 n = proxy->Size();
1444
1445 if (n > fMaximum) {
1446 fMaximum = n;
1447 }
1448 b << n;
1449
1452 } else {
1453 //NOTE: this does not work for not vectors since the CreateIterators expects a TGenCollectionProxy::TStaging as its argument!
1454 //NOTE: and those not work in general yet, since the TStaging object is neither created nor passed.
1455 // We need to review how to avoid the need for a TStaging during the writing.
1458 } else {
1460 }
1461 }
1462
1463}
1464
1465////////////////////////////////////////////////////////////////////////////////
1466/// Write leaves into i/o buffers for this branch.
1467/// Case of a data member within a collection (fType == 41).
1468
1470{
1472
1473 //
1474 // Silently do nothing if we have no user i/o buffer.
1475 //
1476
1477 if (!fObject) {
1478 return;
1479 }
1480
1481 // FIXME: This wont work if a pointer to vector is split!
1483 // Note: We cannot pop the proxy here because we need it for the i/o.
1485 if (!si) {
1486 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1487 return;
1488 }
1489
1491 R__ASSERT(0!=iter);
1492 b.ApplySequenceVecPtr(*fFillActionSequence,iter->fBegin,iter->fEnd);
1493}
1494
1495////////////////////////////////////////////////////////////////////////////////
1496/// Write leaves into i/o buffers for this branch.
1497/// Case of a data member within a collection (fType == 41).
1498
1500{
1502
1503 //
1504 // Silently do nothing if we have no user i/o buffer.
1505 //
1506
1507 if (!fObject) {
1508 return;
1509 }
1510
1511 // FIXME: This wont work if a pointer to vector is split!
1513
1514 // Note: We cannot pop the proxy here because we need it for the i/o.
1516 if (!si) {
1517 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1518 return;
1519 }
1520
1522 b.ApplySequence(*fFillActionSequence,iter->fBegin,iter->fEnd);
1523
1524}
1525
1526////////////////////////////////////////////////////////////////////////////////
1527/// Write leaves into i/o buffers for this branch.
1528/// Case of a data member within a collection (fType == 41).
1529
1531{
1533
1534 //
1535 // Silently do nothing if we have no user i/o buffer.
1536 //
1537
1538 if (!fObject) {
1539 return;
1540 }
1541
1542 // FIXME: This wont work if a pointer to vector is split!
1544 // Note: We cannot pop the proxy here because we need it for the i/o.
1546 if (!si) {
1547 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1548 return;
1549 }
1550
1552 R__ASSERT(0!=iter);
1553 b.ApplySequence(*fFillActionSequence,iter->fBegin,iter->fEnd);
1554
1555}
1556
1557////////////////////////////////////////////////////////////////////////////////
1558/// Write leaves into i/o buffers for this branch.
1559/// Case of a data member within a collection (fType == 41).
1560
1562{
1564
1565 //
1566 // Silently do nothing if we have no user i/o buffer.
1567 //
1568
1569 if (!fObject) {
1570 return;
1571 }
1572
1573 // FIXME: This wont work if a pointer to vector is split!
1575 // Note: We cannot pop the proxy here because we need it for the i/o.
1577 if (!si) {
1578 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1579 return;
1580 }
1581
1583 R__ASSERT(0!=iter);
1584 b.ApplySequence(*fFillActionSequence,iter->fBegin,iter->fEnd);
1585
1586}
1587
1588////////////////////////////////////////////////////////////////////////////////
1589/// Write leaves into i/o buffers for this branch.
1590/// Case of a TClonesArray (fType == 3).
1591
1593{
1594 // -- TClonesArray top-level branch. Write out number of entries, sub-branch writes the entries themselves.
1596
1597 //
1598 // Silently do nothing if we have no user i/o buffer.
1599 //
1600
1601 if (!fObject) {
1602 return;
1603 }
1604
1605 TClonesArray* clones = (TClonesArray*) fObject;
1606 Int_t n = clones->GetEntriesFast();
1607 if (n > fMaximum) {
1608 fMaximum = n;
1609 }
1610 b << n;
1611}
1612
1613////////////////////////////////////////////////////////////////////////////////
1614/// Write leaves into i/o buffers for this branch.
1615/// Case of a data member within a TClonesArray (fType == 31).
1616
1618{
1620
1621 //
1622 // Silently do nothing if we have no user i/o buffer.
1623 //
1624
1625 if (!fObject) {
1626 return;
1627 }
1628
1629 TClonesArray* clones = (TClonesArray*) fObject;
1630 Int_t n = clones->GetEntriesFast();
1632 if (!si) {
1633 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1634 return;
1635 }
1636
1637 char **arr = (char **)clones->GetObjectRef(0);
1638 char **end = arr + n;
1639 b.ApplySequenceVecPtr(*fFillActionSequence,arr,end);
1640}
1641
1642////////////////////////////////////////////////////////////////////////////////
1643/// Write leaves into i/o buffers for this branch.
1644/// Case of a non TObject, non collection class with a custom streamer
1645
1647{
1649
1650 //
1651 // Silently do nothing if we have no user i/o buffer.
1652 //
1653
1654 if (!fObject) {
1655 return;
1656 }
1657
1658 //
1659 // Remember tobjects written to the buffer so that
1660 // pointers are handled correctly later.
1661
1662 if (TestBit(kBranchObject)) {
1663 b.MapObject((TObject*) fObject);
1664 } else if (TestBit(kBranchAny)) {
1665 b.MapObject(fObject, fBranchClass);
1666 }
1667
1669}
1670
1671////////////////////////////////////////////////////////////////////////////////
1672/// Write leaves into i/o buffers for this branch.
1673/// For split-class branch, base class branch, data member branch, or top-level branch.
1674/// which do have a branch count and are not a counter.
1675
1677{
1679 /*
1680 ValidateAddress();
1681
1682 //
1683 // Silently do nothing if we have no user i/o buffer.
1684 //
1685
1686 if (!fObject) {
1687 return;
1688 }
1689 */
1690}
1691
1692////////////////////////////////////////////////////////////////////////////////
1693/// Write leaves into i/o buffers for this branch.
1694/// For split-class branch, base class branch, data member branch, or top-level branch.
1695/// which do not have a branch count and are a counter.
1696
1698{
1700
1701 //
1702 // Silently do nothing if we have no user i/o buffer.
1703 //
1704
1705 if (!fObject) {
1706 return;
1707 }
1708 // -- Top-level, data member, base class, or split class branch.
1709 // 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.
1710 // Note: A split top-level branch (0, and fID == -2) should not happen here, see Fill().
1711 // FIXME: What happens with a split base class branch,
1712 // or a split class branch???
1713 TStreamerInfo* si = GetInfoImp();
1714 if (!si) {
1715 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1716 return;
1717 }
1718 // Since info is not null, fFillActionSequence is not null either.
1719 b.ApplySequence(*fFillActionSequence, fObject);
1720 // Int_t n = si->WriteBufferAux(b, &fObject, fID, 1, 0, 0);
1721
1722 Int_t n = *(Int_t*)(fObject + si->TStreamerInfo::GetElementOffset(fID)); // or GetInfoImp()->GetTypedValue<Int_t>(&fObject, fID, j, -1);
1723 if (n > fMaximum) {
1724 fMaximum = n;
1725 }
1726
1727}
1728
1729////////////////////////////////////////////////////////////////////////////////
1730/// Write leaves into i/o buffers for this branch.
1731/// For split-class branch, base class branch, data member branch, or top-level branch.
1732/// which do not have a branch count and are not a counter.
1733
1735{
1737
1738 //
1739 // Silently do nothing if we have no user i/o buffer.
1740 //
1741
1742 if (!fObject) {
1743 return;
1744 }
1745
1746 if (TestBit(kBranchObject)) {
1747 b.MapObject((TObject*) fObject);
1748 } else if (TestBit(kBranchAny)) {
1749 b.MapObject(fObject, fBranchClass);
1750 }
1751
1752 // -- Top-level, data member, base class, or split class branch.
1753 // 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.
1754 // Note: A split top-level branch (0, and fID == -2) should not happen here, see Fill().
1755 // FIXME: What happens with a split base class branch,
1756 // or a split class branch???
1757 TStreamerInfo* si = GetInfoImp();
1758 if (!si) {
1759 Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
1760 return;
1761 }
1762 // Since info is not null, fFillActionSequence is not null either.
1763 b.ApplySequence(*fFillActionSequence, fObject);
1764
1765}
1766
1767////////////////////////////////////////////////////////////////////////////////
1768/// Remove trailing dimensions and make sure
1769/// there is a trailing dot.
1770
1771static void R__CleanName(std::string &name)
1772{
1773 if (name[name.length()-1]==']') {
1774 std::size_t dim = name.find_first_of("[");
1775 if (dim != std::string::npos) {
1776 name.erase(dim);
1777 }
1778 }
1779 if (name[name.size()-1] != '.') {
1780 name += '.';
1781 }
1782}
1783
1784////////////////////////////////////////////////////////////////////////////////
1785/// Find the immediate sub-branch with passed name.
1786
1788{
1789 // The default behavior of TBranch::FindBranch is sometimes
1790 // incorrect if this branch represent a base class, since
1791 // the base class name might or might not be in the name
1792 // of the sub-branches and might or might not be in the
1793 // name being passed.
1794
1795 if (fID >= 0) {
1797 TStreamerElement* se = si->GetElement(fID);
1798 if (se && se->IsBase()) {
1799 // We allow the user to pass only the last dotted component of the name.
1800 UInt_t len = strlen(name);
1801 std::string longnm;
1802 longnm.reserve(fName.Length()+len+3); // Enough space of fName + name + dots
1803 longnm = fName.Data();
1804 R__CleanName(longnm);
1805 longnm += name;
1806 std::string longnm_parent;
1807 longnm_parent.reserve(fName.Length()+len+3);
1808 longnm_parent = (GetMother()->GetSubBranch(this)->GetName());
1809 R__CleanName(longnm_parent);
1810 longnm_parent += name; // Name without the base class name
1811
1812 UInt_t namelen = strlen(name);
1813
1814 TBranch* branch = 0;
1815 Int_t nbranches = fBranches.GetEntries();
1816 for(Int_t i = 0; i < nbranches; ++i) {
1817 branch = (TBranch*) fBranches.UncheckedAt(i);
1818
1819 const char *brname = branch->GetName();
1820 UInt_t brlen = strlen(brname);
1821 if (brname[brlen-1]==']') {
1822 const char *dim = strchr(brname,'[');
1823 if (dim) {
1824 brlen = dim - brname;
1825 }
1826 }
1827 if (namelen == brlen /* same effective size */
1828 && strncmp(name,brname,brlen) == 0) {
1829 return branch;
1830 }
1831 if (brlen == longnm.length()
1832 && strncmp(longnm.c_str(),brname,brlen) == 0) {
1833 return branch;
1834 }
1835 // This check is specific to base class
1836 if (brlen == longnm_parent.length()
1837 && strncmp(longnm_parent.c_str(),brname,brlen) == 0) {
1838 return branch;
1839 }
1840
1841 if (namelen>brlen && name[brlen]=='.' && strncmp(name,brname,brlen)==0) {
1842 // The prefix subbranch name match the branch name.
1843 return branch->FindBranch(name+brlen+1);
1844 }
1845 }
1846 }
1847 }
1848 TBranch *result = TBranch::FindBranch(name);
1849 if (!result) {
1850 // Look in base classes if any
1851 Int_t nbranches = fBranches.GetEntries();
1852 for(Int_t i = 0; i < nbranches; ++i) {
1853 TObject *obj = fBranches.UncheckedAt(i);
1854 if(obj->IsA() != TBranchElement :: Class() )
1855 continue;
1856 TBranchElement *br = (TBranchElement*)obj;
1857 TVirtualStreamerInfo* si = br->GetInfoImp();
1858 if (si && br->GetID() >= 0) {
1859 TStreamerElement* se = si->GetElement(br->GetID());
1860 if (se && se->IsBase()) {
1861 result = br->FindBranch(name);
1862 }
1863 }
1864 }
1865 }
1866 return result;
1867}
1868
1869////////////////////////////////////////////////////////////////////////////////
1870/// Find the leaf corresponding to the name 'searchname'.
1871
1873{
1874 TLeaf *leaf = TBranch::FindLeaf(name);
1875
1876 if (leaf==0 && GetListOfLeaves()->GetEntries()==1) {
1877 TBranch *br = GetMother()->GetSubBranch( this );
1878 if( br->IsA() != TBranchElement::Class() )
1879 return 0;
1880
1881 TBranchElement *parent = (TBranchElement*)br;
1882 if (parent==this || parent->GetID()<0 ) return 0;
1883
1884 TVirtualStreamerInfo* si = parent->GetInfoImp();
1885 TStreamerElement* se = si->GetElement(parent->GetID());
1886
1887 if (! se->IsBase() ) return 0;
1888
1889 br = GetMother()->GetSubBranch( parent );
1890 if( br->IsA() != TBranchElement::Class() )
1891 return 0;
1892
1893 TBranchElement *grand_parent = (TBranchElement*)br;
1894
1895 std::string longname( grand_parent->GetName() );
1896 R__CleanName(longname);
1897 longname += name;
1898
1899 std::string leafname( GetListOfLeaves()->At(0)->GetName() );
1900
1901 if ( longname == leafname ) {
1902 return (TLeaf*)GetListOfLeaves()->At(0);
1903 }
1904 }
1905 return leaf;
1906}
1907
1908////////////////////////////////////////////////////////////////////////////////
1909/// Get the branch address.
1910///
1911/// If we are *not* owned by a MakeClass() tree:
1912///
1913/// - If we are a top-level branch, return a pointer
1914/// - to the pointer to our object.
1915///
1916/// If we are *not* a top-level branch, return a pointer
1917/// to our object.
1918///
1919/// If we are owned by a MakeClass() tree:
1920///
1921/// - Return a pointer to our object.
1922
1924{
1926 return fAddress;
1927}
1928
1929
1930// For a mother branch of type 3 or 4, find the 'correct' StreamerInfo for the
1931// content of the collection by find a sub-branch corresponding to a direct data member
1932// of the containee class (valueClass)
1933// Default to the current StreamerInfo if none are found.
1935{
1936 TStreamerInfo *localInfo = nullptr;
1937
1938 // Search for the correct version.
1939 for(auto subbe : TRangeDynCast<TBranchElement>( branches )) {
1940 if (!subbe->fInfo)
1941 subbe->SetupInfo();
1942 if (valueClass == subbe->fInfo->GetClass()) { // Use GetInfo to provoke its creation.
1943 localInfo = subbe->fInfo;
1944 break;
1945 }
1946 }
1947 if (!localInfo) {
1948 // This is likely sub-optimal as we really should call GetFile but it is non-const.
1949 auto file = fDirectory ? fDirectory->GetFile() : nullptr;
1950 if (file && file->GetSeekInfo()) {
1951 localInfo = (TStreamerInfo*)file->GetStreamerInfoCache()->FindObject(valueClass->GetName());
1952 if (localInfo) {
1953 if (valueClass->IsVersioned()) {
1954 localInfo = (TStreamerInfo*)valueClass->GetStreamerInfo(localInfo->GetClassVersion());
1955 } else {
1956 localInfo = (TStreamerInfo*)valueClass->FindStreamerInfo(localInfo->GetCheckSum());
1957 if (localInfo) {
1958 // Now that we found it, we need to make sure it is initialize (Find does not initialize the StreamerInfo).
1959 localInfo = (TStreamerInfo*)valueClass->GetStreamerInfo(localInfo->GetClassVersion());
1960 }
1961 }
1962 }
1963 }
1964 }
1965 if (!localInfo)
1966 localInfo = (TStreamerInfo*)valueClass->GetStreamerInfo();
1967
1968 if (localInfo) {
1969 // See if we need any conversion.
1970 TClass *targetValueClass = fInfo->GetClass()->GetCollectionProxy()
1972 : nullptr;
1973 // For TClonesArray, the rest of the code probably does not support change in
1974 // value class, but if it does, we would have to look up the target value class
1975 // in the TClonesArray instance.
1976 // if (type == 3 && instance) targetValueClass = ((TClonesArray*)instance)->GetClass();
1977
1978 if (targetValueClass && localInfo->GetClass() != targetValueClass) {
1979 localInfo = (TStreamerInfo*)targetValueClass->GetConversionStreamerInfo(localInfo->GetClass(),
1980 localInfo->GetClassVersion());
1981 }
1982 }
1983 return localInfo;
1984}
1985
1986namespace {
1987static void GatherArtificialElements(const TObjArray &branches, TStreamerInfoActions::TIDs &ids, TString prefix, TStreamerInfo *info, Int_t offset) {
1988 size_t ndata = info->GetNelement();
1989 for (size_t i =0; i < ndata; ++i) {
1990 TStreamerElement *nextel = info->GetElement(i);
1991
1992 if (nextel->GetType() == TStreamerInfo::kCacheDelete
1993 || nextel->GetType() == TStreamerInfo::kCacheNew) {
1994 continue;
1995 }
1996
1997 TString ename = prefix + nextel->GetName();
1998
1999 if (ename[0]=='*')
2000 ename.Remove(0,1);
2001
2002 Ssiz_t pos;
2003 while ((pos = ename.Last('[')) != TString::kNPOS) {
2004 ename = ename.Remove(pos);
2005 }
2006
2007 TBranchElement *be = (TBranchElement*)branches.FindObject(ename);
2008 if (nextel->IsA() == TStreamerArtificial::Class()
2009 && be == nullptr) {
2010
2011 ids.push_back(i);
2012 ids.back().fElement = nextel;
2013 ids.back().fInfo = info;
2014 }
2015
2016 if (nextel->CannotSplit() || nextel->IsTransient() || nextel->GetOffset() == TStreamerInfo::kMissing)
2017 continue;
2018
2019 if (!be && nextel->IsBase()) {
2020 // We could be in the case of a branch created from a Folder or
2021 // a top level branch with a non-trailing dot in its name (case inadvertently confused with the folder case).
2022 // In those case, the name of the base class is *not* used to create the corresponding branch.
2023 TString subprefix(prefix);
2024 if (subprefix.Length() && subprefix[subprefix.Length()-1] == '.')
2025 subprefix.Remove(subprefix.Length()-1);
2026
2027 be = (TBranchElement*)branches.FindObject(subprefix);
2028 if (be) {
2029 // There is at least 'one' base class branch all with the same name, so let's find the
2030 // right one.
2031 TClass *expectedClass = nullptr;
2032 EDataType expectedType;
2033 if (0 != be->GetExpectedType(expectedClass,expectedType)
2034 || expectedClass != nextel->GetClassPointer())
2035 {
2036 be = nullptr;
2037 Int_t nbranches = branches.GetEntriesFast();
2038 for (Int_t bi = 0; bi < nbranches; ++bi) {
2039 TBranchElement* branch = (TBranchElement*) branches[bi];
2040 if (subprefix != branch->GetName())
2041 continue;
2042 if (0 == branch->GetExpectedType(expectedClass,expectedType)
2043 && expectedClass == nextel->GetClassPointer())
2044 {
2045 be = branch;
2046 break;
2047 }
2048 }
2049 } // else we have already found the right branch.
2050 }
2051 }
2052
2053 TClass *elementClass = nextel->GetClassPointer();
2054 if (elementClass && (!be || be->GetType() == -2)) {
2055 // Recurse on sub-objects.
2056 TStreamerInfo *nextinfo = nullptr;
2057
2058 // nextinfo_version = ....
2059 auto search = be ? be->GetListOfBranches() : &branches;
2060 TVirtualArray *onfileObject = nullptr;
2061 for(auto subbe : TRangeDynCast<TBranchElement>( *search )) {
2062
2063 if (elementClass == subbe->GetInfo()->GetClass() && subbe->GetOnfileObject()) { // Use GetInfo to provoke its creation.
2064 nextinfo = subbe->GetInfo();
2065 onfileObject = subbe->GetOnfileObject();
2066 break;
2067 }
2068 }
2069 if (!nextinfo) {
2070 nextinfo = (TStreamerInfo *)elementClass->GetStreamerInfo();
2071 if (elementClass->GetCollectionProxy() && elementClass->GetCollectionProxy()->GetValueClass()) {
2072 nextinfo = (TStreamerInfo *)elementClass->GetCollectionProxy()->GetValueClass()->GetStreamerInfo(); // NOTE: need to find the right version
2073 }
2074 }
2075 ids.emplace_back(nextinfo, offset + nextel->GetOffset());
2076 if (!onfileObject && nextinfo && nextinfo->GetNelement() && nextinfo->GetElement(0)->GetType() == TStreamerInfo::kCacheNew) {
2077 onfileObject = new TVirtualArray( info->GetElement(0)->GetClassPointer(), 1 /* is that always right? */ );
2078 ids.back().fNestedIDs->fOwnOnfileObject = kTRUE;
2079 }
2080 ids.back().fNestedIDs->fOnfileObject = onfileObject;
2081 TString subprefix;
2082 if (prefix.Length() && nextel->IsA() == TStreamerBase::Class()) {
2083 // We skip the name of the base class if there is already a prefix.
2084 // See TBranchElement::Unroll
2085 subprefix = prefix;
2086 } else {
2087 subprefix = ename + ".";
2088 }
2089 GatherArtificialElements(branches, ids.back().fNestedIDs->fIDs, subprefix, nextinfo, offset + nextel->GetOffset());
2090 if (ids.back().fNestedIDs->fIDs.empty())
2091 ids.pop_back();
2092 }
2093 }
2094};
2095} // Anonymous namespace.
2096
2097
2098////////////////////////////////////////////////////////////////////////////////
2099/// Set the value of fInfo. This is part one of InitInfo.
2100/// To be used as:
2101/// if (!fInfo)
2102/// SetupInfo();
2103/// It would only be used within InitInfo (and its callees)
2104
2106{
2107 // We did not already have streamer info, so now we must find it.
2109
2110 //------------------------------------------------------------------------
2111 // Check if we're dealing with the name change
2112 //////////////////////////////////////////////////////////////////////////
2113
2114 TClass* targetClass = 0;
2115 if( fTargetClass.GetClassName()[0] ) {
2116 targetClass = fTargetClass;
2117 if (!targetClass && GetCollectionProxy()) {
2118 // We are in the case where the branch holds a custom collection
2119 // proxy but the dictionary is not loaded, calling
2120 // GetCollectionProxy had the side effect of creating the TClass
2121 // corresponding to this emulated collection.
2122 targetClass = fTargetClass;
2123 }
2124 if ( !targetClass ) {
2125 Error( "InitInfo", "The target class dictionary is not present!" );
2126 return;
2127 }
2128 } else {
2129 targetClass = cl;
2130 }
2131 if (cl) {
2132 //---------------------------------------------------------------------
2133 // Get the streamer info for given version
2134 ///////////////////////////////////////////////////////////////////////
2135
2136 {
2137 if ( (cl->Property() & kIsAbstract) && cl == targetClass) {
2139 if (parent && parent != this && !parent->GetClass()->IsLoaded() ) {
2140 // Our parent's class is emulated and we represent an abstract class.
2141 // and the target class has not been set explicitly.
2142 TString target = cl->GetName();
2143 target += "@@emulated";
2144 fTargetClass.SetName(target);
2145
2146 if (!fTargetClass) {
2148 }
2149 targetClass = fTargetClass;
2150 }
2151 }
2152 if( targetClass != cl ) {
2154 } else {
2156 }
2157 }
2158
2159 // FIXME: Check that the found streamer info checksum matches our branch class checksum here.
2160 // Check to see if the class code was unloaded/reloaded
2161 // since we were created.
2163 if (fCheckSum && (cl->IsForeign() || (!cl->IsLoaded() && (fClassVersion == 1) && cl->GetStreamerInfos()->At(1) && (fCheckSum != ((TVirtualStreamerInfo*) cl->GetStreamerInfos()->At(1))->GetCheckSum())))) {
2164 // Try to compensate for a class that got unloaded on us.
2165 // Search through the streamer infos by checksum
2166 // and take the first match.
2167
2168 TStreamerInfo* info;
2169 if( targetClass != cl )
2170 info = (TStreamerInfo*)targetClass->FindConversionStreamerInfo( cl, fCheckSum );
2171 else {
2173 if (info) {
2174 // Now that we found it, we need to make sure it is initialize (Find does not initialize the StreamerInfo).
2175 info = (TStreamerInfo*)cl->GetStreamerInfo(info->GetClassVersion());
2176 }
2177 }
2178 if( info ) {
2179 fInfo = info;
2180 // We no longer reset the class version so that in case the user is passing us later
2181 // the address of a class that require (another) Conversion we can find the proper
2182 // StreamerInfo.
2183 // fClassVersion = fInfo->GetClassVersion();
2184 }
2185 }
2186 }
2187}
2188
2189
2190////////////////////////////////////////////////////////////////////////////////
2191/// Init the streamer info for the branch class, try to compensate for class
2192/// code unload/reload and schema evolution.
2193
2195{
2196 if (!fInfo)
2197 SetupInfo();
2198
2199 //
2200 // Fixup cached streamer info if necessary.
2201 //
2202 // FIXME: What if the class code was unloaded/reloaded since we were cached?
2203
2204 if (fInfo) {
2205
2206 if (!fInfo->IsCompiled()) {
2207 // Streamer info has not yet been compiled.
2208
2209 Error("InitInfo","StreamerInfo is not compiled.");
2210 }
2211 // return immediately if we are called recursively.
2212 if (fInInitInfo)
2213 return;
2215 if (!fInit) {
2216 // We were read in from a file, figure out what our fID should be,
2217 // schema evolution must be considered.
2218 //
2219 // Force our fID to be the id of the first streamer element that matches our name.
2220 //
2221 auto SetOnfileObject = [this](TStreamerInfo *info) {
2222 Int_t arrlen = 1;
2223 if (fType==31 || fType==41) {
2224 TLeaf *leaf = (TLeaf*)fLeaves.At(0);
2225 if (leaf) {
2226 arrlen = leaf->GetMaximum();
2227 }
2228 }
2229 Bool_t toplevel = (fType == 3 || fType == 4 || (fType == 0 && fID == -2));
2230 Bool_t seenExisting = kFALSE;
2231
2232 fOnfileObject = new TVirtualArray( info->GetElement(0)->GetClassPointer(), arrlen );
2233 if (fType == 31 || fType == 41) {
2235 if (parent && parent->fOnfileObject == nullptr)
2236 parent->fOnfileObject = fOnfileObject;
2237 }
2238 // Propage this to all the other branch of this type.
2239 TObjArray *branches = toplevel ? GetListOfBranches() : GetMother()->GetSubBranch(this)->GetListOfBranches();
2240 Int_t nbranches = branches->GetEntriesFast();
2241 TBranchElement *lastbranch = this;
2242
2243 TClass *currentClass = fBranchClass;
2244 auto currentVersion = fClassVersion;
2245 if (toplevel) {
2246 // Note: Fragile/wrong when using conversion StreamerInfo?
2247 currentClass = info->GetClass();
2248 currentVersion = info->GetClassVersion();
2249 }
2250
2251 for (Int_t i = 0; i < nbranches; ++i) {
2252 TBranchElement* subbranch = (TBranchElement*)branches->At(i);
2253 Bool_t match = kFALSE;
2254 if (this != subbranch) {
2255
2256 if (!subbranch->fInfo)
2257 subbranch->SetupInfo();
2258
2259 if (subbranch->fInfo == info)
2260 match = kTRUE;
2261 else if (subbranch->fInfo == nullptr && subbranch->fBranchClass == currentClass) {
2262 if (!toplevel) {
2263 if (subbranch->fCheckSum == fCheckSum)
2264 match = kTRUE;
2265 } else {
2266 if (!subbranch->fBranchClass->IsForeign() && subbranch->fClassVersion == currentVersion)
2267 match = kTRUE;
2268 else if (subbranch->fCheckSum == info->GetCheckSum()) {
2269 match = kTRUE;
2270 }
2271 }
2272 }
2273 }
2274 if (match) {
2275 if (subbranch->fOnfileObject && subbranch->fOnfileObject != fOnfileObject) {
2276 if (seenExisting) {
2277 Error("SetOnfileObject (lambda)", "2 distincts fOnfileObject are in the hierarchy of %s for type %s",
2278 toplevel ? GetName() : GetMother()->GetSubBranch(this)->GetName(), info->GetName());
2279 } else {
2280 delete fOnfileObject;
2281 fOnfileObject = subbranch->fOnfileObject;
2282 seenExisting = kTRUE;
2283 }
2284 }
2285 subbranch->fOnfileObject = fOnfileObject;
2286 lastbranch = subbranch;
2287 }
2288 }
2289 if (toplevel) {
2291 if (lastbranch != this)
2292 lastbranch->ResetBit(kOwnOnfileObj);
2293 } else {
2294 lastbranch->SetBit(kOwnOnfileObj);
2295 }
2296 };
2297 if (GetID() > -1) {
2298 // We are *not* a top-level branch.
2299 std::string s(GetName());
2300 size_t pos = s.rfind('.');
2301 if (pos != std::string::npos) {
2302 s = s.substr(pos+1);
2303 }
2304 while ((pos = s.rfind('[')) != std::string::npos) {
2305 s = s.substr(0, pos);
2306 }
2307 int offset = 0;
2308 TStreamerElement* elt = fInfo->GetStreamerElement(s.c_str(), offset);
2309 if (elt && offset!=TStreamerInfo::kMissing) {
2310 size_t ndata = fInfo->GetNelement();
2311 fNewIDs.clear();
2312 for (size_t i = 0; i < ndata; ++i) {
2313 if (fInfo->GetElement(i) == elt) {
2315 && (i+1) < ndata
2316 && s == fInfo->GetElement(i)->GetName())
2317 {
2318 // If the TStreamerElement we found is storing the information in the
2319 // cache and is a repeater, we need to use the real one (the next one).
2320 // (At least until the cache/repeat mechanism is properly handle by
2321 // ReadLeaves).
2322 // fID = i+1;
2323 fID = i;
2324 if (fType != 2) {
2326 fNewIDs.push_back(fID+1);
2327 fNewIDs.back().fElement = fInfo->GetElement(i+1);
2328 fNewIDs.back().fInfo = fInfo;
2329 } else if (fInfo->GetElement(i+1)->TestBit(TStreamerElement::kWrite)) {
2330 fNewIDs.push_back(fID+1);
2331 fNewIDs.back().fElement = fInfo->GetElement(i+1);
2332 fNewIDs.back().fInfo = fInfo;
2333 }
2334 }
2335 } else {
2336 fID = i;
2337 }
2338 if (elt->TestBit (TStreamerElement::kCache)) {
2340 }
2341 break;
2342 }
2343 }
2344 for (size_t i = fID+1+(fNewIDs.size()); i < ndata; ++i) {
2345 TStreamerElement *nextel = fInfo->GetElement(i);
2346
2347 std::string ename = nextel->GetName();
2348 if (ename[0] == '*')
2349 ename = ename.substr(1);
2350
2351 while ((pos = ename.rfind('[')) != std::string::npos) {
2352 ename = ename.substr(0, pos);
2353 }
2354
2355 if (s != ename) {
2356 // We moved on to the next set
2357 break;
2358 }
2359 // Add all (and only) the Artificial Elements that follows this StreamerInfo.
2360 // fprintf(stderr,"%s/%d[%zu] passing through %zu %s\n",GetName(),fID,fIDs.size(),i,nextel->GetName());
2361 if (fType==31||fType==41) {
2362 // The nested objects are unfolded and their branch can not be used to
2363 // execute StreamerElements of this StreamerInfo.
2364 if ((nextel->GetType() == TStreamerInfo::kObject
2365 || nextel->GetType() == TStreamerInfo::kAny)
2366 && nextel->GetClassPointer()->CanSplit())
2367 {
2368 continue;
2369 }
2370 }
2371 if (nextel->GetOffset() == TStreamerInfo::kMissing) {
2372 // This element will be 'skipped', it's TBranchElement's fObject will null
2373 // and thus can not be used to execute the artificial StreamerElements
2374 continue;
2375 }
2376 if (nextel->IsA() != TStreamerArtificial::Class()
2377 || nextel->GetType() == TStreamerInfo::kCacheDelete ) {
2378 continue;
2379 }
2380 // NOTE: We should verify that the rule's source are 'before'
2381 // or 'at' this branch.
2382 // fprintf(stderr,"%s/%d[%zu] pushd %zu %s\n",GetName(),fID,fIDs.size(),i,nextel->GetName());
2383 fNewIDs.push_back(i);
2384 fNewIDs.back().fElement = nextel;
2385 fNewIDs.back().fInfo = fInfo;
2386 }
2387 } else if (elt && offset==TStreamerInfo::kMissing) {
2388 // Still re-assign fID properly.
2389 fNewIDs.clear();
2390 size_t ndata = fInfo->GetNelement();
2391 for (size_t i = 0; i < ndata; ++i) {
2392 if (fInfo->GetElement(i) == elt) {
2393 fID = i;
2394 break;
2395 }
2396 }
2397 } else {
2398 // We have not even found the element .. this is strange :(
2399 // fNewIDs.clear();
2400 // fID = -3;
2401 // SetBit(kDoNotProcess);
2402 }
2403 if (fOnfileObject==0 && (fType==31 || fType==41 || (0 <= fType && fType <=2) ) && fInfo->GetNelement()
2405 {
2406 SetOnfileObject(fInfo);
2407 }
2408 }
2409 if (fType == 3 || fType == 4 || (fType == 0 && fID == -2)) {
2410 // Need to add the rule targeting transient members.
2411 TStreamerInfo *localInfo = fInfo;
2412 if (fType == 3 || fType == 4) {
2413 // Don't we have real version information?
2414 // Not unless there is a subbranch with a non-split element of the class.
2415 // Search for the correct version.
2417 }
2418
2419 TString prefix(GetName());
2420 if (prefix[prefix.Length()-1] != '.') {
2421 if (fType == 3 || fType == 4 || prefix.Index('.') != TString::kNPOS) {
2422 prefix += ".";
2423 } else {
2424 prefix = "";
2425 }
2426 }
2427 fNewIDs.clear();
2428
2429 GatherArtificialElements(fBranches, fNewIDs, prefix, localInfo, 0);
2430
2431 if (!fNewIDs.empty() && fOnfileObject == nullptr && localInfo->GetElement(0)->GetType() == TStreamerInfo::kCacheNew)
2432 {
2433 SetOnfileObject(localInfo);
2434 }
2435
2436 }
2437 fInit = kTRUE;
2438
2439 // Get the action sequence we need to copy for reading.
2442 } else if (!fReadActionSequence) {
2443 // Get the action sequence we need to copy for reading.
2446 }
2450 }
2451}
2452
2453////////////////////////////////////////////////////////////////////////////////
2454/// Return the collection proxy describing the branch content, if any.
2455
2457{
2458 if (fCollProxy) {
2459 return fCollProxy;
2460 }
2461 TBranchElement* thiscast = const_cast<TBranchElement*>(this);
2462 if (fType == 4) {
2463 // STL container top-level branch.
2464 const char* className = 0;
2465 TClass* cl = nullptr;
2466 if (fID < 0) {
2467 // We are a top-level branch.
2468 if (fBranchClass.GetClass()) {
2469 cl = fBranchClass.GetClass();
2470 }
2471 } else {
2472 // We are not a top-level branch.
2473 TVirtualStreamerInfo* si = thiscast->GetInfoImp();
2474 if (fCollProxy) {
2475 // The GetInfo set fProxy for us, let's not
2476 // redo it; the value of fCollProxy is possibly
2477 // used/recorded is the actions sequences, so
2478 // if we change it here, we would need to propagate
2479 // the change.
2480 return fCollProxy;
2481 }
2482 TStreamerElement* se = si->GetElement(fID);
2483 cl = se->GetClassPointer();
2484 }
2485 if (!cl) {
2486 // The TClass was not created but we do know (since it
2487 // is used as a collection) that it 'className' was a
2488 // class, so let's create it by hand!.
2489
2490 if (fID < 0) {
2493 className = cl->GetName();
2494 } else {
2495 cl = new TClass(className, fClassVersion);
2497 className = cl->GetName();
2498 }
2499 }
2501 if (!proxy) {
2502 // humm, we must have an older file with a custom collection
2503 // let's try to work-around it.
2504 TString equiv;
2505 equiv.Form("vector<%s>",fClonesName.Data());
2506 TClass *clequiv = TClass::GetClass(equiv);
2507 proxy = clequiv->GetCollectionProxy();
2508 if (!proxy) {
2509 Fatal("GetCollectionProxy",
2510 "Can not create a Collection Proxy of any kind for the class \"%s\" needed by the branch \"%s\" of the TTree \"%s\"!",
2511 className, GetName(), GetTree()->GetName());
2512 }
2513 if (gDebug > 0) Info("GetCollectionProxy",
2514 "Fixing the collection proxy of the class \"%s\" \n"
2515 "\tneeded by the branch \"%s\" of the TTree \"%s\" to be similar to \"%s\".",
2516 className, GetName(), GetTree()->GetName(),equiv.Data());
2517 cl->CopyCollectionProxy( *proxy );
2518 }
2519 fCollProxy = proxy->Generate();
2520 fSTLtype = proxy->GetCollectionType();
2521 } else if (fType == 41) {
2522 // STL container sub-branch.
2524 }
2525 return fCollProxy;
2526}
2527
2528////////////////////////////////////////////////////////////////////////////////
2529/// Return a pointer to the current type of the data member corresponding to branch element.
2530
2532{
2533 TClass* cl = fCurrentClass;
2534 if (cl) {
2535 return cl;
2536 }
2537
2539 if (!brInfo) {
2541 R__ASSERT(cl && cl->GetCollectionProxy());
2542 fCurrentClass = cl;
2543 return cl;
2544 }
2545 TClass* motherCl = brInfo->GetClass();
2546 if (motherCl->GetCollectionProxy()) {
2547 cl = motherCl->GetCollectionProxy()->GetCollectionClass();
2548 if (cl) {
2549 fCurrentClass = cl;
2550 }
2551 return cl;
2552 }
2553 if (GetID() < 0 || GetID()>=brInfo->GetNelement()) {
2554 return 0;
2555 }
2556 TStreamerElement* currentStreamerElement = brInfo->GetElement(GetID());
2557 TDataMember* dm = (TDataMember*) motherCl->GetListOfDataMembers()->FindObject(currentStreamerElement->GetName());
2558
2559 TString newType;
2560 if (!dm) {
2561 // Either the class is not loaded or the data member is gone
2562 if (!motherCl->IsLoaded()) {
2563 TVirtualStreamerInfo* newInfo = motherCl->GetStreamerInfo();
2564 if (newInfo != brInfo) {
2565 TStreamerElement* newElems = (TStreamerElement*) newInfo->GetElements()->FindObject(currentStreamerElement->GetName());
2566 if (newElems) {
2567 if (newElems->GetClassPointer())
2568 newType = newElems->GetClassPointer()->GetName();
2569 else
2570 newType = newElems->GetTypeName();
2571 }
2572 }
2573 if (newType.Length()==0) {
2574 if (currentStreamerElement->GetClassPointer())
2575 newType = currentStreamerElement->GetClassPointer()->GetName();
2576 else
2577 newType = currentStreamerElement->GetTypeName();
2578 }
2579 }
2580 } else {
2581 newType = dm->GetTypeName();
2582 }
2583 cl = TClass::GetClass(newType);
2584 if (cl) {
2585 fCurrentClass = cl;
2586 }
2587 return cl;
2588}
2589
2590////////////////////////////////////////////////////////////////////////////////
2591/// Read all branches of a BranchElement and return total number of bytes.
2592///
2593/// - If entry = 0, then use current entry number + 1.
2594/// - If entry < 0, then reset entry number to 0.
2595///
2596/// Returns the number of bytes read from the input buffer.
2597/// - If entry does not exist, then returns 0.
2598/// - If an I/O error occurs, then returns -1.
2599///
2600/// See IMPORTANT REMARKS in TTree::GetEntry.
2601
2603{
2604 // Remember which entry we are reading.
2605 fReadEntry = entry;
2606
2607 // If our tree has a branch ref, make it remember the entry and
2608 // this branch. This allows a TRef::GetObject() call done during
2609 // the following I/O operation, for example in a custom streamer,
2610 // to search for the referenced object in the proper element of the
2611 // proper branch.
2612 TBranchRef* bref = fTree->GetBranchRef();
2613 if (R__unlikely(bref)) {
2614 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
2615 fBranchID = bref->SetParent(this, fBranchID);
2616 bref->SetRequestedEntry(entry);
2617 }
2618
2619 Int_t nbytes = 0;
2620
2621 if (R__unlikely(IsAutoDelete())) {
2624 } else {
2626 R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
2628 }
2629 }
2630
2631 Int_t nbranches = fBranches.GetEntriesFast();
2632 if (nbranches) {
2633 // -- Branch has daughters.
2634 // One must always read the branch counter.
2635 // In the case when one reads consecutively twice the same entry,
2636 // the user may have cleared the TClonesArray between the GetEntry calls.
2637 if ((fType == 3) || (fType == 4)) {
2638 Int_t nb = TBranch::GetEntry(entry, getall);
2639 if (nb < 0) {
2640 return nb;
2641 }
2642 nbytes += nb;
2643 }
2644 switch(fSTLtype) {
2645 case ROOT::kSTLset:
2646 case ROOT::kSTLmultiset:
2649 case ROOT::kSTLmap:
2650 case ROOT::kSTLmultimap:
2653 break;
2654 default:
2655 ValidateAddress(); // There is no ReadLeave for this node, so we need to do the validation here.
2656 for (Int_t i = 0; i < nbranches; ++i) {
2657 TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
2658 Int_t nb = branch->GetEntry(entry, getall);
2659 if (nb < 0) {
2660 return nb;
2661 }
2662 nbytes += nb;
2663 }
2664 break;
2665 }
2667 if (fType == 3) {
2668 // Apply the unattached rules; by definition they do not need any
2669 // input from a buffer.
2671
2672 auto ndata = GetNdata();
2673
2674 TClonesArray* clones = (TClonesArray*) fObject;
2675 if (clones->IsZombie()) {
2676 return -1;
2677 }
2678 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,ndata);
2679
2680 char **arr = (char **)clones->GetObjectRef();
2681 char **end = arr + fNdata;
2682
2683 b.ApplySequenceVecPtr(*fReadActionSequence,arr,end);
2684 } else if (fType == 4) {
2685 // Apply the unattached rules; by definition they do not need any
2686 // input from a buffer.
2688
2689 auto ndata = GetNdata();
2690
2691 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,ndata);
2694
2696 b.ApplySequence(*fReadActionSequence,iter->fBegin,iter->fEnd);
2697 } else {
2698 // Apply the unattached rules; by definition they do not need any
2699 // input from a buffer.
2701 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,fNdata);
2702 b.ApplySequence(*fReadActionSequence, fObject);
2703 }
2704 }
2705 } else {
2706 // -- Terminal branch.
2707 if (fBranchCount && (fBranchCount->GetReadEntry() != entry)) {
2708 Int_t nb = fBranchCount->TBranch::GetEntry(entry, getall);
2709 if (nb < 0) {
2710 return nb;
2711 }
2712 nbytes += nb;
2713 }
2714 Int_t nb = TBranch::GetEntry(entry, getall);
2715 if (nb < 0) {
2716 return nb;
2717 }
2718 nbytes += nb;
2719 }
2720
2721 if (R__unlikely(fTree->Debug() > 0)) {
2722 if ((entry >= fTree->GetDebugMin()) && (entry <= fTree->GetDebugMax())) {
2723 Info("GetEntry", "%lld, branch=%s, nbytes=%d", entry, GetName(), nbytes);
2724 }
2725 }
2726 return nbytes;
2727}
2728
2729////////////////////////////////////////////////////////////////////////////////
2730/// Fill expectedClass and expectedType with information on the data type of the
2731/// object/values contained in this branch (and thus the type of pointers
2732/// expected to be passed to Set[Branch]Address
2733/// return 0 in case of success and > 0 in case of failure.
2734
2736{
2737 expectedClass = 0;
2738 expectedType = kOther_t;
2739
2741 if ((type == -1) || (fID == -1)) {
2742 expectedClass = fBranchClass;
2743 } else {
2744 // Case of an object data member. Here we allow for the
2745 // variable name to be omitted. Eg, for Event.root with split
2746 // level 1 or above Draw("GetXaxis") is the same as Draw("fH.GetXaxis()")
2748 if (element) {
2749 expectedClass = element->GetClassPointer();
2750 if (!expectedClass) {
2751 TDataType* data = gROOT->GetType(element->GetTypeNameBasic());
2752 if (!data) {
2753 Error("GetExpectedType", "Did not find the type number for %s", element->GetTypeNameBasic());
2754 return 1;
2755 } else {
2756 expectedType = (EDataType) data->GetType();
2757 }
2758 }
2759 } else {
2760 Error("GetExpectedType", "Did not find the type for %s",GetName());
2761 return 2;
2762 }
2763 }
2764 return 0;
2765}
2766
2767////////////////////////////////////////////////////////////////////////////////
2768/// Return the 'full' name of the branch. In particular prefix the mother's name
2769/// when it does not end in a trailing dot and thus is not part of the branch name
2771{
2772 TBranchElement* mother = static_cast<TBranchElement*>(GetMother());
2773 if (!mother || mother==this || mother->GetType() == 3 || mother->GetType() == 4) {
2774 // The parent's name is already included in the name for split TClonesArray and STL collections
2775 return fName;
2776 }
2777 TString motherName(mother->GetName());
2778 if (motherName.Length() && (motherName[motherName.Length()-1] == '.')) {
2779 return fName;
2780 }
2781 return motherName + "." + fName;
2782}
2783
2784////////////////////////////////////////////////////////////////////////////////
2785/// Return icon name depending on type of branch element.
2786
2788{
2789 if (IsFolder()) {
2790 return "TBranchElement-folder";
2791 } else {
2792 return "TBranchElement-leaf";
2793 }
2794}
2795
2796////////////////////////////////////////////////////////////////////////////////
2797/// Return whether this branch is in a mode where the object are decomposed
2798/// or not (Also known as MakeClass mode).
2799
2801{
2802 return TestBit(kDecomposedObj); // Same as TestBit(kMakeClass)
2803}
2804
2805////////////////////////////////////////////////////////////////////////////////
2806/// Return maximum count value of the branchcount if any.
2807
2809{
2810 if (fBranchCount) {
2811 return fBranchCount->GetMaximum();
2812 }
2813 return fMaximum;
2814}
2815
2816////////////////////////////////////////////////////////////////////////////////
2817/// Return a pointer to our object.
2818
2820{
2822 return fObject;
2823}
2824
2825////////////////////////////////////////////////////////////////////////////////
2826/// Return a pointer to the parent class of the branch element.
2827
2829{
2830 return fParentClass.GetClass();
2831}
2832
2833////////////////////////////////////////////////////////////////////////////////
2834/// Return type name of element in the branch.
2835
2837{
2838 if (fType == 3 || fType == 4) {
2839 return "Int_t";
2840 }
2841 // FIXME: Use symbolic constants here.
2842 if ((fStreamerType < 1) || (fStreamerType > 59)) {
2843 if (fBranchClass.GetClass()) {
2844 if (fID>=0) {
2845 return GetInfoImp()->GetElement(fID)->GetTypeName();
2846 } else {
2847 return fBranchClass.GetClass()->GetName();
2848 }
2849 } else {
2850 return 0;
2851 }
2852 }
2853 const char *types[20] = {
2854 "",
2855 "Char_t",
2856 "Short_t",
2857 "Int_t",
2858 "Long_t",
2859 "Float_t",
2860 "Int_t",
2861 "char*",
2862 "Double_t",
2863 "Double32_t",
2864 "",
2865 "UChar_t",
2866 "UShort_t",
2867 "UInt_t",
2868 "ULong_t",
2869 "UInt_t",
2870 "Long64_t",
2871 "ULong64_t",
2872 "Bool_t",
2873 "Float16_t"
2874 };
2875 Int_t itype = fStreamerType % 20;
2876 return types[itype];
2877}
2878
2879////////////////////////////////////////////////////////////////////////////////
2880
2881template Double_t TBranchElement::GetTypedValue(Int_t j, Int_t len, Bool_t subarr) const;
2882template Long64_t TBranchElement::GetTypedValue(Int_t j, Int_t len, Bool_t subarr) const;
2883template LongDouble_t TBranchElement::GetTypedValue(Int_t j, Int_t len, Bool_t subarr) const;
2884
2885template <typename T>
2887{
2888 // -- Returns the branch value.
2889 //
2890 // If the leaf is an array, j is the index in the array.
2891 //
2892 // If leaf is an array inside a TClonesArray, len should be the length
2893 // of the array.
2894 //
2895 // If subarr is true, then len is actually the index within the sub-array.
2896 //
2897
2899
2900 Int_t prID = fID;
2901 char *object = fObject;
2902 if (TestBit(kCache)) {
2903 if (GetInfoImp()->GetElements()->At(fID)->TestBit(TStreamerElement::kRepeat)) {
2904 prID = fID+1;
2905 } else if (fOnfileObject) {
2906 object = fOnfileObject->GetObjectAt(0);
2907 }
2908 }
2909
2910 if (!j && fBranchCount) {
2911 Long64_t entry = fTree->GetReadEntry();
2912 // Since reloading the index, will reset the ClonesArray, let's
2913 // skip the load if we already read this entry.
2914 if (entry != fBranchCount->GetReadEntry()) {
2915 fBranchCount->TBranch::GetEntry(entry);
2916 }
2917 if (fBranchCount2 && entry != fBranchCount2->GetReadEntry()) {
2918 fBranchCount2->TBranch::GetEntry(entry);
2919 }
2920 }
2921
2922 if (TestBit(kDecomposedObj)) {
2923 if (!fAddress) {
2924 return 0;
2925 }
2926 if ((fType == 3) || (fType == 4)) {
2927 // Top-level branch of a TClonesArray.
2928 return fNdata;
2929 } else if ((fType == 31) || (fType == 41)) {
2930 // sub branch of a TClonesArray
2931 Int_t atype = fStreamerType;
2932 if (atype < 20) {
2933 atype += 20;
2934 }
2935 return GetInfoImp()->GetTypedValue<T>(fAddress, atype, j, 1);
2936 } else if (fType <= 2) {
2937 // branch in split mode
2938 // FIXME: This should probably be < 60 instead!
2939 if ((fStreamerType > 40) && (fStreamerType < 55)) {
2940 Int_t atype = fStreamerType - 20;
2941 return GetInfoImp()->GetTypedValue<T>(fAddress, atype, j, 1);
2942 } else {
2943 return GetInfoImp()->GetTypedValue<T>(object, prID, j, -1);
2944 }
2945 }
2946 }
2947
2948 if (object == 0)
2949 {
2950 // We have nowhere to read the data from (probably because the data member was
2951 // 'dropped' from the current schema).
2952 return 0;
2953 }
2954
2955 if (fType == 31) {
2956 TClonesArray* clones = (TClonesArray*) object;
2957 if (subarr) {
2958 return GetInfoImp()->GetTypedValueClones<T>(clones, prID, j, len, fOffset);
2959 }
2960 return GetInfoImp()->GetTypedValueClones<T>(clones, prID, j/len, j%len, fOffset);
2961 } else if (fType == 41) {
2964 {
2965 if (subarr)
2966 return GetInfoImp()->GetTypedValueSTL<T>(((TBranchElement*) this)->GetCollectionProxy(), prID, j, len, fOffset);
2967
2968 return GetInfoImp()->GetTypedValueSTL<T>(((TBranchElement*) this)->GetCollectionProxy(), prID, j/len, j%len, fOffset);
2969 }
2970 else
2971 {
2972 if (subarr)
2973 return GetInfoImp()->GetTypedValueSTLP<T>(((TBranchElement*) this)->GetCollectionProxy(), prID, j, len, fOffset);
2974 return GetInfoImp()->GetTypedValueSTLP<T>(((TBranchElement*) this)->GetCollectionProxy(), prID, j/len, j%len, fOffset);
2975 }
2976 } else {
2977 if (GetInfoImp()) {
2978 return GetInfoImp()->GetTypedValue<T>(object, prID, j, -1);
2979 }
2980 return 0;
2981 }
2982}
2983
2984////////////////////////////////////////////////////////////////////////////////
2985/// Returns pointer to first data element of this branch.
2986/// Currently used only for members of type character.
2987
2989{
2991
2992 Int_t prID = fID;
2993 char *object = fObject;
2994 if (TestBit(kCache)) {
2995 if (GetInfoImp()->GetElements()->At(fID)->TestBit(TStreamerElement::kRepeat)) {
2996 prID = fID+1;
2997 } else if (fOnfileObject) {
2998 object = fOnfileObject->GetObjectAt(0);
2999 }
3000 }
3001
3002 if (fBranchCount) {
3003 Long64_t entry = fTree->GetReadEntry();
3004 fBranchCount->TBranch::GetEntry(entry);
3005 if (fBranchCount2) fBranchCount2->TBranch::GetEntry(entry);
3006 }
3007 if (TestBit(kDecomposedObj)) {
3008 if (!fAddress) {
3009 return 0;
3010 }
3011 if (fType == 3) { //top level branch of a TClonesArray
3012 //return &fNdata;
3013 return 0;
3014 } else if (fType == 4) { //top level branch of a TClonesArray
3015 //return &fNdata;
3016 return 0;
3017 } else if (fType == 31) { // sub branch of a TClonesArray
3018 //Int_t atype = fStreamerType;
3019 //if (atype < 20) atype += 20;
3020 //return GetInfoImp()->GetValue(fAddress, atype, j, 1);
3021 return 0;
3022 } else if (fType == 41) { // sub branch of a TClonesArray
3023 //Int_t atype = fStreamerType;
3024 //if (atype < 20) atype += 20;
3025 //return GetInfoImp()->GetValue(fAddress, atype, j, 1);
3026 return 0;
3027 } else if (fType <= 2) { // branch in split mode
3028 // FIXME: This should probably be < 60 instead!
3029 if (fStreamerType > 40 && fStreamerType < 55) {
3030 //Int_t atype = fStreamerType - 20;
3031 //return GetInfoImp()->GetValue(fAddress, atype, j, 1);
3032 return 0;
3033 } else {
3034 //return GetInfoImp()->GetValue(object, fID, j, -1);
3035 return 0;
3036 }
3037 }
3038 }
3039
3040 if (fType == 31) {
3041 return 0;
3042 } else if (fType == 41) {
3043 return 0;
3044 } else if (prID < 0) {
3045 return object;
3046 } else {
3047 //return GetInfoImp()->GetValue(object,fID,j,-1);
3048 if (!GetInfoImp() || !object) return 0;
3049 char **val = (char**)(object+GetInfoImp()->TStreamerInfo::GetElementOffset(prID));
3050 return *val;
3051 }
3052}
3053
3054////////////////////////////////////////////////////////////////////////////////
3055/// Initialize the base class subobjects offsets of our sub-branches and set fOffset if we are a container sub-branch.
3056///
3057/// Note: The offsets are zero for data members so that when
3058/// SetAddress recursively sets their address, they will get the
3059/// same address as their containing class because i/o is based
3060/// on streamer info offsets from the address of the containing
3061/// class.
3062///
3063/// Offsets are non-zero for base-class sub-branches that are
3064/// not the leftmost direct base class. They are laid out in
3065/// memory sequentially and only the leftmost direct base class
3066/// has the same address as the derived class. The streamer
3067/// offsets need to be added to the address of the base class
3068/// subobject which is not the same as the address of the
3069/// derived class for the non-leftmost direct base classes.
3070
3072{
3073 Int_t nbranches = fBranches.GetEntriesFast();
3074
3075 // See https://sft.its.cern.ch/jira/browse/ROOT-8742
3076 // and https://sft.its.cern.ch/jira/browse/ROOT-9253
3077 // As of commit e21b4f1a3b, removing this lock lead to a failure
3078 // in the test testSetAddress[Loop].
3079 // As of commit 4f8b237849, removing this lock does not lead to
3080 // a visible failure in test. This might be due to the underlying
3081 // problem (missing lock or ?) being solved somewhere else or some
3082 // other perturbation reducing the failure rate.
3083 // Having the lock here is not too costly as InitializeOffsets is
3084 // one called once in the lifetime of the TBranch.
3086
3087 if (fID < 0) {
3088 // -- We are a top-level branch. Let's mark whether we need to use MapObject.
3089 if (CanSelfReference(fBranchClass)) {
3090 if (fBranchClass.GetClass()->IsTObject()) {
3092 } else {
3094 }
3095 }
3096 }
3097 if (nbranches) {
3098 // Allocate space for the new sub-branch offsets.
3099 delete[] fBranchOffset;
3100 fBranchOffset = 0;
3101 fBranchOffset = new Int_t[nbranches];
3102 // Make sure we can instantiate our class meta info.
3103 if (!fBranchClass.GetClass()) {
3104 Warning("InitializeOffsets", "No branch class set for branch: %s", GetName());
3106 return;
3107 }
3108 // Make sure we can instantiate our class streamer info.
3109 if (!GetInfoImp()) {
3110 Warning("InitializeOffsets", "No streamer info available for branch: %s of class: %s", GetName(), fBranchClass.GetClass()->GetName());
3112 return;
3113 }
3114
3115 // Get the class we are a member of now (which is the
3116 // type of our containing subobject) and get our offset
3117 // inside of our containing subobject (our local offset).
3118 // Note: branchElem stays zero if we are a top-level branch,
3119 // we have to be careful about this later.
3120 TStreamerElement* branchElem = 0;
3121 Int_t localOffset = 0;
3122 TClass* branchClass = fBranchClass.GetClass();
3123 Bool_t renamed = kFALSE;
3124 if (fID > -1) {
3125 // -- Branch is *not* a top-level branch.
3126 // Instead of the streamer info class, we want the class of our
3127 // specific element in the streamer info. We could be a data
3128 // member of a base class or a split class, in which case our
3129 // streamer info will be for our containing sub-object, while
3130 // we are actually a different type.
3132 // Note: We tested to make sure the streamer info was available previously.
3133 if (!si->IsCompiled()) {
3134 Warning("InitializeOffsets", "Streamer info for branch: %s has no elements array!", GetName());
3136 return;
3137 }
3138 // FIXME: Check that fID is in range.
3139 branchElem = si->GetElement(fID);
3140 if (!branchElem) {
3141 Warning("InitializeOffsets", "Cannot get streamer element for branch: %s!", GetName());
3143 return;
3144 } else if (branchElem->TestBit(TStreamerElement::kRepeat)) {
3145 // If we have a repeating streamerElement, use the next
3146 // one as it actually hold the 'real' data member('s offset)
3147 if (si->GetElement(fID+1)) {
3148 branchElem = si->GetElement(fID+1);
3149 }
3150 }
3151 localOffset = branchElem->GetOffset();
3152 branchClass = branchElem->GetClassPointer();
3153 if (localOffset == TStreamerInfo::kMissing) {
3154 fObject = 0;
3155 } else {
3156 renamed = branchClass && branchElem->GetNewClass() && (branchClass != branchElem->GetNewClass());
3157 }
3158 } else {
3159 renamed = fTargetClass != fBranchClass;
3160 }
3161 if (!branchClass) {
3162 Error("InitializeOffsets", "Could not find class for branch: %s", GetName());
3164 return;
3165 }
3166
3167 //------------------------------------------------------------------------
3168 // Extract the name of the STL branch in case it has been split.
3169 //////////////////////////////////////////////////////////////////////////
3170
3171 TString stlParentName;
3172 Bool_t stlParentNameUpdated = kFALSE;
3173 if( fType == 4 )
3174 {
3175 TBranch *br = GetMother()->GetSubBranch( this );
3176 stlParentName = br->GetName();
3177 stlParentName = stlParentName.Strip( TString::kTrailing, '.' );
3178
3179 // We may ourself contain the 'Mother' branch name.
3180 // To avoid code duplication, we delegate the removal
3181 // of the mother's name to the first sub-branch loop.
3182 }
3183
3184 // Loop over our sub-branches and compute their offsets.
3185 for (Int_t subBranchIdx = 0; subBranchIdx < nbranches; ++subBranchIdx) {
3186 bool alternateElement = false;
3187
3188 fBranchOffset[subBranchIdx] = 0;
3189 TBranchElement* subBranch = dynamic_cast<TBranchElement*> (fBranches[subBranchIdx]);
3190 if (subBranch == 0) {
3191 // -- Skip sub-branches that are not TBranchElements.
3192 continue;
3193 }
3194
3195 if (renamed) {
3196 if (subBranch->fBranchClass == branchClass) {
3197 if (branchElem) subBranch->SetTargetClass(branchElem->GetNewClass()->GetName());
3198 else subBranch->SetTargetClass(fTargetClass->GetName());
3199 }
3200 }
3201
3202 TVirtualStreamerInfo* sinfo = subBranch->GetInfoImp();
3203 if (!sinfo) {
3204 Warning("InitializeOffsets", "No streamer info for branch: %s subbranch: %s", GetName(), subBranch->GetName());
3205 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3206 continue;
3207 }
3208 if (!sinfo->IsCompiled()) {
3209 Warning("InitializeOffsets", "No elements array for branch: %s subbranch: %s", GetName(), subBranch->GetName());
3210 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3211 continue;
3212 }
3213 // FIXME: Make sure subBranch->fID is in range.
3214 TStreamerElement* subBranchElement = sinfo->GetElement(subBranch->fID);
3215 if (!subBranchElement) {
3216 Warning("InitializeOffsets", "No streamer element for branch: %s subbranch: %s", GetName(), subBranch->GetName());
3217 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3218 continue;
3219 } else if (subBranchElement->TestBit(TStreamerElement::kRepeat)) {
3220 // If we have a repeating streamerElement, use the next
3221 // one as it actually hold the 'real' data member('s offset)
3222 if (sinfo->GetElement(subBranch->fID+1)) {
3223 subBranchElement = sinfo->GetElement(subBranch->fID+1);
3224 }
3225 } else if (subBranchElement->TestBit(TStreamerElement::kCache)) {
3226 // We have a cached item which is not a repeated but we might still
3227 // have some Actions triggered by a rule that affect real
3228 // data member(s).
3229 if (subBranch->fReadActionSequence && subBranch->fReadActionSequence->fActions.size() > 1) {
3230 typedef TStreamerInfoActions::ActionContainer_t::iterator iterator;
3231 iterator end = subBranch->fReadActionSequence->fActions.end();
3232 for(iterator iter = subBranch->fReadActionSequence->fActions.begin();
3233 iter != end; ++iter) {
3234 TStreamerInfoActions::TConfiguration *config = iter->fConfiguration;
3235 UInt_t id = config->fElemId;
3237 if (e && !e->TestBit(TStreamerElement::kCache)) {
3238 subBranchElement = e;
3239 alternateElement = true;
3240 break;
3241 }
3242 }
3243 }
3244 }
3245
3246 localOffset = subBranchElement->GetOffset();
3247 if (localOffset == TStreamerInfo::kMissing) {
3248 subBranch->fObject = 0;
3249 }
3250 {
3251 Int_t streamerType = subBranchElement->GetType();
3252 if (streamerType > TStreamerInfo::kObject
3253 && subBranch->GetListOfBranches()->GetEntriesFast()==0
3254 && CanSelfReference(subBranchElement->GetClass()))
3255 {
3256 subBranch->SetBit(kBranchAny);
3257 } else {
3258 subBranch->ResetBit(kBranchAny);
3259 }
3260 }
3261
3262 if (subBranchElement->GetNewType()<0) {
3263 subBranch->ResetBit(kBranchAny);
3264 subBranch->ResetBit(kBranchObject);
3265 }
3266
3267 // Note: This call is expensive, do it only once.
3268 TBranch* mother = GetMother();
3269 if (!mother) {
3270 Warning("InitializeOffsets", "Branch '%s' has no mother!", GetName());
3271 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3272 continue;
3273 }
3274 TString motherName(mother->GetName());
3275 Bool_t motherDot = kFALSE;
3276 if (motherName.Length() && strchr(motherName.Data(), '.')) {
3277 motherDot = kTRUE;
3278 }
3279 Bool_t motherDotAtEnd = kFALSE;
3280 if (motherName.Length() && (motherName[motherName.Length()-1] == '.')) {
3281 motherDotAtEnd = kTRUE;
3282 }
3283
3284 Bool_t isBaseSubBranch = kFALSE;
3285 if ((subBranch->fType == 1) || (subBranchElement && subBranchElement->IsBase())) {
3286 // -- Base class sub-branch (1).
3287 //
3288 // Note: Our type will not be 1, even though we are
3289 // a base class branch, if we are not split (see the
3290 // constructor), or if we are an STL container master
3291 // branch and a base class branch at the same time
3292 // or an std::string.
3293 isBaseSubBranch = kTRUE;
3294 }
3295
3296 Bool_t isContDataMember = kFALSE;
3297 if ((subBranch->fType == 31) || (subBranch->fType == 41)) {
3298 // -- Container data member sub-branch (31 or 41).
3299 isContDataMember = kTRUE;
3300 }
3301
3302 // I am either a data member sub-branch (0), or a base class
3303 // sub-branch (1), or TClonesArray master sub-branch (3),
3304 // or an STL container master sub-branch (4), or TClonesArray
3305 // data member sub-branch (31), or an STL container data member
3306 // sub-branch (41).
3307 //
3308 // My parent branch is either a top-level branch ((0), fID==(-2,-1)),
3309 // or a base class sub-branch (1), or a split-class branch (2),
3310 // or a TClonesArray master branch (3), or an STL container
3311 // master branch (4).
3312 //
3313
3314 //
3315 // We need to extract from our name the name
3316 // of the data member which contains us, so
3317 // that we may then do a by-name lookup in the
3318 // dictionary meta info of our parent class to
3319 // get our offset in our parent class.
3320 //
3321
3322 // Get our name.
3323 TString dataName(subBranch->GetName());
3324 if (motherDotAtEnd) {
3325 // -- Remove the top-level branch name from our name.
3326 dataName.Remove(0, motherName.Length());
3327 // stlParentNameUpdated is false the first time in this loop.
3328 if (!stlParentNameUpdated && stlParentName.Length()) {
3329 stlParentName.Remove(0, motherName.Length());
3330 stlParentNameUpdated = kTRUE;
3331 }
3332 } else if (motherDot) {
3333 // -- Remove the top-level branch name from our name, folder case.
3334 //
3335 // Note: We are in the case where our mother was created
3336 // by the branch constructor which takes a folder
3337 // as an argument. The mother branch has internal
3338 // dots in its name to represent the folder hierarchy.
3339 // The TTree::Bronch() routine has handled us as a
3340 // special case, we must compensate.
3341 if ((fID < 0) && (subBranchElement->IsA() == TStreamerBase::Class())) {
3342 // -- Our name is the mother name, remove it.
3343 // Note: The test is our parent is a top-level branch
3344 // and our streamer is the base class streamer,
3345 // this matches the exact test in TTree::Bronch().
3346 if (dataName.Length() == motherName.Length()) {
3347 dataName.Remove(0, motherName.Length());
3348 // stlParentNameUpdated is false the first time in this loop.
3349 if (!stlParentNameUpdated && stlParentName.Length()) {
3350 stlParentName.Remove(0, motherName.Length());
3351 }
3352 }
3353 } else {
3354 // -- Remove the mother name and the dot.
3355 if (dataName.Length() > motherName.Length()) {
3356 dataName.Remove(0, motherName.Length() + 1);
3357 if (!stlParentNameUpdated && stlParentName.Length()) {
3358 stlParentName.Remove(0, motherName.Length());
3359 }
3360 }
3361 }
3362 }
3363 stlParentNameUpdated = kTRUE;
3364 if (isBaseSubBranch) {
3365 // -- Remove the base class name suffix from our name.
3366 // Note: The pattern is the name of the base class.
3367 TString pattern(subBranchElement->GetName());
3368 if (pattern.Length() <= dataName.Length()) {
3369 if (!strcmp(dataName.Data() + (dataName.Length() - pattern.Length()), pattern.Data())) {
3370 // The branch name contains the name of the base class in it.
3371 // This name is not reproduced in the sub-branches, so we need to
3372 // remove it.
3373 dataName.Remove(dataName.Length() - pattern.Length());
3374 }
3375 }
3376 // Remove any leading dot.
3377 if (dataName.Length()) {
3378 if (dataName[0] == '.') {
3379 dataName.Remove(0, 1);
3380 }
3381 }
3382 // Note: We intentionally leave any trailing dot
3383 // in our modified name here.
3384 }
3385
3386 // Get our parent branch's name.
3387 TString parentName(GetName());
3388 if (motherDotAtEnd) {
3389 // -- Remove the top-level branch name from our parent's name.
3390 parentName.Remove(0, motherName.Length());
3391 } else if (motherDot) {
3392 // -- Remove the top-level branch name from our parent's name, folder case.
3393 //
3394 // Note: We are in the case where our mother was created
3395 // by the branch constructor which takes a folder
3396 // as an argument. The mother branch has internal
3397 // dots in its name to represent the folder hierarchy.
3398 // The TTree::Bronch() routine has handled us as a
3399 // special case, we must compensate.
3400 if ((fID > -1) && (mother == mother->GetSubBranch(this)) && (branchElem->IsA() == TStreamerBase::Class())) {
3401 // -- Our parent's name is the mother name, remove it.
3402 // Note: The test is our parent's parent is a top-level branch
3403 // and our parent's streamer is the base class streamer,
3404 // this matches the exact test in TTree::Bronch().
3405 if (parentName.Length() == motherName.Length()) {
3406 parentName.Remove(0, motherName.Length());
3407 }
3408 } else {
3409 // -- Remove the mother name and the dot.
3410 if (parentName.Length() > motherName.Length()) {
3411 parentName.Remove(0, motherName.Length() + 1);
3412 }
3413 }
3414 }
3415 // FIXME: Do we need to use the other tests for a base class here?
3416 if (fType == 1) {
3417 // -- Our parent is a base class sub-branch, remove the base class name suffix from its name.
3418 if (mother != mother->GetSubBranch(this)) {
3419 // -- My parent's parent is not a top-level branch.
3420 // Remove the base class name suffix from the parent name.
3421 // Note: The pattern is the name of the base class.
3422 // coverity[var_deref_model] branchElem is non zero here since fType==1 and thus fID > -1
3423 TString pattern(branchElem->GetName());
3424 if (pattern.Length() <= parentName.Length()) {
3425 if (!strcmp(parentName.Data() + (parentName.Length() - pattern.Length()), pattern.Data())) {
3426 // The branch name contains the name of the base class in it.
3427 // This name is not reproduced in the sub-branches, so we need to
3428 // remove it.
3429 parentName.Remove(parentName.Length() - pattern.Length());
3430 }
3431 }
3432 }
3433 // Note: We intentionally leave any trailing dots
3434 // in the modified parent name here.
3435 }
3436
3437 // Remove the parent branch name part from our name,
3438 // but only if the parent branch is not a top-level branch.
3439 // FIXME: We should not assume parent name does not have length 0.
3440 if (fID > -1) {
3441 RemovePrefix(dataName, parentName);
3442 }
3443
3444 // Remove any leading dot.
3445 if (dataName.Length()) {
3446 if (dataName[0] == '.') {
3447 dataName.Remove(0, 1);
3448 }
3449 }
3450
3451 // Remove any trailing dot.
3452 if (dataName.Length()) {
3453 if (dataName[dataName.Length()-1] == '.') {
3454 dataName.Remove(dataName.Length() - 1, 1);
3455 }
3456 }
3457
3458 //
3459 // Now that we have our data member name, find our offset
3460 // in our parent class.
3461 //
3462 // Note: Our data member name can have many dots in it
3463 // if branches were elided between our parent branch
3464 // and us by Unroll().
3465 //
3466 // FIXME: This may not work if our member name is ambiguous.
3467 //
3468
3469 Int_t offset = 0;
3470 if (dataName.Length()) {
3471 // -- We have our data member name, do a lookup in the dictionary meta info of our parent class.
3472 // Get our parent class.
3473 TClass* pClass = 0;
3474 // First check whether this sub-branch is part of the 'cache' (because the data member it
3475 // represents is no longer in the current class layout.
3476 TStreamerInfo *subInfo = subBranch->GetInfoImp();
3477 //if (subInfo && subBranch->TestBit(kCache)) { // subInfo->GetElements()->At(subBranch->GetID())->TestBit(TStreamerElement::kCache)) {
3478 if (subBranchElement->TestBit(TStreamerElement::kCache)) {
3479 pClass = ((TStreamerElement*)subInfo->GetElements()->At(0))->GetClassPointer();
3480 }
3481 // FIXME: Do we need the other base class tests here?
3482 if (!pClass) {
3483 if (fType == 1) {
3484 // -- Parent branch is a base class branch.
3485 // FIXME: Is using branchElem here the right thing?
3486 pClass = branchElem->GetClassPointer();
3487 if (pClass->Property() & kIsAbstract) {
3488 // the class is abstract, let see if the
3489
3491 if (parent && parent != this && !parent->GetClass()->IsLoaded() ) {
3492 // Our parent's class is emulated and we represent an abstract class.
3493 // and the target class has not been set explicitly.
3494 TString target = pClass->GetName();
3495 target += "@@emulated";
3496
3497 pClass = TClass::GetClass(target);
3498 }
3499 }
3500 } else {
3501 // -- Parent branch is *not* a base class branch.
3502 // FIXME: This sometimes returns a null pointer.
3503 pClass = subBranch->GetParentClass();
3504 }
3505 }
3506 if (!pClass) {
3507 // -- No parent class, fix it.
3508 // FIXME: This is probably wrong!
3509 // Assume parent class is our parent branch's clones class or value class.
3510 if (GetClonesName() && strlen(GetClonesName())) {
3511 pClass = fClonesClass;
3512 if (!pClass) {
3513 Warning("InitializeOffsets", "subBranch: '%s' has no parent class, and cannot get class for clones class: '%s'!", subBranch->GetName(), GetClonesName());
3514 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3515 continue;
3516 }
3517 Warning("InitializeOffsets", "subBranch: '%s' has no parent class! Assuming parent class is: '%s'.", subBranch->GetName(), pClass->GetName());
3518 }
3521 Warning("InitializeOffsets", "subBranch: '%s' has no parent class! Assuming parent class is: '%s'.", subBranch->GetName(), pClass ? pClass->GetName() : "unknown class");
3522 }
3523 if (!pClass) {
3524 // -- Still no parent class, assume our parent class is our parent branch's class.
3525 // FIXME: This is probably wrong!
3526 pClass = branchClass;
3527 // FIXME: Enable this warning!
3528 //Warning("InitializeOffsets", "subBranch: '%s' has no parent class! Assuming parent class is: '%s'.", subBranch->GetName(), pClass->GetName());
3529 }
3530 }
3531 if (renamed && pClass) {
3532 if (pClass == branchClass) {
3533 pClass = branchElem->GetNewClass();
3534 } else if (fCollProxy && pClass == branchClass->GetCollectionProxy()->GetValueClass()) {
3535 pClass = fCollProxy->GetValueClass();
3536 }
3537 }
3538
3539 //------------------------------------------------------------------
3540 // If we have the are the sub-branch of the TBranchSTL, we need
3541 // to remove it's name to get the correct real data offsets
3542 ////////////////////////////////////////////////////////////////////
3543
3544 if( dynamic_cast<TBranchSTL*>(fParent) && stlParentName.Length() )
3545 {
3546 if( !strncmp( stlParentName.Data(), dataName.Data(), stlParentName.Length()-1 )
3547 && dataName[ stlParentName.Length() ] == '.' )
3548 dataName.Remove( 0, stlParentName.Length()+1 );
3549 }
3550
3551 // Find our offset in our parent class using
3552 // a lookup by name in the dictionary meta info
3553 // for our parent class.
3554
3555 if (alternateElement) {
3556 Ssiz_t dotpos = dataName.Last('.');
3557 Ssiz_t endpos = dataName.Length();
3558 if (dotpos != kNPOS) ++dotpos; else dotpos = 0;
3559 dataName.Replace(dotpos,endpos-dotpos,subBranchElement->GetFullName());
3560 }
3561 TRealData* rd = pClass->GetRealData(dataName);
3562 if (rd && (!rd->TestBit(TRealData::kTransient) || alternateElement)) {
3563 // -- Data member exists in the dictionary meta info, get the offset.
3564 // If we are using an alternateElement, it is the target of a rule
3565 // and might be indeed transient.
3566 offset = rd->GetThisOffset();
3567 } else if (subBranchElement->TestBit(TStreamerElement::kWholeObject)) {
3568 // We are a rule with no specific target, it applies to the whole
3569 // object, let's set the offset to zero
3570 offset = 0;
3571 } else {
3572 // -- No dictionary meta info for this data member, it must no
3573 // longer exist
3574 if (fEntries == 0) {
3575 // ... unless we creating the branch in which case
3576 // we have an internal error.
3577 if (pClass->GetListOfRealData()->GetEntries() == 0) {
3578 // We are probably missing the ShowMember, let's
3579 // just issue an error.
3580 Error("InitializeOffsets",
3581 "Could not find the real data member '%s' when constructing the branch '%s' [Likely missing ShowMember].",
3582 dataName.Data(),GetName());
3583 } else if (subInfo && subInfo->GetClassVersion()!=subInfo->GetClass()->GetClassVersion()) {
3584 // In the case where we are cloning a TTree that was created with an older version of the layout, we may not
3585 // able to find all the members
3586 Info("InitializeOffsets",
3587 "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'. ",
3588 dataName.Data(),GetName());
3589 } else {
3590 // Something really bad happen.
3591 Fatal("InitializeOffsets",
3592 "Could not find the real data member '%s' when constructing the branch '%s' [Likely an internal error, please report to the developers].",
3593 dataName.Data(),GetName());
3594 }
3595 }
3596 localOffset = TStreamerInfo::kMissing;
3597 }
3598 } else {
3599 // -- We have no data member name, ok for a base class, not good otherwise.
3600 if (isBaseSubBranch) {
3601 // I am a direct base class of my parent class, my local offset is enough.
3602 } else {
3603 Warning("InitializeOffsets", "Could not find the data member name for branch '%s' with parent branch '%s', assuming offset is zero!", subBranch->GetName(), GetName());
3604 }
3605 }
3606
3607 //
3608 // Ok, do final calculations for fOffset and fBranchOffset.
3609 //
3610
3611 if (isContDataMember) {
3612 // -- Container data members set fOffset instead of fBranchOffset.
3613 // The fOffset is what should be added to the start of the entry
3614 // in the collection (i.e., its current absolute address) to find
3615 // the beginning of the data member described by the current branch.
3616 //
3617 // Compensate for the i/o routines adding our local offset later.
3618 if (subBranch->fObject == 0 && localOffset == TStreamerInfo::kMissing) {
3619 subBranch->SetMissing();
3620 // We stil need to set fBranchOffset in the case of a missing
3621 // element so that SetAddress is (as expected) not called
3622 // recursively in this case.
3623 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3624 } else {
3625 if (isBaseSubBranch) {
3626 // The value of 'offset' for a base class does not include its
3627 // 'localOffset'.
3628 subBranch->SetOffset(offset);
3629 } else {
3630 // The value of 'offset' for a regular data member does include its
3631 // 'localOffset', we need to remove it explicitly.
3632 subBranch->SetOffset(offset - localOffset);
3633 }
3634 }
3635 } else {
3636 // -- Set fBranchOffset for sub-branch.
3637 Int_t isSplit = 0 != subBranch->GetListOfBranches()->GetEntriesFast();
3638 if (subBranch->fObject == 0 && localOffset == TStreamerInfo::kMissing) {
3639 // The branch is missing
3640 fBranchOffset[subBranchIdx] = TStreamerInfo::kMissing;
3641
3642 } else if (isSplit) {
3643 if (isBaseSubBranch) {
3644 // We are split, so we need to add in our local offset
3645 // to get our absolute address for our children.
3646 fBranchOffset[subBranchIdx] = offset + localOffset;
3647 } else {
3648 // We are split so our offset will never be
3649 // used in an i/o, so we do not have to subtract
3650 // off our local offset like below.
3651 fBranchOffset[subBranchIdx] = offset;
3652 }
3653 } else {
3654 if (isBaseSubBranch) {
3655 // We are not split, so our local offset will be
3656 // added later by the i/o routines.
3657 fBranchOffset[subBranchIdx] = offset;
3658 } else {
3659 // Compensate for the fact that the i/o routines
3660 // are going to add my local offset later.
3661 fBranchOffset[subBranchIdx] = offset - localOffset;
3662 }
3663 }
3664 }
3665 }
3666 }
3667 else {
3668 if (fID > -1) {
3669 // Branch is *not* a top-level branch.
3670 // Let's check if the target member is still present in memory
3672 fObject = 0;
3673 }
3674 }
3675 }
3676 const bool isSplitNode = (fType == 2 || fType == 1 || (fType == 0 && fID == -2)) && !fBranches.IsEmpty();
3677 if (fReadActionSequence && isSplitNode) {
3678 TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
3679 auto index = parent->fBranches.IndexOf(this);
3680 if (index >= 0) {
3681 fReadActionSequence->AddToOffset( - parent->fBranchOffset[index] );
3682 }
3683 }
3684
3686}
3687
3688////////////////////////////////////////////////////////////////////////////////
3689/// Return kTRUE if more than one leaf, kFALSE otherwise.
3690
3692{
3693 Int_t nbranches = fBranches.GetEntriesFast();
3694 if (nbranches >= 1) {
3695 return kTRUE;
3696 }
3697 TList* browsables = const_cast<TBranchElement*>(this)->GetBrowsables();
3698 return browsables && browsables->GetSize();
3699}
3700
3701////////////////////////////////////////////////////////////////////////////////
3702/// Detect a collection written using a zero pointer in old versions of root.
3703/// In versions of ROOT older than 4.00/03, if a collection (TClonesArray
3704/// or STL container) was split but the pointer to the collection was zeroed
3705/// out, nothing was saved. Hence there is no __easy__ way to detect the
3706/// case. In newer versions, a zero is written so that a 'missing' collection
3707/// appears to be an empty collection.
3708
3710{
3711 Bool_t ismissing = kFALSE;
3713 if (basket && fTree) {
3714 Long64_t entry = fTree->GetReadEntry();
3716 Long64_t last;
3717 if (fReadBasket == fWriteBasket) {
3718 last = fEntryNumber - 1;
3719 } else {
3720 last = fBasketEntry[fReadBasket+1] - 1;
3721 }
3722 Int_t* entryOffset = basket->GetEntryOffset();
3723 Int_t bufbegin;
3724 Int_t bufnext;
3725 if (entryOffset) {
3726 bufbegin = entryOffset[entry-first];
3727
3728 if (entry < last) {
3729 bufnext = entryOffset[entry+1-first];
3730 } else {
3731 bufnext = basket->GetLast();
3732 }
3733 if (bufnext == bufbegin) {
3734 ismissing = kTRUE;
3735 } else {
3736 // fixed length buffer so this is not the case here.
3737 if (basket->GetNevBufSize() == 0) {
3738 ismissing = kTRUE;
3739 }
3740 }
3741 }
3742 }
3743 return ismissing;
3744}
3745
3746////////////////////////////////////////////////////////////////////////////////
3747/// Print branch parameters.
3748
3749static void PrintElements(const TStreamerInfo *info, const TStreamerInfoActions::TIDs &ids)
3750{
3751 for(auto &cursor : ids) {
3752 auto id = cursor.fElemID;
3753 if (id >= 0) {
3754 auto el = info->GetElement(id);
3755 if (el)
3756 el->ls();
3757 else {
3758 Error("TBranchElement::Print", "Element for id #%d not found in StreamerInfo for %s",
3759 id, info->GetName());
3760 info->ls();
3761 }
3762 } else if (cursor.fNestedIDs) {
3763 Printf(" Within subobject of type %s offset = %d", cursor.fNestedIDs->fInfo->GetName(), cursor.fNestedIDs->fOffset);
3764 PrintElements(cursor.fNestedIDs->fInfo, cursor.fNestedIDs->fIDs);
3765 }
3766 }
3767}
3768
3770{
3771 Int_t nbranches = fBranches.GetEntriesFast();
3772 if (strncmp(option,"debugAddress",strlen("debugAddress"))==0) {
3773 if (strlen(option)==strlen("debugAddress")) {
3774 Printf("%-24s %-16s %2s %4s %-16s %-16s %8s %8s %s\n",
3775 "Branch Name", "Streamer Class", "ID", "Type", "Class", "Parent", "pOffset", "fOffset", "fObject");
3776 }
3777 if (strlen(GetName())>24) Printf("%-24s\n%-24s ", GetName(),"");
3778 else Printf("%-24s ", GetName());
3779
3780 TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
3781 Int_t ind = parent ? parent->GetListOfBranches()->IndexOf(this) : -1;
3782 TVirtualStreamerInfo *info = ((TBranchElement*)this)->GetInfoImp();
3783
3784 Printf("%-16s %2d %4d %-16s %-16s %8x %8x %p\n",
3785 info ? info->GetName() : "StreamerInfo unavailable", GetID(), GetType(),
3787 (fBranchOffset&&parent && ind>=0) ? parent->fBranchOffset[ind] : 0,
3788 GetOffset(), GetObject());
3789 for (Int_t i = 0; i < nbranches; ++i) {
3790 TBranchElement* subbranch = (TBranchElement*)fBranches.At(i);
3791 subbranch->Print("debugAddressSub");
3792 }
3793 return;
3794 }
3795 if (strncmp(option,"debugInfo",strlen("debugInfo"))==0) {
3796 Printf("Branch %s uses:",GetName());
3797 if (fID>=0) {
3798 // GetInfoImp()->GetElement(fID)->ls();
3799 // for(UInt_t i=0; i< fIDs.size(); ++i) {
3800 // GetInfoImp()->GetElement(fIDs[i])->ls();
3801 // }
3802 TStreamerInfo *localInfo = GetInfoImp();
3803 if (fType == 3 || fType == 4) {
3804 // Search for the correct version.
3806 }
3807 Printf(" With elements:");
3808 if (fType != 3 && fType != 4)
3809 localInfo->GetElement(fID)->ls();
3810 PrintElements(localInfo, fNewIDs);
3811 Printf(" with read actions:");
3813 Printf(" with write actions:");
3815 } else if (!fNewIDs.empty() && GetInfoImp()) {
3816 TStreamerInfo *localInfo = GetInfoImp();
3817 if (fType == 3 || fType == 4) {
3818 // Search for the correct version.
3820 }
3821 PrintElements(localInfo, fNewIDs);
3822 Printf(" with read actions:");
3824 Printf(" with write actions:");
3826 }
3827 TString suboption = "debugInfoSub";
3828 suboption += (option+strlen("debugInfo"));
3829 for (Int_t i = 0; i < nbranches; ++i) {
3830 TBranchElement* subbranch = (TBranchElement*)fBranches.At(i);
3831 subbranch->Print(suboption);
3832 }
3833 Printf(" ");
3834 return;
3835 }
3836 if (nbranches) {
3837 if (fID == -2) {
3838 if (strcmp(GetName(),GetTitle()) == 0) {
3839 Printf("*Branch :%-66s *",GetName());
3840 } else {
3841 Printf("*Branch :%-9s : %-54s *",GetName(),GetTitle());
3842 }
3843 Printf("*Entries : %8d : BranchElement (see below) *",Int_t(fEntries));
3844 Printf("*............................................................................*");
3845 }
3846 if (fType >= 2) {
3847 TBranch::Print(option);
3848 }
3849 for (Int_t i=0;i<nbranches;i++) {
3850 TBranch *branch = (TBranch*)fBranches.At(i);
3851 branch->Print(option);
3852 }
3853 } else {
3854 TBranch::Print(option);
3855 }
3856}
3857
3858////////////////////////////////////////////////////////////////////////////////
3859/// Prints values of leaves.
3860
3862{
3864
3865 TStreamerInfo *info = GetInfoImp();
3866 Int_t prID = fID;
3867 char *object = fObject;
3868 if (TestBit(kCache)) {
3870 prID = fID+1;
3871 } else if (fOnfileObject) {
3872 object = fOnfileObject->GetObjectAt(0);
3873 }
3874 }
3875
3876 if (TestBit(kDecomposedObj)) {
3877 if (!fAddress) {
3878 return;
3879 }
3880 if (fType == 3 || fType == 4) {
3881 // TClonesArray or STL container top-level branch.
3882 printf(" %-15s = %d\n", GetName(), fNdata);
3883 return;
3884 } else if (fType == 31 || fType == 41) {
3885 // TClonesArray or STL container sub-branch.
3886 Int_t n = TMath::Min(10, fNdata);
3889 // TVirtualStreamerInfo::kOffsetL + TVirtualStreamerInfo::kChar is
3890 // printed as a string and could print weird characters.
3891 // So we print an unsigned char instead (not perfect, but better).
3893 }
3894 if (atype > 54) {
3895 // FIXME: More logic required here (like in ReadLeaves)
3896 printf(" %-15s = %d\n", GetName(), fNdata);
3897 return;
3898 }
3899 if (fStreamerType > 20) {
3900 atype -= 20;
3902 n = n * leaf->GetLenStatic();
3903 }
3904 if (GetInfoImp()) {
3905 GetInfoImp()->PrintValue(GetName(), fAddress, atype, n, lenmax);
3906 }
3907 return;
3908 } else if (fType <= 2) {
3909 // Branch in split mode.
3910 // FIXME: This should probably be < 60 instead.
3911 if ((fStreamerType > 40) && (fStreamerType < 55)) {
3912 Int_t atype = fStreamerType - 20;
3913 TBranchElement* counterElement = (TBranchElement*) fBranchCount;
3914 Int_t n = (Int_t) counterElement->GetValue(0, 0);
3915 if (GetInfoImp()) {
3916 GetInfoImp()->PrintValue(GetName(), fAddress, atype, n, lenmax);
3917 }
3918 } else {
3919 if (GetInfoImp()) {
3920 GetInfoImp()->PrintValue(GetName(), object, prID, -1, lenmax);
3921 }
3922 }
3923 return;
3924 }
3925 } else if (fType == 3) {
3926 printf(" %-15s = %d\n", GetName(), fNdata);
3927 } else if (fType == 31) {
3928 TClonesArray* clones = (TClonesArray*) object;
3929 if (GetInfoImp()) {
3930 GetInfoImp()->PrintValueClones(GetName(), clones, prID, fOffset, lenmax);
3931 }
3932 } else if (fType == 41) {
3934 if (GetInfoImp()) {
3935 GetInfoImp()->PrintValueSTL(GetName(), ((TBranchElement*) this)->GetCollectionProxy(), prID, fOffset, lenmax);
3936 }
3937 } else {
3938 if (GetInfoImp()) {
3939 GetInfoImp()->PrintValue(GetName(), object, prID, -1, lenmax);
3940 }
3941 }
3942}
3943
3944////////////////////////////////////////////////////////////////////////////////
3945/// Unconfiguration Read Leave function.
3946
3948{
3949 Fatal("ReadLeaves","The ReadLeaves function has not been configured for %s",GetName());
3950}
3951
3952////////////////////////////////////////////////////////////////////////////////
3953/// Read leaves into i/o buffers for this branch.
3954/// For the case where the branch is set in MakeClass mode (decomposed object).
3955
3957{
3959
3960 if (fType == 3 || fType == 4) {
3961 // Top level branch of a TClonesArray.
3962 Int_t *n = (Int_t*) fAddress;
3963 b >> n[0];
3964 if ((n[0] < 0) || (n[0] > fMaximum)) {
3965 if (IsMissingCollection()) {
3966 n[0] = 0;
3967 b.SetBufferOffset(b.Length() - sizeof(n));
3968 } else {
3969 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());
3970 n[0] = 0;
3971 }
3972 }
3973 fNdata = n[0];
3974 if (fType == 4) {
3975 Int_t nbranches = fBranches.GetEntriesFast();
3976 switch(fSTLtype) {
3977 case ROOT::kSTLset:
3978 case ROOT::kSTLmultiset:
3979 case ROOT::kSTLmap:
3980 case ROOT::kSTLmultimap:
3981 for (Int_t i=0; i<nbranches; i++) {
3982 TBranch *branch = (TBranch*)fBranches[i];
3983 Int_t nb = branch->GetEntry(GetReadEntry(), 1);
3984 if (nb < 0) {
3985 break;
3986 }
3987 }
3988 break;
3989 default:
3990 break;
3991 }
3992 }
3993 return;
3994 } else if (fType == 31 || fType == 41) { // sub branch of a TClonesArray
3996 Int_t atype = fStreamerType;
3997 // FIXME: This should probably be > 59 instead.
3998 if (atype > 54) return;
3999 if (!fAddress) {
4000 return;
4001 }
4002 Int_t n = fNdata;
4003 if (atype>40) {
4004 atype -= 40;
4005 if (!fBranchCount2) return;
4006 const char *len_where = (char*)fBranchCount2->fAddress;
4007 if (!len_where) return;
4008 Int_t len_atype = fBranchCount2->fStreamerType;
4009 Int_t length;
4010 Int_t k;
4011 Char_t isArray;
4012 for( k=0; k<n; k++) {
4013 char **where = &(((char**)fAddress)[k]);
4014 delete [] *where;
4015 *where = 0;
4016 switch(len_atype) {
4017 case 1: {length = ((Char_t*) len_where)[k]; break;}
4018 case 2: {length = ((Short_t*) len_where)[k]; break;}
4019 case 3: {length = ((Int_t*) len_where)[k]; break;}
4020 case 4: {length = ((Long_t*) len_where)[k]; break;}
4021 //case 5: {length = ((Float_t*) len_where)[k]; break;}
4022 case 6: {length = ((Int_t*) len_where)[k]; break;}
4023 //case 8: {length = ((Double_t*)len_where)[k]; break;}
4024 case 11: {length = ((UChar_t*) len_where)[k]; break;}
4025 case 12: {length = ((UShort_t*) len_where)[k]; break;}
4026 case 13: {length = ((UInt_t*) len_where)[k]; break;}
4027 case 14: {length = ((ULong_t*) len_where)[k]; break;}
4028 case 15: {length = ((UInt_t*) len_where)[k]; break;}
4029 case 16: {length = ((Long64_t*) len_where)[k]; break;}
4030 case 17: {length = ((ULong64_t*)len_where)[k]; break;}
4031 case 18: {length = ((Bool_t*) len_where)[k]; break;}
4032 default: continue;
4033 }
4034 b >> isArray;
4035 if (length <= 0) continue;
4036 if (isArray == 0) continue;
4037 switch (atype) {
4038 case 1: {*where=new char[sizeof(Char_t)*length]; b.ReadFastArray((Char_t*) *where, length); break;}
4039 case 2: {*where=new char[sizeof(Short_t)*length]; b.ReadFastArray((Short_t*) *where, length); break;}
4040 case 3: {*where=new char[sizeof(Int_t)*length]; b.ReadFastArray((Int_t*) *where, length); break;}
4041 case 4: {*where=new char[sizeof(Long_t)*length]; b.ReadFastArray((Long_t*) *where, length); break;}
4042 case 5: {*where=new char[sizeof(Float_t)*length]; b.ReadFastArray((Float_t*) *where, length); break;}
4043 case 6: {*where=new char[sizeof(Int_t)*length]; b.ReadFastArray((Int_t*) *where, length); break;}
4044 case 8: {*where=new char[sizeof(Double_t)*length]; b.ReadFastArray((Double_t*)*where, length); break;}
4045 case 11: {*where=new char[sizeof(UChar_t)*length]; b.ReadFastArray((UChar_t*) *where, length); break;}
4046 case 12: {*where=new char[sizeof(UShort_t)*length]; b.ReadFastArray((UShort_t*)*where, length); break;}
4047 case 13: {*where=new char[sizeof(UInt_t)*length]; b.ReadFastArray((UInt_t*) *where, length); break;}
4048 case 14: {*where=new char[sizeof(ULong_t)*length]; b.ReadFastArray((ULong_t*) *where, length); break;}
4049 case 15: {*where=new char[sizeof(UInt_t)*length]; b.ReadFastArray((UInt_t*) *where, length); break;}
4050 case 16: {*where=new char[sizeof(Long64_t)*length]; b.ReadFastArray((Long64_t*) *where, length); break;}
4051 case 17: {*where=new char[sizeof(ULong64_t)*length]; b.ReadFastArray((ULong64_t*)*where, length); break;}
4052 case 18: {*where=new char[sizeof(Bool_t)*length]; b.ReadFastArray((Bool_t*) *where, length); break;}
4053 }
4054 }
4055 return;
4056 }
4057 if (atype > 20) {
4058 atype -= 20;
4060 n *= leaf->GetLenStatic();
4061 }
4062 switch (atype) {
4063 case 1: {b.ReadFastArray((Char_t*) fAddress, n); break;}
4064 case 2: {b.ReadFastArray((Short_t*) fAddress, n); break;}
4065 case 3: {b.ReadFastArray((Int_t*) fAddress, n); break;}
4066 case 4: {b.ReadFastArray((Long_t*) fAddress, n); break;}
4067 case 5: {b.ReadFastArray((Float_t*) fAddress, n); break;}
4068 case 6: {b.ReadFastArray((Int_t*) fAddress, n); break;}
4069 case 8: {b.ReadFastArray((Double_t*)fAddress, n); break;}
4070 case 11: {b.ReadFastArray((UChar_t*) fAddress, n); break;}
4071 case 12: {b.ReadFastArray((UShort_t*)fAddress, n); break;}
4072 case 13: {b.ReadFastArray((UInt_t*) fAddress, n); break;}
4073 case 14: {b.ReadFastArray((ULong_t*) fAddress, n); break;}
4074 case 15: {b.ReadFastArray((UInt_t*) fAddress, n); break;}
4075 case 16: {b.ReadFastArray((Long64_t*)fAddress, n); break;}
4076 case 17: {b.ReadFastArray((ULong64_t*)fAddress, n); break;}
4077 case 18: {b.ReadFastArray((Bool_t*) fAddress, n); break;}
4078 case 9: {
4081 Double_t *xx = (Double_t*) fAddress;
4082 for (Int_t ii=0;ii<n;ii++) {
4083 b.ReadDouble32(&(xx[ii]),se);
4084 }
4085 break;
4086 }
4087 case 19: {
4090 Float_t *xx = (Float_t*) fAddress;
4091 for (Int_t ii=0;ii<n;ii++) {
4092 b.ReadFloat16(&(xx[ii]),se);
4093 }
4094 break;
4095 }
4096 }
4097 return;
4098 } else if (fType <= 2) { // branch in split mode
4099 // FIXME: This should probably be < 60 instead.
4100 if (fStreamerType > 40 && fStreamerType < 55) {
4101 Int_t atype = fStreamerType - 40;
4102 Int_t n;
4103 if (fBranchCount==0) {
4104 // Missing fBranchCount. let's attempts to recover.
4105
4106 TString countname( GetName() );
4107 Ssiz_t dot = countname.Last('.');
4108 if (dot>=0) {
4109 countname.Remove(dot+1);
4110 } else {
4111 countname = "";
4112 }
4113 TString counter( GetTitle() );
4114 Ssiz_t loc = counter.Last('[');
4115 if (loc>=0) {
4116 counter.Remove(0,loc+1);
4117 }
4118 loc = counter.Last(']');
4119 if (loc>=0) {
4120 counter.Remove(loc);
4121 }
4122 countname += counter;
4124 }
4125 if (fBranchCount) {
4126 n = (Int_t)fBranchCount->GetValue(0,0);
4127 } else {
4128 Warning("ReadLeaves","Missing fBranchCount for %s. Data will not be read correctly by the MakeClass mode.",GetName());
4129 n = 0;
4130 }
4131 fNdata = n;
4132 Char_t isArray;
4133 b >> isArray;
4134 switch (atype) {
4135 case 1: {b.ReadFastArray((Char_t*) fAddress, n); break;}
4136 case 2: {b.ReadFastArray((Short_t*) fAddress, n); break;}
4137 case 3: {b.ReadFastArray((Int_t*) fAddress, n); break;}
4138 case 4: {b.ReadFastArray((Long_t*) fAddress, n); break;}
4139 case 5: {b.ReadFastArray((Float_t*) fAddress, n); break;}
4140 case 6: {b.ReadFastArray((Int_t*) fAddress, n); break;}
4141 case 8: {b.ReadFastArray((Double_t*)fAddress, n); break;}
4142 case 11: {b.ReadFastArray((UChar_t*) fAddress, n); break;}
4143 case 12: {b.ReadFastArray((UShort_t*)fAddress, n); break;}
4144 case 13: {b.ReadFastArray((UInt_t*) fAddress, n); break;}
4145 case 14: {b.ReadFastArray((ULong_t*) fAddress, n); break;}
4146 case 15: {b.ReadFastArray((UInt_t*) fAddress, n); break;}
4147 case 16: {b.ReadFastArray((Long64_t*) fAddress, n); break;}
4148 case 17: {b.ReadFastArray((ULong64_t*)fAddress, n); break;}
4149 case 18: {b.ReadFastArray((Bool_t*) fAddress, n); break;}
4150 case 9: {
4153 Double_t *xx = (Double_t*) fAddress;
4154 for (Int_t ii=0;ii<n;ii++) {
4155 b.ReadDouble32(&(xx[ii]),se);
4156 }
4157 break;
4158 }
4159 case 19: {
4162 Float_t *xx = (Float_t*) fAddress;
4163 for (Int_t ii=0;ii<n;ii++) {
4164 b.ReadFloat16(&(xx[ii]),se);
4165 }
4166 break;
4167 }
4168 }
4169 } else {
4170 fNdata = 1;
4171 if (fAddress) {
4172 if (fType<0) {
4173 // Non TObject, Non collection classes with a custom streamer.
4174
4175 // if (fObject)
4177 } else {
4178 TStreamerInfo *info = GetInfoImp();
4179 if (!info) {
4180 return;
4181 }
4182 // Since info is not null, fReadActionSequence is not null either.
4183 b.ApplySequence(*fReadActionSequence, fObject);
4184 }
4186 fNdata = (Int_t) GetValue(0, 0);
4187 }
4188 } else {
4189 fNdata = 0;
4190 }
4191 }
4192 return;
4193 }
4194}
4195
4196////////////////////////////////////////////////////////////////////////////////
4197/// Read leaves into i/o buffers for this branch.
4198/// Case of a collection (fType == 4).
4199
4201{
4203 if (fObject == 0)
4204 {
4205 // We have nowhere to copy the data (probably because the data member was
4206 // 'dropped' from the current schema) so let's no copy it in a random place.
4207 return;
4208 }
4209
4210 // STL container master branch (has only the number of elements).
4211 Int_t n;
4212 b >> n;
4213 if ((n < 0) || (n > fMaximum)) {
4214 if (IsMissingCollection()) {
4215 n = 0;
4216 b.SetBufferOffset(b.Length()-sizeof(n));
4217 } else {
4218 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());
4219 n = 0;
4220 }
4221 }
4222 fNdata = n;
4223
4224 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,1);
4225
4226 // Note: Proxy-helper needs to "embrace" the entire
4227 // streaming of this STL container if the container
4228 // is a set/multiset/map/multimap (what we do not
4229 // know here).
4230 // For vector/list/deque Allocate == Resize
4231 // and Commit == noop.
4232 // TODO: Exception safety a la TPushPop
4235 void* alternate = proxy->Allocate(fNdata, true);
4237 fPtrIterators->CreateIterators(alternate, proxy);
4238 } else {
4239 fIterators->CreateIterators(alternate, proxy);
4240 }
4241
4242 Int_t nbranches = fBranches.GetEntriesFast();
4243 switch (fSTLtype) {
4244 case ROOT::kSTLset:
4247 case ROOT::kSTLmultiset:
4248 case ROOT::kSTLmap:
4249 case ROOT::kSTLmultimap:
4252 for (Int_t i = 0; i < nbranches; ++i) {
4253 TBranch *branch = (TBranch*) fBranches[i];
4254 Int_t nb = branch->GetEntry(GetReadEntry(), 1);
4255 if (nb < 0) {
4256 // Give up on i/o failure.
4257 // FIXME: We need an error message here.
4258 break;
4259 }
4260 }
4261 break;
4262 default:
4263 break;
4264 }
4265 //------------------------------------------------------------------------
4266 // We have split this stuff, so we need to create the the pointers
4267 /////////////////////////////////////////////////////////////////////////////
4268
4270 {
4271 TClass *elClass = proxy->GetValueClass();
4272
4273 //--------------------------------------------------------------------
4274 // The allocation is done in this strange way because ReadLeaves
4275 // is being called many times by TTreeFormula!!!
4276 //////////////////////////////////////////////////////////////////////////
4277
4278 Int_t i = 0;
4279 // coverity[returned_null] the fNdata is check enough to prevent the use of null value of At(0)
4280 if( !fNdata || *(void**)proxy->At( 0 ) != 0 )
4281 i = fNdata;
4282
4283 for( ; i < fNdata; ++i )
4284 {
4285 void **el = (void**)proxy->At( i );
4286 // coverity[dereference] since this is a member streaming action by definition the collection contains objects and elClass is not null.
4287 *el = elClass->New();
4288 }
4289 }
4290
4291 proxy->Commit(alternate);
4292}
4293
4294////////////////////////////////////////////////////////////////////////////////
4295/// Read leaves into i/o buffers for this branch.
4296/// Case of a data member within a collection (fType == 41).
4297
4299{
4301 if (fObject == 0)
4302 {
4303 // We have nowhere to copy the data (probably because the data member was
4304 // 'dropped' from the current schema) so let's no copy it in a random place.
4305 return;
4306 }
4307
4308 // STL container sub-branch (contains the elements).
4310 if (!fNdata) {
4311 return;
4312 }
4313
4314 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,fNdata);
4315
4316 TStreamerInfo *info = GetInfoImp();
4317 if (info == 0) return;
4318
4321
4322 // R__ASSERT(0);
4324 b.ApplySequence(*fReadActionSequence,iter->fBegin,iter->fEnd);
4325}
4326
4327////////////////////////////////////////////////////////////////////////////////
4328/// Read leaves into i/o buffers for this branch.
4329/// Case of a data member within a collection (fType == 41).
4330
4332{
4334 if (fObject == 0)
4335 {
4336 // We have nowhere to copy the data (probably because the data member was
4337 // 'dropped' from the current schema) so let's no copy it in a random place.
4338 return;
4339 }
4340
4341 // STL container sub-branch (contains the elements).
4343 if (!fNdata) {
4344 return;
4345 }
4346 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,fNdata);
4347
4348 TStreamerInfo *info = GetInfoImp();
4349 if (info == 0) return;
4350
4353
4355 b.ApplySequenceVecPtr(*fReadActionSequence,iter->fBegin,iter->fEnd);
4356}
4357
4358////////////////////////////////////////////////////////////////////////////////
4359/// Read leaves into i/o buffers for this branch.
4360/// Case of a data member within a collection (fType == 41).
4361
4363{
4365 if (fObject == 0)
4366 {
4367 // We have nowhere to copy the data (probably because the data member was
4368 // 'dropped' from the current schema) so let's no copy it in a random place.
4369 return;
4370 }
4371
4372 // STL container sub-branch (contains the elements).
4374 if (!fNdata) {
4375 return;
4376 }
4377 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,fNdata);
4378
4379 TStreamerInfo *info = GetInfoImp();
4380 if (info == 0) return;
4381 // Since info is not null, fReadActionSequence is not null either.
4382
4383 // Still calling PushPop for the legacy entries.
4386
4388 b.ApplySequence(*fReadActionSequence,iter->fBegin,iter->fEnd);
4389}
4390
4391////////////////////////////////////////////////////////////////////////////////
4392/// Read leaves into i/o buffers for this branch.
4393/// Case of a TClonesArray (fType == 3).
4394
4396{
4398 if (fObject == 0)
4399 {
4400 // We have nowhere to copy the data (probably because the data member was
4401 // 'dropped' from the current schema) so let's no copy it in a random place.
4402 return;
4403 }
4404
4405 // TClonesArray master branch (has only the number of elements).
4406 Int_t n;
4407 b >> n;
4408 if ((n < 0) || (n > fMaximum)) {
4409 if (IsMissingCollection()) {
4410 n = 0;
4411 b.SetBufferOffset(b.Length()-sizeof(n));
4412 } else {
4413 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());
4414 n = 0;
4415 }
4416 }
4417 fNdata = n;
4418 TClonesArray* clones = (TClonesArray*) fObject;
4419 if (clones->IsZombie()) {
4420 return;
4421 }
4422 // The salient part of Clear is now 'duplicated in ExpandCreateFast (i.e. the
4423 // setting to zero of the unused slots), so we no longer need to call Clear explicitly
4424 // clones->Clear();
4425 clones->ExpandCreateFast(fNdata);
4426}
4427
4428////////////////////////////////////////////////////////////////////////////////
4429/// Read leaves into i/o buffers for this branch.
4430/// Case of a data member within a TClonesArray (fType == 31).
4431
4433{
4434 // No need to validate the address here, if we are a member of a split ClonesArray,
4435 // fID is positive
4436 // ValidateAddress();
4437
4438 if (fObject == 0)
4439 {
4440 // We have nowhere to copy the data (probably because the data member was
4441 // 'dropped' from the current schema) so let's no copy it in a random place.
4442 return;
4443 }
4444
4445 // TClonesArray sub-branch (contains the elements).
4447 TClonesArray* clones = (TClonesArray*) fObject;
4448 if (clones->IsZombie()) {
4449 return;
4450 }
4451 TStreamerInfo *info = GetInfoImp();
4452 if (info==0) return;
4453 // Since info is not null, fReadActionSequence is not null either.
4454
4455 // Note, we could (possibly) save some more, by configuring the action
4456 // based on the value of fOnfileObject rather than pushing in on a stack.
4457 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,fNdata);
4458
4459 char **arr = (char **)clones->GetObjectRef();
4460 char **end = arr + fNdata;
4461 b.ApplySequenceVecPtr(*fReadActionSequence,arr,end);
4462}
4463
4464////////////////////////////////////////////////////////////////////////////////
4465/// Read leaves into i/o buffers for this branch.
4466/// For split-class branch, base class branch, data member branch, or top-level branch.
4467/// which do not have a branch count and are not a counter.
4468
4470{
4473
4475 if (fObject == 0)
4476 {
4477 // We have nowhere to copy the data (probably because the data member was
4478 // 'dropped' from the current schema) so let's no copy it in a random place.
4479 return;
4480 }
4481
4482 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,1);
4483 // If not a TClonesArray or STL container master branch
4484 // or sub-branch and branch inherits from tobject,
4485 // then register with the buffer so that pointers are
4486 // handled properly.
4487 if (TestBit(kBranchObject)) {
4488 b.MapObject((TObject*) fObject);
4489 } else if (TestBit(kBranchAny)) {
4490 b.MapObject(fObject, fBranchClass);
4491 }
4492
4493 fNdata = 1;
4494 TStreamerInfo *info = GetInfoImp();
4495 if (!info) {
4496 return;
4497 }
4498 // Since info is not null, fReadActionSequence is not null either.
4499 b.ApplySequence(*fReadActionSequence, fObject);
4500}
4501
4502////////////////////////////////////////////////////////////////////////////////
4503/// Read leaves into i/o buffers for this branch.
4504/// For split-class branch, base class branch, data member branch, or top-level branch.
4505/// which do have a branch count and are not a counter.
4506
4508{
4510
4512 if (fObject == 0)
4513 {
4514 // We have nowhere to copy the data (probably because the data member was
4515 // 'dropped' from the current schema) so let's no copy it in a random place.
4516 return;
4517 }
4518
4519 // If not a TClonesArray or STL container master branch
4520 // or sub-branch and branch inherits from tobject,
4521 // then register with the buffer so that pointers are
4522 // handled properly.
4523 if (TestBit(kBranchObject)) {
4524 b.MapObject((TObject*) fObject);
4525 } else if (TestBit(kBranchAny)) {
4526 b.MapObject(fObject, fBranchClass);
4527 }
4528
4529 fNdata = (Int_t) fBranchCount->GetValue(0, 0);
4530 TStreamerInfo *info = GetInfoImp();
4531 if (!info) {
4532 return;
4533 }
4534 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,1); // Here we have a single object that contains a variable size C-style array.
4535 // Since info is not null, fReadActionSequence is not null either.
4536 b.ApplySequence(*fReadActionSequence, fObject);
4537}
4538
4539////////////////////////////////////////////////////////////////////////////////
4540/// Read leaves into i/o buffers for this branch.
4541/// For split-class branch, base class branch, data member branch, or top-level branch.
4542/// which do not have a branch count and are a counter.
4543
4545{
4547 if (fObject == 0)
4548 {
4549 // We have nowhere to copy the data (probably because the data member was
4550 // 'dropped' from the current schema) so let's no copy it in a random place.
4551 return;
4552 }
4553
4554 // If not a TClonesArray or STL container master branch
4555 // or sub-branch and branch inherits from tobject,
4556 // then register with the buffer so that pointers are
4557 // handled properly.
4558 if (TestBit(kBranchObject)) {
4559 b.MapObject((TObject*) fObject);
4560 } else if (TestBit(kBranchAny)) {
4561 b.MapObject(fObject, fBranchClass);
4562 }
4563
4564 TStreamerInfo *info = GetInfoImp();
4565 if (!info) {
4566 return;
4567 }
4568
4569 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,1);
4570
4571 // Since info is not null, fReadActionSequence is not null either.
4572 b.ApplySequence(*fReadActionSequence, fObject);
4573 fNdata = (Int_t) GetValue(0, 0);
4574}
4575
4576////////////////////////////////////////////////////////////////////////////////
4577/// Read leaves into i/o buffers for this branch.
4578/// Non TObject, Non collection classes with a custom streamer.
4579
4581{
4583 if (fObject == 0)
4584 {
4585 // We have nowhere to copy the data (probably because the data member was
4586 // 'dropped' from the current schema) so let's no copy it in a random place.
4587 return;
4588 }
4589
4590 R__PushCache onfileObject(((TBufferFile&)b),fOnfileObject,1);
4592}
4593
4594////////////////////////////////////////////////////////////////////////////////
4595/// Unconfiguration Fill Leave function.
4596
4598{
4599 Fatal("FillLeaves","The FillLeaves function has not been configured for %s",GetName());
4600}
4601
4602////////////////////////////////////////////////////////////////////////////////
4603/// Delete any object we may have allocated on a previous call to SetAddress.
4604
4606{
4607 if (fObject && TestBit(kDeleteObject)) {
4608 if (IsAutoDelete() && fAddress != (char*)&fObject) {
4609 *((char**) fAddress) = 0;
4610 }
4612 if (fType == 3) {
4613 // -- We are a TClonesArray master branch.
4614 TClonesArray::Class()->Destructor(fObject);
4615 fObject = 0;
4618 // -- We are a pointer to a TClonesArray.
4619 // We must zero the pointer in the object.
4620 *((char**) fAddress) = 0;
4621 }
4622 } else if (fType == 4) {
4623 // -- We are an STL container master branch.
4625
4626 if (!proxy) {
4627 Warning("ReleaseObject", "Cannot delete allocated STL container because I do not have a proxy! branch: %s", GetName());
4628 fObject = 0;
4629 } else {
4631 if (needDelete && fID >= 0) {
4634 needDelete = !se->