Skip to content

Commit 41757d6

Browse files
sawenzelclaude
andcommitted
Give the ITS and MFT digit file its usual shape when it is empty
This fixes the digit file of a timeframe without collisions carrying a label branch of the wrong type. - The MC label branch is declared as std::vector<char> and only becomes an IOMCTruthContainerView when a fill remaps it. - With no collision nothing is filled, the branch keeps the raw type, and a reader binding IOMCTruthContainerView gets a class mismatch from SetBranchAddress rather than an empty tree. - The close callback now writes one empty entry in every branch, remapping the label branch on the way, so the file has the same shape as an ordinary timeframe that happens to contain nothing. https://its.cern.ch/jira/browse/O2-7132 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 2fb004f commit 41757d6

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "DataFormatsITSMFT/ROFRecord.h"
2424
#include "SimulationDataFormat/ConstMCTruthContainer.h"
2525
#include "SimulationDataFormat/IOMCTruthContainerView.h"
26+
#include "Framework/Logger.h"
2627
#include "SimulationDataFormat/MCCompLabel.h"
2728
#include <vector>
2829
#include <string>
@@ -73,6 +74,31 @@ DataProcessorSpec getDigitWriterSpec(bool mctruth, bool doStag, bool dec, bool c
7374
}
7475
nent = n;
7576
}
77+
if (nent == 0) {
78+
// A timeframe holds no collision at all whenever the interaction rate is low enough, and no
79+
// branch is then filled. Write one empty entry in every branch, so that the file has the same
80+
// shape as an ordinary timeframe that happens to contain nothing. The label branch matters
81+
// here: it is declared as std::vector<char> and only becomes an IOMCTruthContainerView when a
82+
// fill remaps it, so without this a reader binding that type gets a class mismatch instead of
83+
// an empty tree.
84+
LOG(info) << "No branch was filled, writing one empty entry per branch";
85+
std::vector<TBranch*> branches;
86+
for (auto* o : *brArr) {
87+
branches.push_back((TBranch*)o);
88+
}
89+
o2::dataformats::IOMCTruthContainerView emptyLabels;
90+
auto* labelptr = &emptyLabels;
91+
for (auto* br : branches) {
92+
if (TString(br->GetName()).Contains("MCTruth")) {
93+
auto* remapped = framework::RootTreeWriter::remapBranch(*br, &labelptr);
94+
remapped->Fill();
95+
remapped->ResetAddress();
96+
} else {
97+
br->Fill();
98+
}
99+
}
100+
nent = 1;
101+
}
76102
outputtree->SetEntries(nent);
77103
// do not use TTree::Write .. as this writes to default directory (not the associated file)
78104
// instead of outputtree->Write("", TObject::kOverwrite)

0 commit comments

Comments
 (0)