Project
Loading...
Searching...
No Matches
TrackReaderSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 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
13
14#include <vector>
15#include <cassert>
20
21using namespace o2::framework;
22using namespace o2::its;
23
24namespace o2::its
25{
26
28{
30 ic.options().get<std::string>("its-tracks-infile"));
32}
33
35{
36 auto ent = mTree->GetReadEntry() + 1;
37 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
38 // the tree then has no entry to read. Publish empty containers instead of reading past the
39 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
40 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
41 // every production build since ENABLE_CASSERT defaults to OFF.)
42 const bool noEntry = ent >= mTree->GetEntries();
43 if (noEntry) {
44 LOG(info) << "no entry to read, publishing empty output";
45 } else {
46 mTree->GetEntry(ent);
47 }
48 LOG(info) << "Pushing " << mTracks.size() << " track at entry " << ent;
49 pc.outputs().snapshot(Output{mOrigin, "ITSTrackROF", 0}, mROFRec);
50 pc.outputs().snapshot(Output{mOrigin, "TRACKS", 0}, mTracks);
51 pc.outputs().snapshot(Output{mOrigin, "TRACKCLSID", 0}, mClusInd);
52 pc.outputs().snapshot(Output{"ITS", "VERTICES", 0}, mVertices);
53 pc.outputs().snapshot(Output{"ITS", "VERTICESROF", 0}, mVerticesROFRec);
54 if (mUseMC) {
55 pc.outputs().snapshot(Output{mOrigin, "TRACKSMCTR", 0}, mMCTruth);
56 pc.outputs().snapshot(Output{mOrigin, "VERTICESMCTR", 0}, mMCVertTruth);
57 }
58
59 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
61 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
62 }
63}
64
65void TrackReader::connectTree(const std::string& filename)
66{
67 mTree.reset(nullptr); // in case it was already loaded
68 mFile.reset(TFile::Open(filename.c_str()));
69 assert(mFile && !mFile->IsZombie());
70 mTree.reset((TTree*)mFile->Get(mTrackTreeName.c_str()));
71 assert(mTree);
72 assert(mTree->GetBranch(mROFBranchName.c_str()));
73
74 mTree->SetBranchAddress(mROFBranchName.c_str(), &mROFRecInp);
75 mTree->SetBranchAddress(mTrackBranchName.c_str(), &mTracksInp);
76 mTree->SetBranchAddress(mClusIdxBranchName.c_str(), &mClusIndInp);
77 if (!mTree->GetBranch(mVertexBranchName.c_str())) {
78 LOG(warning) << "No " << mVertexBranchName << " branch in " << mTrackTreeName << " -> vertices will be empty";
79 } else {
80 mTree->SetBranchAddress(mVertexBranchName.c_str(), &mVerticesInp);
81 }
82 if (mUseMC) {
83 if (mTree->GetBranch(mTrackMCTruthBranchName.c_str())) {
84 mTree->SetBranchAddress(mTrackMCTruthBranchName.c_str(), &mMCTruthInp);
85 } else {
86 LOG(warning) << "MC-truth is missing, message will be empty";
87 }
88 }
89 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
90}
91
93{
94 std::vector<OutputSpec> outputSpec;
95 outputSpec.emplace_back("ITS", "ITSTrackROF", 0, Lifetime::Timeframe);
96 outputSpec.emplace_back("ITS", "TRACKS", 0, Lifetime::Timeframe);
97 outputSpec.emplace_back("ITS", "TRACKCLSID", 0, Lifetime::Timeframe);
98 outputSpec.emplace_back("ITS", "VERTICES", 0, Lifetime::Timeframe);
99 outputSpec.emplace_back("ITS", "VERTICESROF", 0, Lifetime::Timeframe);
100 if (useMC) {
101 outputSpec.emplace_back("ITS", "TRACKSMCTR", 0, Lifetime::Timeframe);
102 outputSpec.emplace_back("ITS", "VERTICESMCTR", 0, Lifetime::Timeframe);
103 }
104
105 return DataProcessorSpec{
106 .name = "its-track-reader",
107 .inputs = Inputs{},
108 .outputs = outputSpec,
109 .algorithm = AlgorithmSpec{adaptFromTask<TrackReader>(useMC)},
110 .options = Options{
111 {"its-tracks-infile", VariantType::String, "o2trac_its.root", {"Name of the input track file"}},
112 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
113}
114
115} // namespace o2::its
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
virtual void endOfStream(EndOfStreamContext &context)
This is invoked whenever we have an EndOfStream event.
Definition Task.h:43
std::vector< o2::MCCompLabel > mMCVertTruth
std::vector< int > mClusInd
void init(o2::framework::InitContext &ic) final
std::vector< o2::itsmft::ROFRecord > mROFRec
std::vector< o2::itsmft::ROFRecord > * mROFRecInp
o2::header::DataOrigin mOrigin
std::vector< o2::MCCompLabel > * mMCTruthInp
std::string mTrackMCTruthBranchName
std::vector< o2::itsmft::ROFRecord > mVerticesROFRec
std::string mTrackBranchName
std::string mClusIdxBranchName
std::unique_ptr< TTree > mTree
std::unique_ptr< TFile > mFile
std::vector< o2::its::TrackITS > mTracks
std::vector< Vertex > mVertices
std::vector< Vertex > * mVerticesInp
void run(o2::framework::ProcessingContext &pc) final
void connectTree(const std::string &filename)
std::vector< o2::MCCompLabel > mMCTruth
std::string mVertexBranchName
std::vector< o2::its::TrackITS > * mTracksInp
std::vector< int > * mClusIndInp
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getITSTrackReaderSpec(bool useMC=true)
std::string filename()
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"