TSlaveLite.cxx

Go to the documentation of this file.
00001 // @(#)root/proof:$Id: TSlaveLite.cxx 37978 2011-02-04 11:49:23Z ganis $
00002 // Author: Gerardo Ganis  March 2008
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, 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 // TSlaveLite                                                           //
00015 //                                                                      //
00016 // This is the version of TSlave for local worker servers.              //
00017 // See TSlave for details.                                              //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #include "RConfigure.h"
00022 #include "TSlaveLite.h"
00023 #include "TProof.h"
00024 #include "TProofServ.h"
00025 #include "TSystem.h"
00026 #include "TEnv.h"
00027 #include "TROOT.h"
00028 #include "TUrl.h"
00029 #include "TMessage.h"
00030 #include "TMonitor.h"
00031 #include "TError.h"
00032 #include "TSocket.h"
00033 #include "TSysEvtHandler.h"
00034 #include "TVirtualMutex.h"
00035 #include "TThread.h"
00036 
00037 ClassImp(TSlaveLite)
00038 
00039 //______________________________________________________________________________
00040 //---- error handling ----------------------------------------------------------
00041 //---- Needed to avoid blocking on the CINT mutex in printouts -----------------
00042 
00043 //______________________________________________________________________________
00044 void TSlaveLite::DoError(int level, const char *location,
00045                                     const char *fmt, va_list va) const
00046 {
00047    // Interface to ErrorHandler (protected).
00048 
00049    ::ErrorHandler(level, Form("TSlaveLite::%s", location), fmt, va);
00050 }
00051 
00052 //______________________________________________________________________________
00053 TSlaveLite::TSlaveLite(const char *ord, Int_t perf,
00054                const char *image, TProof *proof, Int_t stype,
00055                const char *workdir, const char *msd) : TSlave()
00056 {
00057    // Create a PROOF slave object. Called via the TProof ctor.
00058    fName = ord;  // Need this during the setup phase; see end of SetupServ
00059    fImage = image;
00060    fProofWorkDir = workdir;
00061    fWorkDir = workdir;
00062    fOrdinal = ord;
00063    fPerfIdx = perf;
00064    fProof = proof;
00065    fSlaveType = (ESlaveType)stype;
00066    fMsd = msd;
00067    fIntHandler = 0;
00068    fValid = kFALSE;
00069    fProtocol = kPROOF_Protocol;
00070 
00071    if (fPerfIdx > 0) Init();
00072 }
00073 
00074 //______________________________________________________________________________
00075 void TSlaveLite::Init()
00076 {
00077    // Init a PROOF worker object. Called via the TSlaveLite ctor.
00078 
00079    // Command to be executed
00080    TString cmd;
00081 #ifdef R__HAVE_CONFIG
00082    cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s\"; %s/proofserv proofslave lite %d %d &",
00083             fWorkDir.Data(), fOrdinal.Data(), ROOTBINDIR, ROOTBINDIR,
00084 #else
00085    cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s/bin\"; %s/bin/proofserv proofslave lite %d %d &",
00086             fWorkDir.Data(), fOrdinal.Data(), gSystem->Getenv("ROOTSYS"), gSystem->Getenv("ROOTSYS"),
00087 #endif
00088             gSystem->GetPid(), gDebug);
00089    // Execute
00090    if (gSystem->Exec(cmd) != 0) {
00091       Error("Init", "an error occured while executing 'proofserv'");
00092       SetBit(kInvalidObject);
00093       return;
00094    }
00095 }
00096 
00097 //______________________________________________________________________________
00098 Int_t TSlaveLite::SetupServ(Int_t, const char *)
00099 {
00100    // Init a PROOF slave object. Called via the TSlaveLite ctor.
00101    // The Init method is technology specific and is overwritten by derived
00102    // classes.
00103 
00104    // Get back startup message of proofserv (we are now talking with
00105    // the real proofserver and not anymore with the proofd front-end)
00106    Int_t what;
00107    char buf[512];
00108    if (fSocket->Recv(buf, sizeof(buf), what) <= 0) {
00109       Error("SetupServ", "failed to receive slave startup message");
00110       Close("S");
00111       SafeDelete(fSocket);
00112       fValid = kFALSE;
00113       return -1;
00114    }
00115 
00116    if (what == kMESS_NOTOK) {
00117       SafeDelete(fSocket);
00118       fValid = kFALSE;
00119       return -1;
00120    }
00121 
00122    // Receive the unique tag and save it as name of this object
00123    TMessage *msg = 0;
00124    if (fSocket->Recv(msg) <= 0 || !msg || msg->What() != kPROOF_SESSIONTAG) {
00125       Error("SetupServ", "failed to receive unique session tag");
00126       Close("S");
00127       SafeDelete(fSocket);
00128       fValid = kFALSE;
00129       return -1;
00130    }
00131    // Extract the unique tag
00132    (*msg) >> fSessionTag;
00133    
00134    // Set the real name (temporarly set to ordinal for the setup)
00135    fName = gSystem->HostName();
00136    
00137    // We are done
00138    return 0;
00139 }
00140 
00141 //______________________________________________________________________________
00142 TSlaveLite::~TSlaveLite()
00143 {
00144    // Destroy slave.
00145 
00146    Close();
00147 }
00148 
00149 //______________________________________________________________________________
00150 void TSlaveLite::Close(Option_t *opt)
00151 {
00152    // Close slave socket.
00153 
00154    if (fSocket)
00155       // Closing socket ...
00156       fSocket->Close(opt);
00157 
00158    SafeDelete(fInput);
00159    SafeDelete(fSocket);
00160 }
00161 
00162 //______________________________________________________________________________
00163 void TSlaveLite::Print(Option_t *) const
00164 {
00165    // Printf info about slave.
00166 
00167    const char *sst[] = { "invalid" , "valid", "inactive" };
00168    Int_t st = fSocket ? ((fStatus == kInactive) ? 2 : 1) : 0;
00169 
00170    Printf("*** Worker %s  (%s)", fOrdinal.Data(), sst[st]);
00171    Printf("    Worker session tag:      %s", GetSessionTag());
00172    Printf("    ROOT version|rev|tag:    %s", GetROOTVersion());
00173    Printf("    Architecture-Compiler:   %s", GetArchCompiler());
00174    if (fSocket) {
00175       Printf("    Working directory:       %s", GetWorkDir());
00176       Printf("    MB's processed:          %.2f", float(GetBytesRead())/(1024*1024));
00177       Printf("    MB's sent:               %.2f", float(fSocket->GetBytesRecv())/(1024*1024));
00178       Printf("    MB's received:           %.2f", float(fSocket->GetBytesSent())/(1024*1024));
00179       Printf("    Real time used (s):      %.3f", GetRealTime());
00180       Printf("    CPU time used (s):       %.3f", GetCpuTime());
00181    }
00182 }

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