Logo ROOT   6.10/09
Reference Guide
TGLiteResult.cxx
Go to the documentation of this file.
1 // @(#) root/glite:$Id: 341cb3fb00aaf4ff088449bebe1b7e95366bd11f $
2 // Author: Anar Manafov <A.Manafov@gsi.de> 2006-07-30
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /************************************************************************/
13 /*! \file TGLiteResult.cxx
14  */ /*
15 
16  version number: $LastChangedRevision: 1678 $
17  created by: Anar Manafov
18  2006-07-30
19  last changed by: $LastChangedBy: manafov $ $LastChangedDate: 2008-01-21 18:22:14 +0100 (Mon, 21 Jan 2008) $
20 
21  Copyright (c) 2006 GSI GridTeam. All rights reserved.
22 *************************************************************************/
23 
24 //////////////////////////////////////////////////////////////////////////
25 //
26 // The TGLiteResult class is a part of RGLite plug-in and
27 // defines an interface to a gLite result set.
28 // Objects of this class are created by TGrid methods.
29 //
30 // Related classes are TGLite.
31 //
32 //////////////////////////////////////////////////////////////////////////
33 
34 
35 #include "TGLiteResult.h"
36 #include "TObjString.h"
37 #include "TMap.h"
38 #include "Riostream.h"
39 #include "TSystem.h"
40 #include "TUrl.h"
41 #include "TFileInfo.h"
42 // STD
43 #include <cstdlib>
44 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Dump result set.
49 
50 void TGLiteResult::DumpResult()
51 {
52  std::cout << "BEGIN DUMP" << std::endl;
53  std::cout << "END DUMP" << std::endl;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 ///return a file name
58 
59 const char *TGLiteResult::GetFileName(UInt_t i) const
60 {
61  if (At(i)) {
62  TObjString * entry;
63  if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue("name"))) {
64  return entry->GetName();
65  }
66  }
67  return 0;
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 ///return file name path
72 
74 {
75  if (At(i)) {
76  TObjString * entry;
77  if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue("name"))) {
78  TObjString * path;
79  if ((path = (TObjString*)((TMap*) At(i)) ->GetValue("path"))) {
80  TString fFilePath(TString(path->GetName()) + TString(entry->GetName()));
81  return fFilePath;
82  }
83  }
84  }
85  return 0;
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 ///return path
90 
91 const char *TGLiteResult::GetPath(UInt_t i) const
92 {
93  if (At(i)) {
94  TObjString * entry;
95  if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue("path"))) {
96  return entry->GetName();
97  }
98  }
99  return 0;
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 ///return the key
104 
105 const char *TGLiteResult::GetKey(UInt_t i, const char* key) const
106 {
107  if (At(i)) {
108  TObjString * entry;
109  if ((entry = (TObjString*)((TMap*) At(i)) ->GetValue(key))) {
110  return entry->GetName();
111  }
112  }
113  return 0;
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 ///set the key
118 
119 Bool_t TGLiteResult::SetKey(UInt_t i, const char* key, const char* value)
120 {
121  if (At(i)) {
122  TPair * entry;
123  if ((entry = (TPair*)((TMap*) At(i)) ->FindObject(key))) {
124  TObject * val = ((TMap*) At(i)) ->Remove((TObject*) entry->Key());
125  if (val) {
126  delete val;
127  }
128  }
129  ((TMap*) At(i)) ->Add((TObject*)(new TObjString(key)),
130  (TObject*)(new TObjString(value)));
131  return kTRUE;
132  }
133  return kFALSE;
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 ///return a file info list
138 
140 {
141  TList * newfileinfolist = new TList();
142 
143 
144  // TODO: Revise me!!! (according to what TGlite::Ls returns)
145 
146  newfileinfolist->SetOwner(kTRUE);
147 
148  for (Int_t i = 0; i < GetSize(); i++) {
149 
150  Long64_t size = -1;
151  if (GetKey(i, "size"))
152  size = atol(GetKey(i, "size"));
153 
154  const char* md5 = GetKey(i, "md5");
155  const char* uuid = GetKey(i, "guid");
156  const char* msd = GetKey(i, "msd");
157 
158  if (md5 && !md5[0])
159  md5 = 0;
160  if (uuid && !uuid[0])
161  uuid = 0;
162  if (msd && !msd[0])
163  msd = 0;
164 
165  TString turl = GetKey(i, "turl");
166 
167  if (msd) {
168  TUrl urlturl(turl);
169  TString options = urlturl.GetOptions();
170  options += "&msd=";
171  options += msd;
172  urlturl.SetOptions(options);
173  turl = urlturl.GetUrl();
174  }
175  Info("GetFileInfoList", "Adding Url %s with Msd %s\n", turl.Data(), msd);
176  newfileinfolist->Add(new TFileInfo(turl, size, uuid, md5));
177  }
178  return newfileinfolist;
179 }
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 ///print the GLiteResult info
183 
184 void TGLiteResult::Print(Option_t * /*wildcard*/, Option_t *option) const
185 {
186  if (TString(option) != TString("all")) {
187  // TODO: Complete me!
188  // Long64_t totaldata = 0;
189  // Int_t totalfiles = 0;
190  // // the default print out format is for a query
191  // for (Int_t i = 0; i< GetSize(); i++) {
192  // if (TString(option) == TString("l") ) {
193  // printf("( %06d ) LFN: %-80s Size[Bytes]: %10s GUID: %s\n",i,GetKey(i,"lfn"),GetKey(i,"size"),GetKey(i,"guid"));
194  // } else {
195  // printf("( %06d ) LFN: .../%-48s Size[Bytes]: %10s GUID: %s\n",i,gSystem->BaseName(GetKey(i,"lfn")),GetKey(i,"size"),GetKey(i,"guid"));
196  // }
197  // if (GetKey(i, "size")) {
198  // totaldata += atol(GetKey(i,"size"));
199  // totalfiles++;
200  // }
201  // }
202  // printf("------------------------------------------------------------\n");
203  // printf("-> Result contains %.02f MB in %d Files.\n",totaldata/1024./1024.,totalfiles);
204  } else {
205  TIter next(this);
206  TMap *map;
207  for (Int_t count = 0; (map = dynamic_cast<TMap*>(next())); ++count) {
208  TIter next2(map->GetTable());
209  TPair *pair;
210  std::cout << "# " << setiosflags(std::ios::left) << std::setw(6) << count << " ------------------------------------------------------------" << std::endl;
211  while ((pair = dynamic_cast< TPair*>(next2()))) {
212  TObjString * keyStr = dynamic_cast<TObjString*>(pair->Key());
213  TObjString* valueStr = dynamic_cast<TObjString*>(pair->Value());
214  if (keyStr && valueStr) {
215  std::cout
216  << std::setw(16) << keyStr->GetName()
217  << valueStr->GetName()
218  << std::endl;
219  }
220  }
221  std::cout << std::endl;
222  }
223  }
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 ///print the GLiteResult info
228 
229 void TGLiteResult::Print(Option_t *option) const
230 {
231  Print("", option);
232 }
virtual const char * GetFileName(UInt_t i) const
return a file name
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:847
void Print(Option_t *option="") const
print the GLiteResult info
long long Long64_t
Definition: RtypesCore.h:69
Collectable string class.
Definition: TObjString.h:28
const char Option_t
Definition: RtypesCore.h:62
This class represents a WWW compatible URL.
Definition: TUrl.h:35
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Basic string class.
Definition: TString.h:129
virtual const char * GetPath(UInt_t i) const
return path
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char * GetOptions() const
Definition: TUrl.h:74
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:501
virtual const char * GetFileNamePath(UInt_t i) const
return file name path
const THashTable * GetTable() const
Definition: TMap.h:75
A doubly linked list.
Definition: TList.h:43
const char * GetName() const
Returns name of object.
Definition: TObjString.h:39
virtual const char * GetKey(UInt_t i, const char *key) const
return the key
TObject * Key() const
Definition: TMap.h:120
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:679
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:315
const Bool_t kFALSE
Definition: RtypesCore.h:92
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:102
#define ClassImp(name)
Definition: Rtypes.h:336
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40
Mother of all ROOT objects.
Definition: TObject.h:37
TList()
Definition: TList.h:68
typedef void((*Func_t)())
virtual void Add(TObject *obj)
Definition: TList.h:77
void SetOptions(const char *opt)
Definition: TUrl.h:90
Class describing a generic file including meta information.
Definition: TFileInfo.h:38
virtual Int_t GetSize() const
Definition: TCollection.h:89
virtual TList * GetFileInfoList() const
return a file info list
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual Bool_t SetKey(UInt_t i, const char *key, const char *value)
set the key
const char * Data() const
Definition: TString.h:347