Project
Loading...
Searching...
No Matches
ServiceSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include "Framework/Logger.h"
15#include "Framework/Plugins.h"
16#include <sstream>
17#include <unordered_set>
18#include <uv.h>
19
20namespace o2::framework
21{
22
23auto findOverrideByName = [](std::string_view name) {
24 return [name](const OverrideServiceSpec& spec) { return spec.name == name; };
25};
26
28{
29 if (overrideString == nullptr || *overrideString == '\0') {
30 return {};
31 }
32 // Helper to split a string into a vector of string_views
33 auto split = [](std::string_view str, char delim) {
34 std::vector<std::string_view> result;
35 std::string_view::size_type start = 0;
36 auto end = str.find(delim);
37 while (end != std::string_view::npos) {
38 result.push_back(str.substr(start, end - start));
39 start = end + 1;
40 end = str.find(delim, start);
41 }
42 result.push_back(str.substr(start, end));
43 return result;
44 };
45
46 // if it is set, it will be a comma separated list of service names and their
47 // enabled/disabled status.
48 // if the service is enabled, it will be added to the list of services to be forced to be enabled.
49 // if the service is disabled, it will be added to the list of services to be forced to be disabled.
50
51 // Keep it simple. This is only a few elements, so we can use a vector.
52 std::vector<OverrideServiceSpec> overrides;
53 auto msg =
54 "DPL(_DRIVER)_OVERRIDE_SERVICES must be a comma separated list of service names and their enabled/disabled status. "
55 "The format is <service name>:<enable/disable/1/0>"
56 "Error while parsing: " +
57 std::string(overrideString);
58 auto overrideList = split(overrideString, ',');
59 for (auto& overrideStr : overrideList) {
60 auto overrideParts = split(overrideStr, ':');
61 if (overrideParts.size() != 2) {
62 throw std::runtime_error(msg.data());
63 }
64 bool active;
65 std::string serviceName{overrideParts[0]};
66 if (overrideParts[1] == "1") {
67 active = true;
68 } else if (overrideParts[1] == "0") {
69 active = false;
70 } else if (overrideParts[1] == "enable") {
71 active = true;
72 } else if (overrideParts[1] == "disable") {
73 active = false;
74 } else {
75 throw std::runtime_error(msg.data());
76 }
77 if (std::find_if(overrides.begin(), overrides.end(), findOverrideByName(serviceName)) != overrides.end()) {
78 throw std::runtime_error("Duplicate service name in DPL(_DRIVER)_OVERRIDE_SERVICES: " + serviceName);
79 }
80 overrides.push_back(OverrideServiceSpec{serviceName, active});
81 }
82 // Print the configuration
83 LOG(detail) << "The following services will be overridden by the DPL_OVERRIDE_SERVICES environment variable:";
84 for (auto& override : overrides) {
85 LOG(detail) << override.name << ": " << override.active;
86 }
87 return overrides;
88};
89
91{
92
93 std::vector<ServiceSpec> result;
94 for (auto& original : originals) {
95 auto override = std::find_if(overrides.begin(), overrides.end(), findOverrideByName(original.name));
96 if (override != overrides.end()) {
97 LOGP(detail, "Overriding service {} to {}", original.name, override->active ? "enabled" : "disabled");
98 original.active = override->active;
99 }
100 if (original.active) {
101 result.push_back(original);
102 }
103 }
104 return result;
105}
106
107} // namespace o2::framework
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint GLuint end
Definition glcorearb.h:469
GLuint const GLchar * name
Definition glcorearb.h:781
GLuint start
Definition glcorearb.h:469
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ServiceSpec > ServiceSpecs
std::vector< OverrideServiceSpec > OverrideServiceSpecs
auto findOverrideByName
std::vector< std::string > split(const std::string &str, char delimiter=',')
static OverrideServiceSpecs parseOverrides(char const *overrideString)
static ServiceSpecs filterDisabled(ServiceSpecs originals, OverrideServiceSpecs const &overrides)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
const std::string str
uint64_t const void const *restrict const msg
Definition x9.h:153