Logo ROOT   6.18/05
Reference Guide
TNetFileStager.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: G. Ganis Feb 2011
3
4/*************************************************************************
5 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TNetFileStager //
15// //
16// TFileStager implementation for a 'rootd' backend. //
17// //
18//////////////////////////////////////////////////////////////////////////
19
20#include "TError.h"
21#include "TObjString.h"
22#include "TUrl.h"
23#include "TNetFile.h"
24#include "TNetFileStager.h"
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor. Init a TNetSystem instance to the remote rootd.
28
30{
31 fSystem = 0;
32 if (url && strlen(url) > 0) {
33 GetPrefix(url, fPrefix);
34
36 }
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Destructor
41
43{
45 fPrefix = "";
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Check if the file defined by 'path' is ready to be used.
50
52{
53 if (!IsValid()) {
54 GetPrefix(path, fPrefix);
55 fSystem = new TNetSystem(path);
56 }
57
58 if (IsValid()) {
59 TString p(path);
60 if (!p.BeginsWith(fPrefix)) p.Insert(0, fPrefix);
62 }
63
64 // Failure
65 Warning("IsStaged","TNetSystem not initialized");
66 return kFALSE;
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Isolate prefix in url
71
72void TNetFileStager::GetPrefix(const char *url, TString &pfx)
73{
74 if (gDebug > 1)
75 ::Info("TNetFileStager::GetPrefix", "enter: %s", url);
76
77 TUrl u(url);
78 pfx = TString::Format("%s://", u.GetProtocol());
79 if (strlen(u.GetUser()) > 0)
80 pfx += TString::Format("%s@", u.GetUser());
81 pfx += u.GetHost();
82 if (u.GetPort() != TUrl("root://host").GetPort())
83 pfx += TString::Format(":%d", u.GetPort());
84 pfx += "/";
85
86 if (gDebug > 1)
87 ::Info("TNetFileStager::GetPrefix", "found prefix: %s", pfx.Data());
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Print basic info about this stager
92
94{
95 Printf("+++ stager: %s %s", GetName(), fPrefix.Data());
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Get actual end-point url for a path
100/// Returns 0 in case of success and 1 if any error occured
101
102Int_t TNetFileStager::Locate(const char *path, TString &eurl)
103{
104 if (!IsValid()) {
105 GetPrefix(path, fPrefix);
106 fSystem = new TNetSystem(path);
107 }
108
109 if (IsValid()) {
110 TString p(path);
111 if (!p.BeginsWith(fPrefix)) p.Insert(0, fPrefix);
113 eurl = p;
114 return 0;
115 }
116 }
117
118 // Unable to initialize TNetSystem or file does not exist
119 return -1;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Returns kTRUE if stager 's' is compatible with current stager.
124/// Avoids multiple instantiations of the potentially the same TNetSystem.
125
127{
128 if (IsValid()) {
129 TString pfx;
130 GetPrefix(s, pfx);
131 return ((fPrefix == pfx) ? kTRUE : kFALSE);
132 }
133
134 // Not valid
135 return kFALSE;
136}
#define SafeDelete(p)
Definition: RConfig.hxx:543
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
R__EXTERN Int_t gDebug
Definition: Rtypes.h:91
void Printf(const char *fmt,...)
@ kReadPermission
Definition: TSystem.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual ~TNetFileStager()
Destructor.
TNetSystem * fSystem
Bool_t Matches(const char *s)
Returns kTRUE if stager 's' is compatible with current stager.
Bool_t IsStaged(const char *path)
Check if the file defined by 'path' is ready to be used.
Bool_t IsValid() const
static void GetPrefix(const char *url, TString &pfx)
Isolate prefix in url.
TNetFileStager(const char *stager="")
Constructor. Init a TNetSystem instance to the remote rootd.
Int_t Locate(const char *path, TString &endpath)
Get actual end-point url for a path Returns 0 in case of success and 1 if any error occured.
void Print(Option_t *option="") const
Print basic info about this stager.
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TNetFile.cxx:1096
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
Basic string class.
Definition: TString.h:131
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:644
const char * Data() const
Definition: TString.h:364
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
This class represents a WWW compatible URL.
Definition: TUrl.h:35
const char * GetUser() const
Definition: TUrl.h:68
const char * GetHost() const
Definition: TUrl.h:70
const char * GetProtocol() const
Definition: TUrl.h:67
Int_t GetPort() const
Definition: TUrl.h:81
static constexpr double s