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>
18#include "Framework/Logger.h"
21
22using namespace o2::framework;
23using namespace o2::mft;
24
25namespace o2
26{
27namespace mft
28{
29
31{
32 mUseMC = useMC;
33}
34
36{
38 ic.options().get<std::string>("mft-tracks-infile"));
40}
41
43{
44 auto ent = mTree->GetReadEntry() + 1;
45 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
46 // the tree then has no entry to read. Publish empty containers instead of reading past the
47 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
48 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
49 // every production build since ENABLE_CASSERT defaults to OFF.)
50 const bool noEntry = ent >= mTree->GetEntries();
51 if (noEntry) {
52 LOG(info) << "no entry to read, publishing empty output";
53 } else {
54 mTree->GetEntry(ent);
55 }
56 LOG(info) << "Pushing " << mTracks.size() << " track in " << mROFRec.size() << " ROFs at entry " << ent;
57 pc.outputs().snapshot(Output{mOrigin, "MFTTrackROF", 0}, mROFRec);
58 pc.outputs().snapshot(Output{mOrigin, "TRACKS", 0}, mTracks);
59 pc.outputs().snapshot(Output{mOrigin, "TRACKCLSID", 0}, mClusInd);
60 if (mUseMC) {
61 pc.outputs().snapshot(Output{mOrigin, "TRACKSMCTR", 0}, mMCTruth);
62 }
63
64 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
66 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
67 }
68}
69
70void TrackReader::connectTree(const std::string& filename)
71{
72 mTree.reset(nullptr); // in case it was already loaded
73 mFile.reset(TFile::Open(filename.c_str()));
74 assert(mFile && !mFile->IsZombie());
75 mTree.reset((TTree*)mFile->Get(mTrackTreeName.c_str()));
76 assert(mTree);
77 assert(mTree->GetBranch(mROFBranchName.c_str()));
78
79 mTree->SetBranchAddress(mROFBranchName.c_str(), &mROFRecInp);
80 mTree->SetBranchAddress(mTrackBranchName.c_str(), &mTracksInp);
81 mTree->SetBranchAddress(mClusIdxBranchName.c_str(), &mClusIndInp);
82
83 if (mUseMC) {
84 if (mTree->GetBranch(mTrackMCTruthBranchName.c_str())) {
85 mTree->SetBranchAddress(mTrackMCTruthBranchName.c_str(), &mMCTruthInp);
86 } else {
87 LOG(warning) << "MC-truth is missing, message will be empty";
88 }
89 }
90 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
91}
92
94{
95 std::vector<OutputSpec> outputSpec;
96 outputSpec.emplace_back("MFT", "MFTTrackROF", 0, Lifetime::Timeframe);
97 outputSpec.emplace_back("MFT", "TRACKS", 0, Lifetime::Timeframe);
98 outputSpec.emplace_back("MFT", "TRACKCLSID", 0, Lifetime::Timeframe);
99 if (useMC) {
100 outputSpec.emplace_back("MFT", "TRACKSMCTR", 0, Lifetime::Timeframe);
101 }
102
103 return DataProcessorSpec{
104 "mft-track-reader",
105 Inputs{},
106 outputSpec,
107 AlgorithmSpec{adaptFromTask<TrackReader>(useMC)},
108 Options{
109 {"mft-tracks-infile", VariantType::String, "mfttracks.root", {"Name of the input track file"}},
110 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
111}
112
113} // namespace mft
114} // 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::vector< int > * mClusIndInp
std::string mTrackMCTruthBranchName
void init(o2::framework::InitContext &ic) final
TrackReader(bool useMC=true)
std::vector< o2::itsmft::ROFRecord > mROFRec
std::vector< o2::mft::TrackMFT > mTracks
void run(o2::framework::ProcessingContext &pc) final
std::unique_ptr< TTree > mTree
std::vector< o2::MCCompLabel > mMCTruth
std::string mTrackBranchName
std::vector< int > mClusInd
std::vector< o2::MCCompLabel > * mMCTruthInp
std::unique_ptr< TFile > mFile
std::string mClusIdxBranchName
std::vector< o2::itsmft::ROFRecord > * mROFRecInp
std::vector< o2::mft::TrackMFT > * mTracksInp
o2::header::DataOrigin mOrigin
void connectTree(const std::string &filename)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getMFTTrackReaderSpec(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"