Logo ROOT   6.10/09
Reference Guide
getProof.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_proof
3 ///
4 /// Attaches to a PROOF session, possibly at the indicated URL.
5 /// If no existing PROOF session is found and no URL is given,
6 /// try to start a local PROOF session.
7 ///
8 /// Arguments:
9 /// 'url' URL of the master where to start/attach the PROOF session;
10 /// this is also the place where to force creation of a new session,
11 /// if needed (use option 'N', e.g. "proof://mymaster:myport/?N")
12 ///
13 /// The following arguments apply to xrootd responding at 'refloc' only:
14 /// 'nwrks' Number of workers to be started. []
15 /// 'dir' Directory to be used for the files and working areas []. When starting a new
16 /// instance of the daemon this directory is cleaned with 'rm -fr'. If 'dir'
17 /// is null, the default is used: '/tmp/<user>/.getproof'
18 /// 'opt' Defines what to do if an existing xrootd uses the same ports; possible
19 /// options are: "ask", ask the user; "force", kill the xrootd and start
20 /// a new one; if any other string is specified the existing xrootd will be
21 /// used ["ask"].
22 /// NB: for a change in 'nwrks' to be effective you need to specify opt = "force"
23 /// 'dyn' This flag can be used to switch on dynamic, per-job worker setup scheduling
24 /// [kFALSE].
25 /// 'tutords' This flag can be used to force a dataset dir under the tutorial dir [kFALSE]
26 ///
27 /// It is possible to trigger the automatic valgrind setup by defining the env GETPROOF_VALGRIND.
28 /// E.g. to run the master in valgrind do
29 ///
30 /// $ export GETPROOF_VALGRIND="valgrind=master"
31 ///
32 /// (or
33 /// $ export GETPROOF_VALGRIND="valgrind=master valgrind_opts:--leak-check=full"
34 ///
35 /// to set some options) before running getProof. Note that 'getProof' is also called by 'stressProof',
36 /// so this holds for 'stressProof' runs too.
37 ///
38 ///
39 /// \macro_code
40 ///
41 /// \author Gerardo Ganis
42 
43 #include "Bytes.h"
44 #include "Getline.h"
45 #include "TEnv.h"
46 #include "TProof.h"
47 #include "TSocket.h"
48 #include "TString.h"
49 #include "TSystem.h"
50 
51 // Auxilliary functions
52 int getDebugEnum(const char *what);
53 Int_t getXrootdPid(Int_t port, const char *subdir = "xpdtut");
54 Int_t checkXrootdAt(Int_t port, const char *host = "localhost");
55 Int_t checkXproofdAt(Int_t port, const char *host = "localhost");
56 Int_t startXrootdAt(Int_t port, const char *exportdirs = 0, Bool_t force = kFALSE);
57 Int_t killXrootdAt(Int_t port, const char *id = 0);
58 
59 // Auxilliary structures for Xrootd/Xproofd pinging ...
60 // The client request
61 typedef struct {
62  int first;
63  int second;
64  int third;
65  int fourth;
66  int fifth;
67 } clnt_HS_t;
68 // The body received after the first handshake's header
69 typedef struct {
70  int msglen;
71  int protover;
72  int msgval;
73 } srv_HS_t;
74 
75 // By default we start a cluster on the local machine
76 const char *refloc = "proof://localhost:40000";
77 
78 TProof *getProof(const char *url = "proof://localhost:40000", Int_t nwrks = -1, const char *dir = 0,
79  const char *opt = "ask", Bool_t dyn = kFALSE, Bool_t tutords = kFALSE)
80 {
81 
82 
83  TProof *p = 0;
84 
85  // Valgrind options, if any
86  TString vopt, vopts;
87 #ifndef WIN32
88  if (gSystem->Getenv("GETPROOF_VALGRIND")) {
89  TString s(gSystem->Getenv("GETPROOF_VALGRIND")), t;
90  Int_t from = 0;
91  while (s.Tokenize(t, from , " ")) {
92  if (t.BeginsWith("valgrind_opts:"))
93  vopts = t;
94  else
95  vopt = t;
96  }
97  if (vopts.IsNull()) vopts = "valgrind_opts:--leak-check=full --track-origins=yes";
98  TProof::AddEnvVar("PROOF_WRAPPERCMD", vopts.Data());
99  Printf("getProof: valgrind run: '%s' (opts: '%s')", vopt.Data(), vopts.Data());
100  }
101 #endif
102 
103  // If an URL has specified get a session there
104  TUrl uu(url), uref(refloc);
105  Bool_t ext = (strcmp(uu.GetHost(), uref.GetHost()) ||
106  (uu.GetPort() != uref.GetPort())) ? kTRUE : kFALSE;
107  Bool_t lite = kFALSE;
108  if (ext && url) {
109  if (!strcmp(url, "lite://") || !url[0]) {
110  if (!url[0]) uu.SetUrl("lite://");
111  if (dir && strlen(dir) > 0) gEnv->SetValue("Proof.Sandbox", dir);
112  TString swrk("<default> workers");
113  if (nwrks > 0) {
114  uu.SetOptions(Form("workers=%d", nwrks));
115  swrk.Form("%d workers", nwrks);
116  }
117  lite = kTRUE;
118  gEnv->SetValue("Proof.MaxOldSessions", 1);
119  Printf("getProof: trying to open a PROOF-Lite session with %s", swrk.Data());
120  } else {
121  Printf("getProof: trying to open a session on the external cluster at '%s'", url);
122  }
123  p = TProof::Open(uu.GetUrl(), vopt);
124  if (p && p->IsValid()) {
125  // Check consistency
126  if (ext && !lite && nwrks > 0) {
127  Printf("getProof: WARNING: started/attached a session on external cluster (%s):"
128  " 'nwrks=%d' ignored", url, nwrks);
129  }
130  if (ext && !lite && dir && strlen(dir) > 0) {
131  Printf("getProof: WARNING: started/attached a session on external cluster (%s):"
132  " 'dir=\"%s\"' ignored", url, dir);
133  }
134  if (ext && !strcmp(opt,"force")) {
135  Printf("getProof: WARNING: started/attached a session on external cluster (%s):"
136  " 'opt=\"force\"' ignored", url);
137  }
138  if (ext && dyn) {
139  Printf("getProof: WARNING: started/attached a session on external cluster (%s):"
140  " 'dyn=kTRUE' ignored", url);
141  }
142  // Done
143  return p;
144  } else {
145  Printf("getProof: could not get/start a valid session at %s", url);
146  return p;
147  }
148  if (p) delete p;
149  p = 0;
150  }
151 
152 #ifdef WIN32
153  // No support for local PROOF on Win32 (yet; the optimized local Proof will work there too)
154  Printf("getProof: local PROOF not yet supported on Windows, sorry!");
155  return p;
156 #else
157 
158  // Temp dir for tutorial daemons
159  TString tutdir = dir;
160  if (!tutdir.IsNull()) {
161  if (gSystem->AccessPathName(tutdir)) {
162  // Directory does not exist: try to make it
163  gSystem->mkdir(tutdir.Data(), kTRUE);
164  if (gSystem->AccessPathName(tutdir, kWritePermission)) {
165  if (gSystem->AccessPathName(tutdir)) {
166  Printf("getProof: unable to create the working area at the requested path: '%s'"
167  " - cannot continue", tutdir.Data());
168  } else {
169  Printf("getProof: working area at the requested path '%s'"
170  " created but it is not writable - cannot continue", tutdir.Data());
171  }
172  return p;
173  }
174  } else {
175  // Check if it is writable ...
177  // ... fail if not
178  Printf("getProof: working area at the requested path '%s'"
179  " exists but is not writable - cannot continue", tutdir.Data());
180  return p;
181  }
182  }
183  } else {
184  // Notify
185  Printf("getProof: working area not specified temp ");
186  // Force "/tmp/<user>" whenever possible to avoid length problems on MacOsX
187  tutdir="/tmp";
188  if (gSystem->AccessPathName(tutdir, kWritePermission)) tutdir = gSystem->TempDirectory();
189  TString us;
191  if (!ug) {
192  Printf("getProof: could not get user info");
193  return p;
194  }
195  us.Form("/%s", ug->fUser.Data());
196  if (!tutdir.EndsWith(us.Data())) tutdir += us;
197  // Add our own subdir
198  tutdir += "/.getproof";
199  if (gSystem->AccessPathName(tutdir)) {
200  gSystem->mkdir(tutdir.Data(), kTRUE);
201  if (gSystem->AccessPathName(tutdir, kWritePermission)) {
202  Printf("getProof: unable to get a writable working area (tried: %s)"
203  " - cannot continue", tutdir.Data());
204  return p;
205  }
206  }
207  }
208  Printf("getProof: working area (tutorial dir): %s", tutdir.Data());
209 
210  // Dataset dir
211  TString datasetdir;
212  if (tutords) {
213  datasetdir = Form("%s/dataset", tutdir.Data());
214  if (gSystem->AccessPathName(datasetdir, kWritePermission)) {
215  gSystem->mkdir(datasetdir, kTRUE);
216  if (gSystem->AccessPathName(datasetdir, kWritePermission)) {
217  Printf("getProof: unable to get a writable dataset directory (tried: %s)"
218  " - cannot continue", datasetdir.Data());
219  return p;
220  }
221  Printf("getProof: dataset dir: %s", datasetdir.Data());
222  }
223  }
224 
225  // Local url (use a special port to try to not disturb running daemons)
226  TUrl u(refloc);
227  u.SetProtocol("proof");
228  if (!strcmp(uu.GetHost(), uref.GetHost()) && (uu.GetPort() != uref.GetPort()))
229  u.SetPort(uu.GetPort());
230  Int_t lportp = u.GetPort();
231  Int_t lportx = lportp + 1;
232  TString lurl = u.GetUrl();
233 
234  // Prepare to start the daemon
235  TString workarea = Form("%s/proof", tutdir.Data());
236  TString xpdcf(Form("%s/xpd.cf",tutdir.Data()));
237  TString xpdlog(Form("%s/xpd.log",tutdir.Data()));
238  TString xpdlogprt(Form("%s/xpdtut/xpd.log",tutdir.Data()));
239  TString xpdpid(Form("%s/xpd.pid",tutdir.Data()));
240  TString proofsessions(Form("%s/sessions",tutdir.Data()));
241  TString cmd;
242  Int_t rc = 0;
243 
244  // Is there something listening already ?
245  Int_t pid = -1;
246  Bool_t restart = kTRUE;
247  if ((rc = checkXproofdAt(lportp)) == 1) {
248  Printf("getProof: something else the a XProofd service is running on"
249  " port %d - cannot continue", lportp);
250  return p;
251 
252  } else if (rc == 0) {
253 
254  restart = kFALSE;
255 
256  pid = getXrootdPid(lportx);
257  Printf("getProof: daemon found listening on dedicated ports {%d,%d} (pid: %d)",
258  lportx, lportp, pid);
259  if (isatty(0) == 0 || isatty(1) == 0) {
260  // Cannot ask: always restart
261  restart = kTRUE;
262  } else {
263  if (!strcmp(opt,"ask")) {
264  char *answer = (char *) Getline("getProof: would you like to restart it (N,Y)? [N] ");
265  if (answer && (answer[0] == 'Y' || answer[0] == 'y'))
266  restart = kTRUE;
267  }
268  }
269  if (!strcmp(opt,"force"))
270  // Always restart
271  restart = kTRUE;
272 
273  // Cleanup, if required
274  if (restart) {
275  Printf("getProof: cleaning existing instance ...");
276  // Cleaning up existing daemon
277  cmd = Form("kill -9 %d", pid);
278  if ((rc = gSystem->Exec(cmd)) != 0)
279  Printf("getProof: problems stopping xrootd process %d (%d)", pid, rc);
280  // Wait for all previous connections being cleaned
281  Printf("getProof: wait 5 secs so that previous connections are cleaned ...");
282  gSystem->Sleep(5000);
283  }
284  }
285 
286  if (restart) {
287 
288  // Try to start something locally; make sure that everything is there
289  char *xpd = gSystem->Which(gSystem->Getenv("PATH"), "xproofd", kExecutePermission);
290  if (!xpd) {
291  Printf("getProof: xproofd not found: please check the environment!");
292  return p;
293  }
294 
295  // Cleanup the working area
296  cmd = Form("rm -fr %s/xpdtut %s %s %s %s", tutdir.Data(), workarea.Data(),
297  xpdcf.Data(), xpdpid.Data(), proofsessions.Data());
298  gSystem->Exec(cmd);
299 
300  // Try to start something locally; create the xproofd config file
301  FILE *fcf = fopen(xpdcf.Data(), "w");
302  if (!fcf) {
303  Printf("getProof: could not create config file for XPD (%s)", xpdcf.Data());
304  return p;
305  }
306  fprintf(fcf,"### Use admin path at %s/admin to avoid interferences with other users\n", tutdir.Data());
307  fprintf(fcf,"xrd.adminpath %s/admin\n", tutdir.Data());
308 #if defined(R__MACOSX)
309  fprintf(fcf,"### Use dedicated socket path under /tmp to avoid length problems\n");
310  fprintf(fcf,"xpd.sockpathdir /tmp/xpd-sock\n");
311 #endif
312  fprintf(fcf,"### Load the XrdProofd protocol on port %d\n", lportp);
313  fprintf(fcf,"xrd.protocol xproofd libXrdProofd.so\n");
314  fprintf(fcf,"xpd.port %d\n", lportp);
315  if (nwrks > 0) {
316  fprintf(fcf,"### Force number of local workers\n");
317  fprintf(fcf,"xpd.localwrks %d\n", nwrks);
318  }
319  fprintf(fcf,"### Root path for working dir\n");
320  fprintf(fcf,"xpd.workdir %s\n", workarea.Data());
321  fprintf(fcf,"### Allow different users to connect\n");
322  fprintf(fcf,"xpd.multiuser 1\n");
323  fprintf(fcf,"### Limit the number of query results kept in the master sandbox\n");
324  fprintf(fcf,"xpd.putrc ProofServ.UserQuotas: maxquerykept=2\n");
325  fprintf(fcf,"### Limit the number of sessions kept in the sandbox\n");
326  fprintf(fcf,"xpd.putrc Proof.MaxOldSessions: 1\n");
327  if (tutords) {
328  fprintf(fcf,"### Use dataset directory under the tutorial dir\n");
329  fprintf(fcf,"xpd.datasetsrc file url:%s opt:-Cq:Av:As:\n", datasetdir.Data());
330  }
331  if (dyn) {
332  fprintf(fcf,"### Use dynamic, per-job scheduling\n");
333  fprintf(fcf,"xpd.putrc Proof.DynamicStartup 1\n");
334  }
335  fprintf(fcf,"### For internal file serving use the xrootd protocol on the same port\n");
336  fprintf(fcf,"xpd.xrootd libXrdXrootd-4.so\n");
337  fprintf(fcf,"### Set the local data server for the temporary output files accordingly\n");
338  fprintf(fcf,"xpd.putenv LOCALDATASERVER=root://%s:%d\n", gSystem->HostName(), lportp);
339  fclose(fcf);
340  Printf("getProof: xproofd config file at %s", xpdcf.Data());
341 
342  // Start xrootd in the background
343  Printf("getProof: xproofd log file at %s", xpdlogprt.Data());
344  cmd = Form("%s -c %s -b -l %s -n xpdtut -p %d",
345  xpd, xpdcf.Data(), xpdlog.Data(), lportp);
346  Printf("(NB: any error line from XrdClientSock::RecvRaw and XrdClientMessage::ReadRaw should be ignored)");
347  if ((rc = gSystem->Exec(cmd)) != 0) {
348  Printf("getProof: problems starting xproofd (%d)", rc);
349  return p;
350  }
351  delete[] xpd;
352 
353  // Wait a bit
354  Printf("getProof: waiting for xproofd to start ...");
355  gSystem->Sleep(2000);
356 
357  pid = getXrootdPid(lportp);
358  Printf("getProof: xproofd pid: %d", pid);
359 
360  // Save it in the PID file
361  FILE *fpid = fopen(xpdpid.Data(), "w");
362  if (!fpid) {
363  Printf("getProof: could not create pid file for XPD");
364  } else {
365  fprintf(fpid,"%d\n", pid);
366  fclose(fpid);
367  }
368  }
369  Printf("getProof: start / attach the PROOF session ...");
370 
371  // Start / attach the session now
372  p = TProof::Open(lurl, vopt.Data());
373  if (!p || !(p->IsValid())) {
374  Printf("getProof: starting local session failed");
375  if (p) delete p;
376  p = 0;
377  return p;
378  }
379 
380  // Return the session
381  return p;
382 #endif
383 }
384 
385 Int_t getXrootdPid(Int_t port, const char *subdir)
386 {
387 #ifdef WIN32
388  // No support for Xrootd/Proof on Win32 (yet; the optimized local Proof will work there too)
389  Printf("getXrootdPid: Xrootd/Proof not supported on Windows, sorry!");
390  return -1;
391 #else
392  // Get the pid of the started xrootd process
393  Int_t pid = -1;
394 #if defined(__sun)
395  const char *com = "-eo pid,comm";
396 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
397  const char *com = "ax -w -w";
398 #else
399  const char *com = "-w -w -eo pid,command";
400 #endif
401  TString cmd;
402  if (subdir && strlen(subdir) > 0) {
403  cmd.Form("ps %s | grep xrootd | grep \"\\-p %d\" | grep %s", com, port, subdir);
404  } else {
405  cmd.Form("ps %s | grep xrootd | grep \"\\-p %d\"", com, port);
406  }
407  FILE *fp = gSystem->OpenPipe(cmd.Data(), "r");
408  if (fp) {
409  char line[2048], rest[2048];
410  while (fgets(line, sizeof(line), fp)) {
411  sscanf(line,"%d %s", &pid, rest);
412  break;
413  }
414  gSystem->ClosePipe(fp);
415  }
416  // Done
417  return pid;
418 #endif
419 }
420 
421 Int_t checkXrootdAt(Int_t port, const char *host)
422 {
423  // Check if a XrdXrootd service is running on 'port' at 'host'
424  // Return
425  // 0 if OK
426  // -1 if nothing is listening on the port (connection cannot be open)
427  // 1 if something is listening but not XROOTD
428 
429  // Open the connection
430  TSocket s(host, port);
431  if (!(s.IsValid())) {
432  if (gDebug > 0)
433  Printf("checkXrootdAt: could not open connection to %s:%d", host, port);
434  return -1;
435  }
436  // Send the first bytes
437  clnt_HS_t initHS;
438  memset(&initHS, 0, sizeof(initHS));
439  initHS.fourth = host2net((int)4);
440  initHS.fifth = host2net((int)2012);
441  int len = sizeof(initHS);
442  s.SendRaw(&initHS, len);
443  // Read first server response
444  int type;
445  len = sizeof(type);
446  int readCount = s.RecvRaw(&type, len); // 4(2+2) bytes
447  if (readCount != len) {
448  if (gDebug > 0)
449  Printf("checkXrootdAt: 1st: wrong number of bytes read: %d (expected: %d)",
450  readCount, len);
451  return 1;
452  }
453  // to host byte order
454  type = net2host(type);
455  // Check if the server is the eXtended proofd
456  if (type == 0) {
457  srv_HS_t xbody;
458  len = sizeof(xbody);
459  readCount = s.RecvRaw(&xbody, len); // 12(4+4+4) bytes
460  if (readCount != len) {
461  if (gDebug > 0)
462  Printf("checkXrootdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
463  readCount, len);
464  return 1;
465  }
466 
467  } else if (type == 8) {
468  // Standard proofd
469  if (gDebug > 0)
470  Printf("checkXrootdAt: server is ROOTD");
471  return 1;
472  } else {
473  // We don't know the server type
474  if (gDebug > 0)
475  Printf("checkXrootdAt: unknown server type: %d", type);
476  return 1;
477  }
478  // Done
479  return 0;
480 }
481 
482 Int_t checkXproofdAt(Int_t port, const char *host)
483 {
484  // Check if a XrdProofd service is running on 'port' at 'host'
485  // Return
486  // 0 if OK
487  // -1 if nothing is listening on the port (connection cannot be open)
488  // 1 if something is listening but not XPROOFD
489 
490  // Open the connection
491  TSocket s(host, port);
492  if (!(s.IsValid())) {
493  if (gDebug > 0)
494  Printf("checkXproofdAt: could not open connection to %s:%d", host, port);
495  return -1;
496  }
497  // Send the first bytes
498  clnt_HS_t initHS;
499  memset(&initHS, 0, sizeof(initHS));
500  initHS.third = (int)host2net((int)1);
501  int len = sizeof(initHS);
502  s.SendRaw(&initHS, len);
503  // These 8 bytes are need by 'proofd' and discarded by XPD
504  int dum[2];
505  dum[0] = (int)host2net((int)4);
506  dum[1] = (int)host2net((int)2012);
507  s.SendRaw(&dum[0], sizeof(dum));
508  // Read first server response
509  int type;
510  len = sizeof(type);
511  int readCount = s.RecvRaw(&type, len); // 4(2+2) bytes
512  if (readCount != len) {
513  if (gDebug > 0)
514  Printf("checkXproofdAt: 1st: wrong number of bytes read: %d (expected: %d)",
515  readCount, len);
516  return 1;
517  }
518  // to host byte order
519  type = net2host(type);
520  // Check if the server is the eXtended proofd
521  if (type == 0) {
522  srv_HS_t xbody;
523  len = sizeof(xbody);
524  readCount = s.RecvRaw(&xbody, len); // 12(4+4+4) bytes
525  if (readCount != len) {
526  if (gDebug > 0)
527  Printf("checkXproofdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
528  readCount, len);
529  return 1;
530  }
531  xbody.protover = net2host(xbody.protover);
532  xbody.msgval = net2host(xbody.msglen);
533  xbody.msglen = net2host(xbody.msgval);
534 
535  } else if (type == 8) {
536  // Standard proofd
537  if (gDebug > 0)
538  Printf("checkXproofdAt: server is PROOFD");
539  return 1;
540  } else {
541  // We don't know the server type
542  if (gDebug > 0)
543  Printf("checkXproofdAt: unknown server type: %d", type);
544  return 1;
545  }
546  // Done
547  return 0;
548 }
549 
550 Int_t startXrootdAt(Int_t port, const char *exportdirs, Bool_t force)
551 {
552  // Start a basic xrootd service on 'port' exporting the dirs in 'exportdirs'
553  // (blank separated list)
554 
555 #ifdef WIN32
556  // No support for Xrootd on Win32 (yet; the optimized local Proof will work there too)
557  Printf("startXrootdAt: Xrootd not supported on Windows, sorry!");
558  return -1;
559 #else
560  Bool_t restart = kTRUE;
561 
562  // Already there?
563  Int_t rc = 0;
564  if ((rc = checkXrootdAt(port)) == 1) {
565 
566  Printf("startXrootdAt: some other service running on port %d - cannot proceed ", port);
567  return -1;
568 
569  } else if (rc == 0) {
570 
571  restart = kFALSE;
572 
573  if (force) {
574  // Always restart
575  restart = kTRUE;
576  } else {
577  Printf("startXrootdAt: xrootd service already available on port %d: ", port);
578  char *answer = (char *) Getline("startXrootdAt: would you like to restart it (N,Y)? [N] ");
579  if (answer && (answer[0] == 'Y' || answer[0] == 'y')) {
580  restart = kTRUE;
581  }
582  }
583 
584  // Cleanup, if required
585  if (restart) {
586  Printf("startXrootdAt: cleaning existing instance ...");
587 
588  // Get the Pid
589  Int_t pid = getXrootdPid(port, "xrd-basic");
590 
591  // Cleanimg up existing daemon
592  TString cmd = Form("kill -9 %d", pid);
593  if ((rc = gSystem->Exec(cmd)) != 0)
594  Printf("startXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
595  }
596  }
597 
598  if (restart) {
599  if (gSystem->AccessPathName("/tmp/xrd-basic")) {
600  gSystem->mkdir("/tmp/xrd-basic");
601  if (gSystem->AccessPathName("/tmp/xrd-basic")) {
602  Printf("startXrootdAt: could not assert dir for log file");
603  return -1;
604  }
605  }
606  TString cmd;
607  cmd.Form("xrootd -d -p %d -b -l /tmp/xrd-basic/xrootd.log", port);
608  if (exportdirs && strlen(exportdirs) > 0) {
609  TString dirs(exportdirs), d;
610  Int_t from = 0;
611  while (dirs.Tokenize(d, from, " ")) {
612  if (!d.IsNull()) {
613  cmd += " ";
614  cmd += d;
615  }
616  }
617  }
618  Printf("cmd: %s", cmd.Data());
619  if ((rc = gSystem->Exec(cmd)) != 0) {
620  Printf("startXrootdAt: problems executing starting command (%d)", rc);
621  return -1;
622  }
623  // Wait a bit
624  Printf("startXrootdAt: waiting for xrootd to start ...");
625  gSystem->Sleep(2000);
626  // Check the result
627  if ((rc = checkXrootdAt(port)) != 0) {
628  Printf("startXrootdAt: xrootd service not available at %d (rc = %d) - startup failed",
629  port, rc);
630  return -1;
631  }
632  Printf("startXrootdAt: basic xrootd started!");
633  }
634 
635  // Done
636  return 0;
637 #endif
638 }
639 
640 Int_t killXrootdAt(Int_t port, const char *id)
641 {
642  // Kill running xrootd service on 'port'
643 
644 #ifdef WIN32
645  // No support for Xrootd on Win32 (yet; the optimized local Proof will work there too)
646  Printf("killXrootdAt: Xrootd not supported on Windows, sorry!");
647  return -1;
648 #else
649 
650  Int_t pid = -1, rc= 0;
651  if ((pid = getXrootdPid(port, id)) > 0) {
652 
653  // Cleanimg up existing daemon
654  TString cmd = Form("kill -9 %d", pid);
655  if ((rc = gSystem->Exec(cmd)) != 0)
656  Printf("killXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
657  }
658 
659  // Done
660  return rc;
661 #endif
662 }
663 
664 int getDebugEnum(const char *what)
665 {
666  // Check if 'what' matches one of the TProofDebug enum and return the corresponding
667  // integer. Relies on a perfect synchronization with the content of TProofDebug.h .
668 
669  TString sws(what), sw;
670  int rcmask = 0;
671  int from = 0;
672  while (sws.Tokenize(sw, from , "|")) {
673  if (sw.BeginsWith("k")) sw.Remove(0,1);
674 
675  if (sw == "None") {
676  rcmask |= TProofDebug::kNone;
677  } else if (sw == "Packetizer") {
678  rcmask |= TProofDebug::kPacketizer;
679  } else if (sw == "Loop") {
680  rcmask |= TProofDebug::kLoop;
681  } else if (sw == "Selector") {
682  rcmask |= TProofDebug::kSelector;
683  } else if (sw == "Output") {
684  rcmask |= TProofDebug::kOutput;
685  } else if (sw == "Input") {
686  rcmask |= TProofDebug::kInput;
687  } else if (sw == "Global") {
688  rcmask |= TProofDebug::kGlobal;
689  } else if (sw == "Package") {
690  rcmask |= TProofDebug::kPackage;
691  } else if (sw == "Feedback") {
692  rcmask |= TProofDebug::kFeedback;
693  } else if (sw == "Condor") {
694  rcmask |= TProofDebug::kCondor;
695  } else if (sw == "Draw") {
696  rcmask |= TProofDebug::kDraw;
697  } else if (sw == "Asyn") {
698  rcmask |= TProofDebug::kAsyn;
699  } else if (sw == "Cache") {
700  rcmask |= TProofDebug::kCache;
701  } else if (sw == "Collect") {
702  rcmask |= TProofDebug::kCollect;
703  } else if (sw == "Dataset") {
704  rcmask |= TProofDebug::kDataset;
705  } else if (sw == "Submerger") {
706  rcmask |= TProofDebug::kSubmerger;
707  } else if (sw == "Monitoring") {
708  rcmask |= TProofDebug::kMonitoring;
709  } else if (sw == "All") {
710  rcmask |= TProofDebug::kAll;
711  } else if (!sw.IsNull()) {
712  Printf("WARNING: requested debug enum name '%s' does not exist: assuming 'All'", sw.Data());
713  rcmask |= TProofDebug::kAll;
714  }
715  }
716  // Done
717  return rcmask;
718 }
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:1272
TLine * line
This class represents a WWW compatible URL.
Definition: TUrl.h:35
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1518
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition: TSystem.cxx:669
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition: TSystem.cxx:903
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:727
UShort_t net2host(UShort_t x)
Definition: Bytes.h:577
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:444
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1634
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1570
static TProof * Open(const char *url=0, const char *conffile=0, const char *confdir=0, Int_t loglevel=0)
Start a PROOF session on a specific cluster.
Definition: TProof.cxx:11555
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition: TSystem.cxx:1454
Int_t getProof(const char *where, Int_t verbose=1)
Open a PROOF session at gUrl.
TString fUser
Definition: TSystem.h:142
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:563
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2332
char * Form(const char *fmt,...)
static void AddEnvVar(const char *name, const char *value)
Add an variable to the list of environment variables passed to proofserv on the master and slaves...
Definition: TProof.cxx:11732
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:660
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition: TSystem.cxx:678
#define Printf
Definition: TGeoToOCC.h:18
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString & Remove(Ssiz_t pos)
Definition: TString.h:621
virtual const char * HostName()
Return the system&#39;s host name.
Definition: TSystem.cxx:310
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:320
virtual Int_t GetUid(const char *user=0)
Returns the user&#39;s id. If user = 0, returns current user&#39;s id.
Definition: TSystem.cxx:1531
Bool_t IsNull() const
Definition: TString.h:385
R__EXTERN Int_t gDebug
Definition: Rtypes.h:83
Bool_t IsValid() const
Definition: TProof.h:941
Definition: first.py:1
UShort_t host2net(UShort_t x)
Definition: Bytes.h:564
const Bool_t kTRUE
Definition: RtypesCore.h:91
const char * Data() const
Definition: TString.h:347