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");
57 Int_t killXrootdAt(
Int_t port,
const char *
id = 0);
76 const char *refloc =
"proof://localhost:40000";
78 TProof *
getProof(
const char *url =
"proof://localhost:40000",
Int_t nwrks = -1,
const char *dir = 0,
91 while (s.Tokenize(t, from ,
" ")) {
92 if (t.BeginsWith(
"valgrind_opts:"))
97 if (vopts.
IsNull()) vopts =
"valgrind_opts:--leak-check=full --track-origins=yes";
99 Printf(
"getProof: valgrind run: '%s' (opts: '%s')", vopt.
Data(), vopts.
Data());
104 TUrl uu(url), uref(refloc);
105 Bool_t ext = (strcmp(uu.GetHost(), uref.GetHost()) ||
106 (uu.GetPort() != uref.GetPort())) ?
kTRUE :
kFALSE;
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");
114 uu.SetOptions(
Form(
"workers=%d", nwrks));
115 swrk.Form(
"%d workers", nwrks);
119 Printf(
"getProof: trying to open a PROOF-Lite session with %s", swrk.Data());
121 Printf(
"getProof: trying to open a session on the external cluster at '%s'", url);
126 if (ext && !lite && nwrks > 0) {
127 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):" 128 " 'nwrks=%d' ignored", url, nwrks);
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);
134 if (ext && !strcmp(opt,
"force")) {
135 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):" 136 " 'opt=\"force\"' ignored", url);
139 Printf(
"getProof: WARNING: started/attached a session on external cluster (%s):" 140 " 'dyn=kTRUE' ignored", url);
146 Printf(
"getProof: could not get/start a valid session at %s", url);
149 Printf(
"getProof: could not get/start a valid session at %s - try resarting the daemon", url);
158 Printf(
"getProof: local PROOF not yet supported on Windows, sorry!");
170 Printf(
"getProof: unable to create the working area at the requested path: '%s'" 171 " - cannot continue", tutdir.
Data());
173 Printf(
"getProof: working area at the requested path '%s'" 174 " created but it is not writable - cannot continue", tutdir.
Data());
182 Printf(
"getProof: working area at the requested path '%s'" 183 " exists but is not writable - cannot continue", tutdir.
Data());
189 Printf(
"getProof: working area not specified temp ");
196 Printf(
"getProof: could not get user info");
202 tutdir +=
"/.getproof";
206 Printf(
"getProof: unable to get a writable working area (tried: %s)" 207 " - cannot continue", tutdir.
Data());
212 Printf(
"getProof: working area (tutorial dir): %s", tutdir.
Data());
217 datasetdir =
Form(
"%s/dataset", tutdir.
Data());
221 Printf(
"getProof: unable to get a writable dataset directory (tried: %s)" 222 " - cannot continue", datasetdir.Data());
225 Printf(
"getProof: dataset dir: %s", datasetdir.Data());
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;
251 if ((rc = checkXproofdAt(lportp)) == 1) {
252 Printf(
"getProof: something else the a XProofd service is running on" 253 " port %d - cannot continue", lportp);
256 }
else if (rc == 0) {
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) {
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'))
273 if (!strcmp(opt,
"force"))
279 Printf(
"getProof: cleaning existing instance ...");
281 cmd =
Form(
"kill -9 %d", pid);
283 Printf(
"getProof: problems stopping xrootd process %d (%d)", pid, rc);
285 Printf(
"getProof: wait 5 secs so that previous connections are cleaned ...");
295 Printf(
"getProof: xproofd not found: please check the environment!");
300 cmd =
Form(
"rm -fr %s/xpdtut %s %s %s %s", tutdir.
Data(), workarea.
Data(),
301 xpdcf.Data(), xpdpid.Data(), proofsessions.Data());
305 FILE *fcf = fopen(xpdcf.Data(),
"w");
307 Printf(
"getProof: could not create config file for XPD (%s)", xpdcf.Data());
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");
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);
320 fprintf(fcf,
"### Force number of local workers\n");
321 fprintf(fcf,
"xpd.localwrks %d\n", nwrks);
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");
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());
336 fprintf(fcf,
"### Use dynamic, per-job scheduling\n");
337 fprintf(fcf,
"xpd.putrc Proof.DynamicStartup 1\n");
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);
344 Printf(
"getProof: xproofd config file at %s", xpdcf.Data());
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)");
352 Printf(
"getProof: problems starting xproofd (%d)", rc);
358 Printf(
"getProof: waiting for xproofd to start ...");
361 pid = getXrootdPid(lportp);
362 Printf(
"getProof: xproofd pid: %d", pid);
365 FILE *fpid = fopen(xpdpid.Data(),
"w");
367 Printf(
"getProof: could not create pid file for XPD");
369 fprintf(fpid,
"%d\n", pid);
373 Printf(
"getProof: start / attach the PROOF session ...");
378 Printf(
"getProof: starting local session failed");
389 Int_t getXrootdPid(
Int_t port,
const char *subdir)
393 Printf(
"getXrootdPid: Xrootd/Proof not supported on Windows, sorry!");
399 const char *com =
"-eo pid,comm";
400 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) 401 const char *com =
"ax -w -w";
403 const char *com =
"-w -w -eo pid,command";
406 if (subdir && strlen(subdir) > 0) {
407 cmd.
Form(
"ps %s | grep xrootd | grep \"\\-p %d\" | grep %s", com, port, subdir);
409 cmd.
Form(
"ps %s | grep xrootd | grep \"\\-p %d\"", com, port);
413 char line[2048], rest[2048];
414 while (fgets(line,
sizeof(line), fp)) {
415 sscanf(line,
"%d %s", &pid, rest);
425 Int_t checkXrootdAt(
Int_t port,
const char *host)
435 if (!(s.IsValid())) {
437 Printf(
"checkXrootdAt: could not open connection to %s:%d", host, port);
442 memset(&initHS, 0,
sizeof(initHS));
445 int len =
sizeof(initHS);
446 s.SendRaw(&initHS, len);
450 int readCount = s.RecvRaw(&type, len);
451 if (readCount != len) {
453 Printf(
"checkXrootdAt: 1st: wrong number of bytes read: %d (expected: %d)",
463 readCount = s.RecvRaw(&xbody, len);
464 if (readCount != len) {
466 Printf(
"checkXrootdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
471 }
else if (type == 8) {
474 Printf(
"checkXrootdAt: server is ROOTD");
479 Printf(
"checkXrootdAt: unknown server type: %d", type);
486 Int_t checkXproofdAt(
Int_t port,
const char *host)
496 if (!(s.IsValid())) {
498 Printf(
"checkXproofdAt: could not open connection to %s:%d", host, port);
503 memset(&initHS, 0,
sizeof(initHS));
504 initHS.third = (int)
host2net((
int)1);
505 int len =
sizeof(initHS);
506 s.SendRaw(&initHS, len);
511 s.SendRaw(&dum[0],
sizeof(dum));
515 int readCount = s.RecvRaw(&type, len);
516 if (readCount != len) {
518 Printf(
"checkXproofdAt: 1st: wrong number of bytes read: %d (expected: %d)",
528 readCount = s.RecvRaw(&xbody, len);
529 if (readCount != len) {
531 Printf(
"checkXproofdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
535 xbody.protover =
net2host(xbody.protover);
536 xbody.msgval =
net2host(xbody.msglen);
537 xbody.msglen =
net2host(xbody.msgval);
539 }
else if (type == 8) {
542 Printf(
"checkXproofdAt: server is PROOFD");
547 Printf(
"checkXproofdAt: unknown server type: %d", type);
561 Printf(
"startXrootdAt: Xrootd not supported on Windows, sorry!");
568 if ((rc = checkXrootdAt(port)) == 1) {
570 Printf(
"startXrootdAt: some other service running on port %d - cannot proceed ", port);
573 }
else if (rc == 0) {
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')) {
590 Printf(
"startXrootdAt: cleaning existing instance ...");
593 Int_t pid = getXrootdPid(port,
"xrd-basic");
598 Printf(
"startXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
606 Printf(
"startXrootdAt: could not assert dir for log file");
611 cmd.
Form(
"xrootd -d -p %d -b -l /tmp/xrd-basic/xrootd.log", port);
612 if (exportdirs && strlen(exportdirs) > 0) {
615 while (dirs.Tokenize(d, from,
" ")) {
624 Printf(
"startXrootdAt: problems executing starting command (%d)", rc);
628 Printf(
"startXrootdAt: waiting for xrootd to start ...");
631 if ((rc = checkXrootdAt(port)) != 0) {
632 Printf(
"startXrootdAt: xrootd service not available at %d (rc = %d) - startup failed",
636 Printf(
"startXrootdAt: basic xrootd started!");
644 Int_t killXrootdAt(
Int_t port,
const char *
id)
650 Printf(
"killXrootdAt: Xrootd not supported on Windows, sorry!");
654 Int_t pid = -1, rc= 0;
655 if ((pid = getXrootdPid(port,
id)) > 0) {
660 Printf(
"killXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
668 int getDebugEnum(
const char *
what)
676 while (sws.Tokenize(sw, from ,
"|")) {
681 }
else if (sw ==
"Packetizer") {
683 }
else if (sw ==
"Loop") {
685 }
else if (sw ==
"Selector") {
687 }
else if (sw ==
"Output") {
689 }
else if (sw ==
"Input") {
691 }
else if (sw ==
"Global") {
693 }
else if (sw ==
"Package") {
695 }
else if (sw ==
"Feedback") {
697 }
else if (sw ==
"Condor") {
699 }
else if (sw ==
"Draw") {
701 }
else if (sw ==
"Asyn") {
703 }
else if (sw ==
"Cache") {
705 }
else if (sw ==
"Collect") {
707 }
else if (sw ==
"Dataset") {
709 }
else if (sw ==
"Submerger") {
711 }
else if (sw ==
"Monitoring") {
713 }
else if (sw ==
"All") {
715 }
else if (!sw.
IsNull()) {
716 Printf(
"WARNING: requested debug enum name '%s' does not exist: assuming 'All'", sw.
Data());
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
This class represents a WWW compatible URL.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
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.
UShort_t net2host(UShort_t x)
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual const char * Getenv(const char *env)
Get environment variable.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
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.
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Int_t getProof(const char *where, Int_t verbose=1)
Open a PROOF session at gUrl.
R__EXTERN TSystem * gSystem
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
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...
virtual Int_t Exec(const char *shellcmd)
Execute a command.
virtual int ClosePipe(FILE *pipe)
Close the pipe.
TString & Remove(Ssiz_t pos)
virtual const char * HostName()
Return the system's host name.
This class controls a Parallel ROOT Facility, PROOF, cluster.
virtual Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
UShort_t host2net(UShort_t x)
const char * Data() const