4242#include " ROOT/RSlotStack.hxx"
4343#endif
4444
45- #ifdef R__UNIX
46- // Functions needed to perform EOS XRootD redirection in ChangeSpec
47- #include " TEnv.h"
45+ #include " ROOT/IOUtils.hxx"
4846#include " TSystem.h"
49- #ifndef R__FBSD
50- #include < sys/xattr.h>
51- #else
52- #include < sys/extattr.h>
53- #endif
54- #ifdef R__MACOSX
55- /* On macOS getxattr takes two extra arguments that should be set to 0 */
56- #define getxattr (path, name, value, size ) getxattr(path, name, value, size, 0u , 0 )
57- #endif
58- #ifdef R__FBSD
59- #define getxattr (path, name, value, size ) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size)
60- #endif
61- #endif
6247
6348#include < algorithm>
6449#include < atomic>
@@ -267,37 +252,20 @@ RLoopManager::RLoopManager(ROOT::RDF::Experimental::RDatasetSpec &&spec)
267252 ChangeSpec (std::move (spec));
268253}
269254
270- #ifdef R__UNIX
271255namespace {
272256std::optional<std::string> GetRedirectedSampleId (std::string_view path, std::string_view datasetName)
273257{
274258 // Mimick the redirection done in TFile::Open to see if the path points to a FUSE-mounted EOS path.
275259 // If so, we create a redirected sample ID with the full xroot URL.
276260 TString expandedUrl (path.data ());
277261 gSystem ->ExpandPathName (expandedUrl);
278- if (gEnv ->GetValue (" TFile.CrossProtocolRedirects" , 1 ) == 1 ) {
279- TUrl fileurl (expandedUrl, /* default is file */ kTRUE );
280- if (strcmp (fileurl.GetProtocol (), " file" ) == 0 ) {
281- ssize_t len = getxattr (fileurl.GetFile (), " eos.url.xroot" , nullptr , 0 );
282- if (len > 0 ) {
283- std::string xurl (len, 0 );
284- std::string fileNameFromUrl{fileurl.GetFile ()};
285- if (getxattr (fileNameFromUrl.c_str (), " eos.url.xroot" , &xurl[0 ], len) == len) {
286- // Sometimes the `getxattr` call may return an invalid URL due
287- // to the POSIX attribute not being yet completely filled by EOS.
288- if (auto baseName = fileNameFromUrl.substr (fileNameFromUrl.find_last_of (" /" ) + 1 );
289- std::equal (baseName.crbegin (), baseName.crend (), xurl.crbegin ())) {
290- return xurl + ' /' + datasetName.data ();
291- }
292- }
293- }
294- }
295- }
262+ TUrl fileurl (expandedUrl, /* default is file */ kTRUE );
263+ if (auto xurl = ROOT::Internal::GetEOSRedirectedXRootUrl (fileurl.GetFile ()))
264+ return *xurl + ' /' + datasetName.data ();
296265
297266 return std::nullopt ;
298267}
299268} // namespace
300- #endif
301269
302270/* *
303271 * @brief Changes the internal TTree held by the RLoopManager.
@@ -348,11 +316,10 @@ void RLoopManager::ChangeSpec(ROOT::RDF::Experimental::RDatasetSpec &&spec)
348316 // is exposed to users via RSampleInfo and DefinePerSample).
349317 const auto sampleId = files[i] + ' /' + trees[i];
350318 fSampleMap .insert ({sampleId, &sample});
351- # ifdef R__UNIX
319+
352320 // Also add redirected EOS xroot URL when available
353321 if (auto redirectedSampleId = GetRedirectedSampleId (files[i], trees[i]))
354322 fSampleMap .insert ({redirectedSampleId.value (), &sample});
355- #endif
356323 }
357324 }
358325 fDataSource = std::make_unique<ROOT::Internal::RDF::RTTreeDS>(std::move (chain), spec.GetFriendInfo ());
@@ -370,11 +337,9 @@ void RLoopManager::ChangeSpec(ROOT::RDF::Experimental::RDatasetSpec &&spec)
370337 fileNames.push_back (files[i]);
371338 rntupleNames.insert (trees[i]);
372339
373- #ifdef R__UNIX
374340 // Also add redirected EOS xroot URL when available
375341 if (auto redirectedSampleId = GetRedirectedSampleId (files[i], trees[i]))
376342 fSampleMap .insert ({redirectedSampleId.value (), &sample});
377- #endif
378343 }
379344 }
380345
0 commit comments