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