Skip to content

Commit 46c872e

Browse files
matthiasrichterktf
authored andcommitted
DPL RootTreeWriter: always amend branch name(s) if the callback is configured
So far, branch names have only been amended for branch definitions handling more than one branch. The more logical behavior is to amend whenever a callback is configured.
1 parent 00cba71 commit 46c872e

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

Framework/Utils/include/DPLUtils/RootTreeWriter.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ class RootTreeWriter
188188
/// number of branches controlled by this definition for the same type
189189
size_t nofBranches = 1;
190190
/// extractor function for the index for parallel branches
191-
IndexExtractor getIndex; // = [](o2::framework::DataRef const&) {return 0;}
191+
IndexExtractor getIndex = nullptr;
192192
/// get name of branch from base name and index
193-
BranchNameMapper getName = [](std::string base, size_t i) { return base + "_" + std::to_string(i); };
193+
BranchNameMapper getName = nullptr;
194194

195195
using Fill = std::function<void(TBranch& branch, T const&)>;
196196
using FillExt = std::function<void(TBranch& branch, T const&, DataRef const&)>;
@@ -317,8 +317,9 @@ class RootTreeWriter
317317
void setBranchName(size_t index, const char* branchName)
318318
{
319319
auto& spec = mBranchSpecs.at(index);
320-
if (spec.names.size() > 1 && spec.getName) {
321-
// set the branch names for this group
320+
if (spec.getName) {
321+
// set the branch names for this group, we also amend if there is only one branch but
322+
// the callback is configured
322323
size_t idx = 0;
323324
std::generate(spec.names.begin(), spec.names.end(), [&]() { return spec.getName(branchName, idx++); });
324325
} else {
@@ -423,8 +424,8 @@ class RootTreeWriter
423424
std::vector<std::string> names;
424425
std::vector<TBranch*> branches;
425426
TClass* classinfo = nullptr;
426-
IndexExtractor getIndex;
427-
BranchNameMapper getName;
427+
IndexExtractor getIndex = nullptr;
428+
BranchNameMapper getName = nullptr;
428429
};
429430

430431
using InputContext = InputRecord;
@@ -845,12 +846,15 @@ class RootTreeWriter
845846
// a getIndex function makes only sense if there are multiple branches
846847
assert(def.nofBranches <= 1 || def.getIndex);
847848
if (def.nofBranches > 1) {
849+
// FIXME: should that be an exception since assert is disabled in the normal build?
848850
assert(def.getIndex && def.getName);
849851
mBranchSpecs.back().getIndex = def.getIndex;
850-
mBranchSpecs.back().getName = def.getName;
851852
mBranchSpecs.back().names.resize(def.nofBranches);
853+
}
852854

853-
// fill the branch names by calling the getName callback
855+
// always amend the branch name(s) if the callback is configured
856+
if (def.getName) {
857+
mBranchSpecs.back().getName = def.getName;
854858
idx = 0;
855859
std::generate(mBranchSpecs.back().names.begin(), mBranchSpecs.back().names.end(),
856860
[&def, &idx]() { return def.getName(def.branchName, idx++); });

0 commit comments

Comments
 (0)