Project
Loading...
Searching...
No Matches
TrackTPCITSReaderSpec.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 "TFile.h"
16#include "TTree.h"
17#include "Framework/Task.h"
27
28using namespace o2::framework;
29using namespace o2::globaltracking;
30
31namespace o2
32{
33namespace globaltracking
34{
35
36class TrackTPCITSReader : public Task
37{
38 public:
39 TrackTPCITSReader(bool useMC) : mUseMC(useMC) {}
40 ~TrackTPCITSReader() override = default;
41 void init(InitContext& ic) final;
42 void run(ProcessingContext& pc) final;
43
44 private:
45 void connectTree(const std::string& filename);
46 bool mUseMC = true;
47 std::unique_ptr<TFile> mFile;
48 std::unique_ptr<TTree> mTree;
49 std::string mFileName = "";
50 std::vector<o2::dataformats::TrackTPCITS> mTracks, *mTracksPtr = &mTracks;
51 std::vector<o2::itsmft::TrkClusRef> mABTrkClusRefs, *mABTrkClusRefsPtr = &mABTrkClusRefs;
52 std::vector<int> mABTrkClIDs, *mABTrkClIDsPtr = &mABTrkClIDs;
53 std::vector<o2::MCCompLabel> mLabels, *mLabelsPtr = &mLabels;
54 std::vector<o2::MCCompLabel> mLabelsAB, *mLabelsABPtr = &mLabelsAB;
55};
56
58{
59 mFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
60 ic.options().get<std::string>("itstpc-track-infile"));
61 connectTree(mFileName);
62}
63
65{
66 auto ent = mTree->GetReadEntry() + 1;
67 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
68 // the tree then has no entry to read. Publish empty containers instead of reading past the
69 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
70 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
71 // every production build since ENABLE_CASSERT defaults to OFF.)
72 const bool noEntry = ent >= mTree->GetEntries();
73 if (noEntry) {
74 LOG(info) << "no entry to read, publishing empty output";
75 } else {
76 mTree->GetEntry(ent);
77 }
78 LOG(info) << "Pushing " << mTracks.size() << " TPC-ITS matches at entry " << ent;
79
80 pc.outputs().snapshot(Output{"GLO", "TPCITS", 0}, mTracks);
81 pc.outputs().snapshot(Output{"GLO", "TPCITSAB_REFS", 0}, mABTrkClusRefs);
82 pc.outputs().snapshot(Output{"GLO", "TPCITSAB_CLID", 0}, mABTrkClIDs);
83 if (mUseMC) {
84 pc.outputs().snapshot(Output{"GLO", "TPCITS_MC", 0}, mLabels);
85 pc.outputs().snapshot(Output{"GLO", "TPCITSAB_MC", 0}, mLabelsAB);
86 }
87
88 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
90 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
91 }
92}
93
94void TrackTPCITSReader::connectTree(const std::string& filename)
95{
96 mTree.reset(nullptr); // in case it was already loaded
97 mFile.reset(TFile::Open(filename.c_str()));
98 assert(mFile && !mFile->IsZombie());
99 mTree.reset((TTree*)mFile->Get("matchTPCITS"));
100 assert(mTree);
101 mTree->SetBranchAddress("TPCITS", &mTracksPtr);
102 mTree->SetBranchAddress("TPCITSABRefs", &mABTrkClusRefsPtr);
103 mTree->SetBranchAddress("TPCITSABCLID", &mABTrkClIDsPtr);
104 if (mUseMC) {
105 mTree->SetBranchAddress("MatchMCTruth", &mLabelsPtr);
106 mTree->SetBranchAddress("MatchABMCTruth", &mLabelsABPtr);
107 }
108 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
109}
110
112{
113 std::vector<OutputSpec> outputs;
114 outputs.emplace_back("GLO", "TPCITS", 0, Lifetime::Timeframe);
115 outputs.emplace_back("GLO", "TPCITSAB_REFS", 0, Lifetime::Timeframe); // AftetBurner ITS tracklet references (referred by GlobalTrackID::ITSAB) on cluster indices
116 outputs.emplace_back("GLO", "TPCITSAB_CLID", 0, Lifetime::Timeframe); // cluster indices of ITS tracklets attached by the AfterBurner
117 if (useMC) {
118 outputs.emplace_back("GLO", "TPCITS_MC", 0, Lifetime::Timeframe);
119 outputs.emplace_back("GLO", "TPCITSAB_MC", 0, Lifetime::Timeframe); // AfterBurner ITS tracklet MC
120 }
121
122 return DataProcessorSpec{
123 "itstpc-track-reader",
124 Inputs{},
125 outputs,
126 AlgorithmSpec{adaptFromTask<TrackTPCITSReader>(useMC)},
127 Options{
128 {"itstpc-track-infile", VariantType::String, "o2match_itstpc.root", {"Name of the input file"}},
129 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
130}
131
132} // namespace globaltracking
133} // namespace o2
Header of the General Run Parameters object.
Definition of the Names Generator class.
Type wrappers for enfording a specific serialization method.
Result of refitting TPC-ITS matched track.
Reference on ITS/MFT clusters set.
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
void run(ProcessingContext &pc) final
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getTrackTPCITSReaderSpec(bool useMC)
create a processor spec
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"