Project
Loading...
Searching...
No Matches
TPCUnbinnedResidualReaderSpec.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
15
18#include "fairlogger/Logger.h"
20
21using namespace o2::framework;
22
23namespace o2
24{
25namespace tpc
26{
27
29{
30 // get the option from the init context
31 LOG(info) << "Init TPC unbinned residual reader!";
32 mInFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
33 ic.options().get<std::string>("input-filename"));
34 mInTreeName = ic.options().get<std::string>("treename");
35 connectTree();
36}
37
38void TPCUnbinnedResidualReader::connectTree()
39{
40 mTreeIn.reset(nullptr); // in case it was already loaded
41 mFileIn.reset(TFile::Open(mInFileName.c_str()));
42 assert(mFileIn && !mFileIn->IsZombie());
43 mTreeIn.reset((TTree*)mFileIn->Get(mInTreeName.c_str()));
44 assert(mTreeIn);
45 mTreeIn->SetBranchAddress("residuals", &mUnbinnedResidPtr);
46 mTreeIn->SetBranchAddress("trackRefs", &mTrackDataCompactPtr);
47 if (mTreeIn->GetBranch("detInfo")) {
48 mTreeIn->SetBranchAddress("detInfo", &mDetInfoUnbResPtr);
49 } else {
50 LOGP(warn, "No detInfo branch found in the unbinned residuals tree, empty vector will be sent");
51 }
52 if (mTrackInput) {
53 mTreeIn->SetBranchAddress("tracks", &mTrackDataPtr);
54 }
55 if (mMCInput) {
56 if (!mTreeIn->GetBranch("tracksMC")) {
57 LOG(fatal) << "No tracksMC branch found in the unbinned residuals tree, the interpolation workflow must run with --enable-mc";
58 }
59 mTreeIn->SetBranchAddress("tracksMC", &mTrackDataMCPtr);
60 }
61 LOG(info) << "Loaded tree from " << mInFileName << " with " << mTreeIn->GetEntries() << " entries";
62}
63
65{
66 auto currEntry = mTreeIn->GetReadEntry() + 1;
67 assert(currEntry < mTreeIn->GetEntries()); // this should not happen
68 mTreeIn->GetEntry(currEntry);
69 LOG(info) << "Pushing " << mUnbinnedResid.size() << " unbinned residuals at entry " << currEntry;
70 pc.outputs().snapshot(Output{"GLO", "UNBINNEDRES", 0}, mUnbinnedResid);
71 pc.outputs().snapshot(Output{"GLO", "TRKREFS", 0}, mTrackDataCompact);
72 pc.outputs().snapshot(Output{"GLO", "DETINFORES", 0}, mDetInfoUnbRes);
73 if (mTrackInput) {
74 LOG(info) << "Pushing " << mTrackData.size() << " reference tracks for these residuals";
75 pc.outputs().snapshot(Output{"GLO", "TRKDATA", 0}, mTrackData);
76 }
77 if (mMCInput) {
78 pc.outputs().snapshot(Output{"GLO", "TRKDATAMC", 0}, mTrackDataMC);
79 }
80
81 if (mTreeIn->GetReadEntry() + 1 >= mTreeIn->GetEntries()) {
83 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
84 }
85}
86
88{
89 std::vector<OutputSpec> outputs;
90 outputs.emplace_back("GLO", "UNBINNEDRES", 0, Lifetime::Timeframe);
91 outputs.emplace_back("GLO", "DETINFORES", 0, Lifetime::Timeframe);
92 outputs.emplace_back("GLO", "TRKREFS", 0, Lifetime::Timeframe);
93 if (trkInput) {
94 outputs.emplace_back("GLO", "TRKDATA", 0, Lifetime::Timeframe);
95 }
96 if (mcInput) {
97 outputs.emplace_back("GLO", "TRKDATAMC", 0, Lifetime::Timeframe);
98 }
99
100 return DataProcessorSpec{
101 "TPCUnbinnedResidualReader",
102 Inputs{},
103 outputs,
104 AlgorithmSpec{adaptFromTask<TPCUnbinnedResidualReader>(trkInput, mcInput)},
105 Options{
106 {"input-filename", VariantType::String, "o2residuals_tpc.root", {"Name of the input file"}},
107 {"input-dir", VariantType::String, "none", {"Input directory"}},
108 {"treename", VariantType::String, "residualsTPC", {"Name of top-level TTree"}},
109 }};
110}
111
112} // namespace tpc
113} // 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
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput, bool mcInput)
read unbinned TPC residuals and reference tracks (with mcInput also their MC truth) from a root file
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"