Skip to content

Commit e4332b1

Browse files
hageboeckvepadulano
andcommitted
[RDF] Unify members of Snapshot helpers into structs.
In order to implement snapshots with systematic variations, it is beneficial to place all members related to output branches into structs. At present, this only constitutes a move from member of SnapshotHelper to member of RBranchData struct. The TTree snapshot helpers are changed accordingly. Co-authored-by: Vincenzo Eduardo Padulano <[email protected]>
1 parent f956573 commit e4332b1

File tree

2 files changed

+225
-145
lines changed

2 files changed

+225
-145
lines changed

tree/dataframe/inc/ROOT/RDF/SnapshotHelpers.hxx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,34 @@ public:
109109
UntypedSnapshotRNTupleHelper MakeNew(void *newName);
110110
};
111111

112+
/// Stores properties of each output branch in a Snapshot.
113+
struct RBranchData {
114+
std::string fInputBranchName; // This contains resolved aliases
115+
std::string fOutputBranchName;
116+
const std::type_info *fInputTypeID = nullptr;
117+
TBranch *fOutputBranch = nullptr;
118+
void *fBranchAddressForCArrays = nullptr; // Used to detect if branch addresses need to be updated
119+
120+
std::unique_ptr<void, std::function<void(void *)>> fEmptyInstance;
121+
bool fIsCArray = false;
122+
bool fIsDefine = false;
123+
124+
RBranchData(std::string inputBranchName, std::string outputBranchName, bool isDefine, const std::type_info *typeID,
125+
TBranch *outputBranch = nullptr)
126+
: fInputBranchName{std::move(inputBranchName)},
127+
fOutputBranchName{std::move(outputBranchName)},
128+
fInputTypeID{typeID},
129+
fOutputBranch{outputBranch},
130+
fIsDefine(isDefine)
131+
{
132+
}
133+
void ClearBranchPointers()
134+
{
135+
fOutputBranch = nullptr;
136+
fBranchAddressForCArrays = nullptr;
137+
}
138+
};
139+
112140
class R__CLING_PTRCHECK(off) UntypedSnapshotTTreeHelper final : public RActionImpl<UntypedSnapshotTTreeHelper> {
113141
std::string fFileName;
114142
std::string fDirName;
@@ -117,17 +145,10 @@ class R__CLING_PTRCHECK(off) UntypedSnapshotTTreeHelper final : public RActionIm
117145
std::unique_ptr<TFile> fOutputFile;
118146
std::unique_ptr<TTree> fOutputTree; // must be a ptr because TTrees are not copy/move constructible
119147
bool fBranchAddressesNeedReset{true};
120-
ColumnNames_t fInputBranchNames; // This contains the resolved aliases
121-
ColumnNames_t fOutputBranchNames;
122148
TTree *fInputTree = nullptr; // Current input tree. Set at initialization time (`InitTask`)
123-
// TODO we might be able to unify fBranches, fBranchAddresses and fOutputBranches
124-
std::vector<TBranch *> fBranches; // Addresses of branches in output, non-null only for the ones holding C arrays
125-
std::vector<void *> fBranchAddresses; // Addresses of objects associated to output branches
126-
RBranchSet fOutputBranches;
127-
std::vector<bool> fIsDefine;
149+
std::vector<RBranchData> fBranchData; // Information for all output branches
128150
ROOT::Detail::RDF::RLoopManager *fOutputLoopManager;
129151
ROOT::Detail::RDF::RLoopManager *fInputLoopManager;
130-
std::vector<const std::type_info *> fInputColumnTypeIDs; // Types for the input columns
131152

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

185202
// Attributes of the output TTree
186203

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

194210
// Attributes related to the computation graph
195211

196212
ROOT::Detail::RDF::RLoopManager *fOutputLoopManager;
197213
ROOT::Detail::RDF::RLoopManager *fInputLoopManager;
198-
std::vector<std::string> fInputBranchNames; // This contains the resolved aliases
199-
std::vector<const std::type_info *> fInputColumnTypeIDs; // Types for the input columns
200-
201-
std::vector<bool> fIsDefine;
202214

203215
public:
204216
UntypedSnapshotTTreeHelperMT(unsigned int nSlots, std::string_view filename, std::string_view dirname,

0 commit comments

Comments
 (0)