|
| 1 | +// Copyright 2019-2020 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 TrackCosmicsExtendedReaderSpec.cxx |
| 13 | + |
| 14 | +#include <vector> |
| 15 | + |
| 16 | +#include "Framework/ConfigParamRegistry.h" |
| 17 | +#include "Framework/ControlService.h" |
| 18 | +#include "GlobalTrackingWorkflowReaders/TrackCosmicsExtendedReaderSpec.h" |
| 19 | +#include "CommonUtils/NameConf.h" |
| 20 | +#include "CommonUtils/StringUtils.h" |
| 21 | + |
| 22 | +using namespace o2::framework; |
| 23 | +using namespace o2::globaltracking; |
| 24 | + |
| 25 | +namespace o2 |
| 26 | +{ |
| 27 | +namespace globaltracking |
| 28 | +{ |
| 29 | +void TrackCosmicsExtendedReader::init(InitContext& ic) |
| 30 | +{ |
| 31 | + mFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), |
| 32 | + ic.options().get<std::string>("cosmics-full-infile")); |
| 33 | + connectTree(mFileName); |
| 34 | +} |
| 35 | + |
| 36 | +void TrackCosmicsExtendedReader::run(ProcessingContext& pc) |
| 37 | +{ |
| 38 | + auto ent = mTree->GetReadEntry() + 1; |
| 39 | + // Same as in TrackCosmicsReader: publish empty containers if the tree has no entry left |
| 40 | + const bool noEntry = ent >= mTree->GetEntries(); |
| 41 | + if (noEntry) { |
| 42 | + LOG(info) << "no entry to read, publishing empty output"; |
| 43 | + mCosmics.clear(); |
| 44 | + mTFInfo = {}; |
| 45 | + mTFID = {}; |
| 46 | + } else { |
| 47 | + mTree->GetEntry(ent); |
| 48 | + } |
| 49 | + LOG(info) << "Pushing " << mCosmics.size() << " cosmics with clusters at entry " << ent; |
| 50 | + |
| 51 | + pc.outputs().snapshot(Output{"GLO", "COSMFULL", 0}, mCosmics); |
| 52 | + pc.outputs().snapshot(Output{"GLO", "COSMFULLTF", 0}, mTFInfo); |
| 53 | + pc.outputs().snapshot(Output{"GLO", "COSMFULLTFID", 0}, mTFID); |
| 54 | + |
| 55 | + if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) { |
| 56 | + pc.services().get<ControlService>().endOfStream(); |
| 57 | + pc.services().get<ControlService>().readyToQuit(QuitRequest::Me); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +void TrackCosmicsExtendedReader::connectTree(const std::string& filename) |
| 62 | +{ |
| 63 | + mTree.reset(nullptr); // in case it was already loaded |
| 64 | + mFile.reset(TFile::Open(filename.c_str())); |
| 65 | + if (!mFile || mFile->IsZombie()) { |
| 66 | + LOGP(fatal, "Failed to open {}", filename); |
| 67 | + } |
| 68 | + mTree.reset((TTree*)mFile->Get("cosmicsFull")); |
| 69 | + if (!mTree) { |
| 70 | + LOGP(fatal, "Tree cosmicsFull is not found in {}", filename); |
| 71 | + } |
| 72 | + mTree->SetBranchAddress("cosmics", &mCosmicsPtr); |
| 73 | + mTree->SetBranchAddress("tfInfo", &mTFInfoPtr); |
| 74 | + mTree->SetBranchAddress("tfID", &mTFIDPtr); |
| 75 | + LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries"; |
| 76 | +} |
| 77 | + |
| 78 | +DataProcessorSpec getTrackCosmicsExtendedReaderSpec() |
| 79 | +{ |
| 80 | + std::vector<OutputSpec> outputs; |
| 81 | + outputs.emplace_back("GLO", "COSMFULL", 0, Lifetime::Timeframe); |
| 82 | + outputs.emplace_back("GLO", "COSMFULLTF", 0, Lifetime::Timeframe); |
| 83 | + outputs.emplace_back("GLO", "COSMFULLTFID", 0, Lifetime::Timeframe); |
| 84 | + |
| 85 | + return DataProcessorSpec{ |
| 86 | + "cosmic-ext-reader", |
| 87 | + Inputs{}, |
| 88 | + outputs, |
| 89 | + AlgorithmSpec{adaptFromTask<TrackCosmicsExtendedReader>()}, |
| 90 | + Options{ |
| 91 | + {"cosmics-full-infile", VariantType::String, "o2_cosmics_full.root", {"Name of the input file"}}, |
| 92 | + {"input-dir", VariantType::String, "none", {"Input directory"}}}}; |
| 93 | +} |
| 94 | + |
| 95 | +} // namespace globaltracking |
| 96 | +} // namespace o2 |
0 commit comments