#include "RConfigure.h"
#include "TSlaveLite.h"
#include "TProof.h"
#include "TProofServ.h"
#include "TSystem.h"
#include "TEnv.h"
#include "TROOT.h"
#include "TUrl.h"
#include "TMessage.h"
#include "TMonitor.h"
#include "TError.h"
#include "TSocket.h"
#include "TSysEvtHandler.h"
#include "TVirtualMutex.h"
#include "TThread.h"
ClassImp(TSlaveLite)
void TSlaveLite::DoError(int level, const char *location,
const char *fmt, va_list va) const
{
::ErrorHandler(level, Form("TSlaveLite::%s", location), fmt, va);
}
TSlaveLite::TSlaveLite(const char *ord, Int_t perf,
const char *image, TProof *proof, Int_t stype,
const char *workdir, const char *msd, Int_t) : TSlave()
{
fName = ord;
fImage = image;
fProofWorkDir = workdir;
fWorkDir = workdir;
fOrdinal = ord;
fPerfIdx = perf;
fProof = proof;
fSlaveType = (ESlaveType)stype;
fMsd = msd;
fIntHandler = 0;
fValid = kFALSE;
fProtocol = kPROOF_Protocol;
if (fPerfIdx > 0) Init();
}
void TSlaveLite::Init()
{
TString cmd;
#ifdef R__HAVE_CONFIG
cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s\"; %s/proofserv proofslave lite %d %d 0&",
fWorkDir.Data(), fOrdinal.Data(), ROOTBINDIR, ROOTBINDIR,
#else
cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s/bin\"; %s/bin/proofserv proofslave lite %d %d 0&",
fWorkDir.Data(), fOrdinal.Data(), gSystem->Getenv("ROOTSYS"), gSystem->Getenv("ROOTSYS"),
#endif
gSystem->GetPid(), gDebug);
if (gSystem->Exec(cmd) != 0) {
Error("Init", "an error occured while executing 'proofserv'");
SetBit(kInvalidObject);
return;
}
}
Int_t TSlaveLite::SetupServ(Int_t, const char *)
{
Int_t what;
char buf[512];
if (fSocket->Recv(buf, sizeof(buf), what) <= 0) {
Error("SetupServ", "failed to receive slave startup message");
Close("S");
SafeDelete(fSocket);
fValid = kFALSE;
return -1;
}
if (what == kMESS_NOTOK) {
SafeDelete(fSocket);
fValid = kFALSE;
return -1;
}
TMessage *msg = 0;
if (fSocket->Recv(msg) <= 0 || !msg || msg->What() != kPROOF_SESSIONTAG) {
Error("SetupServ", "failed to receive unique session tag");
Close("S");
SafeDelete(fSocket);
fValid = kFALSE;
return -1;
}
(*msg) >> fSessionTag;
fName = gSystem->HostName();
return 0;
}
TSlaveLite::~TSlaveLite()
{
Close();
}
void TSlaveLite::Close(Option_t *opt)
{
if (fSocket)
fSocket->Close(opt);
SafeDelete(fInput);
SafeDelete(fSocket);
}
void TSlaveLite::Print(Option_t *) const
{
const char *sst[] = { "invalid" , "valid", "inactive" };
Int_t st = fSocket ? ((fStatus == kInactive) ? 2 : 1) : 0;
Printf("*** Worker %s (%s)", fOrdinal.Data(), sst[st]);
Printf(" Worker session tag: %s", GetSessionTag());
Printf(" ROOT version|rev|tag: %s", GetROOTVersion());
Printf(" Architecture-Compiler: %s", GetArchCompiler());
if (fSocket) {
Printf(" Working directory: %s", GetWorkDir());
Printf(" MB's processed: %.2f", float(GetBytesRead())/(1024*1024));
Printf(" MB's sent: %.2f", float(fSocket->GetBytesRecv())/(1024*1024));
Printf(" MB's received: %.2f", float(fSocket->GetBytesSent())/(1024*1024));
Printf(" Real time used (s): %.3f", GetRealTime());
Printf(" CPU time used (s): %.3f", GetCpuTime());
}
}