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/InternalIOUtils.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,21 @@ 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- }
262+ TUrl fileurl (expandedUrl, /* default is file */ kTRUE );
263+ if (strcmp (fileurl.GetProtocol (), " file" ) == 0 ) {
264+ if (auto xurl = ROOT::Internal::GetEOSRedirectedXRootURL (fileurl.GetFile ()))
265+ return *xurl + ' /' + datasetName.data ();
295266 }
296-
297267 return std::nullopt ;
298268}
299269} // namespace
300- #endif
301270
302271/* *
303272 * @brief Changes the internal TTree held by the RLoopManager.
@@ -348,11 +317,10 @@ void RLoopManager::ChangeSpec(ROOT::RDF::Experimental::RDatasetSpec &&spec)
348317 // is exposed to users via RSampleInfo and DefinePerSample).
349318 const auto sampleId = files[i] + ' /' + trees[i];
350319 fSampleMap .insert ({sampleId, &sample});
351- # ifdef R__UNIX
320+
352321 // Also add redirected EOS xroot URL when available
353322 if (auto redirectedSampleId = GetRedirectedSampleId (files[i], trees[i]))
354323 fSampleMap .insert ({redirectedSampleId.value (), &sample});
355- #endif
356324 }
357325 }
358326 fDataSource = std::make_unique<ROOT::Internal::RDF::RTTreeDS>(std::move (chain), spec.GetFriendInfo ());
@@ -370,11 +338,9 @@ void RLoopManager::ChangeSpec(ROOT::RDF::Experimental::RDatasetSpec &&spec)
370338 fileNames.push_back (files[i]);
371339 rntupleNames.insert (trees[i]);
372340
373- #ifdef R__UNIX
374341 // Also add redirected EOS xroot URL when available
375342 if (auto redirectedSampleId = GetRedirectedSampleId (files[i], trees[i]))
376343 fSampleMap .insert ({redirectedSampleId.value (), &sample});
377- #endif
378344 }
379345 }
380346
0 commit comments