TAlienMasterJob.cxx

Go to the documentation of this file.
00001 // @(#)root/alien:$Id: TAlienMasterJob.cxx 30051 2009-09-07 10:48:05Z rdm $
00002 // Author: Jan Fiete Grosse-Oetringhaus   27/10/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TAlienMasterJob                                                      //
00015 //                                                                      //
00016 // Special Grid job which contains a master job which controls          //
00017 // underlying jobs resulting from job splitting.                        //
00018 //                                                                      //
00019 // Related classes are TAlienJobStatus.                                 //
00020 //                                                                      //
00021 //////////////////////////////////////////////////////////////////////////
00022 
00023 #include "TAlienJobStatus.h"
00024 #include "TAlienMasterJob.h"
00025 #include "TAlienMasterJobStatus.h"
00026 #include "TAlienJob.h"
00027 #include "TObjString.h"
00028 #include "gapi_job_operations.h"
00029 #include "Riostream.h"
00030 #include "TGridResult.h"
00031 #include "TAlien.h"
00032 #include "TFileMerger.h"
00033 #include "TBrowser.h"
00034 
00035 ClassImp(TAlienMasterJob)
00036 
00037 //______________________________________________________________________________
00038 void TAlienMasterJob::Browse(TBrowser* b)
00039 {
00040    // Browser interface.
00041 
00042    if (b) {
00043       b->Add(GetJobStatus());
00044    }
00045 }
00046 
00047 //______________________________________________________________________________
00048 TGridJobStatus *TAlienMasterJob::GetJobStatus() const
00049 {
00050    // Gets the status of the master job and all its sub jobs.
00051    // Returns a TAlienMasterJobStatus object, 0 on failure.
00052 
00053    TString jobID;
00054    jobID = fJobID;
00055 
00056    GAPI_JOBARRAY* gjobarray = gapi_queryjobs("-", "%", "-", "-", jobID.Data(),
00057                                              "-", "-", "-", "-");
00058 
00059    if (!gjobarray)
00060       return 0;
00061 
00062    if (gjobarray->size() == 0) {
00063       delete gjobarray;
00064       return 0;
00065    }
00066 
00067    TAlienMasterJobStatus *status = new TAlienMasterJobStatus(fJobID);
00068 
00069    TAlienJob masterJob(fJobID);
00070    status->fMasterJob = dynamic_cast<TAlienJobStatus*>(masterJob.GetJobStatus());
00071 
00072    std::vector<GAPI_JOB>::const_iterator jobIter = gjobarray->begin();
00073    for (; jobIter != gjobarray->end(); ++jobIter) {
00074 
00075       GAPI_JOB gjob = *jobIter;
00076       TAlienJobStatus* jobStatus = new TAlienJobStatus();
00077       TObjString* jID = 0;
00078 
00079       std::map<std::string, std::string>::const_iterator iter = gjob.gapi_jobmap.begin();
00080       for (; iter != gjob.gapi_jobmap.end(); ++iter) {
00081          jobStatus->fStatus.Add(new TObjString(iter->first.c_str()), new TObjString(iter->second.c_str()));
00082          if (strcmp(iter->first.c_str(), "queueId") == 0)
00083             jID = new TObjString(iter->second.c_str());
00084       }
00085 
00086       if (jID != 0)
00087          status->fJobs.Add(jID, jobStatus);
00088       else
00089          delete jobStatus;
00090    }
00091 
00092    return status;
00093 }
00094 
00095 //______________________________________________________________________________
00096 void TAlienMasterJob::Print(Option_t* options) const
00097 {
00098    std::cout << " ------------------------------------------------ " << std::endl;
00099    std::cout << " Master Job ID                   : " << fJobID << std::endl;
00100    std::cout << " ------------------------------------------------ " << std::endl;
00101    TAlienMasterJobStatus* status = (TAlienMasterJobStatus*)(GetJobStatus());
00102    if (!status) {
00103       Error("Print","Cannot get the information for this masterjob");
00104       return;
00105    }
00106 
00107    std::cout << " N of Subjobs                    : " << status->GetNSubJobs() << std::endl;
00108    std::cout << " % finished                      : " << status->PercentFinished()*100 << std::endl;
00109    std::cout << " ------------------------------------------------ " << std::endl;
00110    TIterator* iter = status->GetJobs()->MakeIterator();
00111 
00112    TObjString* obj = 0;
00113    while ((obj = (TObjString*)iter->Next()) != 0) {
00114       TAlienJobStatus* substatus = (TAlienJobStatus*)status->GetJobs()->GetValue(obj->GetName());
00115       printf(" SubJob: [%-7s] %-10s %20s@%s  RunTime: %s\n",substatus->GetKey("queueId"),substatus->GetKey("status"),substatus->GetKey("node"),substatus->GetKey("site"),substatus->GetKey("runtime"));
00116    }
00117    std::cout << " ------------------------------------------------ " << std::endl;
00118    iter->Reset();
00119    if ( strchr(options,'l') ) {
00120       while ((obj = (TObjString*)iter->Next()) != 0) {
00121          TAlienJobStatus* substatus = (TAlienJobStatus*)status->GetJobs()->GetValue(obj->GetName());
00122          // list sandboxes
00123          const char* outputdir = substatus->GetJdlKey("OutputDir");
00124 
00125          TString sandbox;
00126          if (outputdir) {
00127             sandbox = outputdir;
00128          } else {
00129             sandbox = TString("/proc/") + TString(substatus->GetKey("user")) + TString("/") + TString(substatus->GetKey("queueId")) + TString("/job-output");
00130          }
00131 
00132          printf(" Sandbox [%-7s] %s \n", substatus->GetKey("queueId"),sandbox.Data());
00133          std::cout << " ================================================ " << std::endl;
00134 
00135          if (!gGrid->Cd(sandbox)) {
00136             continue;
00137          }
00138 
00139          TGridResult* dirlist = gGrid->Ls(sandbox);
00140          dirlist->Sort(kTRUE);
00141          Int_t i =0;
00142          while (dirlist->GetFileName(i)) {
00143             printf("%-24s ",dirlist->GetFileName(i++));
00144             if (!(i%4)) {
00145                printf("\n");
00146             }
00147          }
00148          printf("\n");
00149          if (dirlist)
00150             delete dirlist;
00151       }
00152    }
00153    std::cout << " ----------LITE_JOB_OPERATIONS-------------------------------------- " << std::endl;
00154    delete status;
00155 }
00156 
00157 //______________________________________________________________________________
00158 Bool_t TAlienMasterJob::Merge()
00159 {
00160    return kFALSE;
00161 }
00162 
00163 //______________________________________________________________________________
00164 Bool_t TAlienMasterJob::Merge(const char* inputname,const char* mergeoutput)
00165 {
00166    TFileMerger merger;
00167 
00168    TAlienMasterJobStatus* status = (TAlienMasterJobStatus*)(GetJobStatus());
00169    TIterator* iter = status->GetJobs()->MakeIterator();
00170 
00171    TObjString* obj = 0;
00172    while ((obj = (TObjString*)iter->Next()) != 0) {
00173       TAlienJobStatus* substatus = (TAlienJobStatus*)status->GetJobs()->GetValue(obj->GetName());
00174       TString sandbox;// list sandboxes
00175       const char* outputdir = substatus->GetJdlKey("OutputDir");
00176       printf(" Sandbox [%-7s] %s \n", substatus->GetKey("queueId"),sandbox.Data());
00177       std::cout << " ================================================ " << std::endl;
00178       if (outputdir) {
00179          sandbox = outputdir;
00180       } else {
00181          sandbox = TString("/proc/") + TString(substatus->GetKey("user")) + TString("/") + TString(substatus->GetKey("queueId")) + TString("/job-output");
00182       }
00183       merger.AddFile(TString("alien://")+sandbox+ TString("/") + TString(inputname));
00184    }
00185 
00186    if (mergeoutput) {
00187       merger.OutputFile(mergeoutput);
00188    }
00189 
00190    return merger.Merge();
00191 }

Generated on Tue Jul 5 14:45:30 2011 for ROOT_528-00b_version by  doxygen 1.5.1