Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TUrl.h"
26#include "TFileCollection.h"
27#include <XrdCl/XrdClFileSystem.hh>
28
30
31////////////////////////////////////////////////////////////////////////////////
32/// Constructor
33///
34/// param url: the URL of the entry-point server
35
37 TFileStager("xrd")
38{
39 fSystem = new TNetXNGSystem(url);
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Destructor
44
46{
47 delete fSystem;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Check if a file is staged
52///
53/// param path: the URL of the file
54
56{
57 FileStat_t st;
58 if (fSystem->GetPathInfo(path, st) != 0) {
59 if (gDebug > 0)
60 Info("IsStaged", "path %s cannot be stat'ed", path);
61 return kFALSE;
62 }
63
64 if (R_ISOFF(st.fMode)) {
65 if (gDebug > 0)
66 Info("IsStaged", "path '%s' is offline", path);
67 return kFALSE;
68 }
69
70 return kTRUE;
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Get actual endpoint URL
75///
76/// param path: the entry-point URL
77/// param endpath: the actual endpoint URL
78/// returns: 0 in the case of success and 1 if any error occurred
79
81{
82 return fSystem->Locate(path, url);
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Bulk locate request for a collection of files
87///
88/// param fc: collection of files to be located
89/// param addDummyUrl: append a dummy noop URL if the file is not staged or
90/// redirector == endpoint
91/// returns: < 0 in case of errors, number of files processed
92/// otherwise
93
95 Bool_t addDummyUrl)
96{
97 if (!fc) {
98 Error("LocateCollection", "No input collection given");
99 return -1;
100 }
101
102 int numFiles = 0;
103 TFileInfo *info;
104 TIter it(fc->GetList());
105 TString startUrl, endUrl;
106
107 while ((info = dynamic_cast<TFileInfo *>(it.Next())) != NULL) {
108 startUrl = info->GetCurrentUrl()->GetUrl();
109
110 // File not staged
111 if (fSystem->Locate(startUrl.Data(), endUrl)) {
113
114 if (addDummyUrl)
115 info->AddUrl("noop://none", kTRUE);
116
117 if (gDebug > 1)
118 Info("LocateCollection", "Not found: %s", startUrl.Data());
119 }
120
121 // File staged
122 else {
124
125 if (startUrl != endUrl) {
126 info->AddUrl(endUrl.Data(), kTRUE);
127 } else if (addDummyUrl) {
128 // Returned URL identical to redirector URL
129 info->AddUrl("noop://redir", kTRUE);
130 }
131
132 if (gDebug > 1)
133 Info("LocateCollection", "Found: %s --> %s", startUrl.Data(),
134 endUrl.Data());
135 }
136 numFiles++;
137 }
138
139 return numFiles;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Returns kTRUE if stager 's' is compatible with current stager. Avoids
144/// multiple instantiations of the potentially the same TNetXNGFileStager.
145
147{
148 return ((s && (fName == s)) ? kTRUE : kFALSE);
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Issue a stage request for a single file
153///
154/// param path: the path of the file to stage
155/// param opt: defines 'option' and 'priority' for 'Prepare': the format is
156/// opt = "option=o priority=p"
157
159{
160 Int_t priority = ParseStagePriority(opt);
161 return fSystem->Stage(path, priority);
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Issue stage requests for multiple files
166///
167/// param pathlist: list of paths of files to stage
168/// param opt: defines 'option' and 'priority' for 'Prepare': the
169/// format is opt = "option=o priority=p"
170
172{
173 Int_t priority = ParseStagePriority(opt);
174 return fSystem->Stage(paths, priority);
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Get a staging priority value from an option string
179
181{
182 UChar_t priority = 0;
183 Ssiz_t from = 0;
184 TString token;
185
186 while (TString(opt).Tokenize(token, from, "[ ,|]")) {
187 if (token.Contains("priority=")) {
188 token.ReplaceAll("priority=", "");
189 if (token.IsDigit()) {
190 priority = token.Atoi();
191 }
192 }
193 }
194
195 return priority;
196}
unsigned char UChar_t
Definition RtypesCore.h:38
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Int_t gDebug
Definition TROOT.cxx:597
Bool_t R_ISOFF(Int_t mode)
Definition TSystem.h:120
Collection abstract base class.
Definition TCollection.h:65
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
THashList * GetList()
Class describing a generic file including meta information.
Definition TFileInfo.h:39
Bool_t AddUrl(const char *url, Bool_t infront=kFALSE)
Add a new URL.
TUrl * GetCurrentUrl() const
Return the current url.
TObject * Next()
TString fName
Definition TNamed.h:32
Bool_t Matches(const char *s) override
Returns kTRUE if stager 's' is compatible with current stager.
TNetXNGFileStager(const char *url="")
Constructor.
Int_t LocateCollection(TFileCollection *fc, Bool_t addDummyUrl=kFALSE) override
Bulk locate request for a collection of files.
Bool_t Stage(const char *path, Option_t *opt=nullptr) override
Issue a stage request for a single file.
UChar_t ParseStagePriority(Option_t *opt)
Get a staging priority value from an option string.
virtual ~TNetXNGFileStager()
Destructor.
Bool_t IsStaged(const char *path) override
Check if a file is staged.
Int_t Locate(const char *path, TString &endpath) override
Get actual endpoint URL.
TNetXNGSystem * fSystem
Int_t GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file (stat)
virtual Int_t Stage(const char *path, UChar_t priority)
Issue a stage request for a single file.
virtual Int_t Locate(const char *path, TString &endurl)
Get the endpoint URL of a file.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
void ResetBit(UInt_t f)
Definition TObject.h:198
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
Basic string class.
Definition TString.h:139
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1988
const char * Data() const
Definition TString.h:376
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition TString.cxx:1830
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition TUrl.cxx:390
Int_t fMode
Definition TSystem.h:125