Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TProofResourcesStatic.cxx
Go to the documentation of this file.
1// @(#)root/proof:$Id$
2// Author: Paul Nilsson 7/12/2005
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 TProofResourcesStatic
13\ingroup proofkernel
14
15The purpose of this class is to provide a standard interface to
16static config files. It interprets Proof config files (proof.conf)
17and sorts the contents into TProofNodeInfo objects. Master info will
18be placed in fMaster (of type TProofNodeInfo). Submaster info will
19be put in fSubmasterList (a TList of TProofNodeInfo objects), while
20workers (and condorworkers) will be placed in fWorkerList (a TList
21of TProofNodeInfo objects).
22
23*/
24
25#include "Riostream.h"
27#include "TSystem.h"
28#include "TInetAddress.h"
29#include "TProofNodeInfo.h"
30#include "TProofDebug.h"
31#include "TUrl.h"
32#include "TList.h"
33#include "TObjArray.h"
34#include "TObjString.h"
35#include "TError.h"
36
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// This ctor is used in TProofServ::Setup() in combination with GetWorkDir()
42/// for a quick scan of the config file to retrieve the work directory.
43
45{
46 // Create master node info and submaster/worker lists, and set default values
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Using this ctor will retrieve all information in the config file
52/// and store it in fMaster, fSubmasterList and fWorkerList,
53/// condorworkers will be stored in the fWorkerList.
54
56 const char *fileName)
57{
58 // Create master node info and submaster/worker lists, and set default values
60
61 // Open and read the PROOF config file
62 if (!ReadConfigFile(confDir, fileName)) {
63 PDB(kAll,1)
64 Info("TProofResourcesStatic", "error encountered while reading config file");
65 fValid = kFALSE;
66 }
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Destructor.
71
73{
74 delete fSubmasterList;
75 delete fWorkerList;
76 delete fMaster;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Create master node info and submaster/worker lists,
81/// and set default values.
82
84{
85 // Create master
86 fMaster = new TProofNodeInfo();
88 fFoundMaster = kFALSE; // Set to kTRUE if the config file contains master info
89
90 // Create workers
91 fWorkerList = new TList();
93
94 // Create submaster
95 fSubmasterList = new TList();
97
98 // Assume that the config file will be ok
99 fValid = kTRUE;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Get the master node. Only return the master info if it was set
104/// in the config file.
105
107{
108 if (fFoundMaster)
109 return fMaster;
110
111 return 0;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Get the list of submaster nodes.
116
118{
119 return fSubmasterList;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Get the list of worker nodes.
124
126{
127 return fWorkerList;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Read the PROOF config file and fill the master and worker list.
132
134 const char *fileName)
135{
136 Bool_t status = kTRUE;
137
138 // Skip prefix (e.g. "sm:") if any
139 const char *p = (const char *) strstr(fileName,":");
140 if (p)
141 fileName = p+1;
142
143 // Use file specified by the cluster administrator, if any
144 const char *cf = gSystem->Getenv("ROOTPROOFCONF");
145 if (cf && !(gSystem->AccessPathName(cf, kReadPermission))) {
146 fFileName = cf;
147 } else {
148 if (cf)
149 PDB(kGlobal,1)
150 Info("ReadConfigFile", "file %s cannot be read:"
151 " check existence and/or permissions", cf);
152 if (fileName && strlen(fileName) > 0) {
153 // Use user defined file or default
154 // Add a proper path to the file name
155 fFileName.Form("%s/.%s", gSystem->HomeDirectory(), fileName);
156 PDB(kGlobal,2)
157 Info("ReadConfigFile", "checking PROOF config file %s", fFileName.Data());
159 fFileName.Form("%s/etc/proof/%s", confDir, fileName);
160 PDB(kGlobal,2)
161 Info("ReadConfigFile", "checking PROOF config file %s", fFileName.Data());
163 PDB(kAll,1)
164 Info("ReadConfigFile", "no PROOF config file found");
165 return kFALSE;
166 }
167 }
168 } else {
169 PDB(kAll,1)
170 Info("ReadConfigFile", "no PROOF config file specified");
171 return kFALSE;
172 }
173 }
174 PDB(kGlobal,1)
175 Info("ReadConfigFile", "using PROOF config file: %s", fFileName.Data());
176
177 // Open the config file
178 std::fstream infile(fFileName.Data(), std::ios::in);
179 if (infile.is_open()) {
180 Bool_t isMaster = kFALSE;
181 Bool_t isSubmaster = kFALSE;
182 Bool_t isWorker = kFALSE;
183
184 // Each line in the file consists of several 'keywords', e.g.
185 // line = "master mypc image=local"
186 // keyword[0] = "master"
187 // keyword[1] = "mypc"
188 // keyword[2] = "image=local"
189 // The last keyword has an option "image" with value "local"
190 TString line = "";
191 TString keyword = "";
192
193 // Read the entire file into the allLines object
194 TString allLines = "";
195 allLines.ReadString(infile);
196 TObjArray *lines = allLines.Tokenize("\n");
197 Int_t numberOfLines = lines->GetEntries();
198
199 // Process one line at the time
200 for (Int_t j = 0; j < numberOfLines; j++) {
201 TObjString *objLine = (TObjString *)lines->At(j);
202 line = objLine->GetString();
203 line = line.Strip(TString::kBoth);
204
205 // Unless this line was empty or a comment, interpret the line
206 if ( !((line(0,1) == "#") || (line == "")) ) {
207 TProofNodeInfo *nodeinfo = 0;
208
209 // Reset boolean (condorworkers are treated as a workers)
210 isMaster = kFALSE;
211 isSubmaster = kFALSE;
212 isWorker = kFALSE;
213
214 // Extract all words in the current line
215 TObjArray *tokens = line.Tokenize(" ");
216 Int_t n = tokens->GetEntries();
219 for (Int_t i = 0; i < n; i++) {
220
221 // Extrace one word from the current line
222 keyword = ((TObjString *)tokens->At(i))->GetString();
223
224 // Interpret this keyword
225 switch (GetInfoType(keyword)) {
226 case kNodeType: {
227 if (keyword == "master" || keyword == "node") {
228 nodeinfo = CreateNodeInfo(keyword);
229 isMaster = kTRUE; // will be reset
230 }
231 // [either submaster, worker or condorworker]
232 else if (keyword == "submaster") {
233 // Get a submaster info node
234 nodeinfo = CreateNodeInfo(keyword);
235 isSubmaster = kTRUE;
236 } else {
237 // Get a worker or condorworker info node
238 nodeinfo = CreateNodeInfo(keyword);
239 isWorker = kTRUE;
240 }
241 break;
242 }
243 case kHost: {
244 // Store the host name
245 if (nodeinfo) {
246 nodeinfo->fNodeName = keyword;
247
248 // Set default image
249 if (isMaster) {
250 TString node = TUrl(nodeinfo->fNodeName).GetHost();
251 nodeinfo->fImage = strstr(nodeinfo->fNodeName, node.Data());
252 } else {
253 // If the node name contains an '@' sign, it should be removed
254 // before copying it into the [default] image info
255 // On what position is the '@' sign? (if there is one)
256 TString tmp = nodeinfo->fNodeName;
257 const Ssiz_t equalPosition = tmp.Index("@", 1, 0, TString::kExact);
258
259 // Extract the host
260 nodeinfo->fImage = tmp(equalPosition + 1, tmp.Length());
261 }
262 } else {
263 Error("ReadConfigFile","Command not recognized: %s (ignored)",
264 keyword.Data());
265 }
266 break;
267 }
268 case kOption: {
269 // On what position is the '=' sign?
270 const Ssiz_t equalPosition =
271 keyword.Index("=", 1, 0, TString::kExact);
272
273 // Extract the option and its value
274 TString tmp = keyword;
275 option = tmp(0, equalPosition);
276 value = tmp(equalPosition + 1, tmp.Length());
277
278 // Set the node info options
279 SetOption(nodeinfo, option, value);
280 break;
281 }
282 default:
283 break;
284 } // end switch
285
286 } // end if
287
288 // Check if we found a good master
289 if (isMaster) {
290 // Check if the master can run on this node
291 TString node = TUrl(nodeinfo->fNodeName).GetHost();
293 TInetAddress inetaddr = gSystem->GetHostByName(node);
294 if (!host.CompareTo(inetaddr.GetHostName()) || (node == "localhost")) {
296 fMaster->Assign(*nodeinfo);
297 }
298 }
299
300 // Store the submaster, worker or condorworker
301 if (isWorker) {
302 fWorkerList->Add(nodeinfo);
303 }
304 else if (isSubmaster) {
305 fSubmasterList->Add(nodeinfo);
306 }
307 } // else
308
309 } // while (! infile.eof() )
310 infile.close();
311
312 // Did the config file contain appropriate master information?
313 if (!fFoundMaster) {
314 Error("ReadConfigFile","No master info found in config file");
315 status = kFALSE;
316 }
317 } // end if (infile.is_open())
318 else {
319 // Error: could not open file
320 status = kFALSE;
321 }
322
323 return status;
324}
325
326
327////////////////////////////////////////////////////////////////////////////////
328/// Static method to set the node info options.
329
331 const TString &option,
332 const TString &value)
333{
334 if (!nodeinfo) return;
335
336 if (option == "workdir") {
337 nodeinfo->fWorkDir = value;
338 } else if (option == "image") {
339 nodeinfo->fImage = value;
340 } else if (option == "perf") {
341 nodeinfo->fPerfIndex = value.Atoi();
342 } else if (option == "config") {
343 nodeinfo->fConfig = value;
344 } else if (option == "msd") {
345 nodeinfo->fMsd = value;
346 } else if (option == "port") {
347 nodeinfo->fPort = value.Atoi();
348 } else {
349 ::Error("SetOption","No such option [%s=%s]",option.Data(),value.Data());
350 }
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Static method to determine the info type.
355
357{
359
360 if ((word == "node") || (word == "master") || (word == "submaster") ||
361 (word == "worker") || (word == "slave") ||
362 (word == "condorworker") || (word == "condorslave")) {
363 type = kNodeType;
364 }
365 else if (word.Contains("=", TString::kExact)) {
366 type = kOption;
367 } else {
368 type = kHost;
369 }
370
371 return type;
372}
373
374////////////////////////////////////////////////////////////////////////////////
375/// Fill out the preliminary TProofNodeInfo structure.
376
378{
379 TProofNodeInfo *nodeInfo = new TProofNodeInfo();
381 nodeInfo->fNodeName = name;
382 nodeInfo->fPort = -1;
383 nodeInfo->fPerfIndex = 100;
384
385 return nodeInfo;
386}
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define PDB(mask, level)
Definition TProofDebug.h:56
@ kReadPermission
Definition TSystem.h:47
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
This class represents an Internet Protocol (IP) address.
const char * GetHostName() const
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Collectable string class.
Definition TObjString.h:28
const TString & GetString() const
Definition TObjString.h:46
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:970
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:944
The purpose of this class is to provide a complete node description for masters, submasters and worke...
ENodeType fNodeType
void Assign(const TProofNodeInfo &n)
Asssign content of node n to this node.
ENodeType GetNodeType() const
The purpose of this class is to provide a standard interface to static config files.
virtual ~TProofResourcesStatic()
Destructor.
static void SetOption(TProofNodeInfo *nodeinfo, const TString &option, const TString &value)
Static method to set the node info options.
static TProofNodeInfo * CreateNodeInfo(const TString &name)
Fill out the preliminary TProofNodeInfo structure.
TProofNodeInfo * GetMaster()
Get the master node.
TList * GetSubmasters()
Get the list of submaster nodes.
TProofResourcesStatic()
This ctor is used in TProofServ::Setup() in combination with GetWorkDir() for a quick scan of the con...
static EInfoType GetInfoType(const TString &word)
Static method to determine the info type.
TList * GetWorkers()
Get the list of worker nodes.
void InitResources()
Create master node info and submaster/worker lists, and set default values.
Bool_t ReadConfigFile(const char *confDir, const char *fileName)
Read the PROOF config file and fill the master and worker list.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:450
const char * Data() const
Definition TString.h:380
static TString * ReadString(TBuffer &b, const TClass *clReq)
Read TString object from buffer.
Definition TString.cxx:1340
@ kBoth
Definition TString.h:278
@ kExact
Definition TString.h:279
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2242
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2334
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1666
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1299
virtual const char * HostName()
Return the system's host name.
Definition TSystem.cxx:306
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition TSystem.cxx:2292
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition TSystem.cxx:890
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetHost() const
Definition TUrl.h:67
TLine * line
const Int_t n
Definition legend1.C:16