60 mLabels = std::make_unique<TTreeReaderValue<dataformats::MCTruthContainer<MCCompLabel>>>(mTreeReader,
"MCHMCLabels");
67 ic.
options().
get<std::string>(
"mch-digit-infile"));
68 connectTree(fileName);
87 TTreeReader mTreeReader{};
88 TTreeReaderValue<std::vector<ROFRecord>> mRofs = {mTreeReader,
"MCHROFRecords"};
89 TTreeReaderValue<std::vector<Digit>> mDigits = {mTreeReader,
"MCHDigit"};
90 std::unique_ptr<TTreeReaderValue<dataformats::MCTruthContainer<MCCompLabel>>> mLabels{};
92 bool mUseIRFrames =
false;
95 void connectTree(std::string fileName)
97 auto file = TFile::Open(fileName.c_str());
99 throw std::invalid_argument(fmt::format(
"Opening file {} failed", fileName));
102 auto tree =
file->Get<TTree>(
"o2sim");
104 throw std::invalid_argument(fmt::format(
"Tree o2sim not found in {}", fileName));
106 mTreeReader.SetTree(
tree);
107 mTreeReader.Restart();
113 if (!mTreeReader.Next()) {
114 throw std::invalid_argument(mTreeReader.fgEntryStatusText[mTreeReader.GetEntryStatus()]);
125 if (mTreeReader.GetCurrentEntry() + 1 >= mTreeReader.GetEntries()) {
133 std::vector<ROFRecord> rofs{};
134 std::vector<Digit>
digits{};
138 auto irFrames = pc.
inputs().
get<gsl::span<dataformats::IRFrame>>(
"driverInfo");
140 if (!irFrames.empty()) {
143 const auto irMin = irfSel.getIRFrames().front().getMin();
144 const auto irMax = irfSel.getIRFrames().back().getMax();
147 bool loadNextTF = mTreeReader.GetCurrentEntry() < 0;
151 if (loadNextTF && !mTreeReader.Next()) {
152 throw std::invalid_argument(mTreeReader.fgEntryStatusText[mTreeReader.GetEntryStatus()]);
156 if (!mRofs->empty() && mRofs->front().getBCData() <= irMax &&
157 mRofs->back().getBCData() + mRofs->back().getBCWidth() - 1 >= irMin) {
158 for (
const auto& rof : *mRofs) {
159 if (irfSel.check({rof.getBCData(), rof.getBCData() + rof.getBCWidth() - 1}) != -1) {
160 rofs.emplace_back(rof);
161 rofs.back().setDataRef(
digits.size(), rof.getNEntries());
162 digits.insert(
digits.end(), mDigits->begin() + rof.getFirstIdx(), mDigits->begin() + rof.getFirstIdx() + rof.getNEntries());
164 for (
auto i = 0;
i < rof.getNEntries(); ++
i) {
165 labels.addElements(labels.getIndexedSize(), (*mLabels)->getLabels(rof.getFirstIdx() +
i));
173 if ((mRofs->empty() || mRofs->back().getBCData() + mRofs->back().getBCWidth() - 1 < irMax) &&
174 mTreeReader.GetCurrentEntry() + 1 < mTreeReader.GetEntries()) {
191 if (irFrames.empty() || irFrames.back().isLast()) {
199 std::string_view outputDigitDataDescription,
200 std::string_view outputDigitRofDataDescription,
201 std::string_view outputDigitLabelDataDescription)
203 std::string
output = fmt::format(
"digits:MCH/{}/0;rofs:MCH/{}/0", outputDigitDataDescription, outputDigitRofDataDescription);
205 output += fmt::format(
";labels:MCH/{}/0", outputDigitLabelDataDescription);
208 std::vector<OutputSpec> outputs;
210 for (
auto& matcher : matchers) {
219 Options{{
"mch-digit-infile", VariantType::String,
"mchdigits.root", {
"Name of the input file"}},
220 {
"input-dir", VariantType::String,
"none", {
"Input directory"}},
221 {
"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")