Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAlienJobStatus.cxx
Go to the documentation of this file.
1// @(#)root/alien:$Id$
2// Author: Jan Fiete Grosse-Oetringhaus 06/10/2004
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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// TAlienJobStatus //
15// //
16// Alien implementation of TGridJobStatus //
17// //
18//////////////////////////////////////////////////////////////////////////
19
20#include "TGridJobStatus.h"
21#include "TAlienJobStatus.h"
22#include "TObjString.h"
23#include "TBrowser.h"
24#include "TNamed.h"
25#include "TAlienDirectory.h"
26
28
29////////////////////////////////////////////////////////////////////////////////
30/// Creates a TAlienJobStatus object.
31/// If a status map is provided it is copied to the status information.
32
34{
35 TObjString* key;
36 TObjString* val;
37
38 if (status) {
39 TMapIter next(status);
40 while ( (key = (TObjString*)next())) {
41 val = (TObjString*)status->GetValue(key->GetName());
42 fStatus.Add(key->Clone(), val->Clone());
43 }
44 }
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Cleanup.
49
51{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Browser interface to ob status.
57
59{
60 if (b) {
62 TObject *obj = 0;
63 while ((obj = iter->Next()) != 0) {
64 TObject* value = fStatus.GetValue(obj);
65
66 TObjString* keyStr = dynamic_cast<TObjString*>(obj);
67 TObjString* valueStr = dynamic_cast<TObjString*>(value);
68
69 if (keyStr->GetString() == TString("jdl")) {
70 TString valueParsed(valueStr->GetString());
71 valueParsed.ReplaceAll("\n", 1);
72 valueParsed.ReplaceAll(" ", 2);
73 b->Add(new TPair(new TObjString("jdl"), new TObjString(valueParsed)));
74
75 // list sandboxes
76 const char* outputdir = GetJdlKey("OutputDir");
77
78 TString sandbox;
79 if (outputdir) {
80 sandbox = outputdir;
81 } else {
82 sandbox = TString("/proc/") + TString(GetKey("user")) + TString("/") + TString(GetKey("queueId")) + TString("/job-output");
83 }
84
85 b->Add(new TAlienDirectory(sandbox.Data(),"job-output"));
86
87 } else {
88 b->Add(new TNamed(valueStr->GetString(), keyStr->GetString()));
89 }
90 }
91 delete iter;
92 }
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Return the JDL key.
97
98const char *TAlienJobStatus::GetJdlKey(const char* key)
99{
100 const char *jdl = GetKey("jdl");
101 if (!jdl)
102 return 0;
103 const char* jdltagbegin = strstr(jdl,key);
104 const char* jdltagquote = strchr(jdltagbegin,'"');
105 const char* jdltagend = strchr(jdltagbegin,';');
106
107 if (!jdltagend) {
108 return 0;
109 }
110 if (!jdltagquote) {
111 return 0;
112 }
113 jdltagquote++;
114 const char* jdltagquote2 = strchr(jdltagquote,'"');
115 if (!jdltagquote2) {
116 return 0;
117 }
118 fJdlTag = TString(jdltagquote);
119 fJdlTag = fJdlTag(0,jdltagquote2-jdltagquote);
120
121 return fJdlTag.Data();
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Return a key.
126
127const char *TAlienJobStatus::GetKey(const char* key)
128{
129 TObject* obj = fStatus.FindObject(key);
130 TPair* pair = dynamic_cast<TPair*>(obj);
131 if (pair) {
132 TObjString* string = dynamic_cast<TObjString*> (pair->Value());
133 return string->GetName();
134 }
135 return 0;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Gets the status of the job reduced to the subset defined
140/// in TGridJobStatus.
141
143{
144 TObject* obj = fStatus.FindObject("status");
145 TPair* pair = dynamic_cast<TPair*>(obj);
146
147 if (pair) {
148 TObjString* string = dynamic_cast<TObjString*> (pair->Value());
149
150 if (string) {
151 const char* status = string->GetString().Data();
152
153 if (strcmp(status, "INSERTING") == 0 ||
154 strcmp(status, "WAITING") == 0 ||
155 strcmp(status, "QUEUED") == 0 ||
156 strcmp(status, "ASSIGNED") == 0)
157 return kWAITING;
158 else if (strcmp(status, "STARTED") == 0 ||
159 strcmp(status, "SAVING") == 0 ||
160 strcmp(status, "SPLITTING") == 0 ||
161 strcmp(status, "RUNNING") == 0 ||
162 strcmp(status, "SPLIT") == 0)
163 return kRUNNING;
164 else if (strcmp(status, "EXPIRED") == 0 ||
165 string->GetString().BeginsWith("ERROR_") == kTRUE ||
166 strcmp(status, "FAILED") == 0 ||
167 strcmp(status, "ZOMBIE") == 0)
168 return kFAIL;
169 else if (strcmp(status, "KILLED") == 0)
170 return kABORTED;
171 else if (strcmp(status, "DONE") == 0)
172 return kDONE;
173 }
174 }
175 return kUNKNOWN;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Prints the job information.
180
182{
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Prints this job.
188/// If full is kFALSE only the status is printed, otherwise all information.
189
191{
192 TObject* obj = fStatus.FindObject("status");
193 TPair* pair = dynamic_cast<TPair*>(obj);
194
195 if (pair) {
196 TObjString* string = dynamic_cast<TObjString*> (pair->Value());
197 if (string) {
198 printf("The status of the job is %s\n", string->GetString().Data());
199 }
200 }
201
202 if (full != kTRUE)
203 return;
204
205 printf("==================================================\n");
206 printf("Detail Information:\n");
207
209
210 while ((obj = iter->Next()) != 0) {
211 TObject* value = fStatus.GetValue(obj);
212
213 TObjString* keyStr = dynamic_cast<TObjString*>(obj);
214 TObjString* valueStr = dynamic_cast<TObjString*>(value);
215
216 printf("%s => %s\n", (keyStr) ? keyStr->GetString().Data() : "", (valueStr) ? valueStr->GetString().Data() : "");
217 }
218
219 delete iter;
220}
#define b(i)
Definition RSha256.hxx:100
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
const char * GetJdlKey(const char *key)
Return the JDL key.
void PrintJob(Bool_t full=kTRUE) const
Prints this job.
const char * GetKey(const char *key)
Return a key.
virtual void Print(Option_t *) const
Prints the job information.
virtual EGridJobStatus GetStatus() const
Gets the status of the job reduced to the subset defined in TGridJobStatus.
void Browse(TBrowser *b)
Browser interface to ob status.
virtual ~TAlienJobStatus()
Cleanup.
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Iterator abstract base class.
Definition TIterator.h:30
virtual TObject * Next()=0
Iterator of map.
Definition TMap.h:144
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
void DeleteAll()
Remove all (key,value) pairs from the map AND delete the keys AND values when they are allocated on t...
Definition TMap.cxx:168
TIterator * MakeIterator(Bool_t dir=kIterForward) const
Create an iterator for TMap.
Definition TMap.cxx:258
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition TMap.cxx:54
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:236
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:215
TNamed()
Definition TNamed.h:36
Collectable string class.
Definition TObjString.h:28
const char * GetName() const
Returns name of object.
Definition TObjString.h:38
const TString & GetString() const
Definition TObjString.h:46
Mother of all ROOT objects.
Definition TObject.h:41
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:216
Class used by TMap to store (key,value) pairs.
Definition TMap.h:102
TObject * Value() const
Definition TMap.h:121
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692