Project
Loading...
Searching...
No Matches
TrackReaderSpec.cxx
Go to the documentation of this file.
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
13
14#include <vector>
15#include <cassert>
20
21using namespace o2::framework;
22using namespace o2::its3;
23
24namespace o2
25{
26namespace its3
27{
28
30{
31 mUseMC = useMC;
32}
33
35{
37 ic.options().get<std::string>("its3-tracks-infile"));
39}
40
42{
43 auto ent = mTree->GetReadEntry() + 1;
44 assert(ent < mTree->GetEntries()); // this should not happen
45 mTree->GetEntry(ent);
46 LOG(info) << "Pushing " << mTracks.size() << " track in " << mROFRec.size() << " ROFs at entry " << ent;
47 pc.outputs().snapshot(Output{mOrigin, "ITSTrackROF", 0}, mROFRec);
48 pc.outputs().snapshot(Output{mOrigin, "TRACKS", 0}, mTracks);
49 pc.outputs().snapshot(Output{mOrigin, "TRACKCLSID", 0}, mClusInd);
50 pc.outputs().snapshot(Output{"ITS", "VERTICES", 0}, mVertices);
51 pc.outputs().snapshot(Output{"ITS", "VERTICESROF", 0}, mVerticesROFRec);
52 if (mUseMC) {
53 pc.outputs().snapshot(Output{mOrigin, "TRACKSMCTR", 0}, mMCTruth);
54 pc.outputs().snapshot(Output{mOrigin, "VERTICESMCTR", 0}, mMCVertTruth);
55 }
56
57 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
59 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
60 }
61}
62
63void TrackReader::connectTree(const std::string& filename)
64{
65 mTree.reset(nullptr); // in case it was already loaded
66 mFile.reset(TFile::Open(filename.c_str()));
67 assert(mFile && !mFile->IsZombie());
68 mTree.reset((TTree*)mFile->Get(mTrackTreeName.c_str()));
69 assert(mTree);
70 assert(mTree->GetBranch(mROFBranchName.c_str()));
71
72 mTree->SetBranchAddress(mROFBranchName.c_str(), &mROFRecInp);
73 mTree->SetBranchAddress(mTrackBranchName.c_str(), &mTracksInp);
74 mTree->SetBranchAddress(mClusIdxBranchName.c_str(), &mClusIndInp);
75 if (!mTree->GetBranch(mVertexBranchName.c_str())) {
76 LOG(warning) << "No " << mVertexBranchName << " branch in " << mTrackTreeName << " -> vertices will be empty";
77 } else {
78 mTree->SetBranchAddress(mVertexBranchName.c_str(), &mVerticesInp);
79 }
80 if (!mTree->GetBranch(mVertexROFBranchName.c_str())) {
81 LOG(warning) << "No " << mVertexROFBranchName << " branch in " << mTrackTreeName
82 << " -> vertices ROFrecords will be empty";
83 } else {
84 mTree->SetBranchAddress(mVertexROFBranchName.c_str(), &mVerticesROFRecInp);
85 }
86 if (mUseMC) {
87 if (mTree->GetBranch(mTrackMCTruthBranchName.c_str())) {
88 mTree->SetBranchAddress(mTrackMCTruthBranchName.c_str(), &mMCTruthInp);
89 } else {
90 LOG(warning) << "MC-truth is missing, message will be empty";
91 }
92 }
93 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
94}
95
97{
98 std::vector<OutputSpec> outputSpec;
99 outputSpec.emplace_back("ITS", "ITSTrackROF", 0, Lifetime::Timeframe);
100 outputSpec.emplace_back("ITS", "TRACKS", 0, Lifetime::Timeframe);
101 outputSpec.emplace_back("ITS", "TRACKCLSID", 0, Lifetime::Timeframe);
102 outputSpec.emplace_back("ITS", "VERTICES", 0, Lifetime::Timeframe);
103 outputSpec.emplace_back("ITS", "VERTICESROF", 0, Lifetime::Timeframe);
104 if (useMC) {
105 outputSpec.emplace_back("ITS", "TRACKSMCTR", 0, Lifetime::Timeframe);
106 outputSpec.emplace_back("ITS", "VERTICESMCTR", 0, Lifetime::Timeframe);
107 }
108
109 return DataProcessorSpec{
110 "its3-track-reader",
111 Inputs{},
112 outputSpec,
113 AlgorithmSpec{adaptFromTask<TrackReader>(useMC)},
114 Options{
115 {"its-tracks-infile", VariantType::String, "o2trac_its.root", {"Name of the input ITS3 track file"}},
116 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
117}
118
119} // namespace its3
120} // namespace o2
Definition of the Names Generator class.
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::unique_ptr< TFile > mFile
std::string mTrackMCTruthBranchName
o2::header::DataOrigin mOrigin
std::string mVertexBranchName
void init(o2::framework::InitContext &ic) final
std::vector< Vertex > * mVerticesInp
std::vector< o2::itsmft::ROFRecord > * mROFRecInp
std::vector< o2::itsmft::ROFRecord > mVerticesROFRec
std::vector< o2::MCCompLabel > mMCVertTruth
void run(o2::framework::ProcessingContext &pc) final
std::vector< int > * mClusIndInp
std::vector< o2::itsmft::ROFRecord > * mVerticesROFRecInp
TrackReader(bool useMC=true)
std::unique_ptr< TTree > mTree
std::vector< o2::MCCompLabel > * mMCTruthInp
void connectTree(const std::string &filename)
std::vector< int > mClusInd
std::string mClusIdxBranchName
std::vector< o2::its::TrackITS > * mTracksInp
std::vector< o2::MCCompLabel > mMCTruth
std::vector< Vertex > mVertices
std::vector< o2::its::TrackITS > mTracks
std::string mVertexROFBranchName
std::vector< o2::itsmft::ROFRecord > mROFRec
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getITS3TrackReaderSpec(bool useMC=true)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
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"