-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDataSampling.cxx
More file actions
209 lines (180 loc) · 8.14 KB
/
DataSampling.cxx
File metadata and controls
209 lines (180 loc) · 8.14 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
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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.
/// \file DataSampling.cxx
/// \brief Implementation of O2 Data Sampling, v1.0
///
/// \author Piotr Konopka, piotr.jan.konopka@cern.ch
#include "DataSampling/DataSampling.h"
#include "DataSampling/DataSamplingPolicy.h"
#include "DataSampling/Dispatcher.h"
#include "Framework/CompletionPolicyHelpers.h"
#include "Framework/DataSpecUtils.h"
#include "Framework/Logger.h"
#include <Configuration/ConfigurationInterface.h>
#include <Configuration/ConfigurationFactory.h>
using namespace o2::configuration;
using namespace o2::framework;
using SubSpecificationType = o2::header::DataHeader::SubSpecificationType;
namespace o2::utilities
{
std::string DataSampling::createDispatcherName()
{
return std::string("Dispatcher"); //_") + getenv("HOSTNAME");
}
void DataSampling::GenerateInfrastructure(WorkflowSpec& workflow, const std::string& policiesSource, size_t threads)
{
std::unique_ptr<ConfigurationInterface> cfg = ConfigurationFactory::getConfiguration(policiesSource);
if (cfg->getRecursive("").count("dataSamplingPolicies") == 0) {
LOG(WARN) << "No \"dataSamplingPolicies\" structure found in the config file. If no Data Sampling is expected, then it is completely fine.";
return;
}
auto policiesTree = cfg->getRecursive("dataSamplingPolicies");
Dispatcher dispatcher(createDispatcherName(), policiesSource);
DataSampling::DoGenerateInfrastructure(dispatcher, workflow, policiesTree, threads);
}
void DataSampling::GenerateInfrastructure(WorkflowSpec& workflow, const boost::property_tree::ptree& policiesTree, size_t threads)
{
Dispatcher dispatcher(createDispatcherName(), "");
DataSampling::DoGenerateInfrastructure(dispatcher, workflow, policiesTree, threads);
}
void DataSampling::DoGenerateInfrastructure(Dispatcher& dispatcher, WorkflowSpec& workflow, const boost::property_tree::ptree& policiesTree, size_t threads)
{
LOG(DEBUG) << "Generating Data Sampling infrastructure...";
for (auto&& policyConfig : policiesTree) {
std::unique_ptr<DataSamplingPolicy> policy;
// We don't want the Dispatcher to exit due to one faulty Policy
try {
dispatcher.registerPolicy(std::make_unique<DataSamplingPolicy>(DataSamplingPolicy::fromConfiguration(policyConfig.second)));
} catch (const std::exception& ex) {
LOG(WARN) << "Could not load the Data Sampling Policy '"
<< policyConfig.second.get_optional<std::string>("id").value_or("") << "', because: " << ex.what();
continue;
} catch (...) {
LOG(WARN) << "Could not load the Data Sampling Policy '"
<< policyConfig.second.get_optional<std::string>("id").value_or("") << "'";
continue;
}
}
if (dispatcher.numberOfPolicies() > 0) {
DataProcessorSpec spec;
spec.name = dispatcher.getName();
spec.inputs = dispatcher.getInputSpecs();
spec.outputs = dispatcher.getOutputSpecs();
spec.maxInputTimeslices = threads;
spec.labels = {{"DataSampling"}, {"Dispatcher"}};
spec.options = dispatcher.getOptions();
spec.algorithm = adaptFromTask<Dispatcher>(std::move(dispatcher));
workflow.emplace_back(std::move(spec));
} else {
LOG(DEBUG) << "No input to this dispatcher, it won't be added to the workflow.";
}
}
void DataSampling::CustomizeInfrastructure(std::vector<CompletionPolicy>& policies)
{
CompletionPolicy dispatcherConsumesASAP = CompletionPolicyHelpers::defineByName(createDispatcherName(), CompletionPolicy::CompletionOp::Consume);
policies.push_back(dispatcherConsumesASAP);
}
void DataSampling::CustomizeInfrastructure(std::vector<ChannelConfigurationPolicy>& policies)
{
// todo: add push-pull for channels that require blocking
// now it cannot be done, since matching is possible only using data processors names
}
std::vector<InputSpec> DataSampling::InputSpecsForPolicy(const std::string& policiesSource, const std::string& policyName)
{
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
return InputSpecsForPolicy(config.get(), policyName);
}
std::vector<InputSpec> DataSampling::InputSpecsForPolicy(ConfigurationInterface* const config, const std::string& policyName)
{
std::vector<InputSpec> inputs;
auto policiesTree = config->getRecursive("dataSamplingPolicies");
for (auto&& policyConfig : policiesTree) {
if (policyConfig.second.get<std::string>("id") == policyName) {
auto policy = DataSamplingPolicy::fromConfiguration(policyConfig.second);
for (const auto& path : policy.getPathMap()) {
InputSpec input = DataSpecUtils::matchingInput(path.second);
inputs.push_back(input);
}
break;
}
}
return inputs;
}
std::vector<InputSpec> DataSampling::InputSpecsForPolicy(std::shared_ptr<configuration::ConfigurationInterface> config, const std::string& policyName)
{
std::vector<InputSpec> inputs;
auto policiesTree = config->getRecursive("dataSamplingPolicies");
for (auto&& policyConfig : policiesTree) {
if (policyConfig.second.get<std::string>("id") == policyName) {
auto policy = DataSamplingPolicy::fromConfiguration(policyConfig.second);
for (const auto& path : policy.getPathMap()) {
InputSpec input = DataSpecUtils::matchingInput(path.second);
inputs.push_back(input);
}
break;
}
}
return inputs;
}
std::vector<OutputSpec> DataSampling::OutputSpecsForPolicy(const std::string& policiesSource, const std::string& policyName)
{
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
return OutputSpecsForPolicy(config.get(), policyName);
}
std::vector<OutputSpec> DataSampling::OutputSpecsForPolicy(ConfigurationInterface* const config, const std::string& policyName)
{
std::vector<OutputSpec> outputs;
auto policiesTree = config->getRecursive("dataSamplingPolicies");
for (auto&& policyConfig : policiesTree) {
if (policyConfig.second.get<std::string>("id") == policyName) {
auto policy = DataSamplingPolicy::fromConfiguration(policyConfig.second);
for (const auto& path : policy.getPathMap()) {
outputs.push_back(path.second);
}
break;
}
}
return outputs;
}
uint16_t DataSampling::PortForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName)
{
auto policiesTree = config->getRecursive("dataSamplingPolicies");
for (auto&& policyConfig : policiesTree) {
if (policyConfig.second.get<std::string>("id") == policyName) {
return policyConfig.second.get<uint16_t>("port");
}
}
throw std::runtime_error("Could not find the policy '" + policyName + "'");
}
uint16_t DataSampling::PortForPolicy(const std::string& policiesSource, const std::string& policyName)
{
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
return PortForPolicy(config.get(), policyName);
}
std::vector<std::string> DataSampling::MachinesForPolicy(configuration::ConfigurationInterface* const config, const std::string& policyName)
{
std::vector<std::string> machines;
auto policiesTree = config->getRecursive("dataSamplingPolicies");
for (auto&& policyConfig : policiesTree) {
if (policyConfig.second.get<std::string>("id") == policyName) {
for (const auto& machine : policyConfig.second.get_child("machines")) {
machines.emplace_back(machine.second.get<std::string>(""));
}
return machines;
}
}
throw std::runtime_error("Could not find the policy '" + policyName + "'");
}
std::vector<std::string> DataSampling::MachinesForPolicy(const std::string& policiesSource, const std::string& policyName)
{
std::unique_ptr<ConfigurationInterface> config = ConfigurationFactory::getConfiguration(policiesSource);
return MachinesForPolicy(config.get(), policyName);
}
} // namespace o2::utilities