|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// @file VertexReaderSpec.cxx |
| 12 | + |
| 13 | +#include <vector> |
| 14 | + |
| 15 | +#include "Framework/ControlService.h" |
| 16 | +#include "Framework/ConfigParamRegistry.h" |
| 17 | +#include "GlobalTrackingWorkflow/PrimaryVertexReaderSpec.h" |
| 18 | + |
| 19 | +using namespace o2::framework; |
| 20 | + |
| 21 | +namespace o2 |
| 22 | +{ |
| 23 | +namespace vertexing |
| 24 | +{ |
| 25 | + |
| 26 | +void PrimaryVertexReader::init(InitContext& ic) |
| 27 | +{ |
| 28 | + mFileName = ic.options().get<std::string>("primary-vertex-infile"); |
| 29 | + connectTree(mFileName); |
| 30 | +} |
| 31 | + |
| 32 | +void PrimaryVertexReader::run(ProcessingContext& pc) |
| 33 | +{ |
| 34 | + auto ent = mTree->GetReadEntry() + 1; |
| 35 | + assert(ent < mTree->GetEntries()); // this should not happen |
| 36 | + mTree->GetEntry(ent); |
| 37 | + LOG(INFO) << "Pushing " << mVerticesPtr->size() << " vertices at entry " << ent; |
| 38 | + |
| 39 | + pc.outputs().snapshot(Output{"GLO", "PVERTEX", 0, Lifetime::Timeframe}, mVertices); |
| 40 | + pc.outputs().snapshot(Output{"GLO", "PVERTEX_TRIDREFS", 0, Lifetime::Timeframe}, mPV2TrIdx); |
| 41 | + pc.outputs().snapshot(Output{"GLO", "PVERTEX_TRID", 0, Lifetime::Timeframe}, mPVTrIdx); |
| 42 | + |
| 43 | + if (mUseMC) { |
| 44 | + pc.outputs().snapshot(Output{"GLO", "PVERTEX_MCTR", 0, Lifetime::Timeframe}, mLabels); |
| 45 | + } |
| 46 | + |
| 47 | + if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) { |
| 48 | + pc.services().get<ControlService>().endOfStream(); |
| 49 | + pc.services().get<ControlService>().readyToQuit(QuitRequest::Me); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void PrimaryVertexReader::connectTree(const std::string& filename) |
| 54 | +{ |
| 55 | + mTree.reset(nullptr); // in case it was already loaded |
| 56 | + mFile.reset(TFile::Open(filename.c_str())); |
| 57 | + assert(mFile && !mFile->IsZombie()); |
| 58 | + mTree.reset((TTree*)mFile->Get(mVertexTreeName.c_str())); |
| 59 | + assert(mTree); |
| 60 | + assert(mTree->GetBranch(mVertexBranchName.c_str())); |
| 61 | + assert(mTree->GetBranch(mVertexTrackIDsBranchName.c_str())); |
| 62 | + assert(mTree->GetBranch(mVertex2TrackIDRefsBranchName.c_str())); |
| 63 | + |
| 64 | + mTree->SetBranchAddress(mVertexBranchName.c_str(), &mVerticesPtr); |
| 65 | + mTree->SetBranchAddress(mVertexTrackIDsBranchName.c_str(), &mPVTrIdxPtr); |
| 66 | + mTree->SetBranchAddress(mVertex2TrackIDRefsBranchName.c_str(), &mPV2TrIdxPtr); |
| 67 | + |
| 68 | + if (mUseMC) { |
| 69 | + assert(mTree->GetBranch(mVertexLabelsBranchName.c_str())); |
| 70 | + mTree->SetBranchAddress(mVertexLabelsBranchName.c_str(), &mLabelsPtr); |
| 71 | + } |
| 72 | + |
| 73 | + LOG(INFO) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries"; |
| 74 | +} |
| 75 | + |
| 76 | +DataProcessorSpec getPrimaryVertexReaderSpec(bool useMC) |
| 77 | +{ |
| 78 | + std::vector<OutputSpec> outputs; |
| 79 | + outputs.emplace_back("GLO", "PVERTEX", 0, Lifetime::Timeframe); |
| 80 | + outputs.emplace_back("GLO", "PVERTEX_TRIDREFS", 0, Lifetime::Timeframe); |
| 81 | + outputs.emplace_back("GLO", "PVERTEX_TRID", 0, Lifetime::Timeframe); |
| 82 | + if (useMC) { |
| 83 | + outputs.emplace_back("GLO", "PVERTEX_MCTR", 0, Lifetime::Timeframe); |
| 84 | + } |
| 85 | + |
| 86 | + return DataProcessorSpec{ |
| 87 | + "primary-vertex-reader", |
| 88 | + Inputs{}, |
| 89 | + outputs, |
| 90 | + AlgorithmSpec{adaptFromTask<PrimaryVertexReader>(useMC)}, |
| 91 | + Options{ |
| 92 | + {"primary-vertex-infile", VariantType::String, "o2_primary_vertex.root", {"Name of the input primary vertex file"}}}}; |
| 93 | +} |
| 94 | + |
| 95 | +} // namespace vertexing |
| 96 | +} // namespace o2 |
0 commit comments