-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathO2ControlHelpers.cxx
More file actions
114 lines (109 loc) · 3.78 KB
/
O2ControlHelpers.cxx
File metadata and controls
114 lines (109 loc) · 3.78 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
// 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 "O2ControlHelpers.h"
#include "ChannelSpecHelpers.h"
#include <map>
#include <iostream>
#include <cstring>
namespace o2
{
namespace framework
{
void dumpDeviceSpec2O2Control(std::ostream& out,
const std::vector<DeviceSpec>& specs,
const std::vector<DeviceExecution>& executions)
{
out << R"(- o2:)"
<< "\n";
out << R"( tasks:)"
<< "\n";
assert(specs.size() == executions.size());
for (size_t di = 0; di < specs.size(); ++di) {
auto& spec = specs[di];
auto& execution = executions[di];
out << R"( - name: )" << spec.id << "\n";
out << R"( control: )"
<< "\n";
out << R"( mode: "fairmq")"
<< "\n";
if (spec.outputChannels.empty()) {
out << R"( bind: [])"
<< "\n";
} else {
out << R"( bind: )"
<< "\n";
for (auto& channel : spec.outputChannels) {
out << R"( - name: ")" << channel.name << "\"\n";
out << R"( type: ")" << ChannelSpecHelpers::typeAsString(channel.type) << "\"\n";
}
}
out << R"( command:)"
<< "\n";
out << R"( - shell: true)"
<< "\n";
out << R"( - value: )" << execution.args[0] << "\n";
out << R"( - arguments:)"
<< "\n";
out << R"( - -b)"
<< "\n";
out << R"( - --monitoring-backend)"
<< "\n";
out << R"( - no-op://)"
<< "\n";
for (size_t ai = 1; ai < execution.args.size(); ++ai) {
const char* option = execution.args[ai];
const char* value = nullptr; // no value by default (i.e. a boolean)
// If the subsequent option exists and does not start with -, we assume
// it is an argument to the previous one.
if (ai + 1 < execution.args.size() && execution.args[ai + 1][0] != '-') {
value = execution.args[ai + 1];
ai++;
}
if (!option) {
break;
}
// Do not print out channel information
if (strcmp(option, "--channel-config") == 0) {
ai += 2;
continue;
} else if (strcmp(option, "--control") == 0) {
continue;
}
out << R"( - )" << option << "\n";
if (value) {
out << R"( - )" << value << "\n";
}
}
out << "\n";
}
out << " workflows:\n";
out << " o2-workflow:\n";
out << " name: \"o2-workflow-roles\"\n";
out << " roles: \"\n";
for (size_t di = 0; di < specs.size(); ++di) {
auto& spec = specs[di];
out << " - name: \"" << spec.name << "\"\n";
out << " connect:\n";
for (auto& channel : spec.inputChannels) {
out << R"( - name: ")" << channel.name << "\"\n";
// FIXME: Until we get a {{workflow}} placeholder.
std::string sourceDevice = channel.name;
sourceDevice.erase(0, 5);
auto startSuffix = sourceDevice.find_last_of("_to_");
sourceDevice = sourceDevice.substr(0, startSuffix - 3);
out << R"( target: "{{parent}}.)" << sourceDevice << ":" << channel.name << "\"\n";
out << R"( type: ")" << ChannelSpecHelpers::typeAsString(channel.type) << "\"\n";
}
out << " task:\n";
out << " load: " << spec.name << "\n";
}
}
} // namespace framework
} // namespace o2