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
29
30////////////////////////////////////////////////////////////////////////////////
31/// Constructor
32///
33/// param url: the URL of the entry-point server
34
40
41////////////////////////////////////////////////////////////////////////////////
42/// Destructor
43
48
49////////////////////////////////////////////////////////////////////////////////
50/// Check if a file is staged
51///
52/// param path: the URL of the file
53
55{
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
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
95{
96 if (!fc) {
97 Error("LocateCollection", "No input collection given");
98 return -1;
99 }
100
101 int numFiles = 0;
103 TIter it(fc->GetList());
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)) {
111 info->ResetBit(TFileInfo::kStaged);
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
158{
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
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}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
Bool_t R_ISOFF(Int_t mode)
Definition TSystem.h:130
Collection abstract base class.
Definition TCollection.h:65
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Class describing a generic file including meta information.
Definition TFileInfo.h:39
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
Enables access to XRootD filesystem interface using the new client.
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.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
Basic string class.
Definition TString.h:138
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1994
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition TString.cxx:1836
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:712
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640