61 mLabels = std::make_unique<TTreeReaderValue<dataformats::MCTruthContainer<MCCompLabel>>>(mTreeReader,
"MCHMCLabels");
68 ic.
options().
get<std::string>(
"mch-digit-infile"));
69 connectTree(fileName);
88 TTreeReader mTreeReader{};
89 TTreeReaderValue<std::vector<ROFRecord>> mRofs = {mTreeReader,
"MCHROFRecords"};
90 TTreeReaderValue<std::vector<Digit>> mDigits = {mTreeReader,
"MCHDigit"};
91 std::unique_ptr<TTreeReaderValue<dataformats::MCTruthContainer<MCCompLabel>>> mLabels{};
93 bool mUseIRFrames =
false;
96 void connectTree(std::string fileName)
98 auto file = TFile::Open(fileName.c_str());
99 if (!file ||
file->IsZombie()) {
100 throw std::invalid_argument(fmt::format(
"Opening file {} failed", fileName));
103 auto tree =
file->Get<TTree>(
"o2sim");
105 throw std::invalid_argument(fmt::format(
"Tree o2sim not found in {}", fileName));
107 mTreeReader.SetTree(
tree);
108 mTreeReader.Restart();
115 if (mTreeReader.GetEntries() == 0) {
116 LOG(info) <<
"digit tree has no entry, sending empty output";
128 if (!mTreeReader.Next()) {
129 throw std::invalid_argument(mTreeReader.fgEntryStatusText[mTreeReader.GetEntryStatus()]);
140 if (mTreeReader.GetCurrentEntry() + 1 >= mTreeReader.GetEntries()) {
148 std::vector<ROFRecord> rofs{};
149 std::vector<Digit>
digits{};
153 auto irFrames = pc.
inputs().
get<gsl::span<dataformats::IRFrame>>(
"driverInfo");
155 if (!irFrames.empty()) {
158 const auto irMin = irfSel.getIRFrames().front().getMin();
159 const auto irMax = irfSel.getIRFrames().back().getMax();
162 bool loadNextTF = mTreeReader.GetCurrentEntry() < 0;
166 if (loadNextTF && !mTreeReader.Next()) {
167 throw std::invalid_argument(mTreeReader.fgEntryStatusText[mTreeReader.GetEntryStatus()]);
171 if (!mRofs->empty() && mRofs->front().getBCData() <= irMax &&
172 mRofs->back().getBCData() + mRofs->back().getBCWidth() - 1 >= irMin) {
173 for (
const auto& rof : *mRofs) {
174 if (irfSel.check({rof.getBCData(), rof.getBCData() + rof.getBCWidth() - 1}) != -1) {
175 rofs.emplace_back(rof);
176 rofs.back().setDataRef(
digits.size(), rof.getNEntries());
177 digits.insert(
digits.end(), mDigits->begin() + rof.getFirstIdx(), mDigits->begin() + rof.getFirstIdx() + rof.getNEntries());
179 for (
auto i = 0;
i < rof.getNEntries(); ++
i) {
180 labels.addElements(
labels.getIndexedSize(), (*mLabels)->getLabels(rof.getFirstIdx() +
i));
188 if ((mRofs->empty() || mRofs->back().getBCData() + mRofs->back().getBCWidth() - 1 < irMax) &&
189 mTreeReader.GetCurrentEntry() + 1 < mTreeReader.GetEntries()) {
206 if (irFrames.empty() || irFrames.back().isLast()) {
214 std::string_view outputDigitDataDescription,
215 std::string_view outputDigitRofDataDescription,
216 std::string_view outputDigitLabelDataDescription)
218 std::string
output = fmt::format(
"digits:MCH/{}/0;rofs:MCH/{}/0", outputDigitDataDescription, outputDigitRofDataDescription);
220 output += fmt::format(
";labels:MCH/{}/0", outputDigitLabelDataDescription);
223 std::vector<OutputSpec> outputs;
234 Options{{
"mch-digit-infile", VariantType::String,
"mchdigits.root", {
"Name of the input file"}},
235 {
"input-dir", VariantType::String,
"none", {
"Input directory"}},
236 {
"no-time-offset", VariantType::Bool,
false, {
"no time offset between IRFrames and digits"}}}};
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
framework::DataProcessorSpec getDigitReaderSpec(bool useMC, std::string_view specName="mch-digit-reader", std::string_view outputDigitDataDescription="DIGITS", std::string_view outputDigitRofDataDescription="DIGITROFS", std::string_view outputDigitLabelDataDescription="DIGITLABELS")