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