#include "TFileInfo.h"
#include "Riostream.h"
#include "TSystem.h"
#include "TClass.h"
ClassImp(TFileInfo)
ClassImp(TFileInfoMeta)
TFileInfo::TFileInfo(const char *url, Long64_t size, const char *uuid,
const char *md5, TObject *meta)
: fCurrentUrl(0), fUrlList(0), fSize(size), fUUID(0), fMD5(0),
fMetaDataList(0)
{
if (uuid)
fUUID = new TUUID(uuid);
else
fUUID = new TUUID;
if (md5)
fMD5 = new TMD5((const UChar_t*)md5);
else
fMD5 = new TMD5;
SetName(fUUID->AsString());
SetTitle("TFileInfo");
if (url)
AddUrl(url);
if (meta)
AddMetaData(meta);
}
TFileInfo::~TFileInfo()
{
SafeDelete(fMetaDataList);
SafeDelete(fUUID);
SafeDelete(fMD5);
SafeDelete(fUrlList);
}
TUrl *TFileInfo::GetCurrentUrl() const
{
if (!fCurrentUrl)
const_cast<TFileInfo*>(this)->ResetUrl();
return fCurrentUrl;
}
TUrl *TFileInfo::NextUrl()
{
if (!fUrlList)
return 0;
TUrl *returl = fCurrentUrl;
if (fCurrentUrl)
fCurrentUrl = (TUrl*)fUrlList->After(fCurrentUrl);
return returl;
}
TUrl *TFileInfo::FindByUrl(const char *url)
{
TIter nextUrl(fUrlList);
TUrl *urlelement;
while ((urlelement = (TUrl*) nextUrl())) {
if ( TString(urlelement->GetUrl()) == TString(url) ) {
return urlelement;
}
}
return 0;
}
Bool_t TFileInfo::AddUrl(const char *url, Bool_t infront)
{
if (FindByUrl(url))
return kFALSE;
if (!fUrlList) {
fUrlList = new TList;
fUrlList->SetOwner();
}
TUrl *newurl = new TUrl(url, kTRUE);
if (fUrlList->GetSize() == 0)
fCurrentUrl = newurl;
if (infront)
fUrlList->AddFirst(newurl);
else
fUrlList->Add(newurl);
return kTRUE;
}
Bool_t TFileInfo::RemoveUrl(const char *url)
{
TUrl *lurl;
if ((lurl = FindByUrl(url))) {
fUrlList->Remove(lurl);
if (lurl == fCurrentUrl)
ResetUrl();
delete lurl;
return kTRUE;
}
return kFALSE;
}
Bool_t TFileInfo::AddMetaData(TObject *meta)
{
if (meta) {
if (!fMetaDataList) {
fMetaDataList = new TList;
fMetaDataList->SetOwner();
}
fMetaDataList->Add(meta);
return kTRUE;
}
return kFALSE;
}
Bool_t TFileInfo::RemoveMetaData(const char *meta)
{
if (fMetaDataList) {
if (!meta || strlen(meta) <= 0) {
SafeDelete(fMetaDataList);
return kTRUE;
} else {
TObject *o = fMetaDataList->FindObject(meta);
if (o) {
fMetaDataList->Remove(o);
delete o;
return kTRUE;
}
}
}
return kFALSE;
}
TFileInfoMeta *TFileInfo::GetMetaData(const char *meta) const
{
if (fMetaDataList) {
TFileInfoMeta *m;
if (!meta || strlen(meta) <= 0)
m = (TFileInfoMeta *) fMetaDataList->First();
else
m = (TFileInfoMeta *) fMetaDataList->FindObject(meta);
if (m) {
TClass *c = m->IsA();
return (c && c->InheritsFrom("TFileInfoMeta")) ? m : 0;
}
}
return 0;
}
Int_t TFileInfo::Compare(const TObject *obj) const
{
if (this == obj) return 0;
if (TFileInfo::Class() != obj->IsA()) return -1;
return (GetFirstUrl()->Compare(((TFileInfo*)obj)->GetFirstUrl()));
}
void TFileInfo::Print(Option_t * ) const
{
GetMD5()->Final();
cout << "UUID: " << GetUUID()->AsString() << "\n"
<< "MD5: " << GetMD5()->AsString() << "\n"
<< "Size: " << GetSize() << endl;
TIter next(fUrlList);
TUrl *u;
cout << " === URLs ===" << endl;
while ((u = (TUrl*)next()))
cout << " URL: " << u->GetUrl() << endl;
TIter nextm(fMetaDataList);
TObject *m = 0;
while ((m = (TObject*) nextm())) {
cout << " === Meta Data Object ===" << endl;
m->Print();
}
}
TFileInfoMeta::TFileInfoMeta(const char *objPath, const char *objClass,
Long64_t entries, Long64_t first, Long64_t last,
Long64_t totbytes, Long64_t zipbytes)
: TNamed(objPath, objClass), fEntries(entries), fFirst(first),
fLast(last), fTotBytes(totbytes), fZipBytes(zipbytes)
{
TString p = objPath;
if (!p.BeginsWith("/")) {
p.Prepend("/");
SetName(p);
}
TClass *c = TClass::GetClass(objClass);
fIsTree = (c && c->InheritsFrom("TTree")) ? kTRUE : kFALSE;
}
TFileInfoMeta::TFileInfoMeta(const char *objPath, const char *objDir,
const char *objClass, Long64_t entries,
Long64_t first, Long64_t last,
Long64_t totbytes, Long64_t zipbytes)
: TNamed(objPath, objClass), fEntries(entries), fFirst(first),
fLast(last), fTotBytes(totbytes), fZipBytes(zipbytes)
{
TString sdir = objDir;
if (!sdir.BeginsWith("/"))
sdir.Prepend("/");
if (!sdir.EndsWith("/"))
sdir += "/";
sdir += objPath;
SetName(sdir);
TClass *c = TClass::GetClass(objClass);
fIsTree = (c && c->InheritsFrom("TTree")) ? kTRUE : kFALSE;
}
const char *TFileInfoMeta::GetDirectory() const
{
return gSystem->DirName(GetName());
}
const char *TFileInfoMeta::GetObject() const
{
return gSystem->BaseName(GetName());
}
void TFileInfoMeta::Print(Option_t * ) const
{
cout << " Name: " << fName << "\n"
<< " Class: " << fTitle << "\n"
<< " Entries: " << fEntries << "\n"
<< " First: " << fFirst << "\n"
<< " Last: " << fLast << endl;
}
Last change: Wed Jun 25 08:39:02 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.