-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathReaderSpec.cxx
More file actions
242 lines (217 loc) · 11.7 KB
/
ReaderSpec.cxx
File metadata and controls
242 lines (217 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "DataFormatsPHOS/PHOSBlockHeader.h"
#include "DataFormatsPHOS/Cell.h"
#include "DataFormatsPHOS/Digit.h"
#include "DataFormatsPHOS/TriggerRecord.h"
#include "PHOSWorkflow/ReaderSpec.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/ControlService.h"
#include "Headers/DataHeader.h"
#include "DPLUtils/RootTreeReader.h"
#include "DPLUtils/MakeRootTreeWriterSpec.h"
#include "Framework/DataSpecUtils.h"
#include "CommonUtils/NameConf.h"
#include <memory>
#include <utility>
using namespace o2::framework;
namespace o2
{
namespace phos
{
template <typename T>
using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;
struct ProcessAttributes {
std::shared_ptr<RootTreeReader> reader;
std::string datatype;
bool terminateOnEod;
bool finished;
};
DataProcessorSpec getDigitsReaderSpec(bool propagateMC)
{
auto initFunction = [propagateMC](InitContext& ic) {
// get the option from the init context
auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
ic.options().get<std::string>("infile"));
auto treename = ic.options().get<std::string>("treename");
auto nofEvents = ic.options().get<int>("nevents");
auto publishingMode = nofEvents == -1 ? RootTreeReader::PublishingMode::Single : RootTreeReader::PublishingMode::Loop;
auto processAttributes = std::make_shared<ProcessAttributes>();
{
processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
processAttributes->finished = false;
processAttributes->datatype = "PHOSDigit";
o2::header::DataHeader::SubSpecificationType subSpec = 0;
if (propagateMC) {
processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
filename.c_str(), // input file name
nofEvents, // number of entries to publish
publishingMode,
RootTreeReader::BranchDefinition<std::vector<o2::phos::Digit>>{
Output{"PHS", "DIGITS", subSpec}, "PHOSDigit"},
RootTreeReader::BranchDefinition<std::vector<o2::phos::TriggerRecord>>{
Output{"PHS", "DIGITTRIGREC", subSpec}, "PHOSDigitTrigRecords"},
Output{"PHS", "DIGITSMCTR", subSpec}, "PHOSDigitMCTruth"); // name of mc label branch
} else {
processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
filename.c_str(), // input file name
nofEvents, // number of entries to publish
publishingMode,
RootTreeReader::BranchDefinition<std::vector<o2::phos::Digit>>{
Output{"PHS", "DIGITS", subSpec}, "PHOSDigit"},
RootTreeReader::BranchDefinition<std::vector<o2::phos::TriggerRecord>>{
Output{"PHS", "DIGITTRIGREC", subSpec}, "PHOSDigitTrigRecords"});
}
}
auto processFunction = [processAttributes, propagateMC](ProcessingContext& pc) {
if (processAttributes->finished) {
return;
}
auto publish = [&processAttributes, &pc, propagateMC]() {
o2::phos::PHOSBlockHeader phosheader(true);
if (processAttributes->reader->next()) {
(*processAttributes->reader)(pc, phosheader);
} else {
processAttributes->reader.reset();
return false;
}
return true;
};
bool active(true);
if (!publish()) {
active = false;
// Send dummy header with no payload option
o2::phos::PHOSBlockHeader dummyheader(false);
pc.outputs().snapshot(OutputRef{"output", 0, {dummyheader}}, 0);
pc.outputs().snapshot(OutputRef{"outputTR", 0, {dummyheader}}, 0);
if (propagateMC) {
pc.outputs().snapshot(OutputRef{"outputMC", 0, {dummyheader}}, 0);
}
}
if ((processAttributes->finished = (active == false)) && processAttributes->terminateOnEod) {
pc.services().get<ControlService>().endOfStream();
pc.services().get<ControlService>().readyToQuit(framework::QuitRequest::Me);
}
};
return processFunction;
};
std::vector<OutputSpec> outputSpecs;
outputSpecs.emplace_back(OutputSpec{{"output"}, "PHS", "DIGITS", 0, Lifetime::Timeframe});
outputSpecs.emplace_back(OutputSpec{{"outputTR"}, "PHS", "DIGITTRIGREC", 0, Lifetime::Timeframe});
if (propagateMC) {
outputSpecs.emplace_back(OutputSpec{{"outputMC"}, "PHS", "DIGITSMCTR", 0, Lifetime::Timeframe});
}
return DataProcessorSpec{
"phos-digit-reader",
Inputs{}, // no inputs
outputSpecs,
AlgorithmSpec(initFunction),
Options{
{"infile", VariantType::String, "phosdigits.root", {"Name of the input file"}},
{"input-dir", VariantType::String, "none", {"Input directory"}},
{"treename", VariantType::String, "o2sim", {"Name of input tree"}},
{"nevents", VariantType::Int, -1, {"number of events to run, -1: inf loop"}},
{"terminate-on-eod", VariantType::Bool, true, {"terminate on end-of-data"}},
}};
}
///////////////Cell reader
DataProcessorSpec getCellReaderSpec(bool propagateMC)
{
auto initFunction = [propagateMC](InitContext& ic) {
// get the option from the init context
auto filename = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
ic.options().get<std::string>("infile"));
auto treename = ic.options().get<std::string>("treename");
auto nofEvents = ic.options().get<int>("nevents");
auto publishingMode = nofEvents == -1 ? RootTreeReader::PublishingMode::Single : RootTreeReader::PublishingMode::Loop;
auto processAttributes = std::make_shared<ProcessAttributes>();
{
processAttributes->terminateOnEod = ic.options().get<bool>("terminate-on-eod");
processAttributes->finished = false;
processAttributes->datatype = "PHOSCell";
o2::header::DataHeader::SubSpecificationType subSpec = 0;
if (propagateMC) {
processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
filename.c_str(), // input file name
nofEvents, // number of entries to publish
publishingMode,
RootTreeReader::BranchDefinition<std::vector<o2::phos::Cell>>{
Output{"PHS", "CELLS", subSpec}, "PHOSCell"},
RootTreeReader::BranchDefinition<std::vector<o2::phos::TriggerRecord>>{
Output{"PHS", "CELLTRIGREC", subSpec}, "PHOSCellTrigRec"},
Output{"PHS", "CELLSMCTR", subSpec},
"PHOSCellTrueMC"); // name of mc label branch
} else {
processAttributes->reader = std::make_shared<RootTreeReader>(treename.c_str(), // tree name
filename.c_str(), // input file name
nofEvents, // number of entries to publish
publishingMode,
RootTreeReader::BranchDefinition<std::vector<o2::phos::Cell>>{
Output{"PHS", "CELLS", subSpec}, "PHOSCell"},
RootTreeReader::BranchDefinition<std::vector<o2::phos::TriggerRecord>>{
Output{"PHS", "CELLTRIGREC", subSpec}, "PHOSCellTrigRec"});
}
}
auto processFunction = [processAttributes, propagateMC](ProcessingContext& pc) {
if (processAttributes->finished) {
return;
}
auto publish = [&processAttributes, &pc, propagateMC]() {
PHOSBlockHeader phosheader(true);
if (processAttributes->reader->next()) {
(*processAttributes->reader)(pc, phosheader);
} else {
processAttributes->reader.reset();
return false;
}
return true;
};
bool active(true);
if (!publish()) {
active = false;
// Send dummy header with no payload option
PHOSBlockHeader dummyheader(false);
pc.outputs().snapshot(OutputRef{"output", 0, {dummyheader}}, 0);
pc.outputs().snapshot(OutputRef{"outputTR", 0, {dummyheader}}, 0);
if (propagateMC) {
pc.outputs().snapshot(OutputRef{"outputMC", 0, {dummyheader}}, 0);
pc.outputs().snapshot(OutputRef{"outputMCmap", 0, {dummyheader}}, 0);
}
}
if ((processAttributes->finished = (active == false)) && processAttributes->terminateOnEod) {
pc.services().get<ControlService>().endOfStream();
pc.services().get<ControlService>().readyToQuit(framework::QuitRequest::Me);
}
};
return processFunction;
};
std::vector<OutputSpec> outputSpecs;
outputSpecs.emplace_back(OutputSpec{{"output"}, "PHS", "CELLS", 0, Lifetime::Timeframe});
outputSpecs.emplace_back(OutputSpec{{"outputTR"}, "PHS", "CELLTRIGREC", 0, Lifetime::Timeframe});
if (propagateMC) {
outputSpecs.emplace_back(OutputSpec{{"outputMC"}, "PHS", "CELLSMCTR", 0, Lifetime::Timeframe});
outputSpecs.emplace_back(OutputSpec{{"outputMCmap"}, "PHS", "CELLSMCMAP", 0, Lifetime::Timeframe});
}
return DataProcessorSpec{
"phos-cell-reader",
Inputs{}, // no inputs
outputSpecs,
AlgorithmSpec(initFunction),
Options{
{"infile", VariantType::String, "phoscells.root", {"Name of the input file"}},
{"input-dir", VariantType::String, "none", {"Input directory"}},
{"treename", VariantType::String, "o2sim", {"Name of input tree"}},
{"nevents", VariantType::Int, -1, {"number of events to run, -1: inf loop"}},
{"terminate-on-eod", VariantType::Bool, true, {"terminate on end-of-data"}},
}};
}
} // namespace phos
} // namespace o2