Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions tree/dataframe/inc/ROOT/RDF/SnapshotHelpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ class TBufferMergerFile;

namespace ROOT::Internal::RDF {

class RBranchSet {
std::vector<TBranch *> fBranches;
std::vector<std::string> fNames;
std::vector<bool> fIsCArray;

public:
TBranch *Get(const std::string &name) const;
bool IsCArray(const std::string &name) const;
void Insert(const std::string &name, TBranch *address, bool isCArray = false);
void Clear();
void AssertNoNullBranchAddresses();
};

class R__CLING_PTRCHECK(off) UntypedSnapshotRNTupleHelper final : public RActionImpl<UntypedSnapshotRNTupleHelper> {
std::string fFileName;
std::string fDirName;
Expand Down Expand Up @@ -109,6 +96,34 @@ public:
UntypedSnapshotRNTupleHelper MakeNew(void *newName);
};

/// Stores properties of each output branch in a Snapshot.
struct RBranchData {
std::string fInputBranchName; // This contains resolved aliases
std::string fOutputBranchName;
const std::type_info *fInputTypeID = nullptr;
TBranch *fOutputBranch = nullptr;
void *fBranchAddressForCArrays = nullptr; // Used to detect if branch addresses need to be updated

std::unique_ptr<void, std::function<void(void *)>> fEmptyInstance;
bool fIsCArray = false;
bool fIsDefine = false;

RBranchData(std::string inputBranchName, std::string outputBranchName, bool isDefine, const std::type_info *typeID,
TBranch *outputBranch = nullptr)
: fInputBranchName{std::move(inputBranchName)},
fOutputBranchName{std::move(outputBranchName)},
fInputTypeID{typeID},
fOutputBranch{outputBranch},
fIsDefine(isDefine)
{
}
void ClearBranchPointers()
{
fOutputBranch = nullptr;
fBranchAddressForCArrays = nullptr;
}
};

class R__CLING_PTRCHECK(off) UntypedSnapshotTTreeHelper final : public RActionImpl<UntypedSnapshotTTreeHelper> {
std::string fFileName;
std::string fDirName;
Expand All @@ -117,17 +132,10 @@ class R__CLING_PTRCHECK(off) UntypedSnapshotTTreeHelper final : public RActionIm
std::unique_ptr<TFile> fOutputFile;
std::unique_ptr<TTree> fOutputTree; // must be a ptr because TTrees are not copy/move constructible
bool fBranchAddressesNeedReset{true};
ColumnNames_t fInputBranchNames; // This contains the resolved aliases
ColumnNames_t fOutputBranchNames;
TTree *fInputTree = nullptr; // Current input tree. Set at initialization time (`InitTask`)
// TODO we might be able to unify fBranches, fBranchAddresses and fOutputBranches
std::vector<TBranch *> fBranches; // Addresses of branches in output, non-null only for the ones holding C arrays
std::vector<void *> fBranchAddresses; // Addresses of objects associated to output branches
RBranchSet fOutputBranches;
std::vector<bool> fIsDefine;
std::vector<RBranchData> fBranchData; // Information for all output branches
ROOT::Detail::RDF::RLoopManager *fOutputLoopManager;
ROOT::Detail::RDF::RLoopManager *fInputLoopManager;
std::vector<const std::type_info *> fInputColumnTypeIDs; // Types for the input columns

public:
UntypedSnapshotTTreeHelper(std::string_view filename, std::string_view dirname, std::string_view treename,
Expand Down Expand Up @@ -176,11 +184,7 @@ class R__CLING_PTRCHECK(off) UntypedSnapshotTTreeHelperMT final : public RAction
std::vector<std::unique_ptr<TTree>> fOutputTrees;
std::vector<int> fBranchAddressesNeedReset; // vector<bool> does not allow concurrent writing of different elements
std::vector<TTree *> fInputTrees; // Current input trees, one per slot. Set at initialization time (`InitTask`)
// Addresses of branches in output per slot, non-null only for the ones holding C arrays
std::vector<std::vector<TBranch *>> fBranches;
// Addresses of objects associated to output branches per slot, non-null only for the ones holding C arrays
std::vector<std::vector<void *>> fBranchAddresses;
std::vector<RBranchSet> fOutputBranches; // Unique set of output branches, one per slot.
std::vector<std::vector<RBranchData>> fBranchData; // Information for all output branches of each slot

// Attributes of the output TTree

Expand All @@ -189,16 +193,11 @@ class R__CLING_PTRCHECK(off) UntypedSnapshotTTreeHelperMT final : public RAction
std::string fTreeName;
TFile *fOutputFile; // Non-owning view on the output file
RSnapshotOptions fOptions;
std::vector<std::string> fOutputBranchNames;

// Attributes related to the computation graph

ROOT::Detail::RDF::RLoopManager *fOutputLoopManager;
ROOT::Detail::RDF::RLoopManager *fInputLoopManager;
std::vector<std::string> fInputBranchNames; // This contains the resolved aliases
std::vector<const std::type_info *> fInputColumnTypeIDs; // Types for the input columns

std::vector<bool> fIsDefine;

public:
UntypedSnapshotTTreeHelperMT(unsigned int nSlots, std::string_view filename, std::string_view dirname,
Expand Down
Loading
Loading