-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ntpl] Allow XRootD redirection with EOS files #20272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vepadulano
merged 1 commit into
root-project:master
from
vepadulano:rntuple-eos-xrootd-redirection
Aug 31, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
vepadulano marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Author: Vincenzo Eduardo Padulano (CERN), 08/2026 | ||
|
|
||
| #ifndef ROOT_IO_UTILS | ||
| #define ROOT_IO_UTILS | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| namespace ROOT::Internal { | ||
|
|
||
| /// \brief Get extended attribute value from path | ||
| /// \param path Path to the file to check | ||
| /// \param xattr Extended attribute to evaluate | ||
| /// \return The string containing the extended attribute value if found, std::nullopt otherwise | ||
| std::optional<std::string> GetXAttrVal(std::string_view path, std::string_view xattr); | ||
|
|
||
| /// \brief Redirects the input path to the equivalent XRootD URL on EOS | ||
| /// \param inputUrl The input path to redirect | ||
| /// \return The redirected URL in case of successful redirection, std::nullopt otherwise | ||
| std::optional<std::string> GetEOSRedirectedXRootURL(std::string_view inputPath); | ||
| } // namespace ROOT::Internal | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #include "ROOT/InternalIOUtils.hxx" | ||
|
|
||
| #include "ROOT/RConfig.hxx" // R__UNIX | ||
|
|
||
| #ifdef R__UNIX | ||
|
|
||
| #include <ROOT/RLogger.hxx> | ||
|
|
||
| ROOT::RLogChannel &InternalLogChannel() | ||
| { | ||
| static ROOT::RLogChannel sLog("ROOT.Internal"); | ||
| return sLog; | ||
| } | ||
|
|
||
| // getxattr | ||
| #ifdef R__FBSD | ||
| #include <sys/extattr.h> | ||
| #else | ||
| #include <sys/xattr.h> | ||
| #endif | ||
|
|
||
| #ifdef R__MACOSX | ||
| /* On macOS getxattr takes two extra arguments that should be set to 0 */ | ||
| #define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0) | ||
| #endif | ||
|
|
||
| #ifdef R__FBSD | ||
| #define getxattr(path, name, value, size) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size) | ||
| #endif | ||
|
|
||
| #include "ROOT/StringUtils.hxx" // ROOT::StartsWith | ||
| #include "TEnv.h" // TEnv::GetValue | ||
| #endif | ||
|
|
||
| std::optional<std::string> | ||
| ROOT::Internal::GetXAttrVal([[maybe_unused]] std::string_view path, [[maybe_unused]] std::string_view xattr) | ||
| { | ||
| #ifdef R__UNIX | ||
| // First call to getxattr evaluates the length of the extended attribute value | ||
| if (auto len = getxattr(path.data(), xattr.data(), nullptr, 0); len >= 0) { | ||
| std::string xval(len, 0); | ||
| // Second call extracts the extended attribute value, checking it's of the correct length | ||
| if (getxattr(path.data(), xattr.data(), xval.data(), len) == len) | ||
| return xval; | ||
| } | ||
| #endif | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::optional<std::string> ROOT::Internal::GetEOSRedirectedXRootURL([[maybe_unused]] std::string_view inputPath) | ||
| { | ||
| #ifdef R__UNIX | ||
| if (inputPath.empty() || inputPath.back() == '/') | ||
| return std::nullopt; | ||
|
|
||
| if (gEnv->GetValue("TFile.CrossProtocolRedirects", 1) != 1) | ||
| return std::nullopt; | ||
|
|
||
| auto xurl = ROOT::Internal::GetXAttrVal(inputPath, "eos.url.xroot"); | ||
| if (!xurl) | ||
| return std::nullopt; | ||
|
|
||
| auto baseName = inputPath.substr(inputPath.find_last_of("/") + 1); | ||
| // Sometimes the `getxattr` call may return an invalid URL due | ||
| // to the POSIX attribute not being yet completely filled by EOS. | ||
| if (!std::equal(baseName.crbegin(), baseName.crend(), xurl->crbegin())) { | ||
| R__LOG_WARNING(InternalLogChannel()) | ||
| << "Could not find path base name '" << baseName << "' in redirected URL '" << *xurl << "'."; | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| // Ensure the redirected URL actually starts with the XRootD protocol string | ||
| if (ROOT::StartsWith(*xurl, "root://") || ROOT::StartsWith(*xurl, "xroot://") || | ||
|
vepadulano marked this conversation as resolved.
|
||
| ROOT::StartsWith(*xurl, "roots://") || ROOT::StartsWith(*xurl, "xroots://")) | ||
| return xurl; | ||
| else | ||
| R__LOG_WARNING(InternalLogChannel()) | ||
| << "Redirected URL '" << *xurl << "' does not begin with any valid XRootD protocol string."; | ||
|
|
||
| #endif | ||
| return std::nullopt; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.