Project
Loading...
Searching...
No Matches
ReaderSpec.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
21#include "Headers/DataHeader.h"
26#include <memory>
27#include <utility>
28
29using namespace o2::framework;
30
31namespace o2
32{
33
34namespace cpv
35{
36
37template <typename T>
39
41 std::shared_ptr<RootTreeReader> reader;
42 std::string datatype;
45};
46
48{
49
50 auto initFunction = [propagateMC](InitContext& ic) {
51 // get the option from the init context
52 auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
53 ic.options().get<std::string>("infile"));
54 auto treename = ic.options().get<std::string>("treename");
55 auto nofEvents = ic.options().get<int>("nevents");
57 auto processAttributes = std::make_shared<ProcessAttributes>();
58 {
59 processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
60 processAttributes->finished = false;
61 processAttributes->datatype = "CPVDigit";
63 if (propagateMC) {
64 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
65 filename.c_str(), // input file name
66 nofEvents, // number of entries to publish
67 publishingMode,
68 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"CPV", "DIGITS", subSpec}, "CPVDigit"},
69 RootTreeReader::BranchDefinition<std::vector<TriggerRecord>>{Output{"CPV", "DIGITTRIGREC", subSpec}, "CPVDigitTrigRecords"},
70 RootTreeReader::BranchDefinition<dataformats::MCTruthContainer<MCCompLabel>>{Output{"CPV", "DIGITSMCTR", subSpec}, "CPVDigitMCTruth"});
71 } else {
72 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
73 filename.c_str(), // input file name
74 nofEvents, // number of entries to publish
75 publishingMode,
76 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"CPV", "DIGITS", subSpec}, "CPVDigit"},
77 RootTreeReader::BranchDefinition<std::vector<TriggerRecord>>{Output{"CPV", "DIGITTRIGREC", subSpec}, "CPVDigitTrigRecords"});
78 }
79 }
80
81 auto processFunction = [processAttributes, propagateMC](ProcessingContext& pc) {
82 if (processAttributes->finished) {
83 return;
84 }
85
86 auto publish = [&processAttributes, &pc, propagateMC]() {
87 o2::cpv::CPVBlockHeader cpvheader(true);
88 if (processAttributes->reader->next()) {
89 (*processAttributes->reader)(pc, cpvheader);
90 } else {
91 processAttributes->reader.reset();
92 return false;
93 }
94 return true;
95 };
96
97 bool active(true);
98 if (!publish()) {
99 active = false;
100 // Send dummy header with no payload option
101 o2::cpv::CPVBlockHeader dummyheader(false);
102 pc.outputs().snapshot(OutputRef{"output", 0, {dummyheader}}, 0);
103 pc.outputs().snapshot(OutputRef{"outputTR", 0, {dummyheader}}, 0);
104 if (propagateMC) {
105 pc.outputs().snapshot(OutputRef{"outputMC", 0, {dummyheader}}, 0);
106 }
107 }
108 if ((processAttributes->finished = (active == false)) && processAttributes->terminateOnEod) {
109 pc.services().get<ControlService>().endOfStream();
110 pc.services().get<ControlService>().readyToQuit(framework::QuitRequest::Me);
111 }
112 };
113 return processFunction;
114 };
115
116 std::vector<OutputSpec> outputSpecs;
117 outputSpecs.emplace_back(OutputSpec{{"output"}, "CPV", "DIGITS", 0, Lifetime::Timeframe});
118 outputSpecs.emplace_back(OutputSpec{{"outputTR"}, "CPV", "DIGITTRIGREC", 0, Lifetime::Timeframe});
119 if (propagateMC) {
120 outputSpecs.emplace_back(OutputSpec{{"outputMC"}, "CPV", "DIGITSMCTR", 0, Lifetime::Timeframe});
121 }
122
123 return DataProcessorSpec{
124 "cpv-digit-reader",
125 Inputs{}, // no inputs
126 outputSpecs,
127 AlgorithmSpec(initFunction),
128 Options{
129 {"infile", VariantType::String, "cpvdigits.root", {"Name of the input file"}},
130 {"input-dir", VariantType::String, "none", {"Input directory"}},
131 {"treename", VariantType::String, "o2sim", {"Name of input tree"}},
132 {"nevents", VariantType::Int, -1, {"number of events to run, -1: inf loop"}},
133 {"terminate-on-eod", VariantType::Bool, true, {"terminate on end-of-data"}},
134 }};
135}
136
138{
139
140 auto initFunction = [propagateMC](InitContext& ic) {
141 // get the option from the init context
142 auto filename = ic.options().get<std::string>("infile");
143 auto treename = ic.options().get<std::string>("treename");
144 auto nofEvents = ic.options().get<int>("nevents");
146
147 auto processAttributes = std::make_shared<ProcessAttributes>();
148 {
149 processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
150 processAttributes->finished = false;
151 processAttributes->datatype = "CPVCluster";
152 constexpr auto persistency = Lifetime::Timeframe;
154 if (propagateMC) {
155 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
156 filename.c_str(), // input file name
157 nofEvents, // number of entries to publish
158 publishingMode,
159 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"CPV", "CLUSTERS", subSpec}, "CPVCluster"},
160 RootTreeReader::BranchDefinition<std::vector<TriggerRecord>>{Output{"CPV", "CLUSTERTRIGRECS", subSpec}, "CPVClusterTrigRec"},
161 RootTreeReader::BranchDefinition<dataformats::MCTruthContainer<MCCompLabel>>{Output{"CPV", "CLUSTERTRUEMC", subSpec}, "CPVClusterTrueMC"});
162 } else {
163 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
164 filename.c_str(), // input file name
165 nofEvents, // number of entries to publish
166 publishingMode,
167 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"CPV", "CLUSTERS", subSpec}, "CPVCluster"},
168 RootTreeReader::BranchDefinition<std::vector<TriggerRecord>>{Output{"CPV", "CLUSTERTRIGRECS", subSpec}, "CPVClusterTrigRec"});
169 }
170 }
171
172 auto processFunction = [processAttributes, propagateMC](ProcessingContext& pc) {
173 if (processAttributes->finished) {
174 return;
175 }
176
177 auto publish = [&processAttributes, &pc, propagateMC]() {
178 o2::cpv::CPVBlockHeader cpvheader(true);
179 if (processAttributes->reader->next()) {
180 (*processAttributes->reader)(pc, cpvheader);
181 } else {
182 processAttributes->reader.reset();
183 return false;
184 }
185 return true;
186 };
187
188 bool active(true);
189 if (!publish()) {
190 active = false;
191 // Send dummy header with no payload option
192 o2::cpv::CPVBlockHeader dummyheader(false);
193 pc.outputs().snapshot(OutputRef{"output", 0, {dummyheader}}, 0);
194 pc.outputs().snapshot(OutputRef{"outputTR", 0, {dummyheader}}, 0);
195 if (propagateMC) {
196 pc.outputs().snapshot(OutputRef{"outputMC", 0, {dummyheader}}, 0);
197 }
198 }
199 if ((processAttributes->finished = (active == false)) && processAttributes->terminateOnEod) {
200 pc.services().get<ControlService>().endOfStream();
201 pc.services().get<ControlService>().readyToQuit(framework::QuitRequest::Me);
202 }
203 };
204 return processFunction;
205 };
206
207 std::vector<OutputSpec> outputSpecs;
208 outputSpecs.emplace_back(OutputSpec{{"output"}, "CPV", "CLUSTERS", 0, Lifetime::Timeframe});
209 outputSpecs.emplace_back(OutputSpec{{"outputTR"}, "CPV", "CLUSTERTRIGRECS", 0, Lifetime::Timeframe});
210 if (propagateMC) {
211 outputSpecs.emplace_back(OutputSpec{{"outputMC"}, "CPV", "CLUSTERTRUEMC", 0, Lifetime::Timeframe});
212 }
213
214 return DataProcessorSpec{
215 "cpv-cluster-reader",
216 Inputs{}, // no inputs
217 outputSpecs,
218 AlgorithmSpec(initFunction),
219 Options{
220 {"infile", VariantType::String, "cpvclusters.root", {"Name of the input file"}},
221 {"treename", VariantType::String, "o2sim", {"Name of input tree"}},
222 {"input-dir", VariantType::String, "none", {"Input directory"}},
223 {"nevents", VariantType::Int, -1, {"number of events to run, -1: inf loop"}},
224 {"terminate-on-eod", VariantType::Bool, true, {"terminate on end-of-data"}},
225 }};
226}
227
228} // namespace cpv
229
230} // namespace o2
bool publish(std::string const &filename, std::string const &path, std::string CCDBpath)
Definition GRPTool.cxx:198
Definition of a container to keep Monte Carlo truth external to simulation objects.
Configurable generator for RootTreeWriter processor spec.
Definition of the Names Generator class.
A generic reader for ROOT TTrees.
framework::DataProcessorSpec getClustersReaderSpec(bool propagateMC=true)
framework::DataProcessorSpec getDigitsReaderSpec(bool propagateMC=true)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
@ Me
Only quit this data processor.
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
Header for CPV flagging the following CPV payload.
std::shared_ptr< RootTreeReader > reader
uint32_t SubSpecificationType
Definition DataHeader.h:620
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)