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);
76 const char *refloc =
"proof://localhost:40000";
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)
88 if (gSystem->Getenv(
"GETPROOF_VALGRIND")) {
89 TString s(gSystem->Getenv(
"GETPROOF_VALGRIND")), t;
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";
98 TProof::AddEnvVar(
"PROOF_WRAPPERCMD", vopts.Data());
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;
107 Bool_t lite = 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);
118 gEnv->SetValue(
"Proof.MaxOldSessions", 1);
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);
123 p = TProof::Open(uu.GetUrl(), vopt);
124 if (p && p->IsValid()) {
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);
143 Printf(
"getProof: could not get/start a valid session at %s", url);
153 Printf(
"getProof: local PROOF not yet supported on Windows, sorry!");
158 TString tutdir = dir;
159 if (!tutdir.IsNull()) {
160 if (gSystem->AccessPathName(tutdir)) {
162 gSystem->mkdir(tutdir.Data(), kTRUE);
163 if (gSystem->AccessPathName(tutdir, kWritePermission)) {
164 if (gSystem->AccessPathName(tutdir)) {
165 Printf(
"getProof: unable to create the working area at the requested path: '%s'"
166 " - cannot continue", tutdir.Data());
168 Printf(
"getProof: working area at the requested path '%s'"
169 " created but it is not writable - cannot continue", tutdir.Data());
175 if (gSystem->AccessPathName(dir, kWritePermission)) {
177 Printf(
"getProof: working area at the requested path '%s'"
178 " exists but is not writable - cannot continue", tutdir.Data());
184 Printf(
"getProof: working area not specified temp ");
187 if (gSystem->AccessPathName(tutdir, kWritePermission)) tutdir = gSystem->TempDirectory();
189 UserGroup_t *ug = gSystem->GetUserInfo(gSystem->GetUid());
191 Printf(
"getProof: could not get user info");
194 us.Form(
"/%s", ug->fUser.Data());
195 if (!tutdir.EndsWith(us.Data())) tutdir += us;
197 tutdir +=
"/.getproof";
198 if (gSystem->AccessPathName(tutdir)) {
199 gSystem->mkdir(tutdir.Data(), kTRUE);
200 if (gSystem->AccessPathName(tutdir, kWritePermission)) {
201 Printf(
"getProof: unable to get a writable working area (tried: %s)"
202 " - cannot continue", tutdir.Data());
207 Printf(
"getProof: working area (tutorial dir): %s", tutdir.Data());
212 datasetdir = Form(
"%s/dataset", tutdir.Data());
213 if (gSystem->AccessPathName(datasetdir, kWritePermission)) {
214 gSystem->mkdir(datasetdir, kTRUE);
215 if (gSystem->AccessPathName(datasetdir, kWritePermission)) {
216 Printf(
"getProof: unable to get a writable dataset directory (tried: %s)"
217 " - cannot continue", datasetdir.Data());
220 Printf(
"getProof: dataset dir: %s", datasetdir.Data());
226 u.SetProtocol(
"proof");
227 if (!strcmp(uu.GetHost(), uref.GetHost()) && (uu.GetPort() != uref.GetPort()))
228 u.SetPort(uu.GetPort());
229 Int_t lportp = u.GetPort();
230 Int_t lportx = lportp + 1;
231 TString lurl = u.GetUrl();
234 TString workarea = Form(
"%s/proof", tutdir.Data());
235 TString xpdcf(Form(
"%s/xpd.cf",tutdir.Data()));
236 TString xpdlog(Form(
"%s/xpd.log",tutdir.Data()));
237 TString xpdlogprt(Form(
"%s/xpdtut/xpd.log",tutdir.Data()));
238 TString xpdpid(Form(
"%s/xpd.pid",tutdir.Data()));
239 TString proofsessions(Form(
"%s/sessions",tutdir.Data()));
245 Bool_t restart = kTRUE;
246 if ((rc = checkXproofdAt(lportp)) == 1) {
247 Printf(
"getProof: something else the a XProofd service is running on"
248 " port %d - cannot continue", lportp);
251 }
else if (rc == 0) {
255 pid = getXrootdPid(lportx);
256 Printf(
"getProof: daemon found listening on dedicated ports {%d,%d} (pid: %d)",
257 lportx, lportp, pid);
258 if (isatty(0) == 0 || isatty(1) == 0) {
262 if (!strcmp(opt,
"ask")) {
263 char *answer = (
char *) Getline(
"getProof: would you like to restart it (N,Y)? [N] ");
264 if (answer && (answer[0] ==
'Y' || answer[0] ==
'y'))
268 if (!strcmp(opt,
"force"))
274 Printf(
"getProof: cleaning existing instance ...");
276 cmd = Form(
"kill -9 %d", pid);
277 if ((rc = gSystem->Exec(cmd)) != 0)
278 Printf(
"getProof: problems stopping xrootd process %d (%d)", pid, rc);
280 Printf(
"getProof: wait 5 secs so that previous connections are cleaned ...");
281 gSystem->Sleep(5000);
288 char *xpd = gSystem->Which(gSystem->Getenv(
"PATH"),
"xproofd", kExecutePermission);
290 Printf(
"getProof: xproofd not found: please check the environment!");
295 cmd = Form(
"rm -fr %s/xpdtut %s %s %s %s", tutdir.Data(), workarea.Data(),
296 xpdcf.Data(), xpdpid.Data(), proofsessions.Data());
300 FILE *fcf = fopen(xpdcf.Data(),
"w");
302 Printf(
"getProof: could not create config file for XPD (%s)", xpdcf.Data());
305 fprintf(fcf,
"### Use admin path at %s/admin to avoid interferences with other users\n", tutdir.Data());
306 fprintf(fcf,
"xrd.adminpath %s/admin\n", tutdir.Data());
307 #if defined(R__MACOSX)
308 fprintf(fcf,
"### Use dedicated socket path under /tmp to avoid length problems\n");
309 fprintf(fcf,
"xpd.sockpathdir /tmp/xpd-sock\n");
311 fprintf(fcf,
"### Load the XrdProofd protocol on port %d\n", lportp);
312 fprintf(fcf,
"xrd.protocol xproofd libXrdProofd.so\n");
313 fprintf(fcf,
"xpd.port %d\n", lportp);
315 fprintf(fcf,
"### Force number of local workers\n");
316 fprintf(fcf,
"xpd.localwrks %d\n", nwrks);
318 fprintf(fcf,
"### Root path for working dir\n");
319 fprintf(fcf,
"xpd.workdir %s\n", workarea.Data());
320 fprintf(fcf,
"### Allow different users to connect\n");
321 fprintf(fcf,
"xpd.multiuser 1\n");
322 fprintf(fcf,
"### Limit the number of query results kept in the master sandbox\n");
323 fprintf(fcf,
"xpd.putrc ProofServ.UserQuotas: maxquerykept=2\n");
324 fprintf(fcf,
"### Limit the number of sessions kept in the sandbox\n");
325 fprintf(fcf,
"xpd.putrc Proof.MaxOldSessions: 1\n");
327 fprintf(fcf,
"### Use dataset directory under the tutorial dir\n");
328 fprintf(fcf,
"xpd.datasetsrc file url:%s opt:-Cq:Av:As:\n", datasetdir.Data());
331 fprintf(fcf,
"### Use dynamic, per-job scheduling\n");
332 fprintf(fcf,
"xpd.putrc Proof.DynamicStartup 1\n");
334 fprintf(fcf,
"### For internal file serving use the xrootd protocol on the same port\n");
335 fprintf(fcf,
"xpd.xrootd libXrdXrootd-4.so\n");
336 fprintf(fcf,
"### Set the local data server for the temporary output files accordingly\n");
337 fprintf(fcf,
"xpd.putenv LOCALDATASERVER=root://%s:%d\n", gSystem->HostName(), lportp);
339 Printf(
"getProof: xproofd config file at %s", xpdcf.Data());
342 Printf(
"getProof: xproofd log file at %s", xpdlogprt.Data());
343 cmd = Form(
"%s -c %s -b -l %s -n xpdtut -p %d",
344 xpd, xpdcf.Data(), xpdlog.Data(), lportp);
345 Printf(
"(NB: any error line from XrdClientSock::RecvRaw and XrdClientMessage::ReadRaw should be ignored)");
346 if ((rc = gSystem->Exec(cmd)) != 0) {
347 Printf(
"getProof: problems starting xproofd (%d)", rc);
353 Printf(
"getProof: waiting for xproofd to start ...");
354 gSystem->Sleep(2000);
356 pid = getXrootdPid(lportp);
357 Printf(
"getProof: xproofd pid: %d", pid);
360 FILE *fpid = fopen(xpdpid.Data(),
"w");
362 Printf(
"getProof: could not create pid file for XPD");
364 fprintf(fpid,
"%d\n", pid);
368 Printf(
"getProof: start / attach the PROOF session ...");
371 p = TProof::Open(lurl, vopt.Data());
372 if (!p || !(p->IsValid())) {
373 Printf(
"getProof: starting local session failed");
384 Int_t getXrootdPid(Int_t port,
const char *subdir)
388 Printf(
"getXrootdPid: Xrootd/Proof not supported on Windows, sorry!");
394 const char *com =
"-eo pid,comm";
395 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
396 const char *com =
"ax -w -w";
398 const char *com =
"-w -w -eo pid,command";
401 if (subdir && strlen(subdir) > 0) {
402 cmd.Form(
"ps %s | grep xrootd | grep \"\\-p %d\" | grep %s", com, port, subdir);
404 cmd.Form(
"ps %s | grep xrootd | grep \"\\-p %d\"", com, port);
406 FILE *fp = gSystem->OpenPipe(cmd.Data(),
"r");
408 char line[2048], rest[2048];
409 while (fgets(line,
sizeof(line), fp)) {
410 sscanf(line,
"%d %s", &pid, rest);
413 gSystem->ClosePipe(fp);
420 Int_t checkXrootdAt(Int_t port,
const char *host)
429 TSocket s(host, port);
430 if (!(s.IsValid())) {
432 Printf(
"checkXrootdAt: could not open connection to %s:%d", host, port);
437 memset(&initHS, 0,
sizeof(initHS));
438 initHS.fourth = host2net((
int)4);
439 initHS.fifth = host2net((
int)2012);
440 int len =
sizeof(initHS);
441 s.SendRaw(&initHS, len);
445 int readCount = s.RecvRaw(&type, len);
446 if (readCount != len) {
448 Printf(
"checkXrootdAt: 1st: wrong number of bytes read: %d (expected: %d)",
453 type = net2host(type);
458 readCount = s.RecvRaw(&xbody, len);
459 if (readCount != len) {
461 Printf(
"checkXrootdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
466 }
else if (type == 8) {
469 Printf(
"checkXrootdAt: server is ROOTD");
474 Printf(
"checkXrootdAt: unknown server type: %d", type);
481 Int_t checkXproofdAt(Int_t port,
const char *host)
490 TSocket s(host, port);
491 if (!(s.IsValid())) {
493 Printf(
"checkXproofdAt: could not open connection to %s:%d", host, port);
498 memset(&initHS, 0,
sizeof(initHS));
499 initHS.third = (int)host2net((
int)1);
500 int len =
sizeof(initHS);
501 s.SendRaw(&initHS, len);
504 dum[0] = (int)host2net((
int)4);
505 dum[1] = (int)host2net((
int)2012);
506 s.SendRaw(&dum[0],
sizeof(dum));
510 int readCount = s.RecvRaw(&type, len);
511 if (readCount != len) {
513 Printf(
"checkXproofdAt: 1st: wrong number of bytes read: %d (expected: %d)",
518 type = net2host(type);
523 readCount = s.RecvRaw(&xbody, len);
524 if (readCount != len) {
526 Printf(
"checkXproofdAt: 2nd: wrong number of bytes read: %d (expected: %d)",
530 xbody.protover = net2host(xbody.protover);
531 xbody.msgval = net2host(xbody.msglen);
532 xbody.msglen = net2host(xbody.msgval);
534 }
else if (type == 8) {
537 Printf(
"checkXproofdAt: server is PROOFD");
542 Printf(
"checkXproofdAt: unknown server type: %d", type);
549 Int_t startXrootdAt(Int_t port,
const char *exportdirs, Bool_t force)
556 Printf(
"startXrootdAt: Xrootd not supported on Windows, sorry!");
559 Bool_t restart = kTRUE;
563 if ((rc = checkXrootdAt(port)) == 1) {
565 Printf(
"startXrootdAt: some other service running on port %d - cannot proceed ", port);
568 }
else if (rc == 0) {
576 Printf(
"startXrootdAt: xrootd service already available on port %d: ", port);
577 char *answer = (
char *) Getline(
"startXrootdAt: would you like to restart it (N,Y)? [N] ");
578 if (answer && (answer[0] ==
'Y' || answer[0] ==
'y')) {
585 Printf(
"startXrootdAt: cleaning existing instance ...");
588 Int_t pid = getXrootdPid(port,
"xrd-basic");
591 TString cmd = Form(
"kill -9 %d", pid);
592 if ((rc = gSystem->Exec(cmd)) != 0)
593 Printf(
"startXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
598 if (gSystem->AccessPathName(
"/tmp/xrd-basic")) {
599 gSystem->mkdir(
"/tmp/xrd-basic");
600 if (gSystem->AccessPathName(
"/tmp/xrd-basic")) {
601 Printf(
"startXrootdAt: could not assert dir for log file");
606 cmd.Form(
"xrootd -d -p %d -b -l /tmp/xrd-basic/xrootd.log", port);
607 if (exportdirs && strlen(exportdirs) > 0) {
608 TString dirs(exportdirs), d;
610 while (dirs.Tokenize(d, from,
" ")) {
617 Printf(
"cmd: %s", cmd.Data());
618 if ((rc = gSystem->Exec(cmd)) != 0) {
619 Printf(
"startXrootdAt: problems executing starting command (%d)", rc);
623 Printf(
"startXrootdAt: waiting for xrootd to start ...");
624 gSystem->Sleep(2000);
626 if ((rc = checkXrootdAt(port)) != 0) {
627 Printf(
"startXrootdAt: xrootd service not available at %d (rc = %d) - startup failed",
631 Printf(
"startXrootdAt: basic xrootd started!");
639 Int_t killXrootdAt(Int_t port,
const char *
id)
645 Printf(
"killXrootdAt: Xrootd not supported on Windows, sorry!");
649 Int_t pid = -1, rc= 0;
650 if ((pid = getXrootdPid(port,
id)) > 0) {
653 TString cmd = Form(
"kill -9 %d", pid);
654 if ((rc = gSystem->Exec(cmd)) != 0)
655 Printf(
"killXrootdAt: problems stopping xrootd process %d (%d)", pid, rc);
663 int getDebugEnum(
const char *what)
668 TString sws(what), sw;
671 while (sws.Tokenize(sw, from ,
"|")) {
672 if (sw.BeginsWith(
"k")) sw.Remove(0,1);
675 rcmask |= TProofDebug::kNone;
676 }
else if (sw ==
"Packetizer") {
677 rcmask |= TProofDebug::kPacketizer;
678 }
else if (sw ==
"Loop") {
679 rcmask |= TProofDebug::kLoop;
680 }
else if (sw ==
"Selector") {
681 rcmask |= TProofDebug::kSelector;
682 }
else if (sw ==
"Output") {
683 rcmask |= TProofDebug::kOutput;
684 }
else if (sw ==
"Input") {
685 rcmask |= TProofDebug::kInput;
686 }
else if (sw ==
"Global") {
687 rcmask |= TProofDebug::kGlobal;
688 }
else if (sw ==
"Package") {
689 rcmask |= TProofDebug::kPackage;
690 }
else if (sw ==
"Feedback") {
691 rcmask |= TProofDebug::kFeedback;
692 }
else if (sw ==
"Condor") {
693 rcmask |= TProofDebug::kCondor;
694 }
else if (sw ==
"Draw") {
695 rcmask |= TProofDebug::kDraw;
696 }
else if (sw ==
"Asyn") {
697 rcmask |= TProofDebug::kAsyn;
698 }
else if (sw ==
"Cache") {
699 rcmask |= TProofDebug::kCache;
700 }
else if (sw ==
"Collect") {
701 rcmask |= TProofDebug::kCollect;
702 }
else if (sw ==
"Dataset") {
703 rcmask |= TProofDebug::kDataset;
704 }
else if (sw ==
"Submerger") {
705 rcmask |= TProofDebug::kSubmerger;
706 }
else if (sw ==
"Monitoring") {
707 rcmask |= TProofDebug::kMonitoring;
708 }
else if (sw ==
"All") {
709 rcmask |= TProofDebug::kAll;
710 }
else if (!sw.IsNull()) {
711 Printf(
"WARNING: requested debug enum name '%s' does not exist: assuming 'All'", sw.Data());
712 rcmask |= TProofDebug::kAll;