00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00041
00042
00043
00044 void TSlaveLite::DoError(int level, const char *location,
00045 const char *fmt, va_list va) const
00046 {
00047
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
00058 fName = ord;
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
00078
00079
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
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
00101
00102
00103
00104
00105
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
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
00132 (*msg) >> fSessionTag;
00133
00134
00135 fName = gSystem->HostName();
00136
00137
00138 return 0;
00139 }
00140
00141
00142 TSlaveLite::~TSlaveLite()
00143 {
00144
00145
00146 Close();
00147 }
00148
00149
00150 void TSlaveLite::Close(Option_t *opt)
00151 {
00152
00153
00154 if (fSocket)
00155
00156 fSocket->Close(opt);
00157
00158 SafeDelete(fInput);
00159 SafeDelete(fSocket);
00160 }
00161
00162
00163 void TSlaveLite::Print(Option_t *) const
00164 {
00165
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 }