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
19#include "Headers/DataHeader.h"
24#include <memory>
25#include <utility>
26
27using namespace o2::framework;
28
29namespace o2
30{
31
32namespace phos
33{
34
35template <typename T>
37
39 std::shared_ptr<RootTreeReader> reader;
40 std::string datatype;
43};
44
46{
47
48 auto initFunction = [propagateMC](InitContext& ic) {
49 // get the option from the init context
50 auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
51 ic.options().get<std::string>("infile"));
52 auto treename = ic.options().get<std::string>("treename");
53 auto nofEvents = ic.options().get<int>("nevents");
55
56 auto processAttributes = std::make_shared<ProcessAttributes>();
57 {
58 processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
59 processAttributes->finished = false;
60 processAttributes->datatype = "PHOSDigit";
62 if (propagateMC) {
63 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
64 filename.c_str(), // input file name
65 nofEvents, // number of entries to publish
66 publishingMode,
67 RootTreeReader::BranchDefinition<std::vector<o2::phos::Digit>>{
68 Output{"PHS", "DIGITS", subSpec}, "PHOSDigit"},
70 Output{"PHS", "DIGITTRIGREC", subSpec}, "PHOSDigitTrigRecords"},
71 Output{"PHS", "DIGITSMCTR", subSpec}, "PHOSDigitMCTruth"); // name of mc label branch
72 } else {
73 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
74 filename.c_str(), // input file name
75 nofEvents, // number of entries to publish
76 publishingMode,
77 RootTreeReader::BranchDefinition<std::vector<o2::phos::Digit>>{
78 Output{"PHS", "DIGITS", subSpec}, "PHOSDigit"},
80 Output{"PHS", "DIGITTRIGREC", subSpec}, "PHOSDigitTrigRecords"});
81 }
82 }
83
84 auto processFunction = [processAttributes, propagateMC](ProcessingContext& pc) {
85 if (processAttributes->finished) {
86 return;
87 }
88
89 auto publish = [&processAttributes, &pc, propagateMC]() {
90 o2::phos::PHOSBlockHeader phosheader(true);
91 if (processAttributes->reader->next()) {
92 (*processAttributes->reader)(pc, phosheader);
93 } else {
94 processAttributes->reader.reset();
95 return false;
96 }
97 return true;
98 };
99
100 bool active(true);
101 if (!publish()) {
102 active = false;
103 // Send dummy header with no payload option
104 o2::phos::PHOSBlockHeader dummyheader(false);
105 pc.outputs().snapshot(OutputRef{"output", 0, {dummyheader}}, 0);
106 pc.outputs().snapshot(OutputRef{"outputTR", 0, {dummyheader}}, 0);
107 if (propagateMC) {
108 pc.outputs().snapshot(OutputRef{"outputMC", 0, {dummyheader}}, 0);
109 }
110 }
111 if ((processAttributes->finished = (active == false)) && processAttributes->terminateOnEod) {
112 pc.services().get<ControlService>().endOfStream();
113 pc.services().get<ControlService>().readyToQuit(framework::QuitRequest::Me);
114 }
115 };
116 return processFunction;
117 };
118
119 std::vector<OutputSpec> outputSpecs;
120 outputSpecs.emplace_back(OutputSpec{{"output"}, "PHS", "DIGITS", 0, Lifetime::Timeframe});
121 outputSpecs.emplace_back(OutputSpec{{"outputTR"}, "PHS", "DIGITTRIGREC", 0, Lifetime::Timeframe});
122 if (propagateMC) {
123 outputSpecs.emplace_back(OutputSpec{{"outputMC"}, "PHS", "DIGITSMCTR", 0, Lifetime::Timeframe});
124 }
125
126 return DataProcessorSpec{
127 "phos-digit-reader",
128 Inputs{}, // no inputs
129 outputSpecs,
130 AlgorithmSpec(initFunction),
131 Options{
132 {"infile", VariantType::String, "phosdigits.root", {"Name of the input file"}},
133 {"input-dir", VariantType::String, "none", {"Input directory"}},
134 {"treename", VariantType::String, "o2sim", {"Name of input tree"}},
135 {"nevents", VariantType::Int, -1, {"number of events to run, -1: inf loop"}},
136 {"terminate-on-eod", VariantType::Bool, true, {"terminate on end-of-data"}},
137 }};
138}
139
141
142DataProcessorSpec getCellReaderSpec(bool propagateMC)
143{
144
145 auto initFunction = [propagateMC](InitContext& ic) {
146 // get the option from the init context
147 auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
148 ic.options().get<std::string>("infile"));
149 auto treename = ic.options().get<std::string>("treename");
150 auto nofEvents = ic.options().get<int>("nevents");
152
153 auto processAttributes = std::make_shared<ProcessAttributes>();
154 {
155 processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
156 processAttributes->finished = false;
157 processAttributes->datatype = "PHOSCell";
159 if (propagateMC) {
160 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
161 filename.c_str(), // input file name
162 nofEvents, // number of entries to publish
163 publishingMode,
164 RootTreeReader::BranchDefinition<std::vector<o2::phos::Cell>>{
165 Output{"PHS", "CELLS", subSpec}, "PHOSCell"},
167 Output{"PHS", "CELLTRIGREC", subSpec}, "PHOSCellTrigRec"},
168 Output{"PHS", "CELLSMCTR", subSpec},
169 "PHOSCellTrueMC"); // name of mc label branch
170 } else {
171 processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
172 filename.c_str(), // input file name
173 nofEvents, // number of entries to publish
174 publishingMode,
175 RootTreeReader::BranchDefinition<std::vector<o2::phos::Cell>>{
176 Output{"PHS", "CELLS", subSpec}, "PHOSCell"},
178 Output{"PHS", "CELLTRIGREC", subSpec}, "PHOSCellTrigRec"});
179 }
180 }
181
182 auto processFunction = [processAttributes, propagateMC](ProcessingContext& pc) {
183 if (processAttributes->finished) {
184 return;
185 }
186
187 auto publish = [&processAttributes, &pc, propagateMC]() {
188 PHOSBlockHeader phosheader(true);
189 if (processAttributes->reader->next()) {
190 (*processAttributes->reader)(pc, phosheader);
191 } else {
192 processAttributes->reader.reset();
193 return false;
194 }
195 return true;
196 };
197
198 bool active(true);
199 if (!publish()) {
200 active = false;
201 // Send dummy header with no payload option
202 PHOSBlockHeader dummyheader(false);
203 pc.outputs().snapshot(OutputRef{"output", 0, {dummyheader}}, 0);
204 pc.outputs().snapshot(OutputRef{"outputTR", 0, {dummyheader}}, 0);
205 if (propagateMC) {
206 pc.outputs().snapshot(OutputRef{"outputMC", 0, {dummyheader}}, 0);
207 pc.outputs().snapshot(OutputRef{"outputMCmap", 0, {dummyheader}}, 0);
208 }
209 }
210 if ((processAttributes->finished = (active == false)) && processAttributes->terminateOnEod) {
211 pc.services().get<ControlService>().endOfStream();
212 pc.services().get<ControlService>().readyToQuit(framework::QuitRequest::Me);
213 }
214 };
215 return processFunction;
216 };
217
218 std::vector<OutputSpec> outputSpecs;
219 outputSpecs.emplace_back(OutputSpec{{"output"}, "PHS", "CELLS", 0, Lifetime::Timeframe});
220 outputSpecs.emplace_back(OutputSpec{{"outputTR"}, "PHS", "CELLTRIGREC", 0, Lifetime::Timeframe});
221 if (propagateMC) {
222 outputSpecs.emplace_back(OutputSpec{{"outputMC"}, "PHS", "CELLSMCTR", 0, Lifetime::Timeframe});
223 outputSpecs.emplace_back(OutputSpec{{"outputMCmap"}, "PHS", "CELLSMCMAP", 0, Lifetime::Timeframe});
224 }
225
226 return DataProcessorSpec{
227 "phos-cell-reader",
228 Inputs{}, // no inputs
229 outputSpecs,
230 AlgorithmSpec(initFunction),
231 Options{
232 {"infile", VariantType::String, "phoscells.root", {"Name of the input file"}},
233 {"input-dir", VariantType::String, "none", {"Input directory"}},
234 {"treename", VariantType::String, "o2sim", {"Name of input tree"}},
235 {"nevents", VariantType::Int, -1, {"number of events to run, -1: inf loop"}},
236 {"terminate-on-eod", VariantType::Bool, true, {"terminate on end-of-data"}},
237 }};
238}
239
240} // namespace phos
241
242} // namespace o2
bool publish(std::string const &filename, std::string const &path, std::string CCDBpath)
Definition GRPTool.cxx:198
Configurable generator for RootTreeWriter processor spec.
Definition of the Names Generator class.
A generic reader for ROOT TTrees.
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
@ Me
Only quit this data processor.
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getDigitsReaderSpec(bool propagateMC=true)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
uint32_t SubSpecificationType
Definition DataHeader.h:620
Header for PHOS flagging the following PHOS payload.
std::shared_ptr< RootTreeReader > reader
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)