Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TUrl.h"
22#include "TNetFile.h"
23#include "TNetFileStager.h"
24
25////////////////////////////////////////////////////////////////////////////////
26/// Constructor. Init a TNetSystem instance to the remote rootd.
27
29{
30 fSystem = 0;
31 if (url && strlen(url) > 0) {
32 GetPrefix(url, fPrefix);
33
35 }
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Destructor
40
42{
44 fPrefix = "";
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Check if the file defined by 'path' is ready to be used.
49
51{
52 if (!IsValid()) {
53 GetPrefix(path, fPrefix);
54 fSystem = new TNetSystem(path);
55 }
56
57 if (IsValid()) {
58 TString p(path);
59 if (!p.BeginsWith(fPrefix)) p.Insert(0, fPrefix);
61 }
62
63 // Failure
64 Warning("IsStaged","TNetSystem not initialized");
65 return kFALSE;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Isolate prefix in url
70
71void TNetFileStager::GetPrefix(const char *url, TString &pfx)
72{
73 if (gDebug > 1)
74 ::Info("TNetFileStager::GetPrefix", "enter: %s", url);
75
76 TUrl u(url);
77 pfx = TString::Format("%s://", u.GetProtocol());
78 if (strlen(u.GetUser()) > 0)
79 pfx += TString::Format("%s@", u.GetUser());
80 pfx += u.GetHost();
81 if (u.GetPort() != TUrl("root://host").GetPort())
82 pfx += TString::Format(":%d", u.GetPort());
83 pfx += "/";
84
85 if (gDebug > 1)
86 ::Info("TNetFileStager::GetPrefix", "found prefix: %s", pfx.Data());
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Print basic info about this stager
91
93{
94 Printf("+++ stager: %s %s", GetName(), fPrefix.Data());
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Get actual end-point url for a path
99/// Returns 0 in case of success and 1 if any error occured
100
101Int_t TNetFileStager::Locate(const char *path, TString &eurl)
102{
103 if (!IsValid()) {
104 GetPrefix(path, fPrefix);
105 fSystem = new TNetSystem(path);
106 }
107
108 if (IsValid()) {
109 TString p(path);
110 if (!p.BeginsWith(fPrefix)) p.Insert(0, fPrefix);
112 eurl = p;
113 return 0;
114 }
115 }
116
117 // Unable to initialize TNetSystem or file does not exist
118 return -1;
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Returns kTRUE if stager 's' is compatible with current stager.
123/// Avoids multiple instantiations of the potentially the same TNetSystem.
124
126{
127 if (IsValid()) {
128 TString pfx;
129 GetPrefix(s, pfx);
130 return ((fPrefix == pfx) ? kTRUE : kFALSE);
131 }
132
133 // Not valid
134 return kFALSE;
135}
#define SafeDelete(p)
Definition RConfig.hxx:547
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
Int_t gDebug
Definition TROOT.cxx:590
void Printf(const char *fmt,...)
@ kReadPermission
Definition TSystem.h:47
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.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:867
Basic string class.
Definition TString.h:136
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:649
const char * Data() const
Definition TString.h:369
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
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:2331
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetUser() const
Definition TUrl.h:65
const char * GetHost() const
Definition TUrl.h:67
const char * GetProtocol() const
Definition TUrl.h:64
Int_t GetPort() const
Definition TUrl.h:78