|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | +#include "O2ControlHelpers.h" |
| 11 | +#include "ChannelSpecHelpers.h" |
| 12 | +#include <map> |
| 13 | +#include <iostream> |
| 14 | +#include <cstring> |
| 15 | + |
| 16 | +namespace o2 |
| 17 | +{ |
| 18 | +namespace framework |
| 19 | +{ |
| 20 | + |
| 21 | +void dumpDeviceSpec2O2Control(std::ostream& out, |
| 22 | + const std::vector<DeviceSpec>& specs, |
| 23 | + const std::vector<DeviceExecution>& executions) |
| 24 | +{ |
| 25 | + out << R"(- o2:)" |
| 26 | + << "\n"; |
| 27 | + out << R"( tasks:)" |
| 28 | + << "\n"; |
| 29 | + assert(specs.size() == executions.size()); |
| 30 | + |
| 31 | + for (size_t di = 0; di < specs.size(); ++di) { |
| 32 | + auto& spec = specs[di]; |
| 33 | + auto& execution = executions[di]; |
| 34 | + |
| 35 | + out << R"( - name: )" << spec.id << "\n"; |
| 36 | + out << R"( control: )" |
| 37 | + << "\n"; |
| 38 | + out << R"( mode: "fairmq")" |
| 39 | + << "\n"; |
| 40 | + if (spec.outputChannels.empty()) { |
| 41 | + out << R"( bind: [])" |
| 42 | + << "\n"; |
| 43 | + } else { |
| 44 | + out << R"( bind: )" |
| 45 | + << "\n"; |
| 46 | + for (auto& channel : spec.outputChannels) { |
| 47 | + out << R"( - name: ")" << channel.name << "\"\n"; |
| 48 | + out << R"( type: ")" << ChannelSpecHelpers::typeAsString(channel.type) << "\"\n"; |
| 49 | + } |
| 50 | + } |
| 51 | + out << R"( command:)" |
| 52 | + << "\n"; |
| 53 | + out << R"( - shell: true)" |
| 54 | + << "\n"; |
| 55 | + out << R"( - value: )" << execution.args[0] << "\n"; |
| 56 | + out << R"( - arguments:)" |
| 57 | + << "\n"; |
| 58 | + out << R"( - -b)" |
| 59 | + << "\n"; |
| 60 | + out << R"( - --monitoring-backend)" |
| 61 | + << "\n"; |
| 62 | + out << R"( - no-op://)" |
| 63 | + << "\n"; |
| 64 | + for (size_t ai = 1; ai < execution.args.size(); ++ai) { |
| 65 | + const char* option = execution.args[ai]; |
| 66 | + const char* value = nullptr; // no value by default (i.e. a boolean) |
| 67 | + // If the subsequent option exists and does not start with -, we assume |
| 68 | + // it is an argument to the previous one. |
| 69 | + if (ai + 1 < execution.args.size() && execution.args[ai + 1][0] != '-') { |
| 70 | + value = execution.args[ai + 1]; |
| 71 | + ai++; |
| 72 | + } |
| 73 | + if (!option) { |
| 74 | + break; |
| 75 | + } |
| 76 | + // Do not print out channel information |
| 77 | + if (strcmp(option, "--channel-config") == 0) { |
| 78 | + ai += 2; |
| 79 | + continue; |
| 80 | + } else if (strcmp(option, "--control") == 0) { |
| 81 | + continue; |
| 82 | + } |
| 83 | + out << R"( - )" << option << "\n"; |
| 84 | + if (value) { |
| 85 | + out << R"( - )" << value << "\n"; |
| 86 | + } |
| 87 | + } |
| 88 | + out << "\n"; |
| 89 | + } |
| 90 | + out << " workflows:\n"; |
| 91 | + out << " o2-workflow:\n"; |
| 92 | + out << " name: \"o2-workflow-roles\"\n"; |
| 93 | + out << " roles: \"\n"; |
| 94 | + for (size_t di = 0; di < specs.size(); ++di) { |
| 95 | + auto& spec = specs[di]; |
| 96 | + out << " - name: \"" << spec.name << "\"\n"; |
| 97 | + out << " connect:\n"; |
| 98 | + for (auto& channel : spec.inputChannels) { |
| 99 | + out << R"( - name: ")" << channel.name << "\"\n"; |
| 100 | + // FIXME: Until we get a {{workflow}} placeholder. |
| 101 | + std::string sourceDevice = channel.name; |
| 102 | + sourceDevice.erase(0, 5); |
| 103 | + auto startSuffix = sourceDevice.find_last_of("_to_"); |
| 104 | + sourceDevice = sourceDevice.substr(0, startSuffix - 3); |
| 105 | + out << R"( target: "{{parent}}.)" << sourceDevice << ":" << channel.name << "\"\n"; |
| 106 | + out << R"( type: ")" << ChannelSpecHelpers::typeAsString(channel.type) << "\"\n"; |
| 107 | + } |
| 108 | + out << " task:\n"; |
| 109 | + out << " load: " << spec.name << "\n"; |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +} // namespace framework |
| 114 | +} // namespace o2 |
0 commit comments