00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "TAlienResult.h"
00024 #include "TObjString.h"
00025 #include "TMap.h"
00026 #include "Riostream.h"
00027 #include "TSystem.h"
00028 #include "TUrl.h"
00029 #include "TFileInfo.h"
00030 #include "TEntryList.h"
00031 #include <cstdlib>
00032
00033
00034 ClassImp(TAlienResult)
00035
00036
00037 TAlienResult::~TAlienResult()
00038 {
00039
00040
00041 TIter next(this);
00042 while (TMap * obj = (TMap *) next()) {
00043 obj->DeleteAll();
00044 }
00045 }
00046
00047
00048 void TAlienResult::DumpResult()
00049 {
00050
00051
00052 cout << "BEGIN DUMP" << endl;
00053 TIter next(this);
00054 TMap *map;
00055 while ((map = (TMap *) next())) {
00056 TIter next2(map->GetTable());
00057 TPair *pair;
00058 while ((pair = (TPair *) next2())) {
00059 TObjString *keyStr = dynamic_cast < TObjString * >(pair->Key());
00060 TObjString *valueStr =
00061 dynamic_cast < TObjString * >(pair->Value());
00062
00063 if (keyStr) {
00064 cout << "Key: " << keyStr->GetString() << " ";
00065 }
00066 if (valueStr) {
00067 cout << "Value: " << valueStr->GetString();
00068 }
00069 cout << endl;
00070 }
00071 }
00072
00073 cout << "END DUMP" << endl;
00074 }
00075
00076
00077 const char *TAlienResult::GetFileName(UInt_t i) const
00078 {
00079
00080
00081 if (At(i)) {
00082 TObjString *entry;
00083 if ((entry = (TObjString *) ((TMap *) At(i))->GetValue("name"))) {
00084 return entry->GetName();
00085 }
00086 }
00087 return 0;
00088 }
00089
00090
00091 const TEntryList *TAlienResult::GetEntryList(UInt_t i) const
00092 {
00093
00094
00095 if (At(i)) {
00096 TEntryList *entry;
00097 if ((entry = (TEntryList *) ((TMap *) At(i))->GetValue("evlist"))) {
00098 return entry;
00099 }
00100 }
00101 return 0;
00102 }
00103
00104
00105 const char *TAlienResult::GetFileNamePath(UInt_t i) const
00106 {
00107
00108
00109 if (At(i)) {
00110 TObjString *entry;
00111 if ((entry = (TObjString *) ((TMap *) At(i))->GetValue("name"))) {
00112 TObjString *path;
00113 if ((path = (TObjString *) ((TMap *) At(i))->GetValue("path"))) {
00114 fFilePath =
00115 TString(path->GetName()) + TString(entry->GetName());
00116 return fFilePath;
00117 }
00118 }
00119 }
00120 return 0;
00121 }
00122
00123
00124 const char *TAlienResult::GetPath(UInt_t i) const
00125 {
00126
00127
00128 if (At(i)) {
00129 TObjString *entry;
00130 if ((entry = (TObjString *) ((TMap *) At(i))->GetValue("path"))) {
00131 return entry->GetName();
00132 }
00133 }
00134 return 0;
00135 }
00136
00137
00138 const char *TAlienResult::GetKey(UInt_t i, const char *key) const
00139 {
00140
00141
00142 if (At(i)) {
00143 TObjString *entry;
00144 if ((entry = (TObjString *) ((TMap *) At(i))->GetValue(key))) {
00145 return entry->GetName();
00146 }
00147 }
00148 return 0;
00149 }
00150
00151
00152 Bool_t TAlienResult::SetKey(UInt_t i, const char *key, const char *value)
00153 {
00154
00155
00156 if (At(i)) {
00157 TPair *entry;
00158 if ((entry = (TPair *) ((TMap *) At(i))->FindObject(key))) {
00159 TObject *val = ((TMap *) At(i))->Remove((TObject *) entry->Key());
00160 if (val) {
00161 delete val;
00162 }
00163 }
00164 ((TMap *) At(i))->Add(new TObjString(key), new TObjString(value));
00165 return kTRUE;
00166 }
00167 return kFALSE;
00168 }
00169
00170
00171 TList *TAlienResult::GetFileInfoList() const
00172 {
00173
00174
00175 TList *newfileinfolist = new TList();
00176
00177 newfileinfolist->SetOwner(kTRUE);
00178
00179 for (Int_t i = 0; i < GetSize(); i++) {
00180
00181 Long64_t size = -1;
00182 if (GetKey(i, "size"))
00183 size = atol(GetKey(i, "size"));
00184
00185 const char *md5 = GetKey(i, "md5");
00186 const char *uuid = GetKey(i, "guid");
00187 const char *msd = GetKey(i, "msd");
00188
00189 if (md5 && !strlen(md5))
00190 md5 = 0;
00191 if (uuid && !strlen(uuid))
00192 uuid = 0;
00193 if (msd && !strlen(msd))
00194 msd = 0;
00195
00196 TString turl = GetKey(i, "turl");
00197
00198 if (msd) {
00199 TUrl urlturl(turl);
00200 TString options = urlturl.GetOptions();
00201 options += "&msd=";
00202 options += msd;
00203 urlturl.SetOptions(options);
00204 turl = urlturl.GetUrl();
00205 }
00206 Info("GetFileInfoList", "Adding Url %s with Msd %s\n", turl.Data(),
00207 msd);
00208 newfileinfolist->Add(new TFileInfo(turl, size, uuid, md5));
00209 }
00210 return newfileinfolist;
00211 }
00212
00213
00214 void TAlienResult::Print(Option_t * option) const
00215 {
00216
00217
00218 Long64_t totaldata = 0;
00219 Int_t totalfiles = 0;
00220
00221 if (TString(option) != TString("all")) {
00222
00223 for (Int_t i = 0; i < GetSize(); i++) {
00224 if (TString(option) == TString("l")) {
00225 printf("( %06d ) LFN: %-80s Size[Bytes]: %10s GUID: %s\n",
00226 i, GetKey(i, "lfn"), GetKey(i, "size"), GetKey(i,
00227 "guid"));
00228 } else {
00229 printf("( %06d ) LFN: .../%-48s Size[Bytes]: %10s GUID: %s\n",
00230 i, gSystem->BaseName(GetKey(i, "lfn")), GetKey(i, "size"),
00231 GetKey(i, "guid"));
00232 }
00233 if (GetKey(i, "size")) {
00234 totaldata += atol(GetKey(i, "size"));
00235 totalfiles++;
00236 }
00237 }
00238 printf("------------------------------------------------------------\n");
00239 printf("-> Result contains %.02f MB in %d Files.\n",
00240 totaldata / 1024. / 1024., totalfiles);
00241 } else {
00242 TIter next(this);
00243 TMap *map;
00244 Int_t i = 1;
00245 while ((map = (TMap *) next())) {
00246 TIter next2(map->GetTable());
00247 TPair *pair;
00248 printf("------------------------------------------------------------\n");
00249 while ((pair = (TPair *) next2())) {
00250 TObjString *keyStr =
00251 dynamic_cast < TObjString * >(pair->Key());
00252 TObjString *valueStr =
00253 dynamic_cast < TObjString * >(pair->Value());
00254 if (keyStr && valueStr)
00255 printf("( %06d ) [ -%16s ] = %s\n", i, keyStr->GetName(),
00256 valueStr->GetName());
00257 }
00258 i++;
00259 }
00260 }
00261 }