#include "TArchiveFile.h"
#include "TPluginManager.h"
#include "TROOT.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TError.h"
#include "TUrl.h"
#include <stdlib.h>
ClassImp(TArchiveFile)
TArchiveFile::TArchiveFile(const char *archive, const char *member, TFile *file)
{
if (!file)
Error("TArchiveFile", "must specify a valid TFile");
fFile = file;
fArchiveName = archive;
fMemberName = member;
fMemberIndex = -1;
if (fMemberName.IsDigit())
fMemberIndex = atoi(fMemberName);
fMembers = new TObjArray;
fMembers->SetOwner();
fCurMember = 0;
}
TArchiveFile::~TArchiveFile()
{
delete fMembers;
}
Long64_t TArchiveFile::GetMemberFilePosition() const
{
return fCurMember ? fCurMember->GetFilePosition() : 0;
}
Int_t TArchiveFile::GetNumberOfMembers() const
{
return fMembers->GetEntriesFast();
}
Int_t TArchiveFile::SetMember(const char *member)
{
fMemberName = member;
fMemberIndex = -1;
return SetCurrentMember();
}
Int_t TArchiveFile::SetMember(Int_t idx)
{
fMemberName = "";
fMemberIndex = idx;
return SetCurrentMember();
}
TArchiveFile *TArchiveFile::Open(const char *url, TFile *file)
{
if (!file) {
::Error("TArchiveFile::Open", "must specify a valid TFile to access %s",
url);
return 0;
}
TString archive, member, type;
if (!ParseUrl(url, archive, member, type))
return 0;
TArchiveFile *f = 0;
TPluginHandler *h;
if ((h = gROOT->GetPluginManager()->FindHandler("TArchiveFile", type))) {
if (h->LoadPlugin() == -1)
return 0;
f = (TArchiveFile*) h->ExecPlugin(3, archive.Data(), member.Data(), file);
}
return f;
}
Bool_t TArchiveFile::ParseUrl(const char *url, TString &archive, TString &member,
TString &type)
{
TUrl u(url, kTRUE);
archive = "";
member = "";
type = "";
TString urloptions = u.GetOptions();
TObjArray *objOptions = urloptions.Tokenize("&");
for (Int_t n = 0; n < objOptions->GetEntries(); n++) {
TString loption = ((TObjString*)objOptions->At(n))->GetName();
TObjArray *objTags = loption.Tokenize("=");
if (objTags->GetEntries() == 2) {
TString key = ((TObjString*)objTags->At(0))->GetName();
TString value = ((TObjString*)objTags->At(1))->GetName();
if (!key.CompareTo("zip", TString::kIgnoreCase)) {
archive = u.GetFile();
member = value;
type = "dummy.zip";
}
}
delete objTags;
}
delete objOptions;
if (member != "") {
return kTRUE;
}
if (!strlen(u.GetAnchor())) {
archive = u.GetFile();
return kTRUE;
}
archive = u.GetFile();
member = u.GetAnchor();
type = archive;
if (archive == "" || member == "") {
archive = "";
member = "";
return kFALSE;
}
return kTRUE;
}
ClassImp(TArchiveMember)
TArchiveMember::TArchiveMember()
{
fName = "";
fComment = "";
fPosition = 0;
fFilePosition = 0;
fCsize = 0;
fDsize = 0;
fDirectory = kFALSE;
}
TArchiveMember::TArchiveMember(const char *name)
{
fName = name;
fComment = "";
fPosition = 0;
fFilePosition = 0;
fCsize = 0;
fDsize = 0;
fDirectory = kFALSE;
}
TArchiveMember::TArchiveMember(const TArchiveMember &member)
: TObject(member)
{
fName = member.fName;
fComment = member.fComment;
fModTime = member.fModTime;
fPosition = member.fPosition;
fFilePosition = member.fFilePosition;
fCsize = member.fCsize;
fDsize = member.fDsize;
fDirectory = member.fDirectory;
}
TArchiveMember &TArchiveMember::operator=(const TArchiveMember &rhs)
{
if (this != &rhs) {
TObject::operator=(rhs);
fName = rhs.fName;
fComment = rhs.fComment;
fModTime = rhs.fModTime;
fPosition = rhs.fPosition;
fFilePosition = rhs.fFilePosition;
fCsize = rhs.fCsize;
fDsize = rhs.fDsize;
fDirectory = rhs.fDirectory;
}
return *this;
}
Last change: Tue Sep 2 10:48:11 2008
Last generated: 2008-09-02 10:48
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.