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
23#include "Framework/Lifetime.h"
24#include "Framework/Logger.h"
25#include "Framework/Task.h"
26#include <iostream>
27#include <vector>
28
29using namespace o2::framework;
30
31namespace o2::mch
32{
33
34template <typename T>
35void printBranch(char* data, const char* what)
36{
37 auto tdata = reinterpret_cast<std::vector<T>*>(data);
38 LOGP(info, "MCH {:d} {:s}", tdata->size(), what);
39}
40
42 [](std::string_view name, ProcessingContext&, Output const&, char* data) -> bool {
43 if (name == "trackrofs") {
44 printBranch<ROFRecord>(data, "ROFS");
45 }
46 if (name == "trackclusters") {
47 printBranch<Cluster>(data, "CLUSTERS");
48 }
49 if (name == "tracks") {
50 printBranch<TrackMCH>(data, "TRACKS");
51 }
52 if (name == "trackdigits") {
53 printBranch<Digit>(data, "DIGITS");
54 }
55 if (name == "tracklabels") {
56 auto tdata = reinterpret_cast<std::vector<o2::MCCompLabel>*>(data);
57 LOGP(info, "MCH {:d} {:s}", tdata->size(), "LABELS");
58 }
59 return false;
60 }};
61
63 std::unique_ptr<RootTreeReader> mTreeReader;
64 bool mUseMC = false;
65 bool mDigits = false;
67
68 TrackReader(bool useMC, bool digits, uint32_t subSpec = 0) : mUseMC(useMC), mDigits(digits), mSubSpec{subSpec} {}
69 void init(InitContext& ic)
70 {
71 if (!mUseMC) {
72 LOGP(warning, "Not reading MCH Track Labels");
73 }
74 auto treeName = "o2sim";
75 auto fileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), ic.options().get<std::string>("infile"));
76 auto nofEntries{-1};
77 if (mUseMC) {
78 if (mDigits) {
79 mTreeReader = std::make_unique<RootTreeReader>(
80 treeName,
81 fileName.c_str(),
82 nofEntries,
84 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "TRACKROFS", mSubSpec}, "trackrofs"},
86 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", "TRACKCLUSTERS", mSubSpec}, "trackclusters"},
87 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"MCH", "TRACKDIGITS", mSubSpec}, "trackdigits"},
89 &logging);
90 } else {
91 mTreeReader = std::make_unique<RootTreeReader>(
92 treeName,
93 fileName.c_str(),
94 nofEntries,
96 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "TRACKROFS", mSubSpec}, "trackrofs"},
98 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", "TRACKCLUSTERS", mSubSpec}, "trackclusters"},
100 &logging);
101 }
102 } else {
103 if (mDigits) {
104 mTreeReader = std::make_unique<RootTreeReader>(
105 treeName,
106 fileName.c_str(),
107 nofEntries,
109 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "TRACKROFS", mSubSpec}, "trackrofs"},
110 RootTreeReader::BranchDefinition<std::vector<TrackMCH>>{Output{"MCH", "TRACKS", mSubSpec}, "tracks"},
111 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", "TRACKCLUSTERS", mSubSpec}, "trackclusters"},
112 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"MCH", "TRACKDIGITS", mSubSpec}, "trackdigits"},
113 &logging);
114 } else {
115 mTreeReader = std::make_unique<RootTreeReader>(
116 treeName,
117 fileName.c_str(),
118 nofEntries,
120 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "TRACKROFS", mSubSpec}, "trackrofs"},
121 RootTreeReader::BranchDefinition<std::vector<TrackMCH>>{Output{"MCH", "TRACKS", mSubSpec}, "tracks"},
122 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", "TRACKCLUSTERS", mSubSpec}, "trackclusters"},
123 &logging);
124 }
125 }
126 }
127
128 void
130 {
131 if (mTreeReader->next()) {
132 (*mTreeReader)(pc);
133 } else {
134 pc.services().get<ControlService>().endOfStream();
135 }
136 }
137};
138
139DataProcessorSpec getTrackReaderSpec(bool useMC, const char* specName, bool digits, uint32_t subspec)
140{
141 std::vector<OutputSpec> outputSpecs;
142 outputSpecs.emplace_back(OutputSpec{{"tracks"}, "MCH", "TRACKS", subspec, Lifetime::Timeframe});
143 outputSpecs.emplace_back(OutputSpec{{"trackrofs"}, "MCH", "TRACKROFS", subspec, Lifetime::Timeframe});
144 outputSpecs.emplace_back(OutputSpec{{"trackclusters"}, "MCH", "TRACKCLUSTERS", subspec, Lifetime::Timeframe});
145 if (digits) {
146 outputSpecs.emplace_back(OutputSpec{{"trackdigits"}, "MCH", "TRACKDIGITS", subspec, Lifetime::Timeframe});
147 }
148 if (useMC) {
149 outputSpecs.emplace_back(OutputSpec{{"tracklabels"}, "MCH", "TRACKLABELS", subspec, Lifetime::Timeframe});
150 }
151
152 auto options = Options{
153 {"infile", VariantType::String, "mchtracks.root", {"name of the input track file"}},
154 {"input-dir", VariantType::String, "none", {"Input directory"}}};
155
156 return DataProcessorSpec{
157 fmt::format("{}{}", specName, subspec),
158 Inputs{},
159 outputSpecs,
160 adaptFromTask<TrackReader>(useMC, digits, subspec),
161 options};
162}
163} // namespace o2::mch
Definition of the MCH cluster minimal structure.
Definition of the MCH ROFrame record.
A generic reader for ROOT TTrees.
Definition of the MCH track.
const char * specName
ConfigParamRegistry const & options()
Definition InitContext.h:33
ServiceRegistryRef services()
The services registry associated with this processing context.
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean * data
Definition glcorearb.h:298
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
o2::framework::DataProcessorSpec getTrackReaderSpec(bool useMC, const char *specName="mch-tracks-reader", bool digits=false, uint32_t subspec=0)
void printBranch(char *data, const char *what)
RootTreeReader::SpecialPublishHook logging
uint32_t SubSpecificationType
Definition DataHeader.h:620
header::DataHeader::SubSpecificationType mSubSpec
void run(ProcessingContext &pc)
void init(InitContext &ic)
TrackReader(bool useMC, bool digits, uint32_t subSpec=0)
std::unique_ptr< RootTreeReader > mTreeReader
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
std::vector< Digit > digits