ROOT  6.06/09
Reference Guide
TSlaveLite.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: Gerardo Ganis March 2008
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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 // TSlaveLite //
15 // //
16 // This is the version of TSlave for local worker servers. //
17 // See TSlave for details. //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 
21 #include "RConfigure.h"
22 #include "TSlaveLite.h"
23 #include "TProof.h"
24 #include "TProofServ.h"
25 #include "TSystem.h"
26 #include "TEnv.h"
27 #include "TROOT.h"
28 #include "TUrl.h"
29 #include "TMessage.h"
30 #include "TMonitor.h"
31 #include "TError.h"
32 #include "TSocket.h"
33 #include "TSysEvtHandler.h"
34 #include "TVirtualMutex.h"
35 
37 
38 //______________________________________________________________________________
39 //---- error handling ----------------------------------------------------------
40 //---- Needed to avoid blocking on the CINT mutex in printouts -----------------
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Interface to ErrorHandler (protected).
44 
45 void TSlaveLite::DoError(int level, const char *location,
46  const char *fmt, va_list va) const
47 {
48  ::ErrorHandler(level, Form("TSlaveLite::%s", location), fmt, va);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Create a PROOF slave object. Called via the TProof ctor.
53 
54 TSlaveLite::TSlaveLite(const char *ord, Int_t perf,
55  const char *image, TProof *proof, Int_t stype,
56  const char *workdir, const char *msd, Int_t) : TSlave()
57 {
58  fName = ord; // Need this during the setup phase; see end of SetupServ
59  fImage = image;
61  fWorkDir = workdir;
62  fOrdinal = ord;
63  fPerfIdx = perf;
64  fProof = proof;
65  fSlaveType = (ESlaveType)stype;
66  fMsd = msd;
67  fIntHandler = 0;
68  fValid = kFALSE;
70 
71  if (fPerfIdx > 0) Init();
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Init a PROOF worker object. Called via the TSlaveLite ctor.
76 
78 {
79  // Command to be executed
80  TString cmd;
81 #ifdef R__HAVE_CONFIG
82  cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s\"; %s/proofserv proofslave lite %d %d 0&",
83  fWorkDir.Data(), fOrdinal.Data(), ROOTBINDIR, ROOTBINDIR,
84 #else
85  cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s/bin\"; %s/bin/proofserv proofslave lite %d %d 0&",
86  fWorkDir.Data(), fOrdinal.Data(), gSystem->Getenv("ROOTSYS"), gSystem->Getenv("ROOTSYS"),
87 #endif
88  gSystem->GetPid(), gDebug);
89  // Execute
90  if (gSystem->Exec(cmd) != 0) {
91  Error("Init", "an error occured while executing 'proofserv'");
93  return;
94  }
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Init a PROOF slave object. Called via the TSlaveLite ctor.
99 /// The Init method is technology specific and is overwritten by derived
100 /// classes.
101 
103 {
104  // Get back startup message of proofserv (we are now talking with
105  // the real proofserver and not anymore with the proofd front-end)
106  Int_t what;
107  char buf[512];
108  if (fSocket->Recv(buf, sizeof(buf), what) <= 0) {
109  Error("SetupServ", "failed to receive slave startup message");
110  Close("S");
112  fValid = kFALSE;
113  return -1;
114  }
115 
116  if (what == kMESS_NOTOK) {
118  fValid = kFALSE;
119  return -1;
120  }
121 
122  // Receive the unique tag and save it as name of this object
123  TMessage *msg = 0;
124  if (fSocket->Recv(msg) <= 0 || !msg || msg->What() != kPROOF_SESSIONTAG) {
125  Error("SetupServ", "failed to receive unique session tag");
126  Close("S");
128  fValid = kFALSE;
129  return -1;
130  }
131  // Extract the unique tag
132  (*msg) >> fSessionTag;
133 
134  // Set the real name (temporarly set to ordinal for the setup)
135  fName = gSystem->HostName();
136 
137  // We are done
138  return 0;
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Destroy slave.
143 
145 {
146  Close();
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Close slave socket.
151 
153 {
154  if (fSocket)
155  // Closing socket ...
156  fSocket->Close(opt);
157 
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Printf info about slave.
164 
166 {
167  const char *sst[] = { "invalid" , "valid", "inactive" };
168  Int_t st = fSocket ? ((fStatus == kInactive) ? 2 : 1) : 0;
169 
170  Printf("*** Worker %s (%s)", fOrdinal.Data(), sst[st]);
171  Printf(" Worker session tag: %s", GetSessionTag());
172  Printf(" ROOT version|rev|tag: %s", GetROOTVersion());
173  Printf(" Architecture-Compiler: %s", GetArchCompiler());
174  if (fSocket) {
175  Printf(" Working directory: %s", GetWorkDir());
176  Printf(" MB's processed: %.2f", float(GetBytesRead())/(1024*1024));
177  Printf(" MB's sent: %.2f", float(fSocket->GetBytesRecv())/(1024*1024));
178  Printf(" MB's received: %.2f", float(fSocket->GetBytesSent())/(1024*1024));
179  Printf(" Real time used (s): %.3f", GetRealTime());
180  Printf(" CPU time used (s): %.3f", GetCpuTime());
181  }
182 }
void Close(Option_t *opt="")
Close slave socket.
Definition: TSlaveLite.cxx:152
virtual int GetPid()
Get process id.
Definition: TSystem.cxx:711
const char Int_t const char TProof Int_t const char const char * msd
Definition: TXSlave.cxx:46
Float_t GetCpuTime() const
Definition: TSlave.h:142
const char * GetSessionTag() const
Definition: TSlave.h:147
const char Option_t
Definition: RtypesCore.h:62
const char Int_t perf
Definition: TXSlave.cxx:46
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TSocket.cxx:818
Bool_t fValid
Definition: TSlaveLite.h:38
Int_t SetupServ(Int_t stype, const char *conffile)
Init a PROOF slave object.
Definition: TSlaveLite.cxx:102
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
UInt_t GetBytesSent() const
Definition: TSocket.h:149
UInt_t GetBytesRecv() const
Definition: TSocket.h:150
const char * Data() const
Definition: TString.h:349
#define SafeDelete(p)
Definition: RConfig.h:436
TString fSessionTag
Definition: TSlave.h:103
const char * GetROOTVersion() const
Definition: TSlave.h:152
const char * ord
Definition: TXSlave.cxx:46
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1627
TString fOrdinal
Definition: TSlave.h:90
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
const char * GetWorkDir() const
Definition: TSlave.h:131
static const char * what
Definition: stlLoader.cc:6
const char Int_t const char TProof Int_t const char * workdir
Definition: TXSlave.cxx:46
virtual void Close(Option_t *opt="")
Close the socket.
Definition: TSocket.cxx:388
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
TString fWorkDir
Definition: TSlave.h:86
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
virtual ~TSlaveLite()
Destroy slave.
Definition: TSlaveLite.cxx:144
char * Form(const char *fmt,...)
TSocket * fSocket
Definition: TSlave.h:93
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:657
const Int_t kPROOF_Protocol
Definition: TProof.h:143
#define Printf
Definition: TGeoToOCC.h:18
Int_t fProtocol
Definition: TSlave.h:92
TFileHandler * fInput
Definition: TSlave.h:95
TString fName
Definition: TSlave.h:83
#define ClassImp(name)
Definition: Rtypes.h:279
TProof * fProof
Definition: TSlave.h:94
virtual const char * HostName()
Return the system's host name.
Definition: TSystem.cxx:307
void Print(Option_t *option="") const
Printf info about slave.
Definition: TSlaveLite.cxx:165
TString fMsd
Definition: TSlave.h:102
Definition: TProof.h:339
TSignalHandler * fIntHandler
Definition: TSlaveLite.h:39
void Init()
Init a PROOF worker object. Called via the TSlaveLite ctor.
Definition: TSlaveLite.cxx:77
UInt_t What() const
Definition: TMessage.h:80
TString fImage
Definition: TSlave.h:84
Int_t fStatus
Definition: TSlave.h:100
const char Int_t const char TProof * proof
Definition: TXSlave.cxx:46
typedef void((*Func_t)())
void ErrorHandler(int level, const char *location, const char *fmt, va_list va)
General error handler function. It calls the user set error handler.
Definition: TError.cxx:202
const char * GetArchCompiler() const
Definition: TSlave.h:151
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Definition: TSlave.h:50
ESlaveType
Definition: TSlave.h:59
ESlaveType fSlaveType
Definition: TSlave.h:99
TString fProofWorkDir
Definition: TSlave.h:85
Float_t GetRealTime() const
Definition: TSlave.h:141
TSlaveLite(const char *ord, Int_t perf, const char *image, TProof *proof, Int_t stype, const char *workdir, const char *msd, Int_t=1)
Int_t fPerfIdx
Definition: TSlave.h:91
Long64_t GetBytesRead() const
Definition: TSlave.h:140
const char Int_t const char * image
Definition: TXSlave.cxx:46