forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisSupportHelpers.cxx
More file actions
269 lines (248 loc) · 10.1 KB
/
AnalysisSupportHelpers.cxx
File metadata and controls
269 lines (248 loc) · 10.1 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// 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 "Framework/AnalysisSupportHelpers.h"
#include "Framework/DataOutputDirector.h"
#include "Framework/OutputObjHeader.h"
#include "Framework/ControlService.h"
#include "Framework/EndOfStreamContext.h"
#include "Framework/DeviceSpec.h"
#include "Framework/PluginManager.h"
#include "Framework/ConfigContext.h"
#include "WorkflowHelpers.h"
template class std::vector<o2::framework::OutputObjectInfo>;
template class std::vector<o2::framework::OutputTaskInfo>;
namespace o2::framework
{
std::shared_ptr<DataOutputDirector> AnalysisSupportHelpers::getDataOutputDirector(ConfigContext const& ctx)
{
auto const& options = ctx.options();
auto const& OutputsInputs = ctx.services().get<AnalysisContext>().outputsInputs;
auto const& isDangling = ctx.services().get<AnalysisContext>().isDangling;
std::shared_ptr<DataOutputDirector> dod = std::make_shared<DataOutputDirector>();
// analyze options and take actions accordingly
// default values
std::string rdn, resdir("./");
std::string fnb, fnbase("AnalysisResults_trees");
float mfs, maxfilesize(-1.);
std::string fmo, filemode("RECREATE");
int ntfm, ntfmerge = 1;
// values from json
if (options.isSet("aod-writer-json")) {
auto fnjson = options.get<std::string>("aod-writer-json");
if (!fnjson.empty()) {
std::tie(rdn, fnb, fmo, mfs, ntfm) = dod->readJson(fnjson);
if (!rdn.empty()) {
resdir = rdn;
}
if (!fnb.empty()) {
fnbase = fnb;
}
if (!fmo.empty()) {
filemode = fmo;
}
if (mfs > 0.) {
maxfilesize = mfs;
}
if (ntfm > 0) {
ntfmerge = ntfm;
}
}
}
// values from command line options, information from json is overwritten
if (options.isSet("aod-writer-resdir")) {
rdn = options.get<std::string>("aod-writer-resdir");
if (!rdn.empty()) {
resdir = rdn;
}
}
if (options.isSet("aod-writer-resfile")) {
fnb = options.get<std::string>("aod-writer-resfile");
if (!fnb.empty()) {
fnbase = fnb;
}
}
if (options.isSet("aod-writer-resmode")) {
fmo = options.get<std::string>("aod-writer-resmode");
if (!fmo.empty()) {
filemode = fmo;
}
}
if (options.isSet("aod-writer-maxfilesize")) {
mfs = options.get<float>("aod-writer-maxfilesize");
if (mfs > 0) {
maxfilesize = mfs;
}
}
if (options.isSet("aod-writer-ntfmerge")) {
ntfm = options.get<int>("aod-writer-ntfmerge");
if (ntfm > 0) {
ntfmerge = ntfm;
}
}
// parse the keepString
if (options.isSet("aod-writer-keep")) {
auto keepString = options.get<std::string>("aod-writer-keep");
if (!keepString.empty()) {
dod->reset();
std::string d("dangling");
if (d.find(keepString) == 0) {
// use the dangling outputs
std::vector<InputSpec> danglingOutputs;
for (auto ii = 0u; ii < OutputsInputs.size(); ii++) {
if (DataSpecUtils::partialMatch(OutputsInputs[ii], writableAODOrigins) && isDangling[ii]) {
danglingOutputs.emplace_back(OutputsInputs[ii]);
}
}
dod->readSpecs(danglingOutputs);
} else {
// use the keep string
dod->readString(keepString);
}
}
}
dod->setResultDir(resdir);
dod->setFilenameBase(fnbase);
dod->setFileMode(filemode);
dod->setMaximumFileSize(maxfilesize);
dod->setNumberTimeFramesToMerge(ntfmerge);
return dod;
}
void AnalysisSupportHelpers::addMissingOutputsToReader(std::vector<OutputSpec> const& providedOutputs,
std::vector<InputSpec> const& requestedInputs,
DataProcessorSpec& publisher)
{
auto matchingOutputFor = [](InputSpec const& requested) {
return [&requested](OutputSpec const& provided) {
return DataSpecUtils::match(requested, provided);
};
};
for (InputSpec const& requested : requestedInputs) {
auto provided = std::find_if(providedOutputs.begin(),
providedOutputs.end(),
matchingOutputFor(requested));
if (provided != providedOutputs.end()) {
continue;
}
auto inList = std::find_if(publisher.outputs.begin(),
publisher.outputs.end(),
matchingOutputFor(requested));
if (inList != publisher.outputs.end()) {
continue;
}
auto concrete = DataSpecUtils::asConcreteDataMatcher(requested);
publisher.outputs.emplace_back(concrete.origin, concrete.description, concrete.subSpec, requested.lifetime, requested.metadata);
}
}
void AnalysisSupportHelpers::addMissingOutputsToSpawner(std::vector<OutputSpec> const& providedSpecials,
std::vector<InputSpec> const& requestedSpecials,
std::vector<InputSpec>& requestedAODs,
DataProcessorSpec& publisher)
{
for (auto& input : requestedSpecials) {
if (std::any_of(providedSpecials.begin(), providedSpecials.end(), [&input](auto const& x) {
return DataSpecUtils::match(input, x);
})) {
continue;
}
auto concrete = DataSpecUtils::asConcreteDataMatcher(input);
publisher.outputs.emplace_back(concrete.origin, concrete.description, concrete.subSpec);
for (auto& i : input.metadata) {
if ((i.type == VariantType::String) && (i.name.find("input:") != std::string::npos)) {
auto spec = DataSpecUtils::fromMetadataString(i.defaultValue.get<std::string>());
auto j = std::find(publisher.inputs.begin(), publisher.inputs.end(), spec);
if (j == publisher.inputs.end()) {
publisher.inputs.push_back(spec);
}
DataSpecUtils::updateInputList(requestedAODs, std::move(spec));
}
}
}
}
void AnalysisSupportHelpers::addMissingOutputsToBuilder(std::vector<InputSpec> const& requestedSpecials,
std::vector<InputSpec>& requestedAODs,
std::vector<InputSpec>& requestedDYNs,
DataProcessorSpec& publisher)
{
for (auto& input : requestedSpecials) {
auto concrete = DataSpecUtils::asConcreteDataMatcher(input);
publisher.outputs.emplace_back(concrete.origin, concrete.description, concrete.subSpec);
for (auto& i : input.metadata) {
if ((i.type == VariantType::String) && (i.name.find("input:") != std::string::npos)) {
auto spec = DataSpecUtils::fromMetadataString(i.defaultValue.get<std::string>());
auto j = std::find_if(publisher.inputs.begin(), publisher.inputs.end(), [&](auto x) { return x.binding == spec.binding; });
if (j == publisher.inputs.end()) {
publisher.inputs.push_back(spec);
}
if (DataSpecUtils::partialMatch(spec, AODOrigins)) {
DataSpecUtils::updateInputList(requestedAODs, std::move(spec));
} else if (DataSpecUtils::partialMatch(spec, header::DataOrigin{"DYN"})) {
DataSpecUtils::updateInputList(requestedDYNs, std::move(spec));
}
}
}
}
}
void AnalysisSupportHelpers::addMissingOutputsToAnalysisCCDBFetcher(
std::vector<OutputSpec> const& providedSpecials,
std::vector<InputSpec> const& requestedSpecials,
std::vector<InputSpec>& requestedAODs,
std::vector<InputSpec>& requestedDYNs,
DataProcessorSpec& publisher)
{
for (auto& input : requestedSpecials) {
auto concrete = DataSpecUtils::asConcreteDataMatcher(input);
publisher.outputs.emplace_back(concrete.origin, concrete.description, concrete.subSpec);
// FIXME: good enough for now...
for (auto& i : input.metadata) {
if ((i.type == VariantType::String) && (i.name.find("input:") != std::string::npos)) {
auto spec = DataSpecUtils::fromMetadataString(i.defaultValue.get<std::string>());
auto j = std::find_if(publisher.inputs.begin(), publisher.inputs.end(), [&](auto x) { return x.binding == spec.binding; });
if (j == publisher.inputs.end()) {
publisher.inputs.push_back(spec);
}
if (DataSpecUtils::partialMatch(spec, AODOrigins)) {
DataSpecUtils::updateInputList(requestedAODs, std::move(spec));
} else if (DataSpecUtils::partialMatch(spec, header::DataOrigin{"DYN"})) {
DataSpecUtils::updateInputList(requestedDYNs, std::move(spec));
}
}
}
}
}
// =============================================================================
DataProcessorSpec AnalysisSupportHelpers::getOutputObjHistSink(ConfigContext const& ctx)
{
// Lifetime is sporadic because we do not ask each analysis task to send its
// results every timeframe.
DataProcessorSpec spec{
.name = "internal-dpl-aod-global-analysis-file-sink",
.inputs = {InputSpec("x", DataSpecUtils::dataDescriptorMatcherFrom(header::DataOrigin{"ATSK"}), Lifetime::Sporadic)},
.outputs = {},
.algorithm = PluginManager::loadAlgorithmFromPlugin("O2FrameworkAnalysisSupport", "ROOTObjWriter", ctx),
};
return spec;
}
// add sink for the AODs
DataProcessorSpec
AnalysisSupportHelpers::getGlobalAODSink(ConfigContext const& ctx)
{
auto& ac = ctx.services().get<AnalysisContext>();
// the command line options relevant for the writer are global
// see runDataProcessing.h
DataProcessorSpec spec{
.name = "internal-dpl-aod-writer",
.inputs = ac.outputsInputsAOD,
.outputs = {},
.algorithm = PluginManager::loadAlgorithmFromPlugin("O2FrameworkAnalysisSupport", "ROOTTTreeWriter", ctx),
};
return spec;
}
} // namespace o2::framework