Skip to content

Commit 9471e71

Browse files
committed
Fix: remap RootTreeWriter branches only once
The automatic branch substitution mechanism used to store MC labels should not be allowed to remap branches with >0 entries, otherwise only the last entry will be stored
1 parent 0a11c2c commit 9471e71

6 files changed

Lines changed: 23 additions & 12 deletions

File tree

Detectors/ITSMFT/common/workflow/src/DigitWriterSpec.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ DataProcessorSpec getDigitWriterSpec(bool mctruth, o2::header::DataOrigin detOri
7070
LOG(INFO) << "WRITING " << labels.getNElements() << " LABELS ";
7171

7272
o2::dataformats::IOMCTruthContainerView outputcontainer;
73-
auto br = framework::RootTreeWriter::remapBranch(branch, &outputcontainer);
73+
auto ptr = &outputcontainer;
74+
auto br = framework::RootTreeWriter::remapBranch(branch, &ptr);
7475
outputcontainer.adopt(labelbuffer);
7576
br->Fill();
7677
br->ResetAddress();

Detectors/TPC/workflow/src/RecoWorkflow.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, std::vecto
323323
auto fillLabels = [](TBranch& branch, std::vector<char> const& labelbuffer, DataRef const& /*ref*/) {
324324
o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel> labels(labelbuffer);
325325
o2::dataformats::IOMCTruthContainerView outputcontainer;
326-
auto br = framework::RootTreeWriter::remapBranch(branch, &outputcontainer);
326+
auto ptr = &outputcontainer;
327+
auto br = framework::RootTreeWriter::remapBranch(branch, &ptr);
327328
outputcontainer.adopt(labelbuffer);
328329
br->Fill();
329330
br->ResetAddress();

Detectors/TRD/workflow/src/TRDDigitWriterSpec.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ o2::framework::DataProcessorSpec getTRDDigitWriterSpec(bool mctruth)
5757
// make the actual output object by adopting/casting the buffer
5858
// into a split format
5959
o2::dataformats::IOMCTruthContainerView outputcontainer(labeldata);
60-
auto br = framework::RootTreeWriter::remapBranch(branch, &outputcontainer);
60+
auto ptr = &outputcontainer;
61+
auto br = framework::RootTreeWriter::remapBranch(branch, &ptr);
6162
br->Fill();
6263
br->ResetAddress();
6364
};

Framework/Utils/include/DPLUtils/RootTreeWriter.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,20 @@ class RootTreeWriter
347347
/// The function needs to be used with care. The user should ensure that "branch" is no longer used
348348
/// after a call to this function.
349349
template <typename T>
350-
static TBranch* remapBranch(TBranch& branch, T* newdata)
350+
static TBranch* remapBranch(TBranch& branchRef, T** newdata)
351351
{
352-
auto name = branch.GetName();
353-
auto branchleaves = branch.GetListOfLeaves();
354-
auto tree = branch.GetTree();
355-
branch.DropBaskets("all");
356-
branch.DeleteBaskets("all");
357-
tree->GetListOfBranches()->Remove(&branch);
352+
auto tree = branchRef.GetTree();
353+
auto name = branchRef.GetName();
354+
auto branch = tree->GetBranch(name); // the input branch might actually no belong to the tree but to TreeWriter cache
355+
assert(branch);
356+
if (branch->GetEntries()) { // if it has entries, then it was already remapped/filled at prevous event
357+
branch->SetAddress(newdata);
358+
return branch;
359+
}
360+
auto branchleaves = branch->GetListOfLeaves();
361+
branch->DropBaskets("all");
362+
branch->DeleteBaskets("all");
363+
tree->GetListOfBranches()->Remove(branch);
358364
for (auto entry : *branchleaves) {
359365
tree->GetListOfLeaves()->Remove(entry);
360366
}

Steer/DigitizerWorkflow/src/FDDDigitWriterSpec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ o2::framework::DataProcessorSpec getFDDDigitWriterSpec(bool mctruth = true)
5656
// make the actual output object by adopting/casting the buffer
5757
// into a split format
5858
o2::dataformats::IOMCTruthContainerView outputcontainer(labeldata);
59-
auto br = framework::RootTreeWriter::remapBranch(branch, &outputcontainer);
59+
auto ptr = &outputcontainer;
60+
auto br = framework::RootTreeWriter::remapBranch(branch, &ptr);
6061
br->Fill();
6162
br->ResetAddress();
6263
};

Steer/DigitizerWorkflow/src/TPCDigitRootWriterSpec.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ DataProcessorSpec getTPCDigitRootWriterSpec(std::vector<int> const& laneConfigur
203203
// first of all redefine the output format (special to labels)
204204
auto tree = branch.GetTree();
205205
auto sector = extractSector(ref);
206-
auto br = framework::RootTreeWriter::remapBranch(branch, &outputcontainer);
206+
auto ptr = &outputcontainer;
207+
auto br = framework::RootTreeWriter::remapBranch(branch, &ptr);
207208

208209
auto const* dh = DataRefUtils::getHeader<DataHeader*>(ref);
209210
LOG(INFO) << "HAVE LABEL DATA FOR SECTOR " << sector << " ON CHANNEL " << dh->subSpecification;

0 commit comments

Comments
 (0)