Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.08/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  if (ext) {
146  Printf("getProof: could not get/start a valid session at %s", url);
147  return p;
148  } else {
149  Printf("getProof: could not get/start a valid session at %s - try resarting the daemon", url);
150  }
151  }
152  if (p) delete p;
153  p = 0;
154  }
155 
156 #ifdef WIN32
157  // No support for local PROOF on Win32 (yet; the optimized local Proof will work there too)
158  Printf("getProof: local PROOF not yet supported on Windows, sorry!");
159  return p;
160 #else
161 
162  // Temp dir for tutorial daemons
163  TString tutdir = dir;
164  if (!tutdir.IsNull()) {
165  if (gSystem->AccessPathName(tutdir)) {
166  // Directory does not exist: try to make it
167  gSystem->mkdir(tutdir.Data(), kTRUE);
168  if (gSystem->AccessPathName(tutdir, kWritePermission)) {
169  if (gSystem->AccessPathName(tutdir)) {
170  Printf("getProof: unable to create the working area at the requested path: '%s'"
171  " - cannot continue", tutdir.Data());
172  } else {
173  Printf("getProof: working area at the requested path '%s'"
174  " created but it is not writable - cannot continue", tutdir.Data());
175  }
176  return p;
177  }
178  } else {
179  // Check if it is writable ...
181  // ... fail if not
182  Printf("getProof: working area at the requested path '%s'"
183  " exists but is not writable - cannot continue", tutdir.Data());
184  return p;
185  }
186  }
187  } else {
188  // Notify
189  Printf("getProof: working area not specified temp ");
190  // Force "/tmp/<user>" whenever possible to avoid length problems on MacOsX
191  tutdir="/tmp";
192  if (gSystem->AccessPathName(tutdir, kWritePermission)) tutdir = gSystem->TempDirectory();
193  TString us;
195  if (!ug) {
196  Printf("getProof: could not get user info");
197  return p;
198  }
199  us.Form("/%s", ug->fUser.Data());
200  if (!tutdir.EndsWith(us.Data())) tutdir += us;
201  // Add our own subdir
202  tutdir += "/.getproof";
203  if (gSystem->AccessPathName(tutdir)) {
204  gSystem->mkdir(tutdir.Data(), kTRUE);
205  if (gSystem->AccessPathName(tutdir, kWritePermission)) {
206  Printf("getProof: unable to get a writable working area (tried: %s)"
207  " - cannot continue", tutdir.Data());
208  return p;
209  }
210  }
211  }
212  Printf("getProof: working area (tutorial dir): %s", tutdir.Data());
213 
214  // Dataset dir
215  TString datasetdir;
216  if (tutords) {
217  datasetdir = Form("%s/dataset", tutdir.Data());
218  if (gSystem->AccessPathName(datasetdir, kWritePermission)) {
219  gSystem->mkdir(datasetdir, kTRUE);
220  if (gSystem->AccessPathName(datasetdir, kWritePermission)) {
221  Printf("getProof: unable to get a writable dataset directory (tried: %s)"
222  " - cannot continue", datasetdir.Data());
223  return p;
224  }
225  Printf("getProof: dataset dir: %s", datasetdir.Data());
226  }
227  }
228 
229  // Local url (use a special port to try to not disturb running daemons)
230  TUrl u(refloc);
231  u.SetProtocol("proof");
232  if (!strcmp(uu.GetHost(), uref.GetHost()) && (uu.GetPort() != uref.GetPort()))
233  u.SetPort(uu.GetPort());
234  Int_t lportp = u.GetPort();
235  Int_t lportx = lportp + 1;
236  TString lurl = u.GetUrl();
237 
238  // Prepare to start the daemon
239  TString workarea = Form("%s/proof", tutdir.Data());
240  TString xpdcf(Form("%s/xpd.cf",tutdir.Data()));
241  TString xpdlog(Form("%s/xpd.log",tutdir.Data()));
242  TString xpdlogprt(Form("%s/xpdtut/xpd.log",tutdir.Data()));
243  TString xpdpid(Form("%s/xpd.pid",tutdir.Data()));
244  TString proofsessions(Form("%s/sessions",tutdir.Data()));
245  TString cmd;
246  Int_t rc = 0;
247 
248  // Is there something listening already ?
249  Int_t pid = -1;
250  Bool_t restart = kTRUE;
251  if ((rc = checkXproofdAt(lportp)) == 1) {
252  Printf("getProof: something else the a XProofd service is running on"
253  " port %d - cannot continue", lportp);
254  return p;
255 
256  } else if (rc == 0) {
257 
258  restart = kFALSE;
259 
260  pid = getXrootdPid(lportx);
261  Printf("getProof: daemon found listening on dedicated ports {%d,%d} (pid: %d)",
262  lportx, lportp, pid);
263  if (isatty(0) == 0 || isatty(1) == 0) {
264  // Cannot ask: always restart
265  restart = kTRUE;
266  } else {
267  if (!strcmp(opt,"ask")) {
268  char *answer = (char *) Getline("getProof: would you like to restart it (N,Y)? [N] ");
269  if (answer && (answer[0] == 'Y' || answer[0] == 'y'))
270  restart = kTRUE;
271  }
272  }
273  if (!strcmp(opt,"force"))
274  // Always restart
275  restart = kTRUE;
276 
277  // Cleanup, if required
278  if (restart) {
279  Printf("getProof: cleaning existing instance ...");
280  // Cleaning up existing daemon
281  cmd = Form("kill -9 %d", pid);
282  if ((rc = gSystem->Exec(cmd)) != 0)
283  Printf("getProof: problems stopping xrootd process %d (%d)", pid, rc);
284  // Wait for all previous connections being cleaned
285  Printf("getProof: wait 5 secs so that previous connections are cleaned ...");
286  gSystem->Sleep(5000);
287  }
288  }
289 
290  if (restart) {
291 
292  // Try to start something locally; make sure that everything is there
293  char *xpd = gSystem->Which(gSystem->Getenv("PATH"), "xproofd", kExecutePermission);
294  if (!xpd) {
295  Printf("getProof: xproofd not found: please check the environment!");
296  return p;
297  }
298 
299  // Cleanup the working area
300  cmd = Form("rm -fr %s/xpdtut %s %s %s %s", tutdir.Data(), workarea.Data(),
301  xpdcf.Data(), xpdpid.Data(), proofsessions.Data());
302  gSystem->Exec(cmd);
303 
304  // Try to start something locally; create the xproofd config file
305  FILE *fcf = fopen(xpdcf.Data(), "w");
306  if (!fcf) {
307  Printf("getProof: could not create config file for XPD (%s)", xpdcf.Data());
308  return p;
309  }
310  fprintf(fcf,"### Use admin path at %s/admin to avoid interferences with other users\n", tutdir.Data());
311  fprintf(fcf,"xrd.adminpath %s/admin\n", tutdir.Data());
312 #if defined(R__MACOSX)
313  fprintf(fcf,"### Use dedicated socket path under /tmp to avoid length problems\n");
314  fprintf(fcf,"xpd.sockpathdir /tmp/xpd-sock\n");
315 #endif
316  fprintf(fcf,"### Load the XrdProofd protocol on port %d\n", lportp);
317  fprintf(fcf,"xrd.protocol xproofd libXrdProofd.so\n");
318  fprintf(fcf,"xpd.port %d\n", lportp);
319  if (nwrks > 0) {
320  fprintf(fcf,"### Force number of local workers\n");
321  fprintf(fcf,"xpd.localwrks %d\n", nwrks);
322  }
323  fprintf(fcf,"### Root path for working dir\n");
324  fprintf(fcf,"xpd.workdir %s\n", workarea.Data());
325  fprintf(fcf,"### Allow different users to connect\n");
326  fprintf(fcf,"xpd.multiuser 1\n");
327  fprintf(fcf,"### Limit the number of query results kept in the master sandbox\n");
328  fprintf(fcf,"xpd.putrc ProofServ.UserQuotas: maxquerykept=2\n");
329  fprintf(fcf,"### Limit the number of sessions kept in the sandbox\n");
330  fprintf(fcf,"xpd.putrc Proof.MaxOldSessions: 1\n");
331  if (tutords) {
332  fprintf(fcf,"### Use dataset directory under the tutorial dir\n");
333  fprintf(fcf,"xpd.datasetsrc file url:%s opt:-Cq:Av:As:\n", datasetdir.Data());
334  }
335  if (dyn) {
336  fprintf(fcf,"### Use dynamic, per-job scheduling\n");
337  fprintf(fcf,"xpd.putrc Proof.DynamicStartup 1\n");
338  }
339  fprintf(fcf,"### For internal file serving use the xrootd protocol on the same port\n");
340  fprintf(fcf,"xpd.xrootd libXrdXrootd-4.so\n");
341  fprintf(fcf,"### Set the local data server for the temporary output files accordingly\n");
342  fprintf(fcf,"xpd.putenv LOCALDATASERVER=root://%s:%d\n", gSystem->HostName(), lportp);
343  fclose(fcf);
344  Printf("getProof: xproofd config file at %s", xpdcf.Data());
345 
346  // Start xrootd in the background
347  Printf("getProof: xproofd log file at %s", xpdlogprt.Data());
348  cmd = Form("%s -c %s -b -l %s -n xpdtut -p %d",
349  xpd, xpdcf.Data(), xpdlog.Data(), lportp);
350  Printf("(NB: any error line from XrdClientSock::RecvRaw and XrdClientMessage::ReadRaw should be ignored)");
351  if ((rc = gSystem->Exec(cmd)) != 0) {
352  Printf("getProof: problems starting xproofd (%d)", rc);
353  return p;
354  }
355  delete[] xpd;
356 
357  // Wait a bit
358  Printf("getProof: waiting for xproofd to start ...");
359  gSystem->Sleep(2000);
360 
361  pid = getXrootdPid(lportp);
362  Printf("getProof: xproofd pid: %d", pid);
363 
364  // Save it in the PID file
365  FILE *fpid = fopen(xpdpid.Data(), "w");
366  if (!fpid) {
367  Printf("getProof: could not create pid file for XPD");
368  } else {
369  fprintf(fpid,"%d\n", pid);
370  fclose(fpid);
371  }
372  }
373  Printf("getProof: start / attach the PROOF session ...");
374 
375  // Start / attach the session now
376  p = TProof::Open(lurl, vopt.Data());
377  if (!p || !(p->IsValid())) {
378  Printf("getProof: starting local session failed");
379  if (p) delete p;
380  p = 0;
381  return p;
382  }
383 
384  // Return the session
385  return p;
386 #endif
387 }
388 
389 Int_t getXrootdPid(Int_t port, const char *subdir)
390 {
391 #ifdef WIN32
392  // No support for Xrootd/Proof on Win32 (yet; the optimized local Proof will work there too)
393  Printf("getXrootdPid: Xrootd/Proof not supported on Windows, sorry!");
394  return -1;
395 #else
396  // Get the pid of the started xrootd process
397  Int_t pid = -1;
398 #if defined(__sun)
399  const char *com = "-eo pid,comm";
400 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
401  const char *com = "ax -w -w";
402 #else
403  const char *com = "-w -w -eo pid,command";
404 #endif
405  TString cmd;
406  if (subdir && strlen(subdir) > 0) {
407  cmd.Form("ps %s | grep xrootd | grep \"\\-p %d\" | grep %s", com, port, subdir);
408  } else {
409  cmd.Form("ps %s | grep xrootd | grep \"\\-p %d\"", com, port);
410  }
411  FILE *fp = gSystem->OpenPipe(cmd.Data(), "r");
412  if (fp) {
413  char line[2048], rest[2048];
414  while (fgets(line, sizeof(line), fp)) {
415  sscanf(line,"%d %s", &pid, rest);
416  break;
417  }
418  gSystem->ClosePipe(fp);
419  }
420  // Done
421  return pid;
422 #endif
423 }
424 
425 Int_t checkXrootdAt(Int_t port, const char *host)
426 {
427  // Check if a XrdXrootd service is running on 'port' at 'host'
428  // Return
429  // 0 if OK
430  // -1 if nothing is listening on the port (connection cannot be open)
431  // 1 if something is listening but not XROOTD
432 
433  // Open the connection
434  TSocket s(host, port);
435  if (!(s.IsValid())) {
436  if (gDebug > 0)
437  Printf("checkXrootdAt: could not open connection to %s:%d", host, port);
438  return -1;
439  }
440  // Send the first bytes
441  clnt_HS_t initHS;
442  memset(&initHS, 0, sizeof(initHS));
443  initHS.fourth = host2net((int)4);
444  initHS.fifth = host2net((int)2012);
445  int len = sizeof(initHS);
446  s.SendRaw(&initHS, len);
447  // Read first server response
448  int type;
449  len = sizeof(type);
450  int readCount = s.RecvRaw(&type, len); // 4(2+2) bytes
451  if (readCount != len) {
452  if (gDebug > 0)
453  Printf("checkXrootdAt: 1st: wrong number of bytes read: %d (expected: %d)",
454  readCount, len);
455  return 1;
456  }
457  // to host byte order
458  type = net2host(type);
459  // Check if the server is the eXtended proofd
460  if (type == 0) {
461  srv_HS_t xbody;
462  len = sizeof(xbody);
463  readCount = s.RecvRaw(&xbody, len); // 12(4+4+4) bytes
464  if (readCount != len) {
465  if (gDebug > 0)
466  Printf("checkXrootdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
467  readCount, len);
468  return 1;
469  }
470 
471  } else if (type == 8) {
472  // Standard proofd
473  if (gDebug > 0)
474  Printf("checkXrootdAt: server is ROOTD");
475  return 1;
476  } else {
477  // We don't know the server type
478  if (gDebug > 0)
479  Printf("checkXrootdAt: unknown server type: %d", type);
480  return 1;
481  }
482  // Done
483  return 0;
484 }
485 
486 Int_t checkXproofdAt(Int_t port, const char *host)
487 {
488  // Check if a XrdProofd service is running on 'port' at 'host'
489  // Return
490  // 0 if OK
491  // -1 if nothing is listening on the port (connection cannot be open)
492  // 1 if something is listening but not XPROOFD
493 
494  // Open the connection
495  TSocket s(host, port);
496  if (!(s.IsValid())) {
497  if (gDebug > 0)
498  Printf("checkXproofdAt: could not open connection to %s:%d", host, port);
499  return -1;
500  }
501  // Send the first bytes
502  clnt_HS_t initHS;
503  memset(&initHS, 0, sizeof(initHS));
504  initHS.third = (int)host2net((int)1);
505  int len = sizeof(initHS);
506  s.SendRaw(&initHS, len);
507  // These 8 bytes are need by 'proofd' and discarded by XPD
508  int dum[2];
509  dum[0] = (int)host2net((int)4);
510  dum[1] = (int)host2net((int)2012);
511  s.SendRaw(&dum[0], sizeof(dum));
512  // Read first server response
513  int type;
514  len = sizeof(type);
515  int readCount = s.RecvRaw(&type, len); // 4(2+2) bytes
516  if (readCount != len) {
517  if (gDebug > 0)
518  Printf("checkXproofdAt: 1st: wrong number of bytes read: %d (expected: %d)",
519  readCount, len);
520  return 1;
521  }
522  // to host byte order
523  type = net2host(type);
524  // Check if the server is the eXtended proofd
525  if (type == 0) {
526  srv_HS_t xbody;
527  len = sizeof(xbody);
528  readCount = s.RecvRaw(&xbody, len); // 12(4+4+4) bytes
529  if (readCount != len) {
530  if (gDebug > 0)
531  Printf("checkXproofdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
532  readCount, len);
533  return 1;
534  }
535  xbody.protover = net2host(xbody.protover);
536  xbody.msgval = net2host(xbody.msglen);
537  xbody.msglen = net2host(xbody.msgval);
538 
539  } else if (type == 8) {
540  // Standard proofd
541  if (gDebug > 0)
542  Printf("checkXproofdAt: server is PROOFD");
543  return 1;
544  } else {
545  // We don't know the server type
546  if (gDebug > 0)
547  Printf("checkXproofdAt: unknown server type: %d", type);
548  return 1;
549  }
550  // Done
551  return 0;
552 }
553 
554 Int_t startXrootdAt(Int_t port, const char *exportdirs, Bool_t force)
555 {
556  // Start a basic xrootd service on 'port' exporting the dirs in 'exportdirs'
557  // (blank separated list)
558 
559 #ifdef WIN32
560  // No support for Xrootd on Win32 (yet; the optimized local Proof will work there too)
561  Printf("startXrootdAt: Xrootd not supported on Windows, sorry!");
562  return -1;
563 #else
564  Bool_t restart = kTRUE;
565 
566  // Already there?
567  Int_t rc = 0;
568  if ((rc = checkXrootdAt(port)) == 1) {
569 
570  Printf("startXrootdAt: some other service running on port %d - cannot proceed ", port);
571  return -1;
572 
573  } else if (rc == 0) {
574 
575  restart = kFALSE;
576 
577  if (force) {
578  // Always restart
579  restart = kTRUE;
580  } else {
581  Printf("startXrootdAt: xrootd service already available on port %d: ", port);
582  char *answer = (char *) Getline("startXrootdAt: would you like to restart it (N,Y)? [N] ");
583  if (answer && (answer[0] == 'Y' || answer[0] == 'y')) {
584  restart = kTRUE;
585  }
586  }
587 
588  // Cleanup, if required
589  if (restart) {
590  Printf("startXrootdAt: cleaning existing instance ...");
591 
592  // Get the Pid
593  Int_t pid = getXrootdPid(port, "xrd-basic");
594 
595  // Cleanimg up existing daemon
596  TString cmd = Form("kill -9 %d", pid);
597  if ((rc = gSystem->Exec(cmd)) != 0)
598  Printf("startXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
599  }
600  }
601 
602  if (restart) {
603  if (gSystem->AccessPathName("/tmp/xrd-basic")) {
604  gSystem->mkdir("/tmp/xrd-basic");
605  if (gSystem->AccessPathName("/tmp/xrd-basic")) {
606  Printf("startXrootdAt: could not assert dir for log file");
607  return -1;
608  }
609  }
610  TString cmd;
611  cmd.Form("xrootd -d -p %d -b -l /tmp/xrd-basic/xrootd.log", port);
612  if (exportdirs && strlen(exportdirs) > 0) {
613  TString dirs(exportdirs), d;
614  Int_t from = 0;
615  while (dirs.Tokenize(d, from, " ")) {
616  if (!d.IsNull()) {
617  cmd += " ";
618  cmd += d;
619  }
620  }
621  }
622  Printf("cmd: %s", cmd.Data());
623  if ((rc = gSystem->Exec(cmd)) != 0) {
624  Printf("startXrootdAt: problems executing starting command (%d)", rc);
625  return -1;
626  }
627  // Wait a bit
628  Printf("startXrootdAt: waiting for xrootd to start ...");
629  gSystem->Sleep(2000);
630  // Check the result
631  if ((rc = checkXrootdAt(port)) != 0) {
632  Printf("startXrootdAt: xrootd service not available at %d (rc = %d) - startup failed",
633  port, rc);
634  return -1;
635  }
636  Printf("startXrootdAt: basic xrootd started!");
637  }
638 
639  // Done
640  return 0;
641 #endif
642 }
643 
644 Int_t killXrootdAt(Int_t port, const char *id)
645 {
646  // Kill running xrootd service on 'port'
647 
648 #ifdef WIN32
649  // No support for Xrootd on Win32 (yet; the optimized local Proof will work there too)
650  Printf("killXrootdAt: Xrootd not supported on Windows, sorry!");
651  return -1;
652 #else
653 
654  Int_t pid = -1, rc= 0;
655  if ((pid = getXrootdPid(port, id)) > 0) {
656 
657  // Cleanimg up existing daemon
658  TString cmd = Form("kill -9 %d", pid);
659  if ((rc = gSystem->Exec(cmd)) != 0)
660  Printf("killXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
661  }
662 
663  // Done
664  return rc;
665 #endif
666 }
667 
668 int getDebugEnum(const char *what)
669 {
670  // Check if 'what' matches one of the TProofDebug enum and return the corresponding
671  // integer. Relies on a perfect synchronization with the content of TProofDebug.h .
672 
673  TString sws(what), sw;
674  int rcmask = 0;
675  int from = 0;
676  while (sws.Tokenize(sw, from , "|")) {
677  if (sw.BeginsWith("k")) sw.Remove(0,1);
678 
679  if (sw == "None") {
680  rcmask |= TProofDebug::kNone;
681  } else if (sw == "Packetizer") {
682  rcmask |= TProofDebug::kPacketizer;
683  } else if (sw == "Loop") {
684  rcmask |= TProofDebug::kLoop;
685  } else if (sw == "Selector") {
686  rcmask |= TProofDebug::kSelector;
687  } else if (sw == "Output") {
688  rcmask |= TProofDebug::kOutput;
689  } else if (sw == "Input") {
690  rcmask |= TProofDebug::kInput;
691  } else if (sw == "Global") {
692  rcmask |= TProofDebug::kGlobal;
693  } else if (sw == "Package") {
694  rcmask |= TProofDebug::kPackage;
695  } else if (sw == "Feedback") {
696  rcmask |= TProofDebug::kFeedback;
697  } else if (sw == "Condor") {
698  rcmask |= TProofDebug::kCondor;
699  } else if (sw == "Draw") {
700  rcmask |= TProofDebug::kDraw;
701  } else if (sw == "Asyn") {
702  rcmask |= TProofDebug::kAsyn;
703  } else if (sw == "Cache") {
704  rcmask |= TProofDebug::kCache;
705  } else if (sw == "Collect") {
706  rcmask |= TProofDebug::kCollect;
707  } else if (sw == "Dataset") {
708  rcmask |= TProofDebug::kDataset;
709  } else if (sw == "Submerger") {
710  rcmask |= TProofDebug::kSubmerger;
711  } else if (sw == "Monitoring") {
712  rcmask |= TProofDebug::kMonitoring;
713  } else if (sw == "All") {
714  rcmask |= TProofDebug::kAll;
715  } else if (!sw.IsNull()) {
716  Printf("WARNING: requested debug enum name '%s' does not exist: assuming 'All'", sw.Data());
717  rcmask |= TProofDebug::kAll;
718  }
719  }
720  // Done
721  return rcmask;
722 }
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:1266
TLine * line
This class represents a WWW compatible URL.
Definition: TUrl.h:41
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1512
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition: TSystem.cxx:667
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition: TSystem.cxx:901
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:751
UShort_t net2host(UShort_t x)
Definition: Bytes.h:579
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:442
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1628
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2221
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1564
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:1448
Int_t getProof(const char *where, Int_t verbose=1)
Open a PROOF session at gUrl.
static const char * what
Definition: stlLoader.cc:6
TString fUser
Definition: TSystem.h:152
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2322
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:658
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition: TSystem.cxx:676
#define Printf
Definition: TGeoToOCC.h:18
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
virtual const char * HostName()
Return the system&#39;s host name.
Definition: TSystem.cxx:308
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:346
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:1525
Bool_t IsNull() const
Definition: TString.h:387
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Bool_t IsValid() const
Definition: TProof.h:967
Definition: first.py:1
const Bool_t kTRUE
Definition: Rtypes.h:91
UShort_t host2net(UShort_t x)
Definition: Bytes.h:566
const char * Data() const
Definition: TString.h:349