// @(#)root/proof:$Id$
// Author: Paul Nilsson   7/12/2005

/*************************************************************************
 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofNodeInfo                                                       //
//                                                                      //
// Implementation of PROOF node info.                                   //
// The purpose of this class is to provide a complete node description  //
// for masters, submasters and workers.                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TObjArray.h"
#include "TObjString.h"
#include "TProofNodeInfo.h"

ClassImp(TProofNodeInfo)

//______________________________________________________________________________
TProofNodeInfo::TProofNodeInfo()
               : fNodeType(kWorker), fPort(-1), fPerfIndex(100), fNWrks(1)
{
   // Default constructor.
}

//______________________________________________________________________________
TProofNodeInfo::TProofNodeInfo(const char *str)
               : fNodeType(kWorker), fPort(-1), fPerfIndex(100), fNWrks(1)
{
   // Constructor from a string containing all the information in a serialized
   // way. Used to decode thr information coming from the coordinator
   // <type>|<host@user>|<port>|<ord>|<id>|<perfidx>|<img>|<workdir>|<msd>|<cfg>

   // Needs a non empty string to do something
   if (!str || strlen(str) <= 0)
      return;

   TString ss(str), s;
   Ssiz_t from = 0;
   // NodeType
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fNodeType = GetNodeType(s);
   // NodeName
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fNodeName = s;
   // Port
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      if (s.IsDigit()) fPort = s.Atoi();
   // Ordinal
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fOrdinal = s;
   // ID string
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fId = s;
   // Performance
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      if (s.IsDigit()) fPerfIndex = s.Atoi();
   // Image
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fImage = s;
   // Working dir
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fWorkDir = s;
   // Mass Storage Domain
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fMsd = s;
   // Config file (master or submaster; for backward compatibility)
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      fConfig = s;
   // Number of workers
   if (ss.Tokenize(s, from, "|") && !s.IsNull() && s != "-")
      if (s.IsDigit()) fNWrks = s.Atoi();

   // Set the name
   fName.Form("%s:%d", fNodeName.Data(), fPort);
}

//______________________________________________________________________________
TProofNodeInfo::TProofNodeInfo(const TProofNodeInfo &nodeInfo) : TObject(nodeInfo)
{
   // Copy constructor.

   fName      = nodeInfo.fName;
   fNodeType  = nodeInfo.fNodeType;
   fNodeName  = nodeInfo.fNodeName;
   fWorkDir   = nodeInfo.fWorkDir;
   fOrdinal   = nodeInfo.fOrdinal;
   fImage     = nodeInfo.fImage;
   fId        = nodeInfo.fId;
   fConfig    = nodeInfo.fConfig;
   fMsd       = nodeInfo.fMsd;
   fPort      = nodeInfo.fPort;
   fPerfIndex = nodeInfo.fPerfIndex;
   fNWrks     = nodeInfo.fNWrks;
}

//______________________________________________________________________________
void TProofNodeInfo::Assign(const TProofNodeInfo &n)
{
   // Asssign content of node n to this node

   fName      = n.fName;
   fNodeType  = n.fNodeType;
   fNodeName  = n.fNodeName;
   fWorkDir   = n.fWorkDir;
   fOrdinal   = n.fOrdinal;
   fImage     = n.fImage;
   fId        = n.fId;
   fConfig    = n.fConfig;
   fMsd       = n.fMsd;
   fPort      = n.fPort;
   fPerfIndex = n.fPerfIndex;
   fNWrks     = n.fNWrks;
}

//______________________________________________________________________________
void TProofNodeInfo::Print(const Option_t *opt) const
{
   // Print the TProofNodeInfo structure.

   if (opt[0] == 'c' || opt[0] == 'C') {
      Printf("%d %s:%d %s %s", fNodeType, fNodeName.Data(), fPort,
                               fOrdinal.Data(), fWorkDir.Data());
   } else {
      Printf(" +++ TProofNodeInfo: %s +++", fName.Data());
      Printf(" NodeName: %s, Port: %d, NodeType: %d, Ordinal: %s",
             fNodeName.Data(), fPort, fNodeType, fOrdinal.Data());
      Printf(" WorkDir: %s, Image: %s", fWorkDir.Data(), fImage.Data());
      Printf(" Id: %s, Config: %s", fId.Data(), fConfig.Data());
      Printf(" Msd: %s", fMsd.Data());
      Printf(" Performance:   %d", fPerfIndex);
      Printf(" NumberOfWrks:  %d", fNWrks);
      Printf("+++++++++++++++++++++++++++++++++++++++++++");
   }
}

//______________________________________________________________________________
TProofNodeInfo::ENodeType TProofNodeInfo::GetNodeType(const TString &type)
{
   // Static method returning node type. Allowed input: "master", "submaster",
   // or anything else which will be interpreted as worker.

   ENodeType enType;

   if (type == "M" || type == "master") {
      enType = kMaster;
   }
   else if (type == "S" || type == "submaster") {
      enType = kSubMaster;
   }
   else { // [worker/slave or condorworker]
      enType = kWorker;
   }

   return enType;
}
 TProofNodeInfo.cxx:1
 TProofNodeInfo.cxx:2
 TProofNodeInfo.cxx:3
 TProofNodeInfo.cxx:4
 TProofNodeInfo.cxx:5
 TProofNodeInfo.cxx:6
 TProofNodeInfo.cxx:7
 TProofNodeInfo.cxx:8
 TProofNodeInfo.cxx:9
 TProofNodeInfo.cxx:10
 TProofNodeInfo.cxx:11
 TProofNodeInfo.cxx:12
 TProofNodeInfo.cxx:13
 TProofNodeInfo.cxx:14
 TProofNodeInfo.cxx:15
 TProofNodeInfo.cxx:16
 TProofNodeInfo.cxx:17
 TProofNodeInfo.cxx:18
 TProofNodeInfo.cxx:19
 TProofNodeInfo.cxx:20
 TProofNodeInfo.cxx:21
 TProofNodeInfo.cxx:22
 TProofNodeInfo.cxx:23
 TProofNodeInfo.cxx:24
 TProofNodeInfo.cxx:25
 TProofNodeInfo.cxx:26
 TProofNodeInfo.cxx:27
 TProofNodeInfo.cxx:28
 TProofNodeInfo.cxx:29
 TProofNodeInfo.cxx:30
 TProofNodeInfo.cxx:31
 TProofNodeInfo.cxx:32
 TProofNodeInfo.cxx:33
 TProofNodeInfo.cxx:34
 TProofNodeInfo.cxx:35
 TProofNodeInfo.cxx:36
 TProofNodeInfo.cxx:37
 TProofNodeInfo.cxx:38
 TProofNodeInfo.cxx:39
 TProofNodeInfo.cxx:40
 TProofNodeInfo.cxx:41
 TProofNodeInfo.cxx:42
 TProofNodeInfo.cxx:43
 TProofNodeInfo.cxx:44
 TProofNodeInfo.cxx:45
 TProofNodeInfo.cxx:46
 TProofNodeInfo.cxx:47
 TProofNodeInfo.cxx:48
 TProofNodeInfo.cxx:49
 TProofNodeInfo.cxx:50
 TProofNodeInfo.cxx:51
 TProofNodeInfo.cxx:52
 TProofNodeInfo.cxx:53
 TProofNodeInfo.cxx:54
 TProofNodeInfo.cxx:55
 TProofNodeInfo.cxx:56
 TProofNodeInfo.cxx:57
 TProofNodeInfo.cxx:58
 TProofNodeInfo.cxx:59
 TProofNodeInfo.cxx:60
 TProofNodeInfo.cxx:61
 TProofNodeInfo.cxx:62
 TProofNodeInfo.cxx:63
 TProofNodeInfo.cxx:64
 TProofNodeInfo.cxx:65
 TProofNodeInfo.cxx:66
 TProofNodeInfo.cxx:67
 TProofNodeInfo.cxx:68
 TProofNodeInfo.cxx:69
 TProofNodeInfo.cxx:70
 TProofNodeInfo.cxx:71
 TProofNodeInfo.cxx:72
 TProofNodeInfo.cxx:73
 TProofNodeInfo.cxx:74
 TProofNodeInfo.cxx:75
 TProofNodeInfo.cxx:76
 TProofNodeInfo.cxx:77
 TProofNodeInfo.cxx:78
 TProofNodeInfo.cxx:79
 TProofNodeInfo.cxx:80
 TProofNodeInfo.cxx:81
 TProofNodeInfo.cxx:82
 TProofNodeInfo.cxx:83
 TProofNodeInfo.cxx:84
 TProofNodeInfo.cxx:85
 TProofNodeInfo.cxx:86
 TProofNodeInfo.cxx:87
 TProofNodeInfo.cxx:88
 TProofNodeInfo.cxx:89
 TProofNodeInfo.cxx:90
 TProofNodeInfo.cxx:91
 TProofNodeInfo.cxx:92
 TProofNodeInfo.cxx:93
 TProofNodeInfo.cxx:94
 TProofNodeInfo.cxx:95
 TProofNodeInfo.cxx:96
 TProofNodeInfo.cxx:97
 TProofNodeInfo.cxx:98
 TProofNodeInfo.cxx:99
 TProofNodeInfo.cxx:100
 TProofNodeInfo.cxx:101
 TProofNodeInfo.cxx:102
 TProofNodeInfo.cxx:103
 TProofNodeInfo.cxx:104
 TProofNodeInfo.cxx:105
 TProofNodeInfo.cxx:106
 TProofNodeInfo.cxx:107
 TProofNodeInfo.cxx:108
 TProofNodeInfo.cxx:109
 TProofNodeInfo.cxx:110
 TProofNodeInfo.cxx:111
 TProofNodeInfo.cxx:112
 TProofNodeInfo.cxx:113
 TProofNodeInfo.cxx:114
 TProofNodeInfo.cxx:115
 TProofNodeInfo.cxx:116
 TProofNodeInfo.cxx:117
 TProofNodeInfo.cxx:118
 TProofNodeInfo.cxx:119
 TProofNodeInfo.cxx:120
 TProofNodeInfo.cxx:121
 TProofNodeInfo.cxx:122
 TProofNodeInfo.cxx:123
 TProofNodeInfo.cxx:124
 TProofNodeInfo.cxx:125
 TProofNodeInfo.cxx:126
 TProofNodeInfo.cxx:127
 TProofNodeInfo.cxx:128
 TProofNodeInfo.cxx:129
 TProofNodeInfo.cxx:130
 TProofNodeInfo.cxx:131
 TProofNodeInfo.cxx:132
 TProofNodeInfo.cxx:133
 TProofNodeInfo.cxx:134
 TProofNodeInfo.cxx:135
 TProofNodeInfo.cxx:136
 TProofNodeInfo.cxx:137
 TProofNodeInfo.cxx:138
 TProofNodeInfo.cxx:139
 TProofNodeInfo.cxx:140
 TProofNodeInfo.cxx:141
 TProofNodeInfo.cxx:142
 TProofNodeInfo.cxx:143
 TProofNodeInfo.cxx:144
 TProofNodeInfo.cxx:145
 TProofNodeInfo.cxx:146
 TProofNodeInfo.cxx:147
 TProofNodeInfo.cxx:148
 TProofNodeInfo.cxx:149
 TProofNodeInfo.cxx:150
 TProofNodeInfo.cxx:151
 TProofNodeInfo.cxx:152
 TProofNodeInfo.cxx:153
 TProofNodeInfo.cxx:154
 TProofNodeInfo.cxx:155
 TProofNodeInfo.cxx:156
 TProofNodeInfo.cxx:157
 TProofNodeInfo.cxx:158
 TProofNodeInfo.cxx:159
 TProofNodeInfo.cxx:160
 TProofNodeInfo.cxx:161
 TProofNodeInfo.cxx:162
 TProofNodeInfo.cxx:163
 TProofNodeInfo.cxx:164
 TProofNodeInfo.cxx:165