Skip to content

Commit 4bac59a

Browse files
committed
config values: added relative symlink
1 parent 309a404 commit 4bac59a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,6 @@ 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+
## next version
653+
- Added symbolic links with relative path in configuration. See @LINK syntax.

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++) {

0 commit comments

Comments
 (0)