void Run_Simple_Test(char *host, const char *data_dir = "/var/tmp", Int_t dbg = 0) { if (gSystem->AccessPathName("../libEvent.so")) { gSystem->Exec("cd $ROOTSYS/test; make libEvent.so"); gSystem->Exec("./make_event_par.sh"); gSystem->Exec("ln -s ../Event.h"); gSystem->Load("../libEvent.so"); } TProof *p = 0; if (dbg > 0) { p = TProof::Open(host, "", "", dbg); } else { p = TProof::Open(host); } if (!p || !p->IsValid()) { cout << "Could not start the PROOF session - exit "<<endl; return; } if (dbg > 0) p->SetLogLevel(dbg); p->UploadPackage("event"); p->EnablePackage("event"); make_event_trees(data_dir, 100000, files_per_node); TDSet *d = make_tdset(data_dir, files_per_node); d->Print("a"); if (show_stats) gEnv->SetValue("Proof.StatsHist", 1); TDrawFeedback *fb(0); if (show_feedback) { if (show_stats) { p->AddFeedback("PROOF_ProcTimeHist"); p->AddFeedback("PROOF_LatencyHist"); p->AddFeedback("PROOF_EventsHist"); } p->AddFeedback("pt_dist"); fb = new TDrawFeedback(p); } // We load the selector before execution to avoid a problem affecting some versions // (in particular 5.22/00 and 5.22/00a); with problem-free versions this is equivalent // to direct processing via d->Process("EventTree_Proc.C+","") p->Load("EventTree_Proc.C+"); d->Process("EventTree_Proc"); if (fb) delete fb; }
TProof *getProof(const char *url = "proof://localhost:40000", Int_t nwrks = -1, const char *dir = 0, const char *opt = "ask", Bool_t dyn = kFALSE, Bool_t tutords = kFALSE) { #ifdef __CINT__ Printf("getProof: this script can only be executed via ACliC:"); Printf("getProof: root [] .x <path>/getProof.C+"); Printf("getProof: or root [] .L <path>/getProof.C+"); Printf("getProof: root [] getProof(...)"); return; #endif TProof *p = 0; // Valgrind options, if any TString vopt, vopts; #ifndef WIN32 if (gSystem->Getenv("GETPROOF_VALGRIND")) { TString s(gSystem->Getenv("GETPROOF_VALGRIND")), t; Int_t from = 0; while (s.Tokenize(t, from , " ")) { if (t.BeginsWith("valgrind_opts:")) vopts = t; else vopt = t; } if (vopts.IsNull()) vopts = "valgrind_opts:--leak-check=full --track-origins=yes"; TProof::AddEnvVar("PROOF_WRAPPERCMD", vopts.Data()); Printf("getProof: valgrind run: '%s' (opts: '%s')", vopt.Data(), vopts.Data()); } #endif // If an URL has specified get a session there TUrl uu(url), uref(refloc); Bool_t ext = (strcmp(uu.GetHost(), uref.GetHost()) || (uu.GetPort() != uref.GetPort())) ? kTRUE : kFALSE; Bool_t lite = kFALSE; if (ext && url) { if (!strcmp(url, "lite://") || !url[0]) { if (!url[0]) uu.SetUrl("lite://"); if (dir && strlen(dir) > 0) gEnv->SetValue("Proof.Sandbox", dir); TString swrk("<default> workers"); if (nwrks > 0) { uu.SetOptions(Form("workers=%d", nwrks)); swrk.Form("%d workers", nwrks); } lite = kTRUE; gEnv->SetValue("Proof.MaxOldSessions", 1); Printf("getProof: trying to open a PROOF-Lite session with %s", swrk.Data()); } else { Printf("getProof: trying to open a session on the external cluster at '%s'", url); } p = TProof::Open(uu.GetUrl(), vopt); if (p && p->IsValid()) { // Check consistency if (ext && !lite && nwrks > 0) { Printf("getProof: WARNING: started/attached a session on external cluster (%s):" " 'nwrks=%d' ignored", url, nwrks); } if (ext && !lite && dir && strlen(dir) > 0) { Printf("getProof: WARNING: started/attached a session on external cluster (%s):" " 'dir=\"%s\"' ignored", url, dir); } if (ext && !strcmp(opt,"force")) { Printf("getProof: WARNING: started/attached a session on external cluster (%s):" " 'opt=\"force\"' ignored", url); } if (ext && dyn) { Printf("getProof: WARNING: started/attached a session on external cluster (%s):" " 'dyn=kTRUE' ignored", url); } // Done return p; } else { if (ext) { Printf("getProof: could not get/start a valid session at %s", url); return p; } else { Printf("getProof: could not get/start a valid session at %s - try resarting the daemon", url); } } if (p) delete p; p = 0; } #ifdef WIN32 // No support for local PROOF on Win32 (yet; the optimized local Proof will work there too) Printf("getProof: local PROOF not yet supported on Windows, sorry!"); return p; #else // Temp dir for tutorial daemons TString tutdir = dir; if (!tutdir.IsNull()) { if (gSystem->AccessPathName(tutdir)) { // Directory does not exist: try to make it gSystem->mkdir(tutdir.Data(), kTRUE); if (gSystem->AccessPathName(tutdir, kWritePermission)) { if (gSystem->AccessPathName(tutdir)) { Printf("getProof: unable to create the working area at the requested path: '%s'" " - cannot continue", tutdir.Data()); } else { Printf("getProof: working area at the requested path '%s'" " created but it is not writable - cannot continue", tutdir.Data()); } return p; } } else { // Check if it is writable ... if (gSystem->AccessPathName(dir, kWritePermission)) { // ... fail if not Printf("getProof: working area at the requested path '%s'" " exists but is not writable - cannot continue", tutdir.Data()); return p; } } } else { // Notify Printf("getProof: working area not specified temp "); // Force "/tmp/<user>" whenever possible to avoid length problems on MacOsX tutdir="/tmp"; if (gSystem->AccessPathName(tutdir, kWritePermission)) tutdir = gSystem->TempDirectory(); TString us; UserGroup_t *ug = gSystem->GetUserInfo(gSystem->GetUid()); if (!ug) { Printf("getProof: could not get user info"); return p; } us.Form("/%s", ug->fUser.Data()); if (!tutdir.EndsWith(us.Data())) tutdir += us; // Add our own subdir tutdir += "/.getproof"; if (gSystem->AccessPathName(tutdir)) { gSystem->mkdir(tutdir.Data(), kTRUE); if (gSystem->AccessPathName(tutdir, kWritePermission)) { Printf("getProof: unable to get a writable working area (tried: %s)" " - cannot continue", tutdir.Data()); return p; } } } Printf("getProof: working area (tutorial dir): %s", tutdir.Data()); // Dataset dir TString datasetdir; if (tutords) { datasetdir = Form("%s/dataset", tutdir.Data()); if (gSystem->AccessPathName(datasetdir, kWritePermission)) { gSystem->mkdir(datasetdir, kTRUE); if (gSystem->AccessPathName(datasetdir, kWritePermission)) { Printf("getProof: unable to get a writable dataset directory (tried: %s)" " - cannot continue", datasetdir.Data()); return p; } Printf("getProof: dataset dir: %s", datasetdir.Data()); } } // Local url (use a special port to try to not disturb running daemons) TUrl u(refloc); u.SetProtocol("proof"); if (!strcmp(uu.GetHost(), uref.GetHost()) && (uu.GetPort() != uref.GetPort())) u.SetPort(uu.GetPort()); Int_t lportp = u.GetPort(); Int_t lportx = lportp + 1; TString lurl = u.GetUrl(); // Prepare to start the daemon TString workarea = Form("%s/proof", tutdir.Data()); TString xpdcf(Form("%s/xpd.cf",tutdir.Data())); TString xpdlog(Form("%s/xpd.log",tutdir.Data())); TString xpdlogprt(Form("%s/xpdtut/xpd.log",tutdir.Data())); TString xpdpid(Form("%s/xpd.pid",tutdir.Data())); TString proofsessions(Form("%s/sessions",tutdir.Data())); TString cmd; Int_t rc = 0; // Is there something listening already ? Int_t pid = -1; Bool_t restart = kTRUE; if ((rc = checkXproofdAt(lportp)) == 1) { Printf("getProof: something else the a XProofd service is running on" " port %d - cannot continue", lportp); return p; } else if (rc == 0) { restart = kFALSE; pid = getXrootdPid(lportx); Printf("getProof: daemon found listening on dedicated ports {%d,%d} (pid: %d)", lportx, lportp, pid); if (isatty(0) == 0 || isatty(1) == 0) { // Cannot ask: always restart restart = kTRUE; } else { if (!strcmp(opt,"ask")) { char *answer = (char *) Getline("getProof: would you like to restart it (N,Y)? [N] "); if (answer && (answer[0] == 'Y' || answer[0] == 'y')) restart = kTRUE; } } if (!strcmp(opt,"force")) // Always restart restart = kTRUE; // Cleanup, if required if (restart) { Printf("getProof: cleaning existing instance ..."); // Cleaning up existing daemon cmd = Form("kill -9 %d", pid); if ((rc = gSystem->Exec(cmd)) != 0) Printf("getProof: problems stopping xrootd process %d (%d)", pid, rc); // Wait for all previous connections being cleaned Printf("getProof: wait 5 secs so that previous connections are cleaned ..."); gSystem->Sleep(5000); } } if (restart) { // Try to start something locally; make sure that everything is there char *xrootd = gSystem->Which(gSystem->Getenv("PATH"), "xrootd", kExecutePermission); if (!xrootd) { Printf("getProof: xrootd not found: please check the environment!"); return p; } // Cleanup the working area cmd = Form("rm -fr %s/xpdtut %s %s %s %s", tutdir.Data(), workarea.Data(), xpdcf.Data(), xpdpid.Data(), proofsessions.Data()); gSystem->Exec(cmd); // Try to start something locally; create the xrootd config file FILE *fcf = fopen(xpdcf.Data(), "w"); if (!fcf) { Printf("getProof: could not create config file for XPD (%s)", xpdcf.Data()); return p; } fprintf(fcf,"### Use admin path at %s/admin to avoid interferences with other users\n", tutdir.Data()); fprintf(fcf,"xrd.adminpath %s/admin\n", tutdir.Data()); #if defined(R__MACOSX) fprintf(fcf,"### Use dedicated socket path under /tmp to avoid length problems\n"); fprintf(fcf,"xpd.sockpathdir /tmp/xpd-sock\n"); #endif fprintf(fcf,"### Run data serving on port %d\n", lportp+1); fprintf(fcf,"xrd.port %d\n", lportp+1); fprintf(fcf,"### Load the XrdProofd protocol on port %d\n", lportp); fprintf(fcf,"xrd.protocol xproofd libXrdProofd.so\n"); fprintf(fcf,"xpd.port %d\n", lportp); if (nwrks > 0) { fprintf(fcf,"### Force number of local workers\n"); fprintf(fcf,"xpd.localwrks %d\n", nwrks); } fprintf(fcf,"### Root path for working dir\n"); fprintf(fcf,"xpd.workdir %s\n", workarea.Data()); fprintf(fcf,"### Allow different users to connect\n"); fprintf(fcf,"xpd.multiuser 1\n"); fprintf(fcf,"### Limit the number of query results kept in the master sandbox\n"); fprintf(fcf,"xpd.putrc ProofServ.UserQuotas: maxquerykept=10\n"); fprintf(fcf,"### Limit the number of sessions kept in the sandbox\n"); fprintf(fcf,"xpd.putrc Proof.MaxOldSessions: 1\n"); if (tutords) { fprintf(fcf,"### Use dataset directory under the tutorial dir\n"); fprintf(fcf,"xpd.datasetsrc file url:%s opt:-Cq:Av:As:\n", datasetdir.Data()); } if (dyn) { fprintf(fcf,"### Use dynamic, per-job scheduling\n"); fprintf(fcf,"xpd.putrc Proof.DynamicStartup 1\n"); } fprintf(fcf,"### Local data server for the temporary output files\n"); fprintf(fcf,"xpd.putenv LOCALDATASERVER=root://%s:%d\n", gSystem->HostName(), lportx); fclose(fcf); Printf("getProof: xrootd config file at %s", xpdcf.Data()); // Start xrootd in the background Printf("getProof: xrootd log file at %s", xpdlogprt.Data()); cmd = Form("%s -c %s -b -l %s -n xpdtut -p %d", xrootd, xpdcf.Data(), xpdlog.Data(), lportx); Printf("(NB: any error line from XrdClientSock::RecvRaw and XrdClientMessage::ReadRaw should be ignored)"); if ((rc = gSystem->Exec(cmd)) != 0) { Printf("getProof: problems starting xrootd (%d)", rc); return p; } delete[] xrootd; // Wait a bit Printf("getProof: waiting for xrootd to start ..."); gSystem->Sleep(2000); pid = getXrootdPid(lportx); Printf("getProof: xrootd pid: %d", pid); // Save it in the PID file FILE *fpid = fopen(xpdpid.Data(), "w"); if (!fpid) { Printf("getProof: could not create pid file for XPD"); } else { fprintf(fpid,"%d\n", pid); fclose(fpid); } } Printf("getProof: start / attach the PROOF session ..."); // Start / attach the session now p = TProof::Open(lurl, vopt.Data()); if (!p || !(p->IsValid())) { Printf("getProof: starting local session failed"); if (p) delete p; p = 0; return p; } // Return the session return p; #endif }