Skip to content

Commit 9d1ee9f

Browse files
committed
tree: Factor out associative collection test.
This allow to document the 2 sets of similar test at the same place to contrast them
1 parent 23072ba commit 9d1ee9f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

tree/tree/src/TBranchElement.cxx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ namespace {
7777
if (fOnfileObject) fBuffer.PopDataCache();
7878
}
7979
};
80+
////////////////////////////////////////////////////////////////////////////////
81+
/// Check if a collection proxy represents an associative collection (e.g., std::map, std::set)
82+
/// rather than a sequential collection (e.g., std::vector, std::list).
83+
/// Both the version based on the fSTLtype integer and the one based on the TVirtualCollectionProxy
84+
/// will return the same result about the 'currently' in memory collection attached to the branch.
85+
/// The main difference is that the fSTLtype can be used without checking whether
86+
/// fCollProxy is set or not but might (or might not) be a tad bit slower.
8087
bool IsAssociativeContainer(Int_t stltype) {
8188
switch (stltype) {
8289
case ROOT::kSTLset:
@@ -92,6 +99,11 @@ namespace {
9299
return false;
93100
}
94101
}
102+
bool IsAssociativeContainer(const TVirtualCollectionProxy &proxy)
103+
{
104+
return proxy.GetProperties() & TVirtualCollectionProxy::kIsAssociative;
105+
}
106+
95107
void RecursiveResetReadEntry(TBranch *br) {
96108
br->ResetReadEntry();
97109
for(auto sub : *br->GetListOfBranches())
@@ -1474,7 +1486,7 @@ void TBranchElement::FillLeavesCollection(TBuffer& b)
14741486
//NOTE: this does not work for not vectors since the CreateIterators expects a TGenCollectionProxy::TStaging as its argument!
14751487
//NOTE: and those not work in general yet, since the TStaging object is neither created nor passed.
14761488
// We need to review how to avoid the need for a TStaging during the writing.
1477-
if (proxy->GetProperties() & TVirtualCollectionProxy::kIsAssociative) {
1489+
if (IsAssociativeContainer(*proxy)) {
14781490
fWriteIterators->CreateIterators(fObject, proxy);
14791491
} else {
14801492
fIterators->CreateIterators(fObject, proxy);
@@ -4344,7 +4356,7 @@ void TBranchElement::ReadLeavesCollection(TBuffer& b)
43444356
fIterators->CreateIterators(alternate, proxy);
43454357
}
43464358

4347-
if (IsAssociativeContainer(fSTLtype)) {
4359+
if (IsAssociativeContainer(*proxy)) {
43484360

43494361
Int_t nbranches = fBranches.GetEntriesFast();
43504362
for (Int_t i = 0; i < nbranches; ++i) {
@@ -5139,7 +5151,7 @@ void TBranchElement::SetAddressImpl(void* addr, bool implied, Int_t offset)
51395151

51405152
if(fSTLtype != ROOT::kSTLvector && fCollProxy->HasPointers() && fSplitLevel > TTree::kSplitCollectionOfPointers ) {
51415153
fPtrIterators = new TVirtualCollectionPtrIterators(fCollProxy);
5142-
} else if (fCollProxy->GetProperties() & TVirtualCollectionProxy::kIsAssociative) {
5154+
} else if (IsAssociativeContainer(*fCollProxy)) {
51435155
fWriteIterators = new TVirtualCollectionIterators(fCollProxy,false);
51445156
fIterators = new TVirtualCollectionIterators(fCollProxy);
51455157
} else {
@@ -5181,7 +5193,7 @@ void TBranchElement::SetAddressImpl(void* addr, bool implied, Int_t offset)
51815193
delete fPtrIterators;
51825194
if(fSTLtype != ROOT::kSTLvector && fCollProxy->HasPointers() && fSplitLevel > TTree::kSplitCollectionOfPointers ) {
51835195
fPtrIterators = new TVirtualCollectionPtrIterators(fCollProxy);
5184-
} else if (fCollProxy->GetProperties() & TVirtualCollectionProxy::kIsAssociative) {
5196+
} else if (IsAssociativeContainer(*fCollProxy)) {
51855197
fWriteIterators = new TVirtualCollectionIterators(fCollProxy,false);
51865198
fIterators = new TVirtualCollectionIterators(fCollProxy);
51875199
} else {
@@ -5217,7 +5229,7 @@ void TBranchElement::SetAddressImpl(void* addr, bool implied, Int_t offset)
52175229
delete fPtrIterators;
52185230
if(fSTLtype != ROOT::kSTLvector && fCollProxy->HasPointers() && fSplitLevel > TTree::kSplitCollectionOfPointers ) {
52195231
fPtrIterators = new TVirtualCollectionPtrIterators(fCollProxy);
5220-
} else if (fCollProxy->GetProperties() & TVirtualCollectionProxy::kIsAssociative) {
5232+
} else if (IsAssociativeContainer(*fCollProxy)) {
52215233
fWriteIterators = new TVirtualCollectionIterators(fCollProxy,false);
52225234
fIterators = new TVirtualCollectionIterators(fCollProxy);
52235235
} else {
@@ -5287,7 +5299,7 @@ void TBranchElement::SetAddressImpl(void* addr, bool implied, Int_t offset)
52875299
if (!fIterators && !fPtrIterators) {
52885300
if(fSTLtype != ROOT::kSTLvector && GetCollectionProxy()->HasPointers() && fSplitLevel > TTree::kSplitCollectionOfPointers ) {
52895301
fPtrIterators = new TVirtualCollectionPtrIterators(GetCollectionProxy());
5290-
} else if (fCollProxy->GetProperties() & TVirtualCollectionProxy::kIsAssociative) {
5302+
} else if (IsAssociativeContainer(*fCollProxy)) {
52915303
fWriteIterators = new TVirtualCollectionIterators(fCollProxy,false);
52925304
fIterators = new TVirtualCollectionIterators(fCollProxy);
52935305
} else {
@@ -5860,7 +5872,7 @@ void TBranchElement::SetFillLeavesPtr()
58605872
} else {
58615873
fFillLeaves = (FillLeaves_t)&TBranchElement::FillLeavesCollectionSplitPtrMember;
58625874
}
5863-
} else if (GetCollectionProxy()->GetProperties() & TVirtualCollectionProxy::kIsAssociative) {
5875+
} else if (IsAssociativeContainer(*GetCollectionProxy())) {
58645876
fFillLeaves = (FillLeaves_t)&TBranchElement::FillLeavesAssociativeCollectionMember;
58655877
} else {
58665878
fFillLeaves = (FillLeaves_t)&TBranchElement::FillLeavesCollectionMember;

0 commit comments

Comments
 (0)