TGLiteResult.cxx

Go to the documentation of this file.
00001 // @(#) root/glite:$Id: TGLiteResult.cxx 24647 2008-07-03 14:20:28Z anar $
00002 // Author: Anar Manafov <A.Manafov@gsi.de> 2006-07-30
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 /************************************************************************/
00013 /*! \file TGLiteresult.cxx
00014  */ /*
00015 
00016          version number:    $LastChangedRevision: 1678 $
00017          created by:        Anar Manafov
00018                             2006-07-30
00019          last changed by:   $LastChangedBy: manafov $ $LastChangedDate: 2008-01-21 18:22:14 +0100 (Mon, 21 Jan 2008) $
00020 
00021          Copyright (c) 2006 GSI GridTeam. All rights reserved.
00022 *************************************************************************/
00023 
00024 //////////////////////////////////////////////////////////////////////////
00025 //
00026 // The TGLiteResult class is a part of RGLite plug-in and
00027 // defines an interface to a gLite result set.
00028 // Objects of this class are created by TGrid methods.
00029 //
00030 // Related classes are TGLite.
00031 //
00032 //////////////////////////////////////////////////////////////////////////
00033 
00034 
00035 #include "TGLiteResult.h"
00036 #include "TObjString.h"
00037 #include "TMap.h"
00038 #include "Riostream.h"
00039 #include "TSystem.h"
00040 #include "TUrl.h"
00041 #include "TFileInfo.h"
00042 // STD
00043 #include <cstdlib>
00044 
00045 ClassImp(TGLiteResult)
00046 
00047 //______________________________________________________________________________
00048 void TGLiteResult::DumpResult()
00049 {
00050    // Dump result set.
00051 
00052    cout << "BEGIN DUMP" << endl;
00053    cout << "END DUMP" << endl;
00054 }
00055 
00056 //______________________________________________________________________________
00057 const char *TGLiteResult::GetFileName(UInt_t i) const
00058 {
00059    //return a file name
00060    if (At(i)) {
00061       TObjString * entry;
00062       if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue("name"))) {
00063          return entry->GetName();
00064       }
00065    }
00066    return 0;
00067 }
00068 
00069 //______________________________________________________________________________
00070 const char *TGLiteResult::GetFileNamePath(UInt_t i) const
00071 {
00072    //return file name path
00073    if (At(i)) {
00074       TObjString * entry;
00075       if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue("name"))) {
00076          TObjString * path;
00077          if ((path = (TObjString*)((TMap*) At(i)) ->GetValue("path"))) {
00078             TString fFilePath(TString(path->GetName()) + TString(entry->GetName()));
00079             return fFilePath;
00080          }
00081       }
00082    }
00083    return 0;
00084 }
00085 
00086 //______________________________________________________________________________
00087 const char *TGLiteResult::GetPath(UInt_t i) const
00088 {
00089    //return path
00090    if (At(i)) {
00091       TObjString * entry;
00092       if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue("path"))) {
00093          return entry->GetName();
00094       }
00095    }
00096    return 0;
00097 }
00098 
00099 //______________________________________________________________________________
00100 const char *TGLiteResult::GetKey(UInt_t i, const char* key) const
00101 {
00102    //return the key
00103    if (At(i)) {
00104       TObjString * entry;
00105       if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue(key))) {
00106          return entry->GetName();
00107       }
00108    }
00109    return 0;
00110 }
00111 
00112 //______________________________________________________________________________
00113 Bool_t TGLiteResult::SetKey(UInt_t i, const char* key, const char* value)
00114 {
00115    //set the key
00116    if (At(i)) {
00117       TPair * entry;
00118       if ((entry = (TPair*)((TMap*) At(i)) ->FindObject(key))) {
00119          TObject * val = ((TMap*) At(i)) ->Remove((TObject*) entry->Key());
00120          if (val) {
00121             delete val;
00122          }
00123       }
00124       ((TMap*) At(i)) ->Add((TObject*)(new TObjString(key)),
00125             (TObject*)(new TObjString(value)));
00126       return kTRUE;
00127    }
00128    return kFALSE;
00129 }
00130 
00131 //______________________________________________________________________________
00132 TList *TGLiteResult::GetFileInfoList() const
00133 {
00134    //return a file info list
00135    TList * newfileinfolist = new TList();
00136 
00137 
00138    // TODO: Revise me!!! (according to what TGlite::Ls returns)
00139 
00140    newfileinfolist->SetOwner(kTRUE);
00141 
00142    for (Int_t i = 0; i < GetSize(); i++) {
00143 
00144       Long64_t size = -1;
00145       if (GetKey(i, "size"))
00146          size = atol(GetKey(i, "size"));
00147 
00148       const char* md5 = GetKey(i, "md5");
00149       const char* uuid = GetKey(i, "guid");
00150       const char* msd = GetKey(i, "msd");
00151 
00152       if (md5 && !strlen(md5))
00153          md5 = 0;
00154       if (uuid && !strlen(uuid))
00155          uuid = 0;
00156       if (msd && !strlen(msd))
00157          msd = 0;
00158 
00159       TString turl = GetKey(i, "turl");
00160 
00161       if (msd) {
00162          TUrl urlturl(turl);
00163          TString options = urlturl.GetOptions();
00164          options += "&msd=";
00165          options += msd;
00166          urlturl.SetOptions(options);
00167          turl = urlturl.GetUrl();
00168       }
00169       Info("GetFileInfoList", "Adding Url %s with Msd %s\n", turl.Data(), msd);
00170       newfileinfolist->Add(new TFileInfo(turl, size, uuid, md5));
00171    }
00172    return newfileinfolist;
00173 }
00174 
00175 //______________________________________________________________________________
00176 void TGLiteResult::Print(Option_t * /*wildcard*/, Option_t *option) const
00177 {
00178    //print the GLiteResult info
00179 
00180    if (TString(option) != TString("all")) {
00181       //  TODO: Complete me!
00182       // Long64_t totaldata = 0;
00183       // Int_t totalfiles = 0;
00184       //       // the default print out format is for a query
00185       //     for (Int_t i = 0; i< GetSize(); i++) {
00186       //       if (TString(option) == TString("l") ) {
00187       //  printf("( %06d ) LFN: %-80s   Size[Bytes]: %10s   GUID: %s\n",i,GetKey(i,"lfn"),GetKey(i,"size"),GetKey(i,"guid"));
00188       //       } else {
00189       //  printf("( %06d ) LFN: .../%-48s   Size[Bytes]: %10s   GUID: %s\n",i,gSystem->BaseName(GetKey(i,"lfn")),GetKey(i,"size"),GetKey(i,"guid"));
00190       //       }
00191       //       if (GetKey(i, "size")) {
00192       //  totaldata += atol(GetKey(i,"size"));
00193       //  totalfiles++;
00194       //       }
00195       //     }
00196       //     printf("------------------------------------------------------------\n");
00197       //     printf("-> Result contains %.02f MB in %d Files.\n",totaldata/1024./1024.,totalfiles);
00198    } else {
00199       TIter next(this);
00200       TMap *map;
00201       for (Int_t count = 0; (map = dynamic_cast<TMap*>(next())); ++count) {
00202          TIter next2(map->GetTable());
00203          TPair *pair;
00204          cout << "# " << setiosflags(ios::left) << setw(6) << count << " ------------------------------------------------------------" << endl;
00205          while ((pair = dynamic_cast< TPair*>(next2()))) {
00206             TObjString * keyStr = dynamic_cast<TObjString*>(pair->Key());
00207             TObjString* valueStr = dynamic_cast<TObjString*>(pair->Value());
00208             if (keyStr && valueStr) {
00209                cout
00210                << setw(16) << keyStr->GetName()
00211                << valueStr->GetName()
00212                << endl;
00213             }
00214          }
00215          cout << endl;
00216       }
00217    }
00218 }
00219 
00220 //______________________________________________________________________________
00221 void TGLiteResult::Print(Option_t *option) const
00222 {
00223    //print the GLiteResult info
00224    Print("", option);
00225 }

Generated on Tue Jul 5 14:45:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1