#include "TError.h"
#include "TFileInfo.h"
#include "TSeqCollection.h"
#include "TFile.h"
#include "TFileStager.h"
#include "TObjString.h"
#include "TPluginManager.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TUrl.h"
TList* TFileStager::GetStaged(TCollection *pathlist)
{
if (!pathlist) {
Error("GetStaged", "list of pathnames was not specified!");
return 0;
}
TList* stagedlist = new TList();
TIter nxt(pathlist);
TObject* o = 0;
Bool_t local = (!strcmp(GetName(), "local")) ? kTRUE : kFALSE;
while ((o = nxt())) {
TString pn = TFileStager::GetPathName(o);
if (pn == "") {
Warning("GetStaged", "object is of unexpected type %s - ignoring", o->ClassName());
} else if (local || IsStaged(pn))
stagedlist->Add(new TObjString(pn));
}
stagedlist->SetOwner(kTRUE);
Info("GetStaged", "%d files staged", stagedlist->GetSize());
return stagedlist;
}
Bool_t TFileStager::Stage(TCollection *pathlist, Option_t *opt)
{
TIter nxt(pathlist);
TObject *o = 0;
Bool_t success = kFALSE;
while ((o = nxt())) {
TString pn = TFileStager::GetPathName(o);
if (pn == "") {
Warning("Stage", "found object of unexpected type %s - ignoring",
o->ClassName());
continue;
}
success &= Stage(pn, opt);
}
return success;
}
TFileStager *TFileStager::Open(const char *stager)
{
TPluginHandler *h;
TFileStager *s = 0;
if (!stager) {
::Error("TFileStager::Open", "stager name missing: do nothing");
return 0;
}
if ((h = gROOT->GetPluginManager()->FindHandler("TFileStager", stager))) {
if (h->LoadPlugin() == -1)
return 0;
s = (TFileStager *) h->ExecPlugin(1, stager);
} else
s = new TFileStager("local");
return s;
}
Bool_t TFileStager::IsStaged(const char *f)
{
TUrl u(f);
u.SetOptions("filetype=raw");
TFile *ff = TFile::Open(u.GetUrl());
Bool_t rc = kTRUE;
if (!ff || ff->IsZombie()) {
rc = kFALSE;
if (ff) {
ff->Close();
delete ff;
}
}
return rc;
}
Int_t TFileStager::Locate(const char *u, TString &f)
{
if (!IsStaged(u))
return -1;
f = u;
return 0;
}
TString TFileStager::GetPathName(TObject *o)
{
TString pathname;
TString cn(o->ClassName());
if (cn == "TUrl") {
pathname = ((TUrl*)o)->GetUrl();
} else if (cn == "TObjString") {
pathname = ((TObjString*)o)->GetName();
} else if (cn == "TFileInfo") {
TFileInfo *fi = (TFileInfo *)o;
pathname = (fi->GetCurrentUrl()) ? fi->GetCurrentUrl()->GetUrl() : "";
if (fi->GetCurrentUrl()) {
if (strlen(fi->GetCurrentUrl()->GetAnchor()) > 0) {
TUrl url(*(fi->GetCurrentUrl()));
url.SetAnchor("");
pathname = url.GetUrl();
}
} else {
pathname = fi->GetCurrentUrl()->GetUrl();
}
}
return pathname;
}
Last change: Wed Jun 25 08:39:05 2008
Last generated: 2008-06-25 08:39
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.