Skip to content

Commit 1d57ee0

Browse files
authored
Merge pull request #287 from sy-c/master
v2.27.0
2 parents 3b75a2f + eb3d0ff commit 1d57ee0

File tree

7 files changed

+92
-33
lines changed

7 files changed

+92
-33
lines changed

doc/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,13 @@ General settings are defined in section `[readout]`.
143143
Section names ending with `-*` can be used to define default parameters. They are applied to all section with similar names. Existing key-value pairs are not overwritten, but are defined according to defaults if they don't exist. For example, it is possible to define the TFperiod for all equipments by adding a section named `[equipment-*]` with `TFperiod=32`.
144144

145145
Values can be symbolic links to a value stored in another configuration file. The syntax is: @LINK,URI,entryPoint,path
146-
For example: @LINK,file:/local/readout-test-config-link1.cfg,,bank.size
147-
Parameters are similar to the command-line arguments of o2-readout-exe, see ```Usage``` below.
146+
The URI can be absolute (file:, consul-ini://) or relative (./, ../) to the current configuration URI used by o2-readout-exe (whatever the backend).
147+
For example:
148+
- @LINK,file:/local/readout-test-config-link1.cfg,,bank.size
149+
- @LINK,consul-ini://alio2-cr1-hv-mvs00.cern.ch:8500/o2/components/readout/ANY/any/readout-global-params,,bank.size
150+
- @LINK,./readout-test-config-link1.cfg,,bank.size
151+
- @LINK,../readout-test-config-link1.cfg,,bank.size
152+
Parameters URI and entryPoint are similar to the command-line arguments of o2-readout-exe, see ```Usage``` below.
148153
Files are cached, i.e. the corresponding configuration tree is loaded only once if several values use a link to the same URI/entryPoint.
149154
Links substitutions are done at the end of the configuration tree aggregation (sections merging, etc).
150155
It is done recursively (up to 5 iterations, after which it fails to avoid circular dependencies).

doc/releaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,7 @@ This file describes the main feature changes for each readout.exe released versi
648648

649649
## v2.26.3 - 22/10/2024
650650
- Minor release for osx compatibility.
651+
652+
## v2.27.0 - 21/01/2024
653+
- Added symbolic links with relative path in configuration. See @LINK syntax.
654+
- Fixed o2-readout-config-generator for RHEL9 compatibility.

src/ReadoutUtils.cxx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,51 @@ void setThreadName(const char* name) {
322322
(void)name;
323323
#endif
324324
}
325+
326+
327+
// @brief Splits a URI string into its scheme and the rest of the URI.
328+
//
329+
// This function parses a given URI and separates it into two parts:
330+
// 1. The scheme (including the colon and double slashes if present)
331+
// 2. The rest of the URI
332+
//
333+
// The function handles the following cases:
334+
// - URIs with "://" (e.g., "http://", "consul-ini://")
335+
// - URIs with only ":" (e.g., "file:")
336+
// - File URIs with varying numbers of slashes (e.g., "file:", "file:/", "file:///")
337+
// - URIs without a scheme
338+
//
339+
// @param uri The input URI string to be split.
340+
// @return A std::pair where:
341+
// - first: The scheme part of the URI (including ":" or "://")
342+
// - second: The rest of the URI after the scheme
343+
// If no scheme is found, first will be empty and second will contain the entire input string.
344+
//
345+
// @note The function does not validate the URI format beyond identifying the scheme.
346+
// It assumes the input is a well-formed URI string.
347+
//
348+
// @example
349+
// auto [scheme, rest] = splitURI("http://example.com");
350+
// // scheme = "http://", rest = "example.com"
351+
//
352+
// auto [scheme, rest] = splitURI("file:///path/to/file");
353+
// // scheme = "file://", rest = "/path/to/file"
354+
//
355+
// This code was generated with the assistance of GitLab Duo Chat, an AI-powered coding assistant.
356+
357+
std::pair<std::string, std::string> splitURI(const std::string& uri) {
358+
constexpr std::string_view double_slash = "://";
359+
auto double_slash_pos = uri.find(double_slash);
360+
if (double_slash_pos != std::string::npos) {
361+
std::string scheme = uri.substr(0, double_slash_pos + double_slash.length());
362+
std::string rest = uri.substr(double_slash_pos + double_slash.length());
363+
return {std::move(scheme), std::move(rest)};
364+
}
365+
auto single_colon_pos = uri.find(':');
366+
if (single_colon_pos != std::string::npos) {
367+
std::string scheme = uri.substr(0, single_colon_pos + 1);
368+
std::string rest = uri.substr(single_colon_pos + 1);
369+
return {std::move(scheme), std::move(rest)};
370+
}
371+
return {"", uri}; // No scheme found, return empty scheme and the whole string as rest
372+
}

src/ReadoutUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <stdint.h>
1818
#include <string>
1919
#include <vector>
20+
#include <string_view>
21+
#include <utility>
22+
2023

2124
#include "RAWDataHeader.h"
2225

@@ -85,6 +88,9 @@ int numaGetNodeFromAddress(void *ptr, int &node);
8588
// function to set a name for current thread
8689
void setThreadName(const char*name);
8790

91+
// function to split string into URI / path
92+
std::pair<std::string, std::string> splitURI(const std::string& uri);
93+
8894
// end of _READOUTUTILS_H
8995
#endif
9096

src/ReadoutVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define READOUT_VERSION "2.26.3"
12+
#define READOUT_VERSION "2.27.0"
1313

src/mainReadout.cxx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ int Readout::_configure(const boost::property_tree::ptree& properties)
934934
std::vector<ConfigCache> cfgCache;
935935
int nSubstitutions = 0;
936936
std::function<void(boost::property_tree::ptree &, const std::string &)> resolveLinks;
937-
resolveLinks = [&resolveLinks, &cfgLinksErrors, &cfgCache, &loadConfig, &nSubstitutions](boost::property_tree::ptree &pt, const std::string &key) -> void {
937+
resolveLinks = [&resolveLinks, &cfgLinksErrors, &cfgCache, &loadConfig, &nSubstitutions, this](boost::property_tree::ptree &pt, const std::string &key) -> void {
938938
if (pt.empty()) {
939939
std::string value = pt.data();
940940
const std::string keywordLink = "@LINK";
@@ -952,6 +952,18 @@ int Readout::_configure(const boost::property_tree::ptree& properties)
952952
const char* cfgLinkUri = linkArgs[1].c_str();
953953
const char* cfgLinkEntryPoint = linkArgs[2].c_str();
954954
const char* cfgLinkPath = linkArgs[3].c_str();
955+
956+
// check if link URI starts with a relative path - and if so, compute address from current URI
957+
// https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
958+
// theLog.log(LogInfoSupport, "Resolving %s / %s", cfgFileURI, cfgLinkUri);
959+
std::string resolvedUri;
960+
if (!strncmp(cfgLinkUri, "../", 3) || !strncmp(cfgLinkUri, "./", 2)) {
961+
std::pair<std::string, std::string> splitPath = splitURI(cfgFileURI);
962+
resolvedUri = splitPath.first + std::filesystem::path((std::filesystem::path(splitPath.second).parent_path().string() + "/" + cfgLinkUri)).lexically_normal().string();
963+
theLog.log(LogInfoSupport, "Using relative path: %s -> %s", cfgLinkUri, resolvedUri.c_str());
964+
cfgLinkUri = resolvedUri.c_str();
965+
}
966+
955967
// search for file in cache
956968
unsigned int ix = 0;
957969
for(;ix < cfgCache.size(); ix++) {

src/readoutAutoConfigure.tcl

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,17 @@ if {[llength $ldev]==0} {
152152
}
153153

154154
# get memory configuration
155-
156-
if {[catch {set hugeOutput [exec hugeadm --pool-list]} err]} {
157-
doLog "hugeadm failed: $err"
158-
exit 1
159-
}
160-
set hugeOutputLines [split $hugeOutput "\n"]
155+
set nHuge1G 0
156+
set nHuge1Gfile "/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages"
161157
if {[catch {
162-
set hugeHeader "Size Minimum Current Maximum Default"
163-
if {[string trim [lindex $hugeOutputLines 0]]!=$hugeHeader} {
164-
# throw only in tcl 8.7... but if not it generates an error anyway, which is what we want
165-
throw
166-
}
167-
for {set i 1} {$i<[llength $hugeOutputLines]} {incr i} {
168-
set l [lindex $hugeOutputLines $i]
169-
set size [string trim [string range $l 0 11]]
170-
set min [string trim [string range $l 12 20]]
171-
set current [string trim [string range $l 21 29]]
172-
set max [string trim [string range $l 30 38]]
173-
lappend lmem "$size" "$current"
158+
set nHugeFd [open $nHuge1Gfile "r"]
159+
gets $nHugeFd line
160+
close $nHugeFd
161+
if {[scan $line "%d" nHuge1G]!=1} {
162+
doLog "Failed to parse $nHuge1Gfile"
174163
}
175164
} err]} {
176-
doLog "Failed to parse hugeadm output: $err"
165+
doLog "Failed to get number of hugepages: $err"
177166
}
178167

179168

@@ -202,9 +191,10 @@ if {[catch {
202191
throw
203192
}
204193
set l [lindex $memOutputLines 1]
205-
set memTotal [string trim [string range $l 7 18]]
206-
set memUsed [string trim [string range $l 19 30]]
207-
set memFree [string trim [string range $l 31 42]]
194+
set theWords [regexp -all -inline {\S+} $l]
195+
set memTotal [lindex $theWords 1]
196+
set memUsed [lindex $theWords 2]
197+
set memFree [lindex $theWords 3]
208198
} err]} {
209199
doLog "Failed to parse free output: $err"
210200
}
@@ -226,13 +216,7 @@ if {$numaNodes==0} {
226216
}
227217

228218
doLog "Memory available (hugepages):"
229-
set nHuge1G 0
230-
foreach {pageSize pagesAvailable} $lmem {
231-
doLog " $pagesAvailable * $pageSize bytes"
232-
if {$pageSize==1073741824} {
233-
set nHuge1G $pagesAvailable
234-
}
235-
}
219+
doLog " $nHuge1G * 1048576kB"
236220
if {$nHuge1G==0} {
237221
doLog "1G pages should not be zero"
238222
incr err

0 commit comments

Comments
 (0)