Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAlienMasterJob.cxx
Go to the documentation of this file.
1// @(#)root/alien:$Id$
2// Author: Jan Fiete Grosse-Oetringhaus 27/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// TAlienMasterJob //
15// //
16// Special Grid job which contains a master job which controls //
17// underlying jobs resulting from job splitting. //
18// //
19// Related classes are TAlienJobStatus. //
20// //
21//////////////////////////////////////////////////////////////////////////
22
23#include "TAlienJobStatus.h"
24#include "TAlienMasterJob.h"
26#include "TAlienJob.h"
27#include "TObjString.h"
28#include "gapi_job_operations.h"
29#include "Riostream.h"
30#include "TGridResult.h"
31#include "TAlien.h"
32#include "TFileMerger.h"
33#include "TBrowser.h"
34
36
37////////////////////////////////////////////////////////////////////////////////
38/// Browser interface.
39
41{
42 if (b) {
43 b->Add(GetJobStatus());
44 }
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Gets the status of the master job and all its sub jobs.
49/// Returns a TAlienMasterJobStatus object, 0 on failure.
50
52{
53 TString jobID;
54 jobID = fJobID;
55
56 GAPI_JOBARRAY* gjobarray = gapi_queryjobs("-", "%", "-", "-", jobID.Data(),
57 "-", "-", "-", "-");
58
59 if (!gjobarray)
60 return 0;
61
62 if (gjobarray->size() == 0) {
63 delete gjobarray;
64 return 0;
65 }
66
68
69 TAlienJob masterJob(fJobID);
70 status->fMasterJob = dynamic_cast<TAlienJobStatus*>(masterJob.GetJobStatus());
71
72 std::vector<GAPI_JOB>::const_iterator jobIter = gjobarray->begin();
73 for (; jobIter != gjobarray->end(); ++jobIter) {
74
75 GAPI_JOB gjob = *jobIter;
76 TAlienJobStatus* jobStatus = new TAlienJobStatus();
77 TObjString* jID = 0;
78
79 std::map<std::string, std::string>::const_iterator iter = gjob.gapi_jobmap.begin();
80 for (; iter != gjob.gapi_jobmap.end(); ++iter) {
81 jobStatus->fStatus.Add(new TObjString(iter->first.c_str()), new TObjString(iter->second.c_str()));
82 if (strcmp(iter->first.c_str(), "queueId") == 0)
83 jID = new TObjString(iter->second.c_str());
84 }
85
86 if (jID != 0)
87 status->fJobs.Add(jID, jobStatus);
88 else
89 delete jobStatus;
90 }
91
92 return status;
93}
94
95////////////////////////////////////////////////////////////////////////////////
96
97void TAlienMasterJob::Print(Option_t* options) const
98{
99 std::cout << " ------------------------------------------------ " << std::endl;
100 std::cout << " Master Job ID : " << fJobID << std::endl;
101 std::cout << " ------------------------------------------------ " << std::endl;
103 if (!status) {
104 Error("Print","Cannot get the information for this masterjob");
105 return;
106 }
107
108 std::cout << " N of Subjobs : " << status->GetNSubJobs() << std::endl;
109 std::cout << " % finished : " << status->PercentFinished()*100 << std::endl;
110 std::cout << " ------------------------------------------------ " << std::endl;
111 TIterator* iter = status->GetJobs()->MakeIterator();
112
113 TObjString* obj = 0;
114 while ((obj = (TObjString*)iter->Next()) != 0) {
115 TAlienJobStatus* substatus = (TAlienJobStatus*)status->GetJobs()->GetValue(obj->GetName());
116 printf(" SubJob: [%-7s] %-10s %20s@%s RunTime: %s\n",substatus->GetKey("queueId"),substatus->GetKey("status"),substatus->GetKey("node"),substatus->GetKey("site"),substatus->GetKey("runtime"));
117 }
118 std::cout << " ------------------------------------------------ " << std::endl;
119 iter->Reset();
120 if ( strchr(options,'l') ) {
121 while ((obj = (TObjString*)iter->Next()) != 0) {
122 TAlienJobStatus* substatus = (TAlienJobStatus*)status->GetJobs()->GetValue(obj->GetName());
123 // list sandboxes
124 const char* outputdir = substatus->GetJdlKey("OutputDir");
125
126 TString sandbox;
127 if (outputdir) {
128 sandbox = outputdir;
129 } else {
130 sandbox = TString("/proc/") + TString(substatus->GetKey("user")) + TString("/") + TString(substatus->GetKey("queueId")) + TString("/job-output");
131 }
132
133 printf(" Sandbox [%-7s] %s \n", substatus->GetKey("queueId"),sandbox.Data());
134 std::cout << " ================================================ " << std::endl;
135
136 if (!gGrid->Cd(sandbox)) {
137 continue;
138 }
139
140 TGridResult* dirlist = gGrid->Ls(sandbox);
141 dirlist->Sort(kTRUE);
142 Int_t i =0;
143 while (dirlist->GetFileName(i)) {
144 printf("%-24s ",dirlist->GetFileName(i++));
145 if (!(i%4)) {
146 printf("\n");
147 }
148 }
149 printf("\n");
150 delete dirlist;
151 }
152 }
153 std::cout << " ----------LITE_JOB_OPERATIONS-------------------------------------- " << std::endl;
154 delete status;
155}
156
157////////////////////////////////////////////////////////////////////////////////
158
160{
161 return kFALSE;
162}
163
164////////////////////////////////////////////////////////////////////////////////
165
166Bool_t TAlienMasterJob::Merge(const char* inputname,const char* mergeoutput)
167{
168 TFileMerger merger;
169
171 TIterator* iter = status->GetJobs()->MakeIterator();
172
173 TObjString* obj = 0;
174 while ((obj = (TObjString*)iter->Next()) != 0) {
175 TAlienJobStatus* substatus = (TAlienJobStatus*)status->GetJobs()->GetValue(obj->GetName());
176 TString sandbox;// list sandboxes
177 const char* outputdir = substatus->GetJdlKey("OutputDir");
178 printf(" Sandbox [%-7s] %s \n", substatus->GetKey("queueId"),sandbox.Data());
179 std::cout << " ================================================ " << std::endl;
180 if (outputdir) {
181 sandbox = outputdir;
182 } else {
183 sandbox = TString("/proc/") + TString(substatus->GetKey("user")) + TString("/") + TString(substatus->GetKey("queueId")) + TString("/job-output");
184 }
185 merger.AddFile(TString("alien://")+sandbox+ TString("/") + TString(inputname));
186 }
187
188 if (mergeoutput) {
189 merger.OutputFile(mergeoutput);
190 }
191
192 return merger.Merge();
193}
#define b(i)
Definition RSha256.hxx:100
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TGrid * gGrid
Definition TGrid.h:128
const char * GetJdlKey(const char *key)
Return the JDL key.
const char * GetKey(const char *key)
Return a key.
virtual TGridJobStatus * GetJobStatus() const
Queries the job for its status and returns a TGridJobStatus object.
Definition TAlienJob.cxx:35
Float_t PercentFinished()
Returns the percentage of finished subjobs, only DONE is considered as finished.
void Print(Option_t *) const
This method must be overridden when a class wants to print itself.
virtual TGridJobStatus * GetJobStatus() const
Gets the status of the master job and all its sub jobs.
void Browse(TBrowser *b)
Browser interface.
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
This class provides file copy and merging services.
Definition TFileMerger.h:30
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
virtual Bool_t Merge(Bool_t=kTRUE)
Merge the files.
TString fJobID
Definition TGridJob.h:34
virtual const char * GetFileName(UInt_t) const
Definition TGridResult.h:37
virtual TGridResult * Ls(const char *="", Option_t *="", Bool_t=kFALSE)
Definition TGrid.h:84
virtual Bool_t Cd(const char *="", Bool_t=kFALSE)
Definition TGrid.h:90
Iterator abstract base class.
Definition TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition TList.cxx:937
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
Collectable string class.
Definition TObjString.h:28
const char * GetName() const
Returns name of object.
Definition TObjString.h:38
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:963
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369