Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
46 ClassImp(TSlaveLite);
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;
79  fProtocol = kPROOF_Protocol;
80 
81  if (fPerfIdx > 0) Init();
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Init a PROOF worker object. Called via the TSlaveLite ctor.
86 
87 void TSlaveLite::Init()
88 {
89  // Command to be executed
90  TString cmd;
91  cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s\"; %s/proofserv proofslave lite %d %d 0&",
92  fWorkDir.Data(), fOrdinal.Data(), TROOT::GetBinDir().Data(), TROOT::GetBinDir().Data(),
93  gSystem->GetPid(), gDebug);
94  // Execute
95  if (gSystem->Exec(cmd) != 0) {
96  Error("Init", "an error occured while executing 'proofserv'");
97  SetBit(kInvalidObject);
98  return;
99  }
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Init a PROOF slave object. Called via the TSlaveLite ctor.
104 /// The Init method is technology specific and is overwritten by derived
105 /// classes.
106 
107 Int_t TSlaveLite::SetupServ(Int_t, const char *)
108 {
109  // Get back startup message of proofserv (we are now talking with
110  // the real proofserver and not anymore with the proofd front-end)
111  Int_t what;
112  char buf[512];
113  if (fSocket->Recv(buf, sizeof(buf), what) <= 0) {
114  Error("SetupServ", "failed to receive slave startup message");
115  Close("S");
116  SafeDelete(fSocket);
117  fValid = kFALSE;
118  return -1;
119  }
120 
121  if (what == kMESS_NOTOK) {
122  SafeDelete(fSocket);
123  fValid = kFALSE;
124  return -1;
125  }
126 
127  // Receive the unique tag and save it as name of this object
128  TMessage *msg = 0;
129  if (fSocket->Recv(msg) <= 0 || !msg || msg->What() != kPROOF_SESSIONTAG) {
130  Error("SetupServ", "failed to receive unique session tag");
131  Close("S");
132  SafeDelete(fSocket);
133  fValid = kFALSE;
134  return -1;
135  }
136  // Extract the unique tag
137  (*msg) >> fSessionTag;
138 
139  // Set the real name (temporarly set to ordinal for the setup)
140  fName = gSystem->HostName();
141 
142  // We are done
143  return 0;
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Destroy slave.
148 
149 TSlaveLite::~TSlaveLite()
150 {
151  Close();
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Close slave socket.
156 
157 void TSlaveLite::Close(Option_t *opt)
158 {
159  if (fSocket)
160  // Closing socket ...
161  fSocket->Close(opt);
162 
163  SafeDelete(fInput);
164  SafeDelete(fSocket);
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Printf info about slave.
169 
170 void TSlaveLite::Print(Option_t *) const
171 {
172  const char *sst[] = { "invalid" , "valid", "inactive" };
173  Int_t st = fSocket ? ((fStatus == kInactive) ? 2 : 1) : 0;
174 
175  Printf("*** Worker %s (%s)", fOrdinal.Data(), sst[st]);
176  Printf(" Worker session tag: %s", GetSessionTag());
177  Printf(" ROOT version|rev|tag: %s", GetROOTVersion());
178  Printf(" Architecture-Compiler: %s", GetArchCompiler());
179  if (fSocket) {
180  Printf(" Working directory: %s", GetWorkDir());
181  Printf(" MB's processed: %.2f", float(GetBytesRead())/(1024*1024));
182  Printf(" MB's sent: %.2f", float(fSocket->GetBytesRecv())/(1024*1024));
183  Printf(" MB's received: %.2f", float(fSocket->GetBytesSent())/(1024*1024));
184  Printf(" Real time used (s): %.3f", GetRealTime());
185  Printf(" CPU time used (s): %.3f", GetCpuTime());
186  }
187 }