Skip to content

Commit

Permalink
Avoid XRootD dependency in public headers
Browse files Browse the repository at this point in the history
This means that we won't have to install any headers from xrootd when
using `builtin_xrootd=ON`. This makes systems that have both XRootD
standalone and ROOT with builtin XRootD installed more stable.
  • Loading branch information
guitargeek committed Oct 11, 2024
1 parent e300cf2 commit 5ac857e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
19 changes: 2 additions & 17 deletions net/netxng/inc/TNetXNGFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,18 @@

#include "TFile.h"
#include "TSemaphore.h"
#ifndef __CLING__
#include <XrdCl/XrdClFileSystem.hh>
#endif

namespace XrdCl {
class File;
class URL;
}
class XrdSysCondVar;

#ifdef __CLING__
namespace XrdCl {
struct OpenFlags {
enum Flags {None = 0};
};
}
#endif

class TNetXNGFile: public TFile {
private:
XrdCl::File *fFile; // Underlying XRootD file
XrdCl::URL *fUrl; // URL of the current file
XrdCl::OpenFlags::Flags fMode; // Open mode of the current file
int fMode; // Open mode of the current file
XrdSysCondVar *fInitCondVar; // Used to block an async open request
// if requested
Int_t fReadvIorMax; // Max size of a single readv chunk
Expand All @@ -54,9 +43,7 @@ class TNetXNGFile: public TFile {
TString fNewUrl;

public:
TNetXNGFile() : TFile(),
fFile(nullptr), fUrl(nullptr), fMode(XrdCl::OpenFlags::None), fInitCondVar(nullptr),
fReadvIorMax(0), fReadvIovMax(0) {}
TNetXNGFile();
TNetXNGFile(const char *url, const char *lurl, Option_t *mode, const char *title,
Int_t compress, Int_t netopt, Bool_t parallelopen);
TNetXNGFile(const char *url, Option_t *mode = "", const char *title = "",
Expand All @@ -83,8 +70,6 @@ class TNetXNGFile: public TFile {
virtual Bool_t IsUseable() const;
virtual Bool_t GetVectorReadLimits();
virtual void SetEnv();
Int_t ParseOpenMode(Option_t *in, TString &modestr,
XrdCl::OpenFlags::Flags &mode, Bool_t assumeRead);

TNetXNGFile(const TNetXNGFile &other); // Not implemented
TNetXNGFile &operator =(const TNetXNGFile &other); // Not implemented
Expand Down
34 changes: 27 additions & 7 deletions net/netxng/src/TNetXNGFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@
#include <XrdCl/XrdClFile.hh>
#include <XrdCl/XrdClXRootDResponses.hh>
#include <XrdCl/XrdClDefaultEnv.hh>
#include <XrdCl/XrdClFileSystem.hh>
#include <XrdVersion.hh>
#include <iostream>

namespace {

Int_t ParseOpenMode(Option_t *in, TString &modestr, int &mode, Bool_t assumeRead);

} // namepsace

//------------------------------------------------------------------------------
// Open handler for async open requests
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -113,6 +120,17 @@ class TAsyncReadvHandler: public XrdCl::ResponseHandler

ClassImp(TNetXNGFile);

TNetXNGFile::TNetXNGFile()
: TFile(),
fFile(nullptr),
fUrl(nullptr),
fMode(XrdCl::OpenFlags::None),
fInitCondVar(nullptr),
fReadvIorMax(0),
fReadvIovMax(0)
{
}

////////////////////////////////////////////////////////////////////////////////
/// Constructor
///
Expand Down Expand Up @@ -183,7 +201,7 @@ TNetXNGFile::TNetXNGFile(const char *url, const char *lurl, Option_t *mode, cons
if (parallelopen) {
// Open the file asynchronously
TAsyncOpenHandler *handler = new TAsyncOpenHandler(this);
status = fFile->Open(fUrl->GetURL(), fMode, Access::None, handler);
status = fFile->Open(fUrl->GetURL(), static_cast<XrdCl::OpenFlags::Flags>(fMode), Access::None, handler);
if (!status.IsOK()) {
Error("Open", "%s", status.ToStr().c_str());
MakeZombie();
Expand All @@ -192,7 +210,7 @@ TNetXNGFile::TNetXNGFile(const char *url, const char *lurl, Option_t *mode, cons
}

// Open the file synchronously
status = fFile->Open(fUrl->GetURL(), fMode);
status = fFile->Open(fUrl->GetURL(), static_cast<XrdCl::OpenFlags::Flags>(fMode));
if (!status.IsOK()) {
#if XrdVNUMBER >= 40000
if( status.code == errRedirect )
Expand Down Expand Up @@ -346,7 +364,7 @@ Int_t TNetXNGFile::ReOpen(Option_t *modestr)
{
using namespace XrdCl;
TString newOpt;
OpenFlags::Flags mode;
int mode;

Int_t parseres = ParseOpenMode(modestr, newOpt, mode, kFALSE);

Expand All @@ -370,7 +388,7 @@ Int_t TNetXNGFile::ReOpen(Option_t *modestr)
fOption = newOpt;
fMode = mode;

st = fFile->Open(fUrl->GetURL(), fMode);
st = fFile->Open(fUrl->GetURL(), static_cast<XrdCl::OpenFlags::Flags>(fMode));
if (!st.IsOK()) {
Error("ReOpen", "%s", st.ToStr().c_str());
return 1;
Expand Down Expand Up @@ -673,6 +691,8 @@ void TNetXNGFile::Seek(Long64_t offset, ERelativeTo position)
SetOffset(offset, position);
}

namespace {

////////////////////////////////////////////////////////////////////////////////
/// Parse a file open mode given as a string into a canonically formatted
/// output mode string and an integer code that the xroot client can use
Expand All @@ -684,9 +704,7 @@ void TNetXNGFile::Seek(Long64_t offset, ERelativeTo position)
/// returns: 0 in case the mode was successfully parsed,
/// -1 in case of failure

Int_t TNetXNGFile::ParseOpenMode(Option_t *in, TString &modestr,
XrdCl::OpenFlags::Flags &mode,
Bool_t assumeRead)
Int_t ParseOpenMode(Option_t *in, TString &modestr, int &mode, Bool_t assumeRead)
{
using namespace XrdCl;
modestr = ToUpper(TString(in));
Expand All @@ -706,6 +724,8 @@ Int_t TNetXNGFile::ParseOpenMode(Option_t *in, TString &modestr,
return 0;
}

} // namespace

////////////////////////////////////////////////////////////////////////////////
/// Check the file is open and isn't a zombie

Expand Down

0 comments on commit 5ac857e

Please sign in to comment.