//*CMZ :  1.03/09 11/12/97  08.15.32  by  Fons Rademakers
//*-- Author :    Fons Rademakers   14/02/97

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun, Fons Rademakers.                                  *
 * For list of contributors see $ROOTSYS/AA_CREDITS.                     *
 *                                                                       *
 * Permission to use, copy, modify and distribute this software and its  *
 * documentation for non-commercial purposes is hereby granted without   *
 * fee, provided that the above copyright notice appears in all copies   *
 * and that both the copyright notice and this permission notice appear  *
 * in the supporting documentation. The authors make no claims about the *
 * suitability of this software for any purpose. It is provided "as is"  *
 * without express or implied warranty.                                  *
 *************************************************************************/
//*KEND.

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSlave                                                               //
//                                                                      //
// This class describes a PROOF slave server.                           //
// It contains information like the slaves host name, ordinal number,   //
// performance index, socket, etc. Objects of this class can only be    //
// created via TProof member functions.                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

//*KEEP,TSlave,T=C++.
#include "TSlave.h"
//*KEEP,TProof,T=C++.
#include "TProof.h"
//*KEEP,TSocket,T=C++.
#include "TSocket.h"
//*KEEP,TSystem.
#include "TSystem.h"
//*KEEP,TROOT.
#include "TROOT.h"
//*KEND.

ClassImp(TSlave)

//______________________________________________________________________________
 TSlave::TSlave(const char *host, Int_t ord, Int_t perf, TProof *proof)
{
   // Create a PROOF slave object. Called via the TProof ctor.

   fName    = host;
   fOrdinal = ord;
   fPerfIdx = perf;
   fProof   = proof;
   fSocket  = 0;

   // Open connection to remote PROOF slave server.
   fSocket = new TSocket(host, fProof->GetService());
   if (fSocket->IsValid()) {
      // Remove socket from global TROOT socket list. Only the TProof object,
      // representing all slave sockets, will be added to this list. This will
      // ensure the correct termination of all proof servers in case the
      // root session terminates.
      gROOT->GetListOfSockets()->Remove(fSocket);

      // Send user name and passwd to remote host (use trivial
      // inverted byte encoding)
      char user_pass[68], buf[512];
      sprintf(user_pass, "%s %s", fProof->GetUser(), fProof->fPasswd.Data());

      for (int i = 0; i < (int)strlen(user_pass); i++)
         user_pass[i] = ~user_pass[i];

      fSocket->Send(user_pass);

      fSocket->Recv(buf, sizeof(buf));

      if (strcmp(buf, "Okay")) {
         Printf("%s", buf);
         SafeDelete(fSocket);
      } else {
         fSocket->Send(fProof->GetVersion());

         // get back startup message of proofserv (we are now talking with
         // the real proofserver and not anymore with the proofd front-end

         Int_t what;
         fSocket->Recv(buf, sizeof(buf), what);
         Printf("%s", buf);

         if (what == kMESS_NOTOK) {
            SafeDelete(fSocket);
            return;
         }

         if (!fProof->IsMaster()) {
            sprintf(buf, "%s %s %s %d", fProof->GetUser(), fProof->GetVersion(),
                    user_pass, fProof->GetProtocol());
            fSocket->Send(buf);
         } else {
            sprintf(buf, "%s %s %s %d %d %d", fProof->GetUser(), fProof->GetVersion(),
                    gSystem->WorkingDirectory(), fProof->GetProtocol(),
                    gSystem->GetPid(), fOrdinal);
            fSocket->Send(buf);
         }

         fSocket->SetOption(kNoDelay, 1);
      }
   } else
      SafeDelete(fSocket);
}

//______________________________________________________________________________
 TSlave::~TSlave()
{
   // Destroy slave.

   Close();
}

//______________________________________________________________________________
 void TSlave::Close(Option_t *)
{
   // Close slave socket.

   SafeDelete(fSocket);
}

//______________________________________________________________________________
 Int_t TSlave::Compare(TObject *obj)
{
   // Used to sort slaves by performance index.

   TSlave *sl = (TSlave *) obj;

   if (fPerfIdx > sl->GetPerfIdx()) return 1;
   if (fPerfIdx < sl->GetPerfIdx()) return -1;
   return 0;
}

//______________________________________________________________________________
 void TSlave::Print(Option_t *)
{
   // Printf info about slave.

   Printf("*** Slave %d  (%s)", fOrdinal, fSocket ? "valid" : "invalid");
   Printf("    Host name:            %s", GetName());
   Printf("    Performance index:    %d", GetPerfIdx());
   Printf("    MB's processed:       %.2f", float(GetBytesRead())/(1024*1024));
   Printf("    MB's sent:            %.2f", fSocket ? float(fSocket->GetBytesRecv())/(1024*1024) : 0.0);
   Printf("    MB's received:        %.2f", fSocket ? float(fSocket->GetBytesSent())/(1024*1024) : 0.0);
   Printf("    Real time used (s):   %.3f", GetRealTime());
   Printf("    CPU time used (s):    %.3f", GetCpuTime());
}



ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.