|
| 1 | +// Copyright 2019-2025 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// @file DigitReaderSpec.cxx |
| 13 | + |
| 14 | +#include <vector> |
| 15 | +#include <TTree.h> |
| 16 | +#include "Framework/ConfigParamRegistry.h" |
| 17 | +#include "Framework/ControlService.h" |
| 18 | +#include "Framework/Logger.h" |
| 19 | +#include "FD3Workflow/FD3DigitReaderSpec.h" |
| 20 | +#include "DataFormatsFD3/Digit.h" |
| 21 | +#include "DataFormatsFD3/ChannelData.h" |
| 22 | +#include "DataFormatsFD3/MCLabel.h" |
| 23 | +#include "SimulationDataFormat/MCTruthContainer.h" |
| 24 | +#include "CommonUtils/NameConf.h" |
| 25 | + |
| 26 | +using namespace o2::framework; |
| 27 | + |
| 28 | +namespace o2 |
| 29 | +{ |
| 30 | +namespace fd3 |
| 31 | +{ |
| 32 | + |
| 33 | +void DigitReader::init(InitContext& ic) |
| 34 | +{ |
| 35 | + auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), |
| 36 | + ic.options().get<std::string>("fd3-digit-infile")); |
| 37 | + mFile.reset(TFile::Open(filename.c_str())); |
| 38 | + if (!mFile->IsOpen()) { |
| 39 | + LOG(error) << "Cannot open the " << filename.c_str() << " file !"; |
| 40 | + throw std::runtime_error("cannot open input digits file"); |
| 41 | + } |
| 42 | + mTree.reset((TTree*)mFile->Get("o2sim")); |
| 43 | + if (!mTree) { |
| 44 | + LOG(error) << "Did not find o2sim tree in " << filename.c_str(); |
| 45 | + throw std::runtime_error("Did not fine o2sim file in FD3 digits tree"); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void DigitReader::run(ProcessingContext& pc) |
| 50 | +{ |
| 51 | + |
| 52 | + std::vector<o2::fd3::Digit> digits, *pdigits = &digits; |
| 53 | + std::vector<o2::fd3::DetTrigInput> trgInput, *ptrTrgInput = &trgInput; |
| 54 | + std::vector<o2::fd3::ChannelData> channels, *pchannels = &channels; |
| 55 | + mTree->SetBranchAddress("FD3DigitBC", &pdigits); |
| 56 | + mTree->SetBranchAddress("FD3DigitCh", &pchannels); |
| 57 | + if (mUseTrgInput) { |
| 58 | + mTree->SetBranchAddress("TRIGGERINPUT", &ptrTrgInput); |
| 59 | + } |
| 60 | + o2::dataformats::MCTruthContainer<o2::fd3::MCLabel> labels, *plabels = &labels; |
| 61 | + if (mUseMC) { |
| 62 | + mTree->SetBranchAddress("FD3DigitLabels", &plabels); |
| 63 | + } |
| 64 | + auto ent = mTree->GetReadEntry() + 1; |
| 65 | + assert(ent < mTree->GetEntries()); // this should not happen |
| 66 | + mTree->GetEntry(ent); |
| 67 | + LOG(debug) << "FD3DigitReader pushed " << channels.size() << " channels in " << digits.size() << " digits"; |
| 68 | + pc.outputs().snapshot(Output{"FD3", "DIGITSBC", 0}, digits); |
| 69 | + pc.outputs().snapshot(Output{"FD3", "DIGITSCH", 0}, channels); |
| 70 | + if (mUseMC) { |
| 71 | + pc.outputs().snapshot(Output{"FD3", "DIGITSMCTR", 0}, labels); |
| 72 | + } |
| 73 | + if (mUseTrgInput) { |
| 74 | + pc.outputs().snapshot(Output{"FD3", "TRIGGERINPUT", 0}, trgInput); |
| 75 | + } |
| 76 | + if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) { |
| 77 | + pc.services().get<ControlService>().endOfStream(); |
| 78 | + pc.services().get<ControlService>().readyToQuit(QuitRequest::Me); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +DataProcessorSpec getDigitReaderSpec(bool useMC, bool useTrgInput) |
| 83 | +{ |
| 84 | + std::vector<OutputSpec> outputs; |
| 85 | + outputs.emplace_back("FD3", "DIGITSBC", 0, Lifetime::Timeframe); |
| 86 | + outputs.emplace_back("FD3", "DIGITSCH", 0, Lifetime::Timeframe); |
| 87 | + if (useMC) { |
| 88 | + outputs.emplace_back("FD3", "DIGITSMCTR", 0, Lifetime::Timeframe); |
| 89 | + } |
| 90 | + if (useTrgInput) { |
| 91 | + outputs.emplace_back("FD3", "TRIGGERINPUT", 0, Lifetime::Timeframe); |
| 92 | + } |
| 93 | + return DataProcessorSpec{ |
| 94 | + "fd3-digit-reader", |
| 95 | + Inputs{}, |
| 96 | + outputs, |
| 97 | + AlgorithmSpec{adaptFromTask<DigitReader>(useMC, useTrgInput)}, |
| 98 | + Options{ |
| 99 | + {"fd3-digit-infile", VariantType::String, "fd3digits.root", {"Name of the input file"}}, |
| 100 | + {"input-dir", VariantType::String, "none", {"Input directory"}}}}; |
| 101 | +} |
| 102 | + |
| 103 | +} // namespace fd3 |
| 104 | +} // namespace o2 |
0 commit comments