-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathdpl-output-proxy.cxx
More file actions
104 lines (91 loc) · 4.59 KB
/
dpl-output-proxy.cxx
File metadata and controls
104 lines (91 loc) · 4.59 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
// 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.
#include "Framework/WorkflowSpec.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Logger.h"
#include "Framework/ConfigParamSpec.h"
#include "Framework/ExternalFairMQDeviceProxy.h"
#include <vector>
using namespace o2::framework;
// we need to add workflow options before including Framework/runDataProcessing
void customize(std::vector<ConfigParamSpec>& workflowOptions)
{
workflowOptions.push_back(
ConfigParamSpec{
"proxy-name", VariantType::String, "dpl-output-proxy", {"name of the proxy processor, will be the default output channel name as well"}});
workflowOptions.push_back(
ConfigParamSpec{
"dataspec", VariantType::String, "dpl-output-proxy:TST/CLUSTERS;dpl-output-proxy:TST/TRACKS", {"selection string for the data to be proxied"}});
workflowOptions.push_back(
ConfigParamSpec{
"output-proxy-method", VariantType::String, "bind", {"proxy socket method: bind, connect"}});
workflowOptions.push_back(
ConfigParamSpec{
"output-proxy-address", VariantType::String, "0.0.0.0", {"address to connect / bind to"}});
workflowOptions.push_back(
ConfigParamSpec{
"default-transport", VariantType::String, "shmem", {"default transport: shmem, zeromq"}});
workflowOptions.push_back(
ConfigParamSpec{
"default-port", VariantType::Int, 4200, {"default port number"}});
}
#include "Framework/runDataProcessing.h"
WorkflowSpec defineDataProcessing(ConfigContext const& config)
{
std::string processorName = config.options().get<std::string>("proxy-name");
std::string inputConfig = config.options().get<std::string>("dataspec");
int defaultPort = config.options().get<int>("default-port");
std::string defaultTransportConfig = config.options().get<std::string>("default-transport");
if (defaultTransportConfig == "zeromq") {
// nothing to do for the moment
} else if (defaultTransportConfig == "shmem") {
// nothing to do for the moment
} else {
throw std::runtime_error("invalid argument for option --default-transport : '" + defaultTransportConfig + "'");
}
std::vector<InputSpec> inputs = select(inputConfig.c_str());
if (inputs.size() == 0) {
throw std::runtime_error("invalid dataspec '" + inputConfig + "'");
}
// we build the default channel configuration from the binding of the first input
// in order to have more than one we would need to possibility to have support for
// vectored options
// use the OutputChannelSpec as a tool to create the default configuration for the out-of-band channel
OutputChannelSpec externalChannelSpec;
externalChannelSpec.name = "downstream";
externalChannelSpec.type = ChannelType::Push;
if (config.options().get<std::string>("output-proxy-method") == "bind") {
externalChannelSpec.method = ChannelMethod::Bind;
} else if (config.options().get<std::string>("output-proxy-method") == "connect") {
externalChannelSpec.method = ChannelMethod::Connect;
}
externalChannelSpec.hostname = config.options().get<std::string>("output-proxy-address");
externalChannelSpec.port = defaultPort;
externalChannelSpec.listeners = 0;
// in principle, protocol and transport are two different things but fur simplicity
// we use ipc when shared memory is selected and the normal tcp url whith zeromq,
// this is for building the default configuration which can be simply changed from the
// command line
if (!defaultTransportConfig.empty()) {
if (defaultTransportConfig == "zeromq") {
externalChannelSpec.protocol = ChannelProtocol::Network;
} else if (defaultTransportConfig == "shmem") {
externalChannelSpec.protocol = ChannelProtocol::IPC;
}
}
std::string defaultChannelConfig = formatExternalChannelConfiguration(externalChannelSpec);
// at some point the formatting tool might add the transport as well so we have to check
if (!defaultTransportConfig.empty() && defaultTransportConfig.find("transport=") == std::string::npos) {
defaultChannelConfig += ",transport=" + defaultTransportConfig;
}
std::vector<DataProcessorSpec> workflow;
workflow.emplace_back(std::move(specifyFairMQDeviceOutputProxy(processorName.c_str(), inputs, defaultChannelConfig.c_str())));
return workflow;
}