#include "TError.h"
#include "TObjString.h"
#include "TUrl.h"
#include "TXNetFileStager.h"
#include "TXNetSystem.h"
TXNetFileStager::TXNetFileStager(const char *url) : TFileStager("xrd")
{
fSystem = 0;
if (url && strlen(url) > 0) {
GetPrefix(url, fPrefix);
fSystem = new TXNetSystem(fPrefix);
}
}
TXNetFileStager::~TXNetFileStager()
{
if (fSystem)
delete fSystem;
fSystem = 0;
fPrefix = "";
}
Bool_t TXNetFileStager::IsStaged(const char *path)
{
if (!IsValid()) {
GetPrefix(path, fPrefix);
fSystem = new TXNetSystem(path);
}
if (IsValid()) {
TString p(path);
if (!p.BeginsWith("root:"))
p.Insert(0, fPrefix);
return (fSystem->IsOnline(p));
}
Warning("IsStaged","TXNetSystem not initialized");
return kFALSE;
}
Bool_t TXNetFileStager::Stage(TCollection *paths, Option_t *opt)
{
if (IsValid()) {
UChar_t o = 8;
UChar_t p = 0;
if (opt && strlen(opt) > 0) {
TString xo(opt), io;
Ssiz_t from = 0;
while (xo.Tokenize(io, from, "[ ,|]")) {
if (io.Contains("option=")) {
io.ReplaceAll("option=","");
if (io.IsDigit()) {
Int_t i = io.Atoi();
if (i >= 0 && i <= 255)
o = (UChar_t) i;
}
}
if (io.Contains("priority=")) {
io.ReplaceAll("priority=","");
if (io.IsDigit()) {
Int_t i = io.Atoi();
if (i >= 0 && i <= 255)
p = (UChar_t) i;
}
}
}
}
return fSystem->Prepare(paths, o, p);
}
Warning("Stage","TXNetSystem not initialized");
return kFALSE;
}
Bool_t TXNetFileStager::Stage(const char *path, Option_t *opt)
{
if (!IsValid()) {
GetPrefix(path, fPrefix);
fSystem = new TXNetSystem(path);
}
if (IsValid()) {
UChar_t o = 8;
UChar_t p = 0;
TString xo(opt), io;
Ssiz_t from = 0;
while (xo.Tokenize(io, from, "[ ,|]")) {
if (io.Contains("option=")) {
io.ReplaceAll("option=","");
if (io.IsDigit()) {
Int_t i = io.Atoi();
if (i >= 0 && i <= 255)
o = (UChar_t) i;
}
}
if (io.Contains("priority=")) {
io.ReplaceAll("priority=","");
if (io.IsDigit()) {
Int_t i = io.Atoi();
if (i >= 0 && i <= 255)
p = (UChar_t) i;
}
}
}
TString pp(path);
if (!pp.BeginsWith("root:"))
pp.Insert(0, fPrefix);
return fSystem->Prepare(pp, o, p);
}
Warning("Stage","TXNetSystem not initialized");
return kFALSE;
}
void TXNetFileStager::GetPrefix(const char *url, TString &pfx)
{
if (gDebug > 1)
::Info("TXNetFileStager::GetPrefix", "enter: %s", url);
TUrl u(url);
pfx = Form("%s://", u.GetProtocol());
if (strlen(u.GetUser()) > 0)
pfx += Form("%s@", u.GetUser());
pfx += u.GetHost();
if (u.GetPort() != TUrl("root://host").GetPort())
pfx += Form(":%d", u.GetPort());
pfx += "/";
if (gDebug > 1)
::Info("TXNetFileStager::GetPrefix", "found prefix: %s", pfx.Data());
}
void TXNetFileStager::Print(Option_t *) const
{
Printf("+++ stager: %s %s", GetName(), fPrefix.Data());
}
Int_t TXNetFileStager::Locate(const char *path, TString &eurl)
{
if (!IsValid()) {
GetPrefix(path, fPrefix);
fSystem = new TXNetSystem(path);
}
if (IsValid())
return fSystem->Locate(path, eurl);
return -1;
}
Bool_t TXNetFileStager::Matches(const char *s)
{
if (IsValid()) {
TString pfx;
GetPrefix(s, pfx);
return ((fPrefix == pfx) ? kTRUE : kFALSE);
}
return kFALSE;
}
Last change: Fri Jul 11 13:54:30 2008
Last generated: 2008-07-11 13:54
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.