Logo ROOT   6.10/09
Reference Guide
TNetXNGFileStager.cxx
Go to the documentation of this file.
1 // @(#)root/netx:$Id$
2 /*************************************************************************
3  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
4  * All rights reserved. *
5  * *
6  * For the licensing terms see $ROOTSYS/LICENSE. *
7  * For the list of contributors see $ROOTSYS/README/CREDITS. *
8  *************************************************************************/
9 
10 ////////////////////////////////////////////////////////////////////////////////
11 // //
12 // TNetXNGFileStager //
13 // //
14 // Authors: Justin Salmon, Lukasz Janyst //
15 // CERN, 2013 //
16 // //
17 // Enables access to XRootD staging capabilities using the new client. //
18 // //
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include "TNetXNGFileStager.h"
22 #include "TNetXNGSystem.h"
23 #include "THashList.h"
24 #include "TFileInfo.h"
25 #include "TFileCollection.h"
26 #include <XrdCl/XrdClFileSystem.hh>
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Constructor
32 ///
33 /// param url: the URL of the entry-point server
34 
36  TFileStager("xrd")
37 {
38  fSystem = new TNetXNGSystem(url);
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Destructor
43 
45 {
46  delete fSystem;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Check if a file is staged
51 ///
52 /// param path: the URL of the file
53 
55 {
56  FileStat_t st;
57  if (fSystem->GetPathInfo(path, st) != 0) {
58  if (gDebug > 0)
59  Info("IsStaged", "path %s cannot be stat'ed", path);
60  return kFALSE;
61  }
62 
63  if (R_ISOFF(st.fMode)) {
64  if (gDebug > 0)
65  Info("IsStaged", "path '%s' is offline", path);
66  return kFALSE;
67  }
68 
69  return kTRUE;
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Get actual endpoint URL
74 ///
75 /// param path: the entry-point URL
76 /// param endpath: the actual endpoint URL
77 /// returns: 0 in the case of success and 1 if any error occurred
78 
79 Int_t TNetXNGFileStager::Locate(const char *path, TString &url)
80 {
81  return fSystem->Locate(path, url);
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Bulk locate request for a collection of files
86 ///
87 /// param fc: collection of files to be located
88 /// param addDummyUrl: append a dummy noop URL if the file is not staged or
89 /// redirector == endpoint
90 /// returns: < 0 in case of errors, number of files processed
91 /// otherwise
92 
94  Bool_t addDummyUrl)
95 {
96  if (!fc) {
97  Error("LocateCollection", "No input collection given");
98  return -1;
99  }
100 
101  int numFiles = 0;
102  TFileInfo *info;
103  TIter it(fc->GetList());
104  TString startUrl, endUrl;
105 
106  while ((info = dynamic_cast<TFileInfo *>(it.Next())) != NULL) {
107  startUrl = info->GetCurrentUrl()->GetUrl();
108 
109  // File not staged
110  if (fSystem->Locate(startUrl.Data(), endUrl)) {
112 
113  if (addDummyUrl)
114  info->AddUrl("noop://none", kTRUE);
115 
116  if (gDebug > 1)
117  Info("LocateCollection", "Not found: %s", startUrl.Data());
118  }
119 
120  // File staged
121  else {
122  info->SetBit(TFileInfo::kStaged);
123 
124  if (startUrl != endUrl) {
125  info->AddUrl(endUrl.Data(), kTRUE);
126  } else if (addDummyUrl) {
127  // Returned URL identical to redirector URL
128  info->AddUrl("noop://redir", kTRUE);
129  }
130 
131  if (gDebug > 1)
132  Info("LocateCollection", "Found: %s --> %s", startUrl.Data(),
133  endUrl.Data());
134  }
135  numFiles++;
136  }
137 
138  return numFiles;
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Returns kTRUE if stager 's' is compatible with current stager. Avoids
143 /// multiple instantiations of the potentially the same TNetXNGFileStager.
144 
146 {
147  return ((s && (fName == s)) ? kTRUE : kFALSE);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Issue a stage request for a single file
152 ///
153 /// param path: the path of the file to stage
154 /// param opt: defines 'option' and 'priority' for 'Prepare': the format is
155 /// opt = "option=o priority=p"
156 
157 Bool_t TNetXNGFileStager::Stage(const char *path, Option_t *opt)
158 {
159  Int_t priority = ParseStagePriority(opt);
160  return fSystem->Stage(path, priority);
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Issue stage requests for multiple files
165 ///
166 /// param pathlist: list of paths of files to stage
167 /// param opt: defines 'option' and 'priority' for 'Prepare': the
168 /// format is opt = "option=o priority=p"
169 
171 {
172  Int_t priority = ParseStagePriority(opt);
173  return fSystem->Stage(paths, priority);
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Get a staging priority value from an option string
178 
180 {
181  UChar_t priority = 0;
182  Ssiz_t from = 0;
183  TString token;
184 
185  while (TString(opt).Tokenize(token, from, "[ ,|]")) {
186  if (token.Contains("priority=")) {
187  token.ReplaceAll("priority=", "");
188  if (token.IsDigit()) {
189  priority = token.Atoi();
190  }
191  }
192  }
193 
194  return priority;
195 }
TNetXNGFileStager(const char *url="")
Constructor.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:847
UChar_t ParseStagePriority(Option_t *opt)
Get a staging priority value from an option string.
const char Option_t
Definition: RtypesCore.h:62
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:640
TUrl * GetCurrentUrl() const
Return the current url.
Definition: TFileInfo.cxx:248
Bool_t Matches(const char *s)
Returns kTRUE if stager &#39;s&#39; is compatible with current stager.
virtual Int_t Stage(const char *path, UChar_t priority)
Issue a stage request for a single file.
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t AddUrl(const char *url, Bool_t infront=kFALSE)
Add a new URL.
Definition: TFileInfo.cxx:295
#define NULL
Definition: RtypesCore.h:88
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
Int_t fMode
Definition: TSystem.h:128
Int_t Locate(const char *path, TString &endpath)
Get actual endpoint URL.
Bool_t Stage(const char *path, Option_t *opt=0)
Issue a stage request for a single file.
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:1956
Int_t LocateCollection(TFileCollection *fc, Bool_t addDummyUrl=kFALSE)
Bulk locate request for a collection of files.
Bool_t IsStaged(const char *path)
Check if a file is staged.
THashList * GetList()
Collection abstract base class.
Definition: TCollection.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
virtual ~TNetXNGFileStager()
Destructor.
TString fName
Definition: TNamed.h:32
const Bool_t kFALSE
Definition: RtypesCore.h:92
int Ssiz_t
Definition: RtypesCore.h:63
#define ClassImp(name)
Definition: Rtypes.h:336
virtual Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file (stat)
TNetXNGSystem * fSystem
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:572
Class that contains a list of TFileInfo&#39;s and accumulated meta data information about its entries...
R__EXTERN Int_t gDebug
Definition: Rtypes.h:83
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1975
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1817
Class describing a generic file including meta information.
Definition: TFileInfo.h:38
void ResetBit(UInt_t f)
Definition: TObject.h:158
unsigned char UChar_t
Definition: RtypesCore.h:34
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual Int_t Locate(const char *path, TString &endurl)
Get the endpoint URL of a file.
Bool_t R_ISOFF(Int_t mode)
Definition: TSystem.h:123