Skip to content

Commit

Permalink
Factor out ActionSequence creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pcanal committed Jun 27, 2018
1 parent 2e6c1b2 commit db24ec7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 39 deletions.
17 changes: 17 additions & 0 deletions io/io/inc/TStreamerInfoActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ namespace TStreamerInfoActions {
return {seq, kFALSE};
}

static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
auto seq = info->GetWriteMemberWiseActions(kTRUE);
return {seq, kFALSE};
}
static SequencePtr WriteMemberWiseActionsViaProxyGetter(TStreamerInfo *, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
auto seq = collectionProxy->GetWriteMemberWiseActions();
return {seq, kFALSE};
}
static SequencePtr WriteMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
auto seq = TStreamerInfoActions::TActionSequence::CreateWriteMemberWiseActions(info,*collectionProxy);
return {seq, kTRUE};
}
// Creator5() = Creator1;
static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
auto seq = info->GetWriteMemberWiseActions(kFALSE);
return {seq, kFALSE};
}
ClassDef(TActionSequence,0);
};

Expand Down
9 changes: 3 additions & 6 deletions tree/tree/inc/TBranchElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ class TVirtualCollectionIterators;
class TVirtualCollectionPtrIterators;
class TVirtualArray;

namespace TStreamerInfoActions {
class TActionSequence;
struct TIDNode;
using TIDs = std::vector<TIDNode>;
}

#include "TStreamerInfoActions.h"

class TBranchElement : public TBranch {

Expand Down Expand Up @@ -139,6 +134,7 @@ class TBranchElement : public TBranch {
void Init(TTree *tree, TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
void Init(TTree *tree, TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);

void SetActionSequence(TClass *originalClass, TStreamerInfo *localInfo, TStreamerInfoActions::TActionSequence::SequenceGetter_t create, TStreamerInfoActions::TActionSequence *&actionSequence);
void ReadLeavesImpl(TBuffer& b);
void ReadLeavesMakeClass(TBuffer& b);
void ReadLeavesCollection(TBuffer& b);
Expand Down Expand Up @@ -170,6 +166,7 @@ class TBranchElement : public TBranch {
void FillLeavesMember(TBuffer& b);
void SetFillLeavesPtr();
void SetFillActionSequence();

// Public Interface.
public:
TBranchElement();
Expand Down
74 changes: 41 additions & 33 deletions tree/tree/src/TBranchElement.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5356,6 +5356,46 @@ void TBranchElement::SetOffset(Int_t offset)
fOffset = offset;
}


////////////////////////////////////////////////////////////////////////////////
/// Set the sequence of actions needed to read the data out of the buffer.
void TBranchElement::SetActionSequence(TClass *originalClass, TStreamerInfo *localInfo, TStreamerInfoActions::TActionSequence::SequenceGetter_t create, TStreamerInfoActions::TActionSequence *&actionSequence)
{
// A 'split' node does not store data itself (it has not associated baskets)
const bool isSplitNode = (fType == 3 || fType == 4 || fType == 2 || fType == 1 || (fType == 0 && fID == -2)) && !fBranches.IsEmpty();

if (!isSplitNode) {
fNewIDs.insert(fNewIDs.begin(),fID); // Include the main element in the sequence.
}
if (!isSplitNode)
fIDs.insert(fIDs.begin(),fID); // Include the main element in the sequence.

if (actionSequence) delete actionSequence;
auto original = create(localInfo, GetCollectionProxy(), originalClass);

TStreamerInfoActions::TIDs element_ids;
for(auto i : fIDs) {
element_ids.push_back(i);
}
actionSequence = original->CreateSubSequence(fNewIDs, fOffset, create);

if (!isSplitNode)
fNewIDs.erase(fNewIDs.begin());
if (!isSplitNode)
fIDs.erase(fIDs.begin());
else {
// fObject has the address of the sub-object but the streamer action have
// offset relative to the parent.
TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
if (fInitOffsets) {
auto index = parent->fBranches.IndexOf(this);
if (index >= 0) {
fReadActionSequence->AddToOffset( - parent->fBranchOffset[index] );
}
} // else it will be done by InitOffsets
}
}

////////////////////////////////////////////////////////////////////////////////
/// Set the sequence of actions needed to read the data out of the buffer.
void TBranchElement::SetReadActionSequence()
Expand Down Expand Up @@ -5399,39 +5439,7 @@ void TBranchElement::SetReadActionSequence()
}

if (create) {
// A 'split' node does not store data itself (it has not associated baskets)
const bool isSplitNode = (fType == 3 || fType == 4 || fType == 2 || fType == 1 || (fType == 0 && fID == -2)) && !fBranches.IsEmpty();

if (!isSplitNode) {
fNewIDs.insert(fNewIDs.begin(),fID); // Include the main element in the sequence.
}
if (!isSplitNode)
fIDs.insert(fIDs.begin(),fID); // Include the main element in the sequence.

if (fReadActionSequence) delete fReadActionSequence;
auto original = create(localInfo, GetCollectionProxy(), originalClass);

TStreamerInfoActions::TIDs element_ids;
for(auto i : fIDs) {
element_ids.push_back(i);
}
fReadActionSequence = original->CreateSubSequence(fNewIDs, fOffset, create);

if (!isSplitNode)
fNewIDs.erase(fNewIDs.begin());
if (!isSplitNode)
fIDs.erase(fIDs.begin());
else {
// fObject has the address of the sub-object but the streamer action have
// offset relative to the parent.
TBranchElement *parent = dynamic_cast<TBranchElement*>(GetMother()->GetSubBranch(this));
if (fInitOffsets) {
auto index = parent->fBranches.IndexOf(this);
if (index >= 0) {
fReadActionSequence->AddToOffset( - parent->fBranchOffset[index] );
}
} // else it will be done by InitOffsets
}
SetActionSequence(originalClass, localInfo, create, fReadActionSequence);
}
}

Expand Down

0 comments on commit db24ec7

Please sign in to comment.