ROOT  6.06/09
Reference Guide
TAlienResult.cxx
Go to the documentation of this file.
1 // @(#)root/alien:$Id: 11fde82f21e66ae11add660ef69f33597f089efb $
2 // Author: Fons Rademakers 23/5/2002
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 // //
14 // TAlienResult //
15 // //
16 // Class defining interface to a Alien result set. //
17 // Objects of this class are created by TGrid methods. //
18 // //
19 // Related classes are TAlien. //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TAlienResult.h"
24 #include "TObjString.h"
25 #include "TMap.h"
26 #include "Riostream.h"
27 #include "TSystem.h"
28 #include "TUrl.h"
29 #include "TFileInfo.h"
30 #include "TEntryList.h"
31 #include <cstdlib>
32 
33 
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Cleanup object.
38 
40 {
41  TIter next(this);
42  while (TMap * obj = (TMap *) next()) {
43  obj->DeleteAll();
44  }
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Dump result set.
49 
51 {
52  std::cout << "BEGIN DUMP" << std::endl;
53  TIter next(this);
54  TMap *map;
55  while ((map = (TMap *) next())) {
56  TIter next2(map->GetTable());
57  TPair *pair;
58  while ((pair = (TPair *) next2())) {
59  TObjString *keyStr = dynamic_cast < TObjString * >(pair->Key());
60  TObjString *valueStr =
61  dynamic_cast < TObjString * >(pair->Value());
62 
63  if (keyStr) {
64  std::cout << "Key: " << keyStr->GetString() << " ";
65  }
66  if (valueStr) {
67  std::cout << "Value: " << valueStr->GetString();
68  }
69  std::cout << std::endl;
70  }
71  }
72 
73  std::cout << "END DUMP" << std::endl;
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 ///Return a file name.
78 
79 const char *TAlienResult::GetFileName(UInt_t i) const
80 {
81  if (At(i)) {
83  if ((entry = (TObjString *) ((TMap *) At(i))->GetValue("name"))) {
84  return entry->GetName();
85  }
86  }
87  return 0;
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Return the entry list, if evtlist was defined as a tag.
92 
94 {
95  if (At(i)) {
97  if ((entry = (TEntryList *) ((TMap *) At(i))->GetValue("evlist"))) {
98  return entry;
99  }
100  }
101  return 0;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Return file name path.
106 
108 {
109  if (At(i)) {
110  TObjString *entry;
111  if ((entry = (TObjString *) ((TMap *) At(i))->GetValue("name"))) {
112  TObjString *path;
113  if ((path = (TObjString *) ((TMap *) At(i))->GetValue("path"))) {
114  fFilePath =
115  TString(path->GetName()) + TString(entry->GetName());
116  return fFilePath;
117  }
118  }
119  }
120  return 0;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Return path.
125 
126 const char *TAlienResult::GetPath(UInt_t i) const
127 {
128  if (At(i)) {
129  TObjString *entry;
130  if ((entry = (TObjString *) ((TMap *) At(i))->GetValue("path"))) {
131  return entry->GetName();
132  }
133  }
134  return 0;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Return the key.
139 
140 const char *TAlienResult::GetKey(UInt_t i, const char *key) const
141 {
142  if (At(i)) {
143  TObjString *entry;
144  if ((entry = (TObjString *) ((TMap *) At(i))->GetValue(key))) {
145  return entry->GetName();
146  }
147  }
148  return 0;
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Set the key.
153 
154 Bool_t TAlienResult::SetKey(UInt_t i, const char *key, const char *value)
155 {
156  if (At(i)) {
157  TPair *entry;
158  if ((entry = (TPair *) ((TMap *) At(i))->FindObject(key))) {
159  TObject *val = ((TMap *) At(i))->Remove((TObject *) entry->Key());
160  if (val) {
161  delete val;
162  }
163  }
164  ((TMap *) At(i))->Add(new TObjString(key), new TObjString(value));
165  return kTRUE;
166  }
167  return kFALSE;
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Return a file info list.
172 
174 {
175  TList *newfileinfolist = new TList();
176 
177  newfileinfolist->SetOwner(kTRUE);
178 
179  for (Int_t i = 0; i < GetSize(); i++) {
180 
181  Long64_t size = -1;
182  if (GetKey(i, "size"))
183  size = atol(GetKey(i, "size"));
184 
185  const char *md5 = GetKey(i, "md5");
186  const char *uuid = GetKey(i, "guid");
187  const char *msd = GetKey(i, "msd");
188 
189  if (md5 && !md5[0])
190  md5 = 0;
191  if (uuid && !uuid[0])
192  uuid = 0;
193  if (msd && !msd[0])
194  msd = 0;
195 
196  TString turl = GetKey(i, "turl");
197 
198  if (msd) {
199  TUrl urlturl(turl);
200  TString options = urlturl.GetOptions();
201  options += "&msd=";
202  options += msd;
203  urlturl.SetOptions(options);
204  turl = urlturl.GetUrl();
205  }
206  Info("GetFileInfoList", "Adding Url %s with Msd %s\n", turl.Data(),
207  msd);
208  newfileinfolist->Add(new TFileInfo(turl, size, uuid, md5));
209  }
210  return newfileinfolist;
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Print the AlienResult info.
215 
216 void TAlienResult::Print(Option_t * option) const
217 {
218  Long64_t totaldata = 0;
219  Int_t totalfiles = 0;
220 
221  if (TString(option) != TString("all")) {
222  // the default print out format is for a query
223  for (Int_t i = 0; i < GetSize(); i++) {
224  if (TString(option) == TString("l")) {
225  printf("( %06d ) LFN: %-80s Size[Bytes]: %10s GUID: %s\n",
226  i, GetKey(i, "lfn"), GetKey(i, "size"), GetKey(i,
227  "guid"));
228  } else {
229  printf("( %06d ) LFN: .../%-48s Size[Bytes]: %10s GUID: %s\n",
230  i, gSystem->BaseName(GetKey(i, "lfn")), GetKey(i, "size"),
231  GetKey(i, "guid"));
232  }
233  if (GetKey(i, "size")) {
234  totaldata += atol(GetKey(i, "size"));
235  totalfiles++;
236  }
237  }
238  printf("------------------------------------------------------------\n");
239  printf("-> Result contains %.02f MB in %d Files.\n",
240  totaldata / 1024. / 1024., totalfiles);
241  } else {
242  TIter next(this);
243  TMap *map;
244  Int_t i = 1;
245  while ((map = (TMap *) next())) {
246  TIter next2(map->GetTable());
247  TPair *pair;
248  printf("------------------------------------------------------------\n");
249  while ((pair = (TPair *) next2())) {
250  TObjString *keyStr =
251  dynamic_cast < TObjString * >(pair->Key());
252  TObjString *valueStr =
253  dynamic_cast < TObjString * >(pair->Value());
254  if (keyStr && valueStr)
255  printf("( %06d ) [ -%16s ] = %s\n", i, keyStr->GetName(),
256  valueStr->GetName());
257  }
258  i++;
259  }
260  }
261 }
const char * GetName() const
Returns name of object.
Definition: TObjString.h:42
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:928
long long Long64_t
Definition: RtypesCore.h:69
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
const char Int_t const char TProof Int_t const char const char * msd
Definition: TXSlave.cxx:46
Collectable string class.
Definition: TObjString.h:32
const char Option_t
Definition: RtypesCore.h:62
This class represents a WWW compatible URL.
Definition: TUrl.h:41
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
const THashTable * GetTable() const
Definition: TMap.h:79
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:496
const char * GetOptions() const
Definition: TUrl.h:80
virtual void Print(Option_t *option="") const
Print the AlienResult info.
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:310
const char * Data() const
Definition: TString.h:349
virtual Bool_t SetKey(UInt_t i, const char *key, const char *value)
Set the key.
virtual TList * GetFileInfoList() const
Return a file info list.
A doubly linked list.
Definition: TList.h:47
TString GetString() const
Definition: TObjString.h:50
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:674
virtual void DumpResult()
Dump result set.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual const TEntryList * GetEntryList(UInt_t i) const
Return the entry list, if evtlist was defined as a tag.
Long64_t entry
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
ClassImp(TAlienResult) TAlienResult
Cleanup object.
virtual const char * GetKey(UInt_t i, const char *key) const
Return the key.
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
virtual Int_t GetSize() const
Definition: TCollection.h:95
TObject * Key() const
Definition: TMap.h:124
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:44
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
TString fFilePath
Definition: TAlienResult.h:34
Mother of all ROOT objects.
Definition: TObject.h:58
TList()
Definition: TList.h:72
virtual void Add(TObject *obj)
Definition: TList.h:81
void SetOptions(const char *opt)
Definition: TUrl.h:96
virtual const char * GetPath(UInt_t i) const
Return path.
Class describing a generic file including meta information.
Definition: TFileInfo.h:50
virtual const char * GetFileNamePath(UInt_t i) const
Return file name path.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
float value
Definition: math.cpp:443
A List of entry numbers in a TTree or TChain.
Definition: TEntryList.h:27
virtual const char * GetFileName(UInt_t i) const
Return a file name.