4343#include " ROOT/RSlotStack.hxx"
4444#endif
4545
46- #ifdef R__UNIX
47- // Functions needed to perform EOS XRootD redirection in ChangeSpec
48- #include " TEnv.h"
46+ #include " ROOT/InternalIOUtils.hxx"
4947#include " TSystem.h"
50- #ifndef R__FBSD
51- #include < sys/xattr.h>
52- #else
53- #include < sys/extattr.h>
54- #endif
55- #ifdef R__MACOSX
56- /* On macOS getxattr takes two extra arguments that should be set to 0 */
57- #define getxattr (path, name, value, size ) getxattr(path, name, value, size, 0u , 0 )
58- #endif
59- #ifdef R__FBSD
60- #define getxattr (path, name, value, size ) extattr_get_file(path, EXTATTR_NAMESPACE_USER , name, value, size)
61- #endif
62- #endif
6348
6449#include < algorithm>
6550#include < atomic>
@@ -370,37 +355,21 @@ RLoopManager::RLoopManager(ROOT::RDF::Experimental::RDatasetSpec &&spec)
370355 ChangeSpec (std::move (spec));
371356}
372357
373- #ifdef R__UNIX
374358namespace {
375359std::optional<std::string> GetRedirectedSampleId (std::string_view path, std::string_view datasetName)
376360{
377361 // Mimick the redirection done in TFile::Open to see if the path points to a FUSE-mounted EOS path.
378362 // If so, we create a redirected sample ID with the full xroot URL.
379363 TString expandedUrl (path.data ());
380364 gSystem ->ExpandPathName (expandedUrl);
381- if (gEnv ->GetValue (" TFile.CrossProtocolRedirects" , 1 ) == 1 ) {
382- TUrl fileurl (expandedUrl, /* default is file */ kTRUE );
383- if (strcmp (fileurl.GetProtocol (), " file" ) == 0 ) {
384- ssize_t len = getxattr (fileurl.GetFile (), " eos.url.xroot" , nullptr , 0 );
385- if (len > 0 ) {
386- std::string xurl (len, 0 );
387- std::string fileNameFromUrl{fileurl.GetFile ()};
388- if (getxattr (fileNameFromUrl.c_str (), " eos.url.xroot" , &xurl[0 ], len) == len) {
389- // Sometimes the `getxattr` call may return an invalid URL due
390- // to the POSIX attribute not being yet completely filled by EOS.
391- if (auto baseName = fileNameFromUrl.substr (fileNameFromUrl.find_last_of (" /" ) + 1 );
392- std::equal (baseName.crbegin (), baseName.crend (), xurl.crbegin ())) {
393- return xurl + ' /' + datasetName.data ();
394- }
395- }
396- }
397- }
365+ TUrl fileurl (expandedUrl, /* default is file */ kTRUE );
366+ if (strcmp (fileurl.GetProtocol (), " file" ) == 0 ) {
367+ if (auto xurl = ROOT::Internal::GetEOSRedirectedXRootURL (fileurl.GetFile ()))
368+ return *xurl + ' /' + datasetName.data ();
398369 }
399-
400370 return std::nullopt ;
401371}
402372} // namespace
403- #endif
404373
405374/* *
406375 * @brief Changes the internal TTree held by the RLoopManager.
@@ -451,11 +420,10 @@ void RLoopManager::ChangeSpec(ROOT::RDF::Experimental::RDatasetSpec &&spec)
451420 // is exposed to users via RSampleInfo and DefinePerSample).
452421 const auto sampleId = files[i] + ' /' + trees[i];
453422 fSampleMap .insert ({sampleId, &sample});
454- # ifdef R__UNIX
423+
455424 // Also add redirected EOS xroot URL when available
456425 if (auto redirectedSampleId = GetRedirectedSampleId (files[i], trees[i]))
457426 fSampleMap .insert ({redirectedSampleId.value (), &sample});
458- #endif
459427 }
460428 }
461429 fDataSource = std::make_unique<ROOT ::Internal::RDF ::RTTreeDS>(std::move (chain), spec.GetFriendInfo ());
@@ -473,11 +441,9 @@ void RLoopManager::ChangeSpec(ROOT::RDF::Experimental::RDatasetSpec &&spec)
473441 fileNames.push_back (files[i]);
474442 rntupleNames.insert (trees[i]);
475443
476- #ifdef R__UNIX
477444 // Also add redirected EOS xroot URL when available
478445 if (auto redirectedSampleId = GetRedirectedSampleId (files[i], trees[i]))
479446 fSampleMap .insert ({redirectedSampleId.value (), &sample});
480- #endif
481447 }
482448 }
483449
0 commit comments