Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TProofServ.cxx
Go to the documentation of this file.
1// @(#)root/proof:$Id$
2// Author: Fons Rademakers 16/02/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TProofServ
13\ingroup proofkernel
14
15Class providing the PROOF server. It can act either as the master
16server or as a slave server, depending on its startup arguments. It
17receives and handles message coming from the client or from the
18master server.
19
20*/
21
22#include "RConfigure.h"
23#include <ROOT/RConfig.hxx>
24#include "Riostream.h"
25
26#ifdef WIN32
27 #include <process.h>
28 #include <io.h>
29 #include "snprintf.h"
30 typedef long off_t;
31#endif
32#include <errno.h>
33#include <time.h>
34#include <fcntl.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#ifndef WIN32
38#include <sys/wait.h>
39#endif
40#include <cstdlib>
41
42// To handle exceptions
43#include <exception>
44#include <new>
45
46using namespace std;
47
48#if (defined(__FreeBSD__) && (__FreeBSD__ < 4)) || \
49 (defined(__APPLE__) && (!defined(MAC_OS_X_VERSION_10_3) || \
50 (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)))
51#include <sys/file.h>
52#define lockf(fd, op, sz) flock((fd), (op))
53#ifndef F_LOCK
54#define F_LOCK (LOCK_EX | LOCK_NB)
55#endif
56#ifndef F_ULOCK
57#define F_ULOCK LOCK_UN
58#endif
59#endif
60
61#include "TProofServ.h"
62#include "TDSetProxy.h"
63#include "TEnv.h"
64#include "TError.h"
65#include "TEventList.h"
66#include "TEntryList.h"
67#include "TException.h"
68#include "TFile.h"
69#include "THashList.h"
70#include "TInterpreter.h"
71#include "TKey.h"
72#include "TMessage.h"
73#include "TVirtualPerfStats.h"
74#include "TProofDebug.h"
75#include "TProof.h"
76#include "TVirtualProofPlayer.h"
77#include "TProofQueryResult.h"
78#include "TQueryResultManager.h"
79#include "TRegexp.h"
80#include "TROOT.h"
81#include "TObjArray.h"
82#include "TSocket.h"
83#include "TStopwatch.h"
84#include "TSystem.h"
85#include "TTimeStamp.h"
86#include "TUrl.h"
87#include "TPluginManager.h"
88#include "TObjString.h"
89#include "compiledata.h"
91#include "TProofNodeInfo.h"
92#include "TFileInfo.h"
93#include "TClass.h"
94#include "TSQLServer.h"
95#include "TSQLResult.h"
96#include "TSQLRow.h"
97#include "TPRegexp.h"
98#include "TParameter.h"
99#include "TMap.h"
100#include "TSortedList.h"
101#include "TFileCollection.h"
102#include "TLockFile.h"
103#include "TDataSetManagerFile.h"
104#include "TProofProgressStatus.h"
105#include "TServerSocket.h"
106#include "TMonitor.h"
107#include "TProofOutputFile.h"
108#include "TSelector.h"
109#include "TPackMgr.h"
110
111// global proofserv handle
113
114// debug hook
115static volatile Int_t gProofServDebug = 1;
116
117// Syslog control
120TString TProofServ::fgSysLogEntity("undef:default");
121
122// File where to log: default stderr
124
125// Integrate with crash reporter.
126#ifdef __APPLE__
127extern "C" {
128static const char *__crashreporter_info__ = 0;
129asm(".desc ___crashreporter_info__, 0x10");
130}
131#endif
132
133// To control allowed actions while processing
135
136// Last message and entry before exceptions
139
140// Memory controllers
145
146// Async Logger
147static void SendAsynMsg(const char *msg) {
149}
150
151//----- Termination signal handler ---------------------------------------------
152////////////////////////////////////////////////////////////////////////////////
153
154class TProofServTerminationHandler : public TSignalHandler {
155 TProofServ *fServ;
156public:
157 TProofServTerminationHandler(TProofServ *s)
158 : TSignalHandler(kSigTermination, kFALSE) { fServ = s; }
159 Bool_t Notify();
160};
161
162////////////////////////////////////////////////////////////////////////////////
163/// Handle this interrupt
164
165Bool_t TProofServTerminationHandler::Notify()
166{
167 Printf("Received SIGTERM: terminating");
168 fServ->HandleTermination();
169 return kTRUE;
170}
171
172//----- Interrupt signal handler -----------------------------------------------
173////////////////////////////////////////////////////////////////////////////////
174
175class TProofServInterruptHandler : public TSignalHandler {
176 TProofServ *fServ;
177public:
178 TProofServInterruptHandler(TProofServ *s)
179 : TSignalHandler(kSigUrgent, kFALSE) { fServ = s; }
180 Bool_t Notify();
181};
182
183////////////////////////////////////////////////////////////////////////////////
184/// Handle this interrupt
185
186Bool_t TProofServInterruptHandler::Notify()
187{
188 fServ->HandleUrgentData();
189 if (TROOT::Initialized()) {
190 Throw(GetSignal());
191 }
192 return kTRUE;
193}
194
195//----- SigPipe signal handler -------------------------------------------------
196////////////////////////////////////////////////////////////////////////////////
197
198class TProofServSigPipeHandler : public TSignalHandler {
199 TProofServ *fServ;
200public:
201 TProofServSigPipeHandler(TProofServ *s) : TSignalHandler(kSigPipe, kFALSE)
202 { fServ = s; }
203 Bool_t Notify();
204};
205
206////////////////////////////////////////////////////////////////////////////////
207/// Handle this signal
208
209Bool_t TProofServSigPipeHandler::Notify()
210{
211 fServ->HandleSigPipe();
212 return kTRUE;
213}
214
215//----- Input handler for messages from parent or master -----------------------
216////////////////////////////////////////////////////////////////////////////////
217
218class TProofServInputHandler : public TFileHandler {
219 TProofServ *fServ;
220public:
221 TProofServInputHandler(TProofServ *s, Int_t fd) : TFileHandler(fd, 1)
222 { fServ = s; }
223 Bool_t Notify();
224 Bool_t ReadNotify() { return Notify(); }
225};
226
227////////////////////////////////////////////////////////////////////////////////
228/// Handle this input
229
230Bool_t TProofServInputHandler::Notify()
231{
232 fServ->HandleSocketInput();
233 return kTRUE;
234}
235
236TString TProofServLogHandler::fgPfx = ""; // Default prefix to be prepended to messages
237Int_t TProofServLogHandler::fgCmdRtn = 0; // Return code of the command execution (available only
238 // after closing the pipe)
239////////////////////////////////////////////////////////////////////////////////
240/// Execute 'cmd' in a pipe and handle output messages from the related file
241
243 TSocket *s, const char *pfx)
244 : TFileHandler(-1, 1), fSocket(s), fPfx(pfx)
245{
247 fgCmdRtn = 0;
248 fFile = 0;
249 if (s && cmd) {
250 fFile = gSystem->OpenPipe(cmd, "r");
251 if (fFile) {
252 SetFd(fileno(fFile));
253 // Notify what already in the file
254 Notify();
255 // Used in the destructor
257 } else {
258 fSocket = 0;
259 Error("TProofServLogHandler", "executing command in pipe");
260 fgCmdRtn = -1;
261 }
262 } else {
263 Error("TProofServLogHandler",
264 "undefined command (%p) or socket (%p)", (int *)cmd, s);
265 }
266}
267////////////////////////////////////////////////////////////////////////////////
268/// Handle available message from the open file 'f'
269
271 : TFileHandler(-1, 1), fSocket(s), fPfx(pfx)
272{
274 fgCmdRtn = 0;
275 fFile = 0;
276 if (s && f) {
277 fFile = f;
278 SetFd(fileno(fFile));
279 // Notify what already in the file
280 Notify();
281 } else {
282 Error("TProofServLogHandler", "undefined file (%p) or socket (%p)", f, s);
283 }
284}
285////////////////////////////////////////////////////////////////////////////////
286/// Handle available message in the open file
287
289{
290 if (TestBit(kFileIsPipe) && fFile) {
292#ifdef WIN32
293 fgCmdRtn = rc;
294#else
295 fgCmdRtn = WIFEXITED(rc) ? WEXITSTATUS(rc) : -1;
296#endif
297 }
298 fFile = 0;
299 fSocket = 0;
301}
302////////////////////////////////////////////////////////////////////////////////
303/// Handle available message in the open file
304
306{
307 if (IsValid()) {
309 // Read buffer
310 char line[4096];
311 char *plf = 0;
312 while (fgets(line, sizeof(line), fFile)) {
313 if ((plf = strchr(line, '\n')))
314 *plf = 0;
315 // Create log string
316 TString log;
317 if (fPfx.Length() > 0) {
318 // Prepend prefix specific to this instance
319 log.Form("%s: %s", fPfx.Data(), line);
320 } else if (fgPfx.Length() > 0) {
321 // Prepend default prefix
322 log.Form("%s: %s", fgPfx.Data(), line);
323 } else {
324 // Nothing to prepend
325 log = line;
326 }
327 // Send the message one level up
328 m.Reset(kPROOF_MESSAGE);
329 m << log;
330 fSocket->Send(m);
331 }
332 }
333 return kTRUE;
334}
335////////////////////////////////////////////////////////////////////////////////
336/// Static method to set the default prefix
337
339{
340 fgPfx = pfx;
341}
342////////////////////////////////////////////////////////////////////////////////
343/// Static method to get the return code from the execution of a command via
344/// the pipe. This is always 0 when the log handler is not used with a pipe
345
347{
348 return fgCmdRtn;
349}
350
351////////////////////////////////////////////////////////////////////////////////
352/// Init a guard for executing a command in a pipe
353
355 const char *pfx, Bool_t on)
356{
357 fExecHandler = 0;
358 if (cmd && on) {
359 fExecHandler = new TProofServLogHandler(cmd, s, pfx);
360 if (fExecHandler->IsValid()) {
362 } else {
363 Error("TProofServLogHandlerGuard","invalid handler");
364 }
365 } else {
366 if (on)
367 Error("TProofServLogHandlerGuard","undefined command");
368 }
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Init a guard for executing a command in a pipe
373
375 const char *pfx, Bool_t on)
376{
377 fExecHandler = 0;
378 if (f && on) {
379 fExecHandler = new TProofServLogHandler(f, s, pfx);
380 if (fExecHandler->IsValid()) {
382 } else {
383 Error("TProofServLogHandlerGuard","invalid handler");
384 }
385 } else {
386 if (on)
387 Error("TProofServLogHandlerGuard","undefined file");
388 }
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Close a guard for executing a command in a pipe
393
395{
399 }
400}
401
402//--- Special timer to control delayed shutdowns ----------------------------//
403////////////////////////////////////////////////////////////////////////////////
404/// Construtor
405
407 : TTimer(delay, kFALSE), fProofServ(p)
408{
409 fTimeout = gEnv->GetValue("ProofServ.ShutdownTimeout", 20);
410 // Backward compaitibility: until 5.32 the variable was called ProofServ.ShutdonwTimeout
411 fTimeout = gEnv->GetValue("ProofServ.ShutdonwTimeout", fTimeout);
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Handle expiration of the shutdown timer. In the case of low activity the
416/// process will be aborted.
417
419{
420 if (gDebug > 0)
421 printf("TShutdownTimer::Notify: checking activity on the input socket\n");
422
423 // Check activity on the socket
424 TSocket *xs = 0;
425 if (fProofServ && (xs = fProofServ->GetSocket())) {
426 TTimeStamp now;
427 TTimeStamp ts = xs->GetLastUsage();
428 Long_t dt = (Long_t)(now.GetSec() - ts.GetSec()) * 1000 +
429 (Long_t)(now.GetNanoSec() - ts.GetNanoSec()) / 1000000 ;
430 if (dt > fTimeout * 60000) {
431 printf("TShutdownTimer::Notify: input socket: %p: did not show any activity"
432 " during the last %d mins: aborting\n", xs, fTimeout);
433 // At this point we lost our controller: we need to abort to avoid
434 // hidden timeouts or loops
435 gSystem->Abort();
436 } else {
437 if (gDebug > 0)
438 printf("TShutdownTimer::Notify: input socket: %p: show activity"
439 " %ld secs ago\n", xs, dt / 60000);
440 }
441 }
442 // Needed for the next shot
443 Reset();
444 return kTRUE;
445}
446
447//--- Synchronous timer used to reap children processes change of state ------//
448////////////////////////////////////////////////////////////////////////////////
449/// Destructor
450
452{
453 if (fChildren) {
455 delete fChildren;
456 fChildren = 0;
457 }
458}
459
460////////////////////////////////////////////////////////////////////////////////
461/// Add an entry for 'pid' in the internal list
462
464{
465 if (pid > 0) {
466 if (!fChildren)
467 fChildren = new TList;
468 TString spid;
469 spid.Form("%d", pid);
470 fChildren->Add(new TParameter<Int_t>(spid.Data(), pid));
471 TurnOn();
472 }
473}
474
475////////////////////////////////////////////////////////////////////////////////
476/// Check if any of the registered children has changed its state.
477/// Unregister those that are gone.
478
480{
481 if (fChildren) {
482 TIter nxp(fChildren);
483 TParameter<Int_t> *p = 0;
484 while ((p = (TParameter<Int_t> *)nxp())) {
485 int status;
486#ifndef WIN32
487 pid_t pid;
488 do {
489 pid = waitpid(p->GetVal(), &status, WNOHANG);
490 } while (pid < 0 && errno == EINTR);
491#else
492 intptr_t pid;
493 pid = _cwait(&status, (intptr_t)p->GetVal(), 0);
494#endif
495 if (pid > 0 && pid == p->GetVal()) {
496 // Remove from the list
497 fChildren->Remove(p);
498 delete p;
499 }
500 }
501 }
502
503 // Stop the timer if no children
504 if (!fChildren || fChildren->GetSize() <= 0) {
505 Stop();
506 } else {
507 // Needed for the next shot
508 Reset();
509 }
510 return kTRUE;
511}
512
513//--- Special timer to terminate idle sessions ----------------------------//
514////////////////////////////////////////////////////////////////////////////////
515/// Handle expiration of the idle timer. The session will just be terminated.
516
518{
519 Info ("Notify", "session idle for more then %lld secs: terminating", Long64_t(fTime)/1000);
520
521 if (fProofServ) {
522 // Set the status to timed-out
523 Int_t uss_rc = -1;
524 if ((uss_rc = fProofServ->UpdateSessionStatus(4)) != 0)
525 Warning("Notify", "problems updating session status (errno: %d)", -uss_rc);
526 // Send a terminate request
527 TString msg;
528 if (fProofServ->GetProtocol() < 29) {
529 msg.Form("\n//\n// PROOF session at %s (%s) terminated because idle for more than %lld secs\n"
530 "// Please IGNORE any error message possibly displayed below\n//",
532 } else {
533 msg.Form("\n//\n// PROOF session at %s (%s) terminated because idle for more than %lld secs\n//",
535 }
538 Reset();
539 Stop();
540 } else {
541 Warning("Notify", "fProofServ undefined!");
542 Start(-1, kTRUE);
543 }
544 return kTRUE;
545}
546
548
549// Hook to the constructor. This is needed to avoid using the plugin manager
550// which may create problems in multi-threaded environments.
551extern "C" {
552 TApplication *GetTProofServ(Int_t *argc, char **argv, FILE *flog)
553 { return new TProofServ(argc, argv, flog); }
554}
555
556////////////////////////////////////////////////////////////////////////////////
557/// Main constructor. Create an application environment. The TProofServ
558/// environment provides an eventloop via inheritance of TApplication.
559/// Actual server creation work is done in CreateServer() to allow
560/// overloading.
561
562TProofServ::TProofServ(Int_t *argc, char **argv, FILE *flog)
563 : TApplication("proofserv", argc, argv, 0, -1)
564{
565 // If test and tty, we are done
566 Bool_t xtest = (argc && *argc == 1) ? kTRUE : kFALSE;
567 if (xtest) {
568 Printf("proofserv: command line testing: OK");
569 exit(0);
570 }
571
572 // Read session specific rootrc file
573 TString rcfile = gSystem->Getenv("ROOTRCFILE") ? gSystem->Getenv("ROOTRCFILE")
574 : "session.rootrc";
576 gEnv->ReadFile(rcfile, kEnvChange);
577
578 // Upper limit on Virtual Memory (in kB)
579 fgVirtMemMax = gEnv->GetValue("Proof.VirtMemMax",-1);
580 if (fgVirtMemMax < 0 && gSystem->Getenv("PROOF_VIRTMEMMAX")) {
581 Long_t mmx = strtol(gSystem->Getenv("PROOF_VIRTMEMMAX"), 0, 10);
582 if (mmx < kMaxLong && mmx > 0)
583 fgVirtMemMax = mmx * 1024;
584 }
585 // Old variable for backward compatibility
586 if (fgVirtMemMax < 0 && gSystem->Getenv("ROOTPROOFASHARD")) {
587 Long_t mmx = strtol(gSystem->Getenv("ROOTPROOFASHARD"), 0, 10);
588 if (mmx < kMaxLong && mmx > 0)
589 fgVirtMemMax = mmx * 1024;
590 }
591 // Upper limit on Resident Memory (in kB)
592 fgResMemMax = gEnv->GetValue("Proof.ResMemMax",-1);
593 if (fgResMemMax < 0 && gSystem->Getenv("PROOF_RESMEMMAX")) {
594 Long_t mmx = strtol(gSystem->Getenv("PROOF_RESMEMMAX"), 0, 10);
595 if (mmx < kMaxLong && mmx > 0)
596 fgResMemMax = mmx * 1024;
597 }
598 // Thresholds for warnings and stop processing
599 fgMemStop = gEnv->GetValue("Proof.MemStop", 0.95);
600 fgMemHWM = gEnv->GetValue("Proof.MemHWM", 0.80);
601 if (fgVirtMemMax > 0 || fgResMemMax > 0) {
602 if ((fgMemStop < 0.) || (fgMemStop > 1.)) {
603 Warning("TProofServ", "requested memory fraction threshold to stop processing"
604 " (MemStop) out of range [0,1] - ignoring");
605 fgMemStop = 0.95;
606 }
607 if ((fgMemHWM < 0.) || (fgMemHWM > fgMemStop)) {
608 Warning("TProofServ", "requested memory fraction threshold for warning and finer monitoring"
609 " (MemHWM) out of range [0,MemStop] - ignoring");
610 fgMemHWM = 0.80;
611 }
612 }
613
614 // Wait (loop) to allow debugger to connect
615 Bool_t test = (argc && *argc >= 4 && !strcmp(argv[3], "test")) ? kTRUE : kFALSE;
616 if ((gEnv->GetValue("Proof.GdbHook",0) == 3 && !test) ||
617 (gEnv->GetValue("Proof.GdbHook",0) == 4 && test)) {
618 while (gProofServDebug)
619 ;
620 }
621
622 // Test instance
623 if (argc && *argc >= 4)
624 if (!strcmp(argv[3], "test"))
625 fService = "prooftest";
626
627 // crude check on number of arguments
628 if (argc && *argc < 2) {
629 Error("TProofServ", "Must have at least 1 arguments (see proofd).");
630 exit(1);
631 }
632
633 // Set global to this instance
634 gProofServ = this;
635
636 // Log control flags
638
639 // Abort on higher than kSysError's and set error handler
641 SetErrorHandlerFile(stderr);
643
644 fNcmd = 0;
645 fGroupPriority = 100;
647 fProtocol = 0;
648 fOrdinal = gEnv->GetValue("ProofServ.Ordinal", "-1");
649 fGroupId = -1;
650 fGroupSize = 0;
651 fRealTime = 0.0;
652 fCpuTime = 0.0;
653 fProof = 0;
654 fPlayer = 0;
655 fSocket = 0;
656
657 fTotSessions = -1;
658 fActSessions = -1;
659 fEffSessions = -1.;
660 fPackMgr = 0;
661
662 fLogFile = flog;
663 fLogFileDes = -1;
664
665 fArchivePath = "";
666 // Init lockers
667 fCacheLock = 0;
668 fQueryLock = 0;
669
670 fQMgr = 0;
672 fIdle = kTRUE;
673 fQuerySeqNum = -1;
674
675 fQueuedMsg = new TList;
676
678
679 fShutdownTimer = 0;
680 fReaperTimer = 0;
681 fIdleTOTimer = 0;
682
683 fDataSetManager = 0; // Initialized in Setup()
684 fDataSetStgRepo = 0; // Initialized in Setup()
685
686 fInputHandler = 0;
687
688 // Quotas disabled by default
689 fMaxQueries = -1;
690 fMaxBoxSize = -1;
691 fHWMBoxSize = -1;
692
693 // Submerger quantities
694 fMergingSocket = 0;
695 fMergingMonitor = 0;
696 fMergedWorkers = 0;
697
698 // Bit to flg high-memory footprint
700
701 // Max message size
702 fMsgSizeHWM = gEnv->GetValue("ProofServ.MsgSizeHWM", 1000000);
703
704 // Message compression
705 fCompressMsg = gEnv->GetValue("ProofServ.CompressMessage", 0);
706
707 gProofDebugLevel = gEnv->GetValue("Proof.DebugLevel",0);
709
711 if (gProofDebugLevel > 0)
712 Info("TProofServ", "DebugLevel %d Mask 0x%x", gProofDebugLevel, gProofDebugMask);
713
714 // Max log file size
715 fLogFileMaxSize = -1;
716 TString logmx = gEnv->GetValue("ProofServ.LogFileMaxSize", "");
717 if (!logmx.IsNull()) {
718 Long64_t xf = 1;
719 if (!logmx.IsDigit()) {
720 if (logmx.EndsWith("K")) {
721 xf = 1024;
722 logmx.Remove(TString::kTrailing, 'K');
723 } else if (logmx.EndsWith("M")) {
724 xf = 1024*1024;
725 logmx.Remove(TString::kTrailing, 'M');
726 } else if (logmx.EndsWith("G")) {
727 xf = 1024*1024*1024;
728 logmx.Remove(TString::kTrailing, 'G');
729 }
730 }
731 if (logmx.IsDigit()) {
732 fLogFileMaxSize = logmx.Atoi() * xf;
733 if (fLogFileMaxSize > 0)
734 Info("TProofServ", "keeping the log file size within %lld bytes", fLogFileMaxSize);
735 } else {
736 logmx = gEnv->GetValue("ProofServ.LogFileMaxSize", "");
737 Warning("TProofServ", "bad formatted log file size limit ignored: '%s'", logmx.Data());
738 }
739 }
740
741 // Parse options
742 GetOptions(argc, argv);
743
744 // Default prefix in the form '<role>-<ordinal>'
745 fPrefix = (IsMaster() ? "Mst-" : "Wrk-");
746 if (test) fPrefix = "Test";
747 if (fOrdinal != "-1")
748 fPrefix += fOrdinal;
750
751 // Syslog control
752 TString slog = gEnv->GetValue("ProofServ.LogToSysLog", "");
753 if (!(slog.IsNull())) {
754 if (slog.IsDigit()) {
755 fgLogToSysLog = slog.Atoi();
756 } else {
757 char c = (slog[0] == 'M' || slog[0] == 'm') ? 'm' : 'a';
758 c = (slog[0] == 'W' || slog[0] == 'w') ? 'w' : c;
759 Bool_t dosyslog = ((c == 'm' && IsMaster()) ||
760 (c == 'w' && !IsMaster()) || c == 'a') ? kTRUE : kFALSE;
761 if (dosyslog) {
762 slog.Remove(0,1);
763 if (slog.IsDigit()) fgLogToSysLog = slog.Atoi();
764 if (fgLogToSysLog <= 0)
765 Warning("TProofServ", "request for syslog logging ineffective!");
766 }
767 }
768 }
769 // Initialize proper service if required
770 if (fgLogToSysLog > 0) {
771 fgSysLogService = (IsMaster()) ? "proofm" : "proofw";
772 if (fOrdinal != "-1") fgSysLogService += TString::Format("-%s", fOrdinal.Data());
774 }
775
776 // Enable optimized sending of streamer infos to use embedded backward/forward
777 // compatibility support between different ROOT versions and different versions of
778 // users classes
779 Bool_t enableSchemaEvolution = gEnv->GetValue("Proof.SchemaEvolution",1);
780 if (enableSchemaEvolution) {
782 } else {
783 Info("TProofServ", "automatic schema evolution in TMessage explicitly disabled");
784 }
785}
786
787////////////////////////////////////////////////////////////////////////////////
788/// Finalize the server setup. If master, create the TProof instance to talk
789/// to the worker or submaster nodes.
790/// Return 0 on success, -1 on error
791
793{
794 // Get socket to be used (setup in proofd)
795 TString opensock = gSystem->Getenv("ROOTOPENSOCK");
796 if (opensock.Length() <= 0)
797 opensock = gEnv->GetValue("ProofServ.OpenSock", "-1");
798 Int_t sock = opensock.Atoi();
799 if (sock <= 0) {
800 Fatal("CreateServer", "Invalid socket descriptor number (%d)", sock);
801 return -1;
802 }
803 fSocket = new TSocket(sock);
804
805 // Set compression level, if any
807
808 // debug hooks
809 if (IsMaster()) {
810 // wait (loop) in master to allow debugger to connect
811 if (gEnv->GetValue("Proof.GdbHook",0) == 1) {
812 while (gProofServDebug)
813 ;
814 }
815 } else {
816 // wait (loop) in slave to allow debugger to connect
817 if (gEnv->GetValue("Proof.GdbHook",0) == 2) {
818 while (gProofServDebug)
819 ;
820 }
821 }
822
823 if (gProofDebugLevel > 0)
824 Info("CreateServer", "Service %s ConfDir %s IsMaster %d\n",
826
827 if (Setup() != 0) {
828 // Setup failure
829 LogToMaster();
830 SendLogFile();
831 Terminate(0);
832 return -1;
833 }
834
835 // Set the default prefix in the form '<role>-<ordinal>' (it was already done
836 // in the constructor, but for standard PROOF the ordinal number is only set in
837 // Setup(), so we need to do it again here)
838 TString pfx = (IsMaster() ? "Mst-" : "Wrk-");
839 pfx += GetOrdinal();
841
842 if (!fLogFile) {
844 // If for some reason we failed setting a redirection file for the logs
845 // we cannot continue
846 if (!fLogFile || (fLogFileDes = fileno(fLogFile)) < 0) {
847 LogToMaster();
848 SendLogFile(-98);
849 Terminate(0);
850 return -1;
851 }
852 } else {
853 // Use the file already open by pmain
854 if ((fLogFileDes = fileno(fLogFile)) < 0) {
855 LogToMaster();
856 SendLogFile(-98);
857 Terminate(0);
858 return -1;
859 }
860 }
861
862 // Send message of the day to the client
863 if (IsMaster()) {
864 if (CatMotd() == -1) {
865 LogToMaster();
866 SendLogFile(-99);
867 Terminate(0);
868 return -1;
869 }
870 }
871
872 // Everybody expects std::iostream to be available, so load it...
873 ProcessLine("#include <iostream>", kTRUE);
874 ProcessLine("#include <string>",kTRUE); // for std::string std::iostream.
875
876 // The following libs are also useful to have, make sure they are loaded...
877 //gROOT->LoadClass("TMinuit", "Minuit");
878 //gROOT->LoadClass("TPostScript", "Postscript");
879
880 // Load user functions
881 const char *logon;
882 logon = gEnv->GetValue("Proof.Load", (char *)0);
883 if (logon) {
884 char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
885 if (mac)
886 ProcessLine(TString::Format(".L %s", logon), kTRUE);
887 delete [] mac;
888 }
889
890 // Execute logon macro
891 logon = gEnv->GetValue("Proof.Logon", (char *)0);
892 if (logon && !NoLogOpt()) {
893 char *mac = gSystem->Which(TROOT::GetMacroPath(), logon, kReadPermission);
894 if (mac)
895 ProcessFile(logon);
896 delete [] mac;
897 }
898
899 // Save current interpreter context
900 gInterpreter->SaveContext();
901 gInterpreter->SaveGlobalsContext();
902
903 // Install interrupt and message input handlers
904 gSystem->AddSignalHandler(new TProofServTerminationHandler(this));
905 gSystem->AddSignalHandler(new TProofServInterruptHandler(this));
906 fInputHandler = new TProofServInputHandler(this, sock);
908
909 // if master, start slave servers
910 if (IsMaster()) {
911 TString master = "proof://__master__";
913 if (a.IsValid()) {
914 master += ":";
915 master += a.GetPort();
916 }
917
918 // Get plugin manager to load appropriate TProof from
919 TPluginManager *pm = gROOT->GetPluginManager();
920 if (!pm) {
921 Error("CreateServer", "no plugin manager found");
922 SendLogFile(-99);
923 Terminate(0);
924 return -1;
925 }
926
927 // Find the appropriate handler
928 TPluginHandler *h = pm->FindHandler("TProof", fConfFile);
929 if (!h) {
930 Error("CreateServer", "no plugin found for TProof with a"
931 " config file of '%s'", fConfFile.Data());
932 SendLogFile(-99);
933 Terminate(0);
934 return -1;
935 }
936
937 // load the plugin
938 if (h->LoadPlugin() == -1) {
939 Error("CreateServer", "plugin for TProof could not be loaded");
940 SendLogFile(-99);
941 Terminate(0);
942 return -1;
943 }
944
945 // make instance of TProof
946 fProof = reinterpret_cast<TProof*>(h->ExecPlugin(5, master.Data(),
947 fConfFile.Data(),
948 GetConfDir(),
949 fLogLevel, 0));
950 if (!fProof || !fProof->IsValid()) {
951 Error("CreateServer", "plugin for TProof could not be executed");
953 SendLogFile(-99);
954 Terminate(0);
955 return -1;
956 }
957 // Find out if we are a master in direct contact only with workers
959
960 SendLogFile();
961 }
962
963 // Setup the shutdown timer
964 if (!fShutdownTimer) {
965 // Check activity on socket every 5 mins
966 fShutdownTimer = new TShutdownTimer(this, 300000);
968 }
969
970 // Check if schema evolution is effective: clients running versions <=17 do not
971 // support that: send a warning message
972 if (fProtocol <= 17) {
973 TString msg;
974 msg.Form("Warning: client version is too old: automatic schema evolution is ineffective.\n"
975 " This may generate compatibility problems between streamed objects.\n"
976 " The advise is to move to ROOT >= 5.21/02 .");
977 SendAsynMessage(msg.Data());
978 }
979
980 // Setup the idle timer
981 if (IsMaster() && !fIdleTOTimer) {
982 // Check activity on socket every 5 mins
983 Int_t idle_to = gEnv->GetValue("ProofServ.IdleTimeout", -1);
984 if (idle_to > 0) {
985 fIdleTOTimer = new TIdleTOTimer(this, idle_to * 1000);
987 if (gProofDebugLevel > 0)
988 Info("CreateServer", " idle timer started (%d secs)", idle_to);
989 } else if (gProofDebugLevel > 0) {
990 Info("CreateServer", " idle timer not started (no idle timeout requested)");
991 }
992 }
993
994 // Done
995 return 0;
996}
997
998////////////////////////////////////////////////////////////////////////////////
999/// Cleanup. Not really necessary since after this dtor there is no
1000/// live anyway.
1001
1003{
1011 close(fLogFileDes);
1012}
1013
1014////////////////////////////////////////////////////////////////////////////////
1015/// Print message of the day (in the file pointed by the env PROOFMOTD
1016/// or from fConfDir/etc/proof/motd). The motd is not shown more than
1017/// once a day. If the file pointed by env PROOFNOPROOF exists (or the
1018/// file fConfDir/etc/proof/noproof exists), show its contents and close
1019/// the connection.
1020
1022{
1023 TString lastname;
1024 FILE *motd;
1025 Bool_t show = kFALSE;
1026
1027 // If we are disabled just print the message and close the connection
1028 TString motdname(GetConfDir());
1029 // The env variable PROOFNOPROOF allows to put the file in an alternative
1030 // location not overwritten by a new installation
1031 if (gSystem->Getenv("PROOFNOPROOF")) {
1032 motdname = gSystem->Getenv("PROOFNOPROOF");
1033 } else {
1034 motdname += "/etc/proof/noproof";
1035 }
1036 if ((motd = fopen(motdname, "r"))) {
1037 Int_t c;
1038 printf("\n");
1039 while ((c = getc(motd)) != EOF)
1040 putchar(c);
1041 fclose(motd);
1042 printf("\n");
1043
1044 return -1;
1045 }
1046
1047 // get last modification time of the file ~/proof/.prooflast
1048 lastname = TString(GetWorkDir()) + "/.prooflast";
1049 gSystem->ExpandPathName(lastname);
1050 Long64_t size;
1051 Long_t id, flags, modtime, lasttime = 0;
1052 if (gSystem->GetPathInfo(lastname.Data(), &id, &size, &flags, &lasttime) == 1)
1053 lasttime = 0;
1054
1055 // show motd at least once per day
1056 if (time(0) - lasttime > (time_t)86400)
1057 show = kTRUE;
1058
1059 // The env variable PROOFMOTD allows to put the file in an alternative
1060 // location not overwritten by a new installation
1061 if (gSystem->Getenv("PROOFMOTD")) {
1062 motdname = gSystem->Getenv("PROOFMOTD");
1063 } else {
1064 motdname = GetConfDir();
1065 motdname += "/etc/proof/motd";
1066 }
1067 if (gSystem->GetPathInfo(motdname, &id, &size, &flags, &modtime) == 0) {
1068 if (modtime > lasttime || show) {
1069 if ((motd = fopen(motdname, "r"))) {
1070 Int_t c;
1071 printf("\n");
1072 while ((c = getc(motd)) != EOF)
1073 putchar(c);
1074 fclose(motd);
1075 printf("\n");
1076 }
1077 }
1078 }
1079
1080 if (lasttime)
1081 gSystem->Unlink(lastname.Data());
1082 Int_t fd = creat(lastname.Data(), 0600);
1083 if (fd >= 0) close(fd);
1084
1085 return 0;
1086}
1087
1088////////////////////////////////////////////////////////////////////////////////
1089/// Get object with name "name;cycle" (e.g. "aap;2") from master or client.
1090/// This method is called by TDirectory::Get() in case the object can not
1091/// be found locally.
1092
1093TObject *TProofServ::Get(const char *namecycle)
1094{
1095 if (fSocket->Send(namecycle, kPROOF_GETOBJECT) < 0) {
1096 Error("Get", "problems sending request");
1097 return (TObject *)0;
1098 }
1099
1100 TObject *idcur = 0;
1101
1102 Bool_t notdone = kTRUE;
1103 while (notdone) {
1104 TMessage *mess = 0;
1105 if (fSocket->Recv(mess) < 0)
1106 return 0;
1107 Int_t what = mess->What();
1108 if (what == kMESS_OBJECT) {
1109 idcur = mess->ReadObject(mess->GetClass());
1110 notdone = kFALSE;
1111 } else {
1112 Int_t xrc = HandleSocketInput(mess, kFALSE);
1113 if (xrc == -1) {
1114 Error("Get", "command %d cannot be executed while processing", what);
1115 } else if (xrc == -2) {
1116 Error("Get", "unknown command %d ! Protocol error?", what);
1117 }
1118 }
1119 delete mess;
1120 }
1121
1122 return idcur;
1123}
1124
1125////////////////////////////////////////////////////////////////////////////////
1126/// Reset the compute time
1127
1129{
1130 fCompute.Stop();
1131 if (fPlayer) {
1133 if (status) status->SetLearnTime(fCompute.RealTime());
1134 Info("RestartComputeTime", "compute time restarted after %f secs (%d entries)",
1136 }
1138}
1139
1140////////////////////////////////////////////////////////////////////////////////
1141/// Get next range of entries to be processed on this server.
1142
1144{
1145 Long64_t bytesRead = 0;
1146
1147 if (gPerfStats) bytesRead = gPerfStats->GetBytesRead();
1148
1149 if (fCompute.Counter() > 0)
1150 fCompute.Stop();
1151
1153 Double_t cputime = fCompute.CpuTime();
1154 Double_t realtime = fCompute.RealTime();
1155
1156 if (fProtocol > 18) {
1157 req << fLatency.RealTime();
1158 TProofProgressStatus *status = 0;
1159 if (fPlayer) {
1161 status = fPlayer->GetProgressStatus();
1162 } else {
1163 Error("GetNextPacket", "no progress status object");
1164 return 0;
1165 }
1166 // the CPU and wallclock proc times are kept in the TProofServ and here
1167 // added to the status object in the fPlayer.
1168 if (status->GetEntries() > 0) {
1169 PDB(kLoop, 2) status->Print(GetOrdinal());
1170 status->IncProcTime(realtime);
1171 status->IncCPUTime(cputime);
1172 }
1173 // Flag cases with problems in opening files
1174 if (totalEntries < 0) status->SetBit(TProofProgressStatus::kFileNotOpen);
1175 // Add to the message
1176 req << status;
1177 // Send tree cache information
1178 Long64_t cacheSize = (fPlayer) ? fPlayer->GetCacheSize() : -1;
1179 Int_t learnent = (fPlayer) ? fPlayer->GetLearnEntries() : -1;
1180 req << cacheSize << learnent;
1181
1182 // Sent over the number of entries in the file, used by packetizer do not relying
1183 // on initial validation. Also, -1 means that the file could not be open, which is
1184 // used to flag files as missing
1185 req << totalEntries;
1186
1187 // Send the time spent in saving the partial result to file
1188 if (fProtocol > 34) req << fSaveOutput.RealTime();
1189
1190 PDB(kLoop, 1) {
1191 PDB(kLoop, 2) status->Print();
1192 Info("GetNextPacket","cacheSize: %lld, learnent: %d", cacheSize, learnent);
1193 }
1194 // Reset the status bits
1197 status = 0; // status is owned by the player.
1198 } else {
1199 req << fLatency.RealTime() << realtime << cputime
1200 << bytesRead << totalEntries;
1201 if (fPlayer)
1202 req << fPlayer->GetEventsProcessed();
1203 }
1204
1205 fLatency.Start();
1206 Int_t rc = fSocket->Send(req);
1207 if (rc <= 0) {
1208 Error("GetNextPacket","Send() failed, returned %d", rc);
1209 return 0;
1210 }
1211
1212 // Save the current output
1213 if (fPlayer) {
1216 Warning("GetNextPacket", "problems saving partial results");
1217 fSaveOutput.Stop();
1218 }
1219
1220 TDSetElement *e = 0;
1221 Bool_t notdone = kTRUE;
1222 while (notdone) {
1223
1224 TMessage *mess;
1225 if ((rc = fSocket->Recv(mess)) <= 0) {
1226 fLatency.Stop();
1227 Error("GetNextPacket","Recv() failed, returned %d", rc);
1228 return 0;
1229 }
1230
1231 Int_t xrc = 0;
1232 TString file, dir, obj;
1233
1234 Int_t what = mess->What();
1235
1236 switch (what) {
1237 case kPROOF_GETPACKET:
1238
1239 fLatency.Stop();
1240 (*mess) >> e;
1241 if (e != 0) {
1242 fCompute.Start();
1243 PDB(kLoop, 2) Info("GetNextPacket", "'%s' '%s' '%s' %lld %lld",
1244 e->GetFileName(), e->GetDirectory(),
1245 e->GetObjName(), e->GetFirst(),e->GetNum());
1246 } else {
1247 PDB(kLoop, 2) Info("GetNextPacket", "Done");
1248 }
1249 notdone = kFALSE;
1250 break;
1251
1252 case kPROOF_STOPPROCESS:
1253 // if a kPROOF_STOPPROCESS message is returned to kPROOF_GETPACKET
1254 // GetNextPacket() will return 0 and the TPacketizer and hence
1255 // TEventIter will be stopped
1256 fLatency.Stop();
1257 PDB(kLoop, 2) Info("GetNextPacket:kPROOF_STOPPROCESS","received");
1258 break;
1259
1260 default:
1261 xrc = HandleSocketInput(mess, kFALSE);
1262 if (xrc == -1) {
1263 Error("GetNextPacket", "command %d cannot be executed while processing", what);
1264 } else if (xrc == -2) {
1265 Error("GetNextPacket", "unknown command %d ! Protocol error?", what);
1266 }
1267 break;
1268 }
1269
1270 delete mess;
1271
1272 }
1273
1274 // Done
1275 return e;
1276}
1277
1278////////////////////////////////////////////////////////////////////////////////
1279/// Get and handle command line options. Fixed format:
1280/// "proofserv"|"proofslave" <confdir>
1281
1282void TProofServ::GetOptions(Int_t *argc, char **argv)
1283{
1284 Bool_t xtest = (argc && *argc > 3 && !strcmp(argv[3], "test")) ? kTRUE : kFALSE;
1285
1286 // If test and tty
1287 if (xtest && !(isatty(0) == 0 || isatty(1) == 0)) {
1288 Printf("proofserv: command line testing: OK");
1289 exit(0);
1290 }
1291
1292 if (!argc || (argc && *argc <= 1)) {
1293 Fatal("GetOptions", "Must be started from proofd with arguments");
1294 exit(1);
1295 }
1296
1297 if (!strcmp(argv[1], "proofserv")) {
1299 fEndMaster = kTRUE;
1300 } else if (!strcmp(argv[1], "proofslave")) {
1303 } else {
1304 Fatal("GetOptions", "Must be started as 'proofserv' or 'proofslave'");
1305 exit(1);
1306 }
1307
1308 fService = argv[1];
1309
1310 // Confdir
1311 if (!(gSystem->Getenv("ROOTCONFDIR"))) {
1312 Fatal("GetOptions", "ROOTCONFDIR shell variable not set");
1313 exit(1);
1314 }
1315 fConfDir = gSystem->Getenv("ROOTCONFDIR");
1316}
1317
1318////////////////////////////////////////////////////////////////////////////////
1319/// Handle input coming from the client or from the master server.
1320
1322{
1323 // The idle timeout guard: stops the timer and restarts when we return from here
1325
1326 Bool_t all = (fgRecursive > 0) ? kFALSE : kTRUE;
1327 fgRecursive++;
1328
1329 TMessage *mess;
1330 Int_t rc = 0;
1331 TString exmsg;
1332
1333 // Check log file length (before the action, so we have the chance to keep the
1334 // latest logs)
1336
1337 try {
1338
1339 // Get message
1340 if (fSocket->Recv(mess) <= 0 || !mess) {
1341 // Pending: do something more intelligent here
1342 // but at least get a message in the log file
1343 Error("HandleSocketInput", "retrieving message from input socket");
1344 Terminate(0);
1345 return;
1346 }
1347 Int_t what = mess->What();
1348 PDB(kCollect, 1)
1349 Info("HandleSocketInput", "got type %d from '%s'", what, fSocket->GetTitle());
1350
1351 fNcmd++;
1352
1353 if (fProof) fProof->SetActive();
1354
1355 Bool_t doit = kTRUE;
1356
1357 while (doit) {
1358
1359 // Process the message
1360 rc = HandleSocketInput(mess, all);
1361 if (rc < 0) {
1362 TString emsg;
1363 if (rc == -1) {
1364 emsg.Form("HandleSocketInput: command %d cannot be executed while processing", what);
1365 } else if (rc == -3) {
1366 emsg.Form("HandleSocketInput: message %d undefined! Protocol error?", what);
1367 } else {
1368 emsg.Form("HandleSocketInput: unknown command %d! Protocol error?", what);
1369 }
1370 SendAsynMessage(emsg.Data());
1371 } else if (rc == 2) {
1372 // Add to the queue
1373 fQueuedMsg->Add(mess);
1374 PDB(kGlobal, 1)
1375 Info("HandleSocketInput", "message of type %d enqueued; sz: %d",
1376 what, fQueuedMsg->GetSize());
1377 mess = 0;
1378 }
1379
1380 // Still something to do?
1381 doit = 0;
1382 if (fgRecursive == 1 && fQueuedMsg->GetSize() > 0) {
1383 // Add to the queue
1384 PDB(kCollect, 1)
1385 Info("HandleSocketInput", "processing enqueued message of type %d; left: %d",
1386 what, fQueuedMsg->GetSize());
1387 all = 1;
1388 SafeDelete(mess);
1389 mess = (TMessage *) fQueuedMsg->First();
1390 if (mess) fQueuedMsg->Remove(mess);
1391 doit = 1;
1392 }
1393 }
1394
1395 } catch (std::bad_alloc &) {
1396 // Memory allocation problem:
1397 exmsg.Form("caught exception 'bad_alloc' (memory leak?) %s %lld",
1399 } catch (std::exception &exc) {
1400 // Standard exception caught
1401 exmsg.Form("caught standard exception '%s' %s %lld",
1402 exc.what(), fgLastMsg.Data(), fgLastEntry);
1403 } catch (int i) {
1404 // Other exception caught
1405 exmsg.Form("caught exception throwing %d %s %lld",
1406 i, fgLastMsg.Data(), fgLastEntry);
1407 } catch (const char *str) {
1408 // Other exception caught
1409 exmsg.Form("caught exception throwing '%s' %s %lld",
1410 str, fgLastMsg.Data(), fgLastEntry);
1411 } catch (...) {
1412 // Caught other exception
1413 exmsg.Form("caught exception <unknown> %s %lld",
1415 }
1416
1417 // Terminate on exception
1418 if (!exmsg.IsNull()) {
1419 // Save info in the log file too
1420 Error("HandleSocketInput", "%s", exmsg.Data());
1421 // Try to warn the user
1422 SendAsynMessage(TString::Format("%s: %s", GetOrdinal(), exmsg.Data()));
1423 // Terminate
1424 Terminate(0);
1425 }
1426
1427 // Terminate also if a high memory footprint was detected before the related
1428 // exception was thrwon
1430 // Save info in the log file too
1431 exmsg.Form("high-memory footprint detected during Process(...) - terminating");
1432 Error("HandleSocketInput", "%s", exmsg.Data());
1433 // Try to warn the user
1434 SendAsynMessage(TString::Format("%s: %s", GetOrdinal(), exmsg.Data()));
1435 // Terminate
1436 Terminate(0);
1437 }
1438
1439 fgRecursive--;
1440
1441 if (fProof) {
1442 // If something wrong went on during processing and we do not have
1443 // any worker anymore, we shutdown this session
1444 Bool_t masterOnly = gEnv->GetValue("Proof.MasterOnly", kFALSE);
1445 Bool_t dynamicStartup = gEnv->GetValue("Proof.DynamicStartup", kFALSE);
1447 if (rc == 0 && ngwrks == 0 && !masterOnly && !dynamicStartup) {
1448 SendAsynMessage(" *** No workers left: cannot continue! Terminating ... *** ");
1449 Terminate(0);
1450 }
1452 // Reset PROOF to running state
1454 }
1455
1456 // Cleanup
1457 SafeDelete(mess);
1458}
1459
1460////////////////////////////////////////////////////////////////////////////////
1461/// Process input coming from the client or from the master server.
1462/// If 'all' is kFALSE, process only those messages that can be handled
1463/// during query processing.
1464/// Returns -1 if the message could not be processed, <-1 if something went
1465/// wrong. Returns 1 if the action may have changed the parallel state.
1466/// Returns 2 if the message has to be enqueued.
1467/// Returns 0 otherwise
1468
1470{
1471 static TStopwatch timer;
1472 char str[2048];
1473 Bool_t aborted = kFALSE;
1474
1475 if (!mess) return -3;
1476
1477 Int_t what = mess->What();
1478 PDB(kCollect, 1)
1479 Info("HandleSocketInput", "processing message type %d from '%s'",
1480 what, fSocket->GetTitle());
1481
1482 timer.Start();
1483
1484 Int_t rc = 0, lirc = 0;
1485 TString slb;
1486 TString *pslb = (fgLogToSysLog > 0) ? &slb : (TString *)0;
1487
1488 switch (what) {
1489
1490 case kMESS_CINT:
1491 if (all) {
1492 mess->ReadString(str, sizeof(str));
1493 // Make sure that the relevant files are available
1494 TString fn;
1495
1496 Bool_t hasfn = TProof::GetFileInCmd(str, fn);
1497
1498 if (IsParallel() && fProof && !fProof->UseDynamicStartup()) {
1499 fProof->SendCommand(str);
1500 } else {
1501 PDB(kGlobal, 1)
1502 Info("HandleSocketInput:kMESS_CINT", "processing: %s...", str);
1503 TString ocwd;
1504 if (hasfn) {
1505 fCacheLock->Lock();
1506 ocwd = gSystem->WorkingDirectory();
1508 }
1509 ProcessLine(str);
1510 if (hasfn) {
1511 gSystem->ChangeDirectory(ocwd);
1512 fCacheLock->Unlock();
1513 }
1514 }
1515
1516 LogToMaster();
1517 } else {
1518 rc = -1;
1519 }
1520 SendLogFile();
1521 if (pslb) slb = str;
1522 break;
1523
1524 case kMESS_STRING:
1525 if (all) {
1526 mess->ReadString(str, sizeof(str));
1527 } else {
1528 rc = -1;
1529 }
1530 break;
1531
1532 case kMESS_OBJECT:
1533 if (all) {
1534 mess->ReadObject(mess->GetClass());
1535 } else {
1536 rc = -1;
1537 }
1538 break;
1539
1540 case kPROOF_GROUPVIEW:
1541 if (all) {
1542 mess->ReadString(str, sizeof(str));
1543 // coverity[secure_coding]
1544 sscanf(str, "%d %d", &fGroupId, &fGroupSize);
1545 } else {
1546 rc = -1;
1547 }
1548 break;
1549
1550 case kPROOF_LOGLEVEL:
1551 { UInt_t mask;
1552 mess->ReadString(str, sizeof(str));
1553 sscanf(str, "%d %u", &fLogLevel, &mask);
1554 Bool_t levelchanged = (fLogLevel != gProofDebugLevel) ? kTRUE : kFALSE;
1557 if (levelchanged)
1558 Info("HandleSocketInput:kPROOF_LOGLEVEL", "debug level set to %d (mask: 0x%x)",
1560 if (IsMaster())
1562 }
1563 break;
1564
1565 case kPROOF_PING:
1566 { if (IsMaster())
1567 fProof->Ping();
1568 // do nothing (ping is already acknowledged)
1569 }
1570 break;
1571
1572 case kPROOF_PRINT:
1573 mess->ReadString(str, sizeof(str));
1574 Print(str);
1575 LogToMaster();
1576 SendLogFile();
1577 break;
1578
1579 case kPROOF_RESET:
1580 if (all) {
1581 mess->ReadString(str, sizeof(str));
1582 Reset(str);
1583 } else {
1584 rc = -1;
1585 }
1586 break;
1587
1588 case kPROOF_STATUS:
1589 Warning("HandleSocketInput:kPROOF_STATUS",
1590 "kPROOF_STATUS message is obsolete");
1592 Warning("HandleSocketInput:kPROOF_STATUS", "problem sending of request");
1593 break;
1594
1595 case kPROOF_GETSTATS:
1597 break;
1598
1599 case kPROOF_GETPARALLEL:
1600 SendParallel();
1601 break;
1602
1603 case kPROOF_STOP:
1604 if (all) {
1605 if (IsMaster()) {
1606 TString ord;
1607 *mess >> ord;
1608 PDB(kGlobal, 1)
1609 Info("HandleSocketInput:kPROOF_STOP", "request for worker %s", ord.Data());
1610 if (fProof) fProof->TerminateWorker(ord);
1611 } else {
1612 PDB(kGlobal, 1)
1613 Info("HandleSocketInput:kPROOF_STOP", "got request to terminate");
1614 Terminate(0);
1615 }
1616 } else {
1617 rc = -1;
1618 }
1619 break;
1620
1621 case kPROOF_STOPPROCESS:
1622 if (all) {
1623 // this message makes only sense when the query is being processed,
1624 // however the message can also be received if the user pressed
1625 // ctrl-c, so ignore it!
1626 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_STOPPROCESS","enter");
1627 } else {
1628 Long_t timeout = -1;
1629 (*mess) >> aborted;
1630 if (fProtocol > 9)
1631 (*mess) >> timeout;
1632 PDB(kGlobal, 1)
1633 Info("HandleSocketInput:kPROOF_STOPPROCESS",
1634 "recursive mode: enter %d, %ld", aborted, timeout);
1635 if (fProof)
1636 // On the master: propagate further
1637 fProof->StopProcess(aborted, timeout);
1638 else
1639 // Worker: actually stop processing
1640 if (fPlayer)
1641 fPlayer->StopProcess(aborted, timeout);
1642 }
1643 break;
1644
1645 case kPROOF_PROCESS:
1646 {
1648 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_PROCESS","enter");
1649 HandleProcess(mess, pslb);
1650 // The log file is send either in HandleProcess or HandleSubmergers.
1651 // The reason is that the order of various messages depend on the
1652 // processing mode (sync/async) and/or merging mode
1653 }
1654 break;
1655
1656 case kPROOF_SENDOUTPUT:
1657 {
1658 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_SENDOUTPUT",
1659 "worker was asked to send output to master");
1660 Int_t sorc = 0;
1661 if (SendResults(fSocket, fPlayer->GetOutputList()) != 0) {
1662 Error("HandleSocketInput:kPROOF_SENDOUTPUT", "problems sending output list");
1663 sorc = 1;
1664 }
1665 // Signal the master that we are idle
1667 SetIdle(kTRUE);
1668 DeletePlayer();
1669 SendLogFile(sorc);
1670 }
1671 break;
1672
1673 case kPROOF_QUERYLIST:
1674 {
1675 HandleQueryList(mess);
1676 // Notify
1677 SendLogFile();
1678 }
1679 break;
1680
1681 case kPROOF_REMOVE:
1682 {
1683 HandleRemove(mess, pslb);
1684 // Notify
1685 SendLogFile();
1686 }
1687 break;
1688
1689 case kPROOF_RETRIEVE:
1690 {
1691 HandleRetrieve(mess, pslb);
1692 // Notify
1693 SendLogFile();
1694 }
1695 break;
1696
1697 case kPROOF_ARCHIVE:
1698 {
1699 HandleArchive(mess, pslb);
1700 // Notify
1701 SendLogFile();
1702 }
1703 break;
1704
1705 case kPROOF_MAXQUERIES:
1706 { PDB(kGlobal, 1)
1707 Info("HandleSocketInput:kPROOF_MAXQUERIES", "Enter");
1709 m << fMaxQueries;
1710 fSocket->Send(m);
1711 // Notify
1712 SendLogFile();
1713 }
1714 break;
1715
1717 if (all) {
1718 PDB(kGlobal, 1)
1719 Info("HandleSocketInput:kPROOF_CLEANUPSESSION", "Enter");
1720 TString stag;
1721 (*mess) >> stag;
1722 if (fQMgr && fQMgr->CleanupSession(stag) == 0) {
1723 Printf("Session %s cleaned up", stag.Data());
1724 } else {
1725 Printf("Could not cleanup session %s", stag.Data());
1726 }
1727 } else {
1728 rc = -1;
1729 }
1730 // Notify
1731 SendLogFile();
1732 break;
1733
1734 case kPROOF_GETENTRIES:
1735 { PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETENTRIES", "Enter");
1736 Bool_t isTree;
1737 TString filename;
1738 TString dir;
1739 TString objname("undef");
1740 Long64_t entries = -1;
1741
1742 if (all) {
1743 (*mess) >> isTree >> filename >> dir >> objname;
1744 PDB(kGlobal, 2) Info("HandleSocketInput:kPROOF_GETENTRIES",
1745 "Report size of object %s (%s) in dir %s in file %s",
1746 objname.Data(), isTree ? "T" : "O",
1747 dir.Data(), filename.Data());
1748 entries = TDSet::GetEntries(isTree, filename, dir, objname);
1749 PDB(kGlobal, 2) Info("HandleSocketInput:kPROOF_GETENTRIES",
1750 "Found %lld %s", entries, isTree ? "entries" : "objects");
1751 } else {
1752 rc = -1;
1753 }
1755 answ << entries << objname;
1756 SendLogFile(); // in case of error messages
1757 fSocket->Send(answ);
1758 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETENTRIES", "Done");
1759 }
1760 break;
1761
1762 case kPROOF_CHECKFILE:
1763 if (!all && fProtocol <= 19) {
1764 // Come back later
1765 rc = 2;
1766 } else {
1767 // Handle file checking request
1768 HandleCheckFile(mess, pslb);
1769 FlushLogFile(); // Avoid sending (error) messages at next action
1770 }
1771 break;
1772
1773 case kPROOF_SENDFILE:
1774 if (!all && fProtocol <= 19) {
1775 // Come back later
1776 rc = 2;
1777 } else {
1778 mess->ReadString(str, sizeof(str));
1779 Long_t size;
1780 Int_t bin, fw = 1;
1781 char name[1024];
1782 if (fProtocol > 5) {
1783 sscanf(str, "%1023s %d %ld %d", name, &bin, &size, &fw);
1784 } else {
1785 sscanf(str, "%1023s %d %ld", name, &bin, &size);
1786 }
1787 TString fnam(name);
1788 Bool_t copytocache = kTRUE;
1789 if (fnam.BeginsWith("cache:")) {
1790 fnam.ReplaceAll("cache:", TString::Format("%s/", fCacheDir.Data()));
1791 copytocache = kFALSE;
1792 }
1793
1794 Int_t rfrc = 0;
1795 if (size > 0) {
1796 rfrc = ReceiveFile(fnam, bin ? kTRUE : kFALSE, size);
1797 } else {
1798 // Take it from the cache
1799 if (!fnam.BeginsWith(fCacheDir.Data())) {
1800 fnam.Insert(0, TString::Format("%s/", fCacheDir.Data()));
1801 }
1802 }
1803 if (rfrc == 0) {
1804 // copy file to cache if not a PAR file
1805 if (copytocache && size > 0 && !fPackMgr->IsInDir(name))
1806 gSystem->Exec(TString::Format("%s %s %s", kCP, fnam.Data(), fCacheDir.Data()));
1807 if (IsMaster() && fw == 1) {
1809 if (bin)
1810 opt |= TProof::kBinary;
1811 PDB(kGlobal, 1)
1812 Info("HandleSocketInput","forwarding file: %s", fnam.Data());
1813 if (fProof->SendFile(fnam, opt, (copytocache ? "cache" : "")) < 0) {
1814 Error("HandleSocketInput", "forwarding file: %s", fnam.Data());
1815 }
1816 }
1818 } else {
1819 // There was an error
1820 SendLogFile(1);
1821 }
1822 }
1823 break;
1824
1825 case kPROOF_LOGFILE:
1826 {
1827 Int_t start, end;
1828 (*mess) >> start >> end;
1829 PDB(kGlobal, 1)
1830 Info("HandleSocketInput:kPROOF_LOGFILE",
1831 "Logfile request - byte range: %d - %d", start, end);
1832
1833 LogToMaster();
1834 SendLogFile(0, start, end);
1835 }
1836 break;
1837
1838 case kPROOF_PARALLEL:
1839 if (all) {
1840 if (IsMaster()) {
1841 Int_t nodes;
1842 Bool_t random = kFALSE;
1843 (*mess) >> nodes;
1844 if ((mess->BufferSize() > mess->Length()))
1845 (*mess) >> random;
1846 if (fProof) fProof->SetParallel(nodes, random);
1847 rc = 1;
1848 }
1849 } else {
1850 rc = -1;
1851 }
1852 // Notify
1853 SendLogFile();
1854 break;
1855
1856 case kPROOF_CACHE:
1857 if (!all && fProtocol <= 19) {
1858 // Come back later
1859 rc = 2;
1860 } else {
1862 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_CACHE","enter");
1863 Int_t hcrc = HandleCache(mess, pslb);
1864 // Notify
1865 SendLogFile(hcrc);
1866 }
1867 break;
1868
1869 case kPROOF_WORKERLISTS:
1870 { Int_t wlrc = -1;
1871 if (all) {
1872 if (IsMaster())
1873 wlrc = HandleWorkerLists(mess);
1874 else
1875 Warning("HandleSocketInput:kPROOF_WORKERLISTS",
1876 "Action meaning-less on worker nodes: protocol error?");
1877 } else {
1878 rc = -1;
1879 }
1880 // Notify
1881 SendLogFile(wlrc);
1882 }
1883 break;
1884
1886 if (all) {
1887 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETSLAVEINFO", "Enter");
1888 if (IsMaster()) {
1889
1890 Bool_t ok = kTRUE;
1891 // if the session does not have workers and is in the dynamic mode
1892 if (fProof->UseDynamicStartup()) {
1893 ok = kFALSE;
1894 // get the a list of workers and start them
1895 Int_t pc = 0;
1896 TList* workerList = new TList();
1897 EQueryAction retVal = GetWorkers(workerList, pc);
1898 if (retVal != TProofServ::kQueryStop && retVal != TProofServ::kQueryEnqueued) {
1899 Int_t ret = fProof->AddWorkers(workerList);
1900 if (ret < 0) {
1901 Error("HandleSocketInput:kPROOF_GETSLAVEINFO",
1902 "adding a list of worker nodes returned: %d", ret);
1903 }
1904 } else {
1905 Error("HandleSocketInput:kPROOF_GETSLAVEINFO",
1906 "getting list of worker nodes returned: %d", retVal);
1907 }
1908 ok = kTRUE;
1909 }
1910 if (ok) {
1911 TList *info = fProof->GetListOfSlaveInfos();
1913 answ << info;
1914 fSocket->Send(answ);
1915 // stop the workers
1917 }
1918 } else {
1920 TList *info = new TList;
1922 SysInfo_t si;
1923 gSystem->GetSysInfo(&si);
1924 wi->SetSysInfo(si);
1925 info->Add(wi);
1926 answ << (TList *)info;
1927 fSocket->Send(answ);
1928 info->SetOwner(kTRUE);
1929 delete info;
1930 }
1931
1932 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETSLAVEINFO", "Done");
1933 } else {
1935 answ << (TList *)0;
1936 fSocket->Send(answ);
1937 rc = -1;
1938 }
1939 break;
1940
1942 if (all) {
1943 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETTREEHEADER", "Enter");
1944
1946 if (p) {
1947 p->HandleGetTreeHeader(mess);
1948 delete p;
1949 } else {
1950 Error("HandleSocketInput:kPROOF_GETTREEHEADER", "could not create TProofPlayer instance!");
1951 }
1952
1953 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETTREEHEADER", "Done");
1954 } else {
1956 answ << TString("Failed") << (TObject *)0;
1957 fSocket->Send(answ);
1958 rc = -1;
1959 }
1960 break;
1961
1963 { PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETOUTPUTLIST", "Enter");
1964 TList* outputList = 0;
1965 if (IsMaster()) {
1966 outputList = fProof->GetOutputList();
1967 if (!outputList)
1968 outputList = new TList();
1969 } else {
1970 outputList = new TList();
1971 if (fProof->GetPlayer()) {
1972 TList *olist = fProof->GetPlayer()->GetOutputList();
1973 TIter next(olist);
1974 TObject *o;
1975 while ( (o = next()) ) {
1976 outputList->Add(new TNamed(o->GetName(), ""));
1977 }
1978 }
1979 }
1980 outputList->SetOwner();
1982 answ << outputList;
1983 fSocket->Send(answ);
1984 delete outputList;
1985 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_GETOUTPUTLIST", "Done");
1986 }
1987 break;
1988
1990 if (all) {
1991 PDB(kGlobal, 1)
1992 Info("HandleSocketInput:kPROOF_VALIDATE_DSET", "Enter");
1993
1994 TDSet* dset = 0;
1995 (*mess) >> dset;
1996
1997 if (IsMaster()) fProof->ValidateDSet(dset);
1998 else dset->Validate();
1999
2001 answ << dset;
2002 fSocket->Send(answ);
2003 delete dset;
2004 PDB(kGlobal, 1)
2005 Info("HandleSocketInput:kPROOF_VALIDATE_DSET", "Done");
2006 } else {
2007 rc = -1;
2008 }
2009 // Notify
2010 SendLogFile();
2011 break;
2012
2013 case kPROOF_DATA_READY:
2014 if (all) {
2015 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_DATA_READY", "Enter");
2017 if (IsMaster()) {
2018 Long64_t totalbytes = 0, bytesready = 0;
2019 Bool_t dataready = fProof->IsDataReady(totalbytes, bytesready);
2020 answ << dataready << totalbytes << bytesready;
2021 } else {
2022 Error("HandleSocketInput:kPROOF_DATA_READY",
2023 "This message should not be sent to slaves");
2024 answ << kFALSE << Long64_t(0) << Long64_t(0);
2025 }
2026 fSocket->Send(answ);
2027 PDB(kGlobal, 1) Info("HandleSocketInput:kPROOF_DATA_READY", "Done");
2028 } else {
2030 answ << kFALSE << Long64_t(0) << Long64_t(0);
2031 fSocket->Send(answ);
2032 rc = -1;
2033 }
2034 // Notify
2035 SendLogFile();
2036 break;
2037
2038 case kPROOF_DATASETS:
2039 { Int_t dsrc = -1;
2040 if (fProtocol > 16) {
2041 dsrc = HandleDataSets(mess, pslb);
2042 } else {
2043 Error("HandleSocketInput", "old client: no or incompatible dataset support");
2044 }
2045 SendLogFile(dsrc);
2046 }
2047 break;
2048
2049 case kPROOF_SUBMERGER:
2050 { HandleSubmerger(mess);
2051 }
2052 break;
2053
2055 if (all) {
2056 lirc = HandleLibIncPath(mess);
2057 } else {
2058 rc = -1;
2059 }
2060 // Notify the client
2061 if (lirc > 0) SendLogFile();
2062 break;
2063
2064 case kPROOF_REALTIMELOG:
2065 { Bool_t on;
2066 (*mess) >> on;
2067 PDB(kGlobal, 1)
2068 Info("HandleSocketInput:kPROOF_REALTIMELOG",
2069 "setting real-time logging %s", (on ? "ON" : "OFF"));
2070 fRealTimeLog = on;
2071 // Forward the request to lower levels
2072 if (IsMaster())
2074 }
2075 break;
2076
2077 case kPROOF_FORK:
2078 if (all) {
2079 HandleFork(mess);
2080 LogToMaster();
2081 } else {
2082 rc = -1;
2083 }
2084 SendLogFile();
2085 break;
2086
2088 if (all) {
2089 // This message resumes the session; should not come during processing.
2090
2091 if (WaitingQueries() == 0) {
2092 Error("HandleSocketInput", "no queries enqueued");
2093 break;
2094 }
2095
2096 // Similar to handle process
2097 // get the list of workers and start them
2098 TList *workerList = (fProof->UseDynamicStartup()) ? new TList : (TList *)0;
2099 Int_t pc = 0;
2100 EQueryAction retVal = GetWorkers(workerList, pc, kTRUE);
2101
2102 if (retVal == TProofServ::kQueryOK) {
2103 Int_t ret = 0;
2104 if (workerList && (ret = fProof->AddWorkers(workerList)) < 0) {
2105 Error("HandleSocketInput", "adding a list of worker nodes returned: %d", ret);
2106 } else {
2107 ProcessNext(pslb);
2108 // Set idle
2109 SetIdle(kTRUE);
2110 // Signal the client that we are idle
2112 Bool_t waiting = (WaitingQueries() > 0) ? kTRUE : kFALSE;
2113 m << waiting;
2114 fSocket->Send(m);
2115 }
2116 } else {
2117 if (retVal == TProofServ::kQueryStop) {
2118 Error("HandleSocketInput", "error getting list of worker nodes");
2119 } else if (retVal != TProofServ::kQueryEnqueued) {
2120 Warning("HandleSocketInput", "query was re-queued!");
2121 } else {
2122 Error("HandleSocketInput", "unexpected answer: %d", retVal);
2123 break;
2124 }
2125 }
2126
2127 }
2128 break;
2129
2130 case kPROOF_GOASYNC:
2131 { // The client requested to switch to asynchronous mode:
2132 // communicate the sequential number of the running query for later
2133 // identification, if any
2134 if (!IsIdle() && fPlayer) {
2135 // Get query currently being processed
2138 m << pq->GetSeqNum() << kFALSE;
2139 fSocket->Send(m);
2140 } else {
2141 // Idle or undefined: nothing to do; ignore
2142 SendAsynMessage("Processing request to go asynchronous:"
2143 " idle or undefined player - ignoring");
2144 }
2145 }
2146 break;
2147
2148 case kPROOF_ECHO:
2149 { // Echo request: an object has been sent along. If the object is a
2150 // string, it is simply echoed back to the client from the master
2151 // and each worker. Elsewhere, the output of TObject::Print() is
2152 // sent. Received object is disposed after usage.
2153
2154 TObject *obj = mess->ReadObject(0x0); // class type ignored
2155
2156 if (IsMaster()) {
2157 // We are on master
2158 // dbTODO: forward on dynamic startup when wrks are up
2159 if (IsParallel() && fProof && !fProof->UseDynamicStartup()) {
2160 fProof->Echo(obj); // forward to lower layer
2161 }
2162 }
2163
2165 TString smsg;
2166
2167 if (obj->InheritsFrom(TObjString::Class())) {
2168 // It's a string: echo it
2169 smsg.Form("Echo response from %s:%s: %s",
2171 ((TObjString *)obj)->String().Data());
2172 }
2173 else {
2174 // Not a string: collect Print() output and send it
2175
2176 // Output to tempfile
2177 TString tmpfn = "echo-out-";
2178 FILE *tf = gSystem->TempFileName(tmpfn, fDataDir);
2179 if (!tf || (gSystem->RedirectOutput(tmpfn.Data()) == -1)) {
2180 Error("HandleSocketInput", "Can't redirect output");
2181 if (tf) {
2182 fclose(tf);
2183 gSystem->Unlink(tmpfn);
2184 }
2185 rc = -1;
2186 delete obj;
2187 break;
2188 }
2189 //cout << obj->ClassName() << endl;
2190 obj->Print();
2191 gSystem->RedirectOutput(0x0); // restore
2192 fclose(tf);
2193
2194 // Read file back and send it via message
2195 smsg.Form("*** Echo response from %s:%s ***\n",
2197 TMacro *fr = new TMacro();
2198 fr->ReadFile(tmpfn);
2199 TIter nextLine(fr->GetListOfLines());
2201 while (( line = (TObjString *)nextLine() )) {
2202 smsg.Append( line->String() );
2203 }
2204
2205 // Close the reader (TMacro) and remove file
2206 delete fr;
2207 gSystem->Unlink(tmpfn);
2208 }
2209
2210 // Send message and dispose object
2211 rmsg << smsg;
2212 GetSocket()->Send(rmsg);
2213 delete obj;
2214 }
2215 break;
2216
2217 default:
2218 Error("HandleSocketInput", "unknown command %d", what);
2219 rc = -2;
2220 break;
2221 }
2222
2223 fRealTime += (Float_t)timer.RealTime();
2224 fCpuTime += (Float_t)timer.CpuTime();
2225
2226 if (!(slb.IsNull()) || fgLogToSysLog > 1) {
2227 TString s;
2228 s.Form("%s %d %.3f %.3f %s", fgSysLogEntity.Data(),
2229 what, timer.RealTime(), timer.CpuTime(), slb.Data());
2231 }
2232
2233 // Done
2234 return rc;
2235}
2236
2237////////////////////////////////////////////////////////////////////////////////
2238/// Accept and merge results from a set of workers
2239
2241{
2242 TMessage *mess = new TMessage();
2243 Int_t mergedWorkers = 0;
2244
2245 PDB(kSubmerger, 1) Info("AcceptResults", "enter");
2246
2247 // Overall result of this procedure
2248 Bool_t result = kTRUE;
2249
2250 fMergingMonitor = new TMonitor();
2252
2253 Int_t numworkers = 0;
2254 while (fMergingMonitor->GetActive() > 0 && mergedWorkers < connections) {
2255
2257 if (!s) {
2258 Info("AcceptResults", "interrupt!");
2259 result = kFALSE;
2260 break;
2261 }
2262
2263 if (s == fMergingSocket) {
2264 // New incoming connection
2265 TSocket *sw = fMergingSocket->Accept();
2266 if (sw && sw != (TSocket *)(-1)) {
2267 fMergingMonitor->Add(sw);
2268
2269 PDB(kSubmerger, 2)
2270 Info("AcceptResults", "connection from a worker accepted on merger %s ",
2271 fOrdinal.Data());
2272 // All assigned workers are connected
2273 if (++numworkers >= connections)
2275 } else {
2276 PDB(kSubmerger, 1)
2277 Info("AcceptResults", "spurious signal found of merging socket");
2278 }
2279 } else {
2280 if (s->Recv(mess) < 0) {
2281 Error("AcceptResults", "problems receiving message");
2282 continue;
2283 }
2284 PDB(kSubmerger, 2)
2285 Info("AcceptResults", "message received: %d ", (mess ? mess->What() : 0));
2286 if (!mess) {
2287 Error("AcceptResults", "message received: %p ", mess);
2288 continue;
2289 }
2290 Int_t type = 0;
2291
2292 // Read output objec(s) from the received message
2293 while ((mess->BufferSize() > mess->Length())) {
2294 (*mess) >> type;
2295
2296 PDB(kSubmerger, 2) Info("AcceptResults", " type %d ", type);
2297 if (type == 2) {
2298 mergedWorkers++;
2299 PDB(kSubmerger, 2)
2300 Info("AcceptResults",
2301 "a new worker has been mergerd. Total merged workers: %d",
2302 mergedWorkers);
2303 }
2304 TObject *o = mess->ReadObject(TObject::Class());
2305 if (mergerPlayer->AddOutputObject(o) == 1) {
2306 // Remove the object if it has been merged
2307 PDB(kSubmerger, 2) Info("AcceptResults", "removing %p (has been merged)", o);
2308 SafeDelete(o);
2309 } else
2310 PDB(kSubmerger, 2) Info("AcceptResults", "%p not merged yet", o);
2311 }
2312 }
2313 }
2315
2317 Int_t size = sockets->GetSize();
2318 for (Int_t i =0; i< size; ++i){
2319 ((TSocket*)(sockets->At(i)))->Close();
2320 PDB(kSubmerger, 2) Info("AcceptResults", "closing socket");
2321 delete ((TSocket*)(sockets->At(i)));
2322 }
2323 delete sockets;
2324
2327
2328 PDB(kSubmerger, 2) Info("AcceptResults", "exit: %d", result);
2329 return result;
2330}
2331
2332////////////////////////////////////////////////////////////////////////////////
2333/// Handle Out-Of-Band data sent by the master or client.
2334
2336{
2337 char oob_byte;
2338 Int_t n, nch, wasted = 0;
2339
2340 const Int_t kBufSize = 1024;
2341 char waste[kBufSize];
2342
2343 // Real-time notification of messages
2345
2346 PDB(kGlobal, 5)
2347 Info("HandleUrgentData", "handling oob...");
2348
2349 // Receive the OOB byte
2350 while ((n = fSocket->RecvRaw(&oob_byte, 1, kOob)) < 0) {
2351 if (n == -2) { // EWOULDBLOCK
2352 //
2353 // The OOB data has not yet arrived: flush the input stream
2354 //
2355 // In some systems (Solaris) regular recv() does not return upon
2356 // receipt of the oob byte, which makes the below call to recv()
2357 // block indefinitely if there are no other data in the queue.
2358 // FIONREAD ioctl can be used to check if there are actually any
2359 // data to be flushed. If not, wait for a while for the oob byte
2360 // to arrive and try to read it again.
2361 //
2363 if (nch == 0) {
2364 gSystem->Sleep(1000);
2365 continue;
2366 }
2367
2368 if (nch > kBufSize) nch = kBufSize;
2369 n = fSocket->RecvRaw(waste, nch);
2370 if (n <= 0) {
2371 Error("HandleUrgentData", "error receiving waste");
2372 break;
2373 }
2374 wasted = 1;
2375 } else {
2376 Error("HandleUrgentData", "error receiving OOB");
2377 return;
2378 }
2379 }
2380
2381 PDB(kGlobal, 5)
2382 Info("HandleUrgentData", "got OOB byte: %d\n", oob_byte);
2383
2384 if (fProof) fProof->SetActive();
2385
2386 switch (oob_byte) {
2387
2389 Info("HandleUrgentData", "*** Hard Interrupt");
2390
2391 // If master server, propagate interrupt to slaves
2392 if (IsMaster())
2394
2395 // Flush input socket
2396 while (1) {
2397 Int_t atmark;
2398
2399 fSocket->GetOption(kAtMark, atmark);
2400
2401 if (atmark) {
2402 // Send the OOB byte back so that the client knows where
2403 // to stop flushing its input stream of obsolete messages
2404 n = fSocket->SendRaw(&oob_byte, 1, kOob);
2405 if (n <= 0)
2406 Error("HandleUrgentData", "error sending OOB");
2407 break;
2408 }
2409
2410 // find out number of bytes to read before atmark
2412 if (nch == 0) {
2413 gSystem->Sleep(1000);
2414 continue;
2415 }
2416
2417 if (nch > kBufSize) nch = kBufSize;
2418 n = fSocket->RecvRaw(waste, nch);
2419 if (n <= 0) {
2420 Error("HandleUrgentData", "error receiving waste (2)");
2421 break;
2422 }
2423 }
2424
2425 SendLogFile();
2426
2427 break;
2428
2430 Info("HandleUrgentData", "Soft Interrupt");
2431
2432 // If master server, propagate interrupt to slaves
2433 if (IsMaster())
2435
2436 if (wasted) {
2437 Error("HandleUrgentData", "soft interrupt flushed stream");
2438 break;
2439 }
2440
2441 Interrupt();
2442
2443 SendLogFile();
2444
2445 break;
2446
2448 Info("HandleUrgentData", "Shutdown Interrupt");
2449
2450 // If master server, propagate interrupt to slaves
2451 if (IsMaster())
2453
2454 Terminate(0);
2455
2456 break;
2457
2458 default:
2459 Error("HandleUrgentData", "unexpected OOB byte");
2460 break;
2461 }
2462
2464}
2465
2466////////////////////////////////////////////////////////////////////////////////
2467/// Called when the client is not alive anymore (i.e. when kKeepAlive
2468/// has failed).
2469
2471{
2472 // Real-time notification of messages
2474
2475 if (IsMaster()) {
2476 // Check if we are here because client is closed. Try to ping client,
2477 // if that works it we are here because some slave died
2478 if (fSocket->Send(kPROOF_PING | kMESS_ACK) < 0) {
2479 Info("HandleSigPipe", "keepAlive probe failed");
2480 // Tell slaves we are going to close since there is no client anymore
2481
2482 fProof->SetActive();
2485 Terminate(0);
2486 }
2487 } else {
2488 Info("HandleSigPipe", "keepAlive probe failed");
2489 Terminate(0); // will not return from here....
2490 }
2491}
2492
2493////////////////////////////////////////////////////////////////////////////////
2494/// True if in parallel mode.
2495
2497{
2498 if (IsMaster() && fProof)
2499 return fProof->IsParallel() || fProof->UseDynamicStartup() ;
2500
2501 // false in case we are a slave
2502 return kFALSE;
2503}
2504
2505////////////////////////////////////////////////////////////////////////////////
2506/// Print status of slave server.
2507
2508void TProofServ::Print(Option_t *option) const
2509{
2510 if (IsMaster() && fProof)
2511 fProof->Print(option);
2512 else
2513 Printf("This is worker %s", gSystem->HostName());
2514}
2515
2516////////////////////////////////////////////////////////////////////////////////
2517/// Redirect stdout to a log file. This log file will be flushed to the
2518/// client or master after each command.
2519
2520void TProofServ::RedirectOutput(const char *dir, const char *mode)
2521{
2522 char logfile[512];
2523
2524 TString sdir = (dir && strlen(dir) > 0) ? dir : fSessionDir.Data();
2525 if (IsMaster()) {
2526 snprintf(logfile, 512, "%s/master-%s.log", sdir.Data(), fOrdinal.Data());
2527 } else {
2528 snprintf(logfile, 512, "%s/worker-%s.log", sdir.Data(), fOrdinal.Data());
2529 }
2530
2531 if ((freopen(logfile, mode, stdout)) == 0)
2532 SysError("RedirectOutput", "could not freopen stdout (%s)", logfile);
2533
2534 if ((dup2(fileno(stdout), fileno(stderr))) < 0)
2535 SysError("RedirectOutput", "could not redirect stderr");
2536
2537 if ((fLogFile = fopen(logfile, "r")) == 0)
2538 SysError("RedirectOutput", "could not open logfile '%s'", logfile);
2539
2540 // from this point on stdout and stderr are properly redirected
2541 if (fProtocol < 4 && fWorkDir != TString::Format("~/%s", kPROOF_WorkDir)) {
2542 Warning("RedirectOutput", "no way to tell master (or client) where"
2543 " to upload packages");
2544 }
2545}
2546
2547////////////////////////////////////////////////////////////////////////////////
2548/// Reset PROOF environment to be ready for execution of next command.
2549
2550void TProofServ::Reset(const char *dir)
2551{
2552 // First go to new directory. Check first that we got a reasonable path;
2553 // in PROOF-Lite it may not be the case
2554 TString dd(dir);
2555 if (!dd.BeginsWith("proofserv")) {
2556 Int_t ic = dd.Index(":");
2557 if (ic != kNPOS)
2558 dd.Replace(0, ic, "proofserv");
2559 }
2560 gDirectory->cd(dd.Data());
2561
2562 // Clear interpreter environment.
2563 gROOT->Reset();
2564
2565 // Make sure current directory is empty (don't delete anything when
2566 // we happen to be in the ROOT memory only directory!?)
2567 if (gDirectory != gROOT) {
2568 gDirectory->Delete();
2569 }
2570
2572}
2573
2574////////////////////////////////////////////////////////////////////////////////
2575/// Receive a file, either sent by a client or a master server.
2576/// If bin is true it is a binary file, other wise it is an ASCII
2577/// file and we need to check for Windows \r tokens. Returns -1 in
2578/// case of error, 0 otherwise.
2579
2581{
2582 if (size <= 0) return 0;
2583
2584 // open file, overwrite already existing file
2585 Int_t fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600);
2586 if (fd < 0) {
2587 SysError("ReceiveFile", "error opening file %s", file);
2588 return -1;
2589 }
2590
2591 const Int_t kMAXBUF = 16384; //32768 //16384 //65536;
2592 char buf[kMAXBUF], cpy[kMAXBUF];
2593
2594 Int_t left, r;
2595 Long64_t filesize = 0;
2596
2597 while (filesize < size) {
2598 left = Int_t(size - filesize);
2599 if (left > kMAXBUF)
2600 left = kMAXBUF;
2601 r = fSocket->RecvRaw(&buf, left);
2602 if (r > 0) {
2603 char *p = buf;
2604
2605 filesize += r;
2606 while (r) {
2607 Int_t w;
2608
2609 if (!bin) {
2610 Int_t k = 0, i = 0, j = 0;
2611 char *q;
2612 while (i < r) {
2613 if (p[i] == '\r') {
2614 i++;
2615 k++;
2616 }
2617 cpy[j++] = buf[i++];
2618 }
2619 q = cpy;
2620 r -= k;
2621 w = write(fd, q, r);
2622 } else {
2623 w = write(fd, p, r);
2624 }
2625
2626 if (w < 0) {
2627 SysError("ReceiveFile", "error writing to file %s", file);
2628 close(fd);
2629 return -1;
2630 }
2631 r -= w;
2632 p += w;
2633 }
2634 } else if (r < 0) {
2635 Error("ReceiveFile", "error during receiving file %s", file);
2636 close(fd);
2637 return -1;
2638 }
2639 }
2640
2641 close(fd);
2642
2643 if (chmod(file, 0644) != 0)
2644 Warning("ReceiveFile", "error setting mode 0644 on file %s", file);
2645
2646 return 0;
2647}
2648
2649////////////////////////////////////////////////////////////////////////////////
2650/// Main server eventloop.
2651
2653{
2654 // Setup the server
2655 if (CreateServer() == 0) {
2656
2657 // Run the main event loop
2658 TApplication::Run(retrn);
2659 }
2660}
2661
2662////////////////////////////////////////////////////////////////////////////////
2663/// Send log file to master.
2664/// If start > -1 send only bytes in the range from start to end,
2665/// if end <= start send everything from start.
2666
2668{
2669 // Determine the number of bytes left to be read from the log file.
2670 fflush(stdout);
2671
2672 // On workers we do not send the logs to masters (to avoid duplication of
2673 // text) unless asked explicitly, e.g. after an Exec(...) request.
2674 if (!IsMaster()) {
2675 if (!fSendLogToMaster) {
2676 FlushLogFile();
2677 } else {
2678 // Decide case by case
2680 }
2681 }
2682
2683 off_t ltot=0, lnow=0;
2684 Int_t left = -1;
2685 Bool_t adhoc = kFALSE;
2686
2687 if (fLogFileDes > -1) {
2688 ltot = lseek(fileno(stdout), (off_t) 0, SEEK_END);
2689 lnow = lseek(fLogFileDes, (off_t) 0, SEEK_CUR);
2690
2691 if (ltot >= 0 && lnow >= 0) {
2692 if (start > -1) {
2693 lseek(fLogFileDes, (off_t) start, SEEK_SET);
2694 if (end <= start || end > ltot)
2695 end = ltot;
2696 left = (Int_t)(end - start);
2697 if (end < ltot)
2698 left++;
2699 adhoc = kTRUE;
2700 } else {
2701 left = (Int_t)(ltot - lnow);
2702 }
2703 }
2704 }
2705
2706 if (left > 0) {
2707 if (fSocket->Send(left, kPROOF_LOGFILE) < 0) {
2708 SysError("SendLogFile", "error sending kPROOF_LOGFILE");
2709 return;
2710 }
2711
2712 const Int_t kMAXBUF = 32768; //16384 //65536;
2713 char buf[kMAXBUF];
2714 Int_t wanted = (left > kMAXBUF) ? kMAXBUF : left;
2715 Int_t len;
2716 do {
2717 while ((len = read(fLogFileDes, buf, wanted)) < 0 &&
2718 TSystem::GetErrno() == EINTR)
2720
2721 if (len < 0) {
2722 SysError("SendLogFile", "error reading log file");
2723 break;
2724 }
2725
2726 if (end == ltot && len == wanted)
2727 buf[len-1] = '\n';
2728
2729 if (fSocket->SendRaw(buf, len) < 0) {
2730 SysError("SendLogFile", "error sending log file");
2731 break;
2732 }
2733
2734 // Update counters
2735 left -= len;
2736 wanted = (left > kMAXBUF) ? kMAXBUF : left;
2737
2738 } while (len > 0 && left > 0);
2739 }
2740
2741 // Restore initial position if partial send
2742 if (adhoc && lnow >=0 )
2743 lseek(fLogFileDes, lnow, SEEK_SET);
2744
2746 if (IsMaster())
2747 mess << status << (fProof ? fProof->GetParallel() : 0);
2748 else
2749 mess << status << (Int_t) 1;
2750
2751 if (fSocket->Send(mess) < 0) {
2752 SysError("SendLogFile", "error sending kPROOF_LOGDONE");
2753 return;
2754 }
2755
2756 PDB(kGlobal, 1) Info("SendLogFile", "kPROOF_LOGDONE sent");
2757}
2758
2759////////////////////////////////////////////////////////////////////////////////
2760/// Send statistics of slave server to master or client.
2761
2763{
2764 Long64_t bytesread = TFile::GetFileBytesRead();
2765 Float_t cputime = fCpuTime, realtime = fRealTime;
2766 if (IsMaster()) {
2767 bytesread = fProof->GetBytesRead();
2768 cputime = fProof->GetCpuTime();
2769 }
2770
2772 TString workdir = gSystem->WorkingDirectory(); // expect TString on other side
2773 mess << bytesread << realtime << cputime << workdir;
2774 if (fProtocol >= 4) mess << TString(gProofServ->GetWorkDir());
2775 mess << TString(gProofServ->GetImage());
2776 fSocket->Send(mess);
2777}
2778
2779////////////////////////////////////////////////////////////////////////////////
2780/// Send number of parallel nodes to master or client.
2781
2783{
2784 Int_t nparallel = 0;
2785 if (IsMaster()) {
2786 PDB(kGlobal, 2)
2787 Info("SendParallel", "Will invoke AskParallel()");
2789 PDB(kGlobal, 2)
2790 Info("SendParallel", "Will invoke GetParallel()");
2791 nparallel = fProof->GetParallel();
2792 } else {
2793 nparallel = 1;
2794 }
2795
2797 mess << nparallel << async;
2798 fSocket->Send(mess);
2799}
2800
2801////////////////////////////////////////////////////////////////////////////////
2802/// Print the ProofServ logo on standard output.
2803/// Return 0 on success, -1 on failure
2804
2806{
2807 char str[512];
2808
2809 if (IsMaster()) {
2810 snprintf(str, 512, "**** Welcome to the PROOF server @ %s ****", gSystem->HostName());
2811 } else {
2812 snprintf(str, 512, "**** PROOF slave server @ %s started ****", gSystem->HostName());
2813 }
2814
2815 if (fSocket->Send(str) != 1+static_cast<Int_t>(strlen(str))) {
2816 Error("Setup", "failed to send proof server startup message");
2817 return -1;
2818 }
2819
2820 // exchange protocol level between client and master and between
2821 // master and slave
2822 Int_t what;
2823 if (fSocket->Recv(fProtocol, what) != 2*sizeof(Int_t)) {
2824 Error("Setup", "failed to receive remote proof protocol");
2825 return -1;
2826 }
2827 if (fSocket->Send(kPROOF_Protocol, kROOTD_PROTOCOL) != 2*sizeof(Int_t)) {
2828 Error("Setup", "failed to send local proof protocol");
2829 return -1;
2830 }
2831
2832 // If old version, setup authentication related stuff
2833 if (fProtocol < 5) {
2834 TString wconf;
2835 if (OldAuthSetup(wconf) != 0) {
2836 Error("Setup", "OldAuthSetup: failed to setup authentication");
2837 return -1;
2838 }
2839 if (IsMaster()) {
2840 fConfFile = wconf;
2841 fWorkDir.Form("~/%s", kPROOF_WorkDir);
2842 } else {
2843 if (fProtocol < 4) {
2844 fWorkDir.Form("~/%s", kPROOF_WorkDir);
2845 } else {
2846 fWorkDir = wconf;
2847 if (fWorkDir.IsNull()) fWorkDir.Form("~/%s", kPROOF_WorkDir);
2848 }
2849 }
2850 } else {
2851
2852 // Receive some useful information
2853 TMessage *mess;
2854 if ((fSocket->Recv(mess) <= 0) || !mess) {
2855 Error("Setup", "failed to receive ordinal and config info");
2856 return -1;
2857 }
2858 if (IsMaster()) {
2859 (*mess) >> fUser >> fOrdinal >> fConfFile;
2860 fWorkDir = gEnv->GetValue("ProofServ.Sandbox", TString::Format("~/%s", kPROOF_WorkDir));
2861 } else {
2862 (*mess) >> fUser >> fOrdinal >> fWorkDir;
2863 if (fWorkDir.IsNull())
2864 fWorkDir = gEnv->GetValue("ProofServ.Sandbox", TString::Format("~/%s", kPROOF_WorkDir));
2865 }
2866 // Set the correct prefix
2867 if (fOrdinal != "-1")
2868 fPrefix += fOrdinal;
2870 delete mess;
2871 }
2872
2873 if (IsMaster()) {
2874
2875 // strip off any prooftype directives
2876 TString conffile = fConfFile;
2877 conffile.Remove(0, 1 + conffile.Index(":"));
2878
2879 // parse config file to find working directory
2880 TProofResourcesStatic resources(fConfDir, conffile);
2881 if (resources.IsValid()) {
2882 if (resources.GetMaster()) {
2883 TString tmpWorkDir = resources.GetMaster()->GetWorkDir();
2884 if (tmpWorkDir != "")
2885 fWorkDir = tmpWorkDir;
2886 }
2887 } else {
2888 Info("Setup", "invalid config file %s (missing or unreadable",
2889 resources.GetFileName().Data());
2890 }
2891 }
2892
2893 // Set $HOME and $PATH. The HOME directory was already set to the
2894 // user's home directory by proofd.
2895 gSystem->Setenv("HOME", gSystem->HomeDirectory());
2896
2897 // Add user name in case of non default workdir
2898 if (fWorkDir.BeginsWith("/") &&
2900 if (!fWorkDir.EndsWith("/"))
2901 fWorkDir += "/";
2903 if (u) {
2904 fWorkDir += u->fUser;
2905 delete u;
2906 }
2907 }
2908
2909 // Goto to the main PROOF working directory
2911 if (gProofDebugLevel > 0)
2912 Info("Setup", "working directory set to %s", fWorkDir.Data());
2913
2914 // host first name
2915 TString host = gSystem->HostName();
2916 if (host.Index(".") != kNPOS)
2917 host.Remove(host.Index("."));
2918
2919 // Session tag
2920 fSessionTag.Form("%s-%s-%ld-%d", fOrdinal.Data(), host.Data(),
2921 (Long_t)TTimeStamp().GetSec(),gSystem->GetPid());
2923
2924 // create session directory and make it the working directory
2926 if (IsMaster())
2927 fSessionDir += "/master-";
2928 else
2929 fSessionDir += "/slave-";
2931
2932 // Common setup
2933 if (SetupCommon() != 0) {
2934 Error("Setup", "common setup failed");
2935 return -1;
2936 }
2937
2938 // Incoming OOB should generate a SIGURG
2940
2941 // Send packets off immediately to reduce latency
2943
2944 // Check every two hours if client is still alive
2946
2947 // Done
2948 return 0;
2949}
2950
2951////////////////////////////////////////////////////////////////////////////////
2952/// Common part (between TProofServ and TXProofServ) of the setup phase.
2953/// Return 0 on success, -1 on error
2954
2956{
2957 // deny write access for group and world
2958 gSystem->Umask(022);
2959
2960#ifdef R__UNIX
2961 // Add bindir to PATH
2962 TString path(gSystem->Getenv("PATH"));
2963 TString bindir(TROOT::GetBinDir());
2964 // Augment PATH, if required
2965 // ^<compiler>, <compiler>, ^<sysbin>, <sysbin>
2966 TString paths = gEnv->GetValue("ProofServ.BinPaths", "");
2967 if (paths.Length() > 0) {
2968 Int_t icomp = 0;
2969 if (paths.Contains("^<compiler>"))
2970 icomp = 1;
2971 else if (paths.Contains("<compiler>"))
2972 icomp = -1;
2973 if (icomp != 0) {
2974# ifdef COMPILER
2975 TString compiler = COMPILER;
2976 if (compiler.Index("is ") != kNPOS)
2977 compiler.Remove(0, compiler.Index("is ") + 3);
2978 compiler = gSystem->GetDirName(compiler);
2979 if (icomp == 1) {
2980 if (!bindir.IsNull()) bindir += ":";
2981 bindir += compiler;
2982 } else if (icomp == -1) {
2983 if (!path.IsNull()) path += ":";
2984 path += compiler;
2985 }
2986#endif
2987 }
2988 Int_t isysb = 0;
2989 if (paths.Contains("^<sysbin>"))
2990 isysb = 1;
2991 else if (paths.Contains("<sysbin>"))
2992 isysb = -1;
2993 if (isysb != 0) {
2994 if (isysb == 1) {
2995 if (!bindir.IsNull()) bindir += ":";
2996 bindir += "/bin:/usr/bin:/usr/local/bin";
2997 } else if (isysb == -1) {
2998 if (!path.IsNull()) path += ":";
2999 path += "/bin:/usr/bin:/usr/local/bin";
3000 }
3001 }
3002 }
3003 // Final insert
3004 if (!bindir.IsNull()) bindir += ":";
3005 path.Insert(0, bindir);
3006 gSystem->Setenv("PATH", path);
3007#endif
3008
3012 Error("SetupCommon", "can not change to PROOF directory %s",
3013 fWorkDir.Data());
3014 return -1;
3015 }
3016 } else {
3021 Error("SetupCommon", "can not change to PROOF directory %s",
3022 fWorkDir.Data());
3023 return -1;
3024 }
3025 }
3026 }
3027
3028 // Set group
3029 fGroup = gEnv->GetValue("ProofServ.ProofGroup", "default");
3030
3031 // Check and make sure "cache" directory exists
3032 fCacheDir = gEnv->GetValue("ProofServ.CacheDir",
3037 if (gProofDebugLevel > 0)
3038 Info("SetupCommon", "cache directory set to %s", fCacheDir.Data());
3039 fCacheLock =
3040 new TProofLockPath(TString::Format("%s/%s%s",
3042 TString(fCacheDir).ReplaceAll("/","%").Data()));
3043 // Make also sure the cache path is in the macro path
3045
3046 // Check and make sure "packages" directory exists
3047 TString packdir = gEnv->GetValue("ProofServ.PackageDir",
3049 ResolveKeywords(packdir);
3050 if (gSystem->AccessPathName(packdir))
3051 gSystem->mkdir(packdir, kTRUE);
3052 fPackMgr = new TPackMgr(packdir);
3054 // Notification message
3055 TString noth;
3056 const char *k = (IsMaster()) ? "Mst" : "Wrk";
3057 noth.Form("%s-%s", k, fOrdinal.Data());
3058 fPackMgr->SetPrefix(noth.Data());
3059 if (gProofDebugLevel > 0)
3060 Info("SetupCommon", "package directory set to %s", packdir.Data());
3061
3062 // Check and make sure "data" directory exists
3063 fDataDir = gEnv->GetValue("ProofServ.DataDir","");
3064 Ssiz_t isep = kNPOS;
3065 if (fDataDir.IsNull()) {
3066 // Use default
3067 fDataDir.Form("%s/%s/<ord>/<stag>", fWorkDir.Data(), kPROOF_DataDir);
3068 } else if ((isep = fDataDir.Last(' ')) != kNPOS) {
3069 fDataDirOpts = fDataDir(isep + 1, fDataDir.Length());
3070 fDataDir.Remove(isep);
3071 }
3074 if (gSystem->mkdir(fDataDir, kTRUE) != 0) {
3075 Warning("SetupCommon", "problems creating path '%s' (errno: %d)",
3077 }
3078 if (gProofDebugLevel > 0)
3079 Info("SetupCommon", "data directory set to %s", fDataDir.Data());
3080
3081 // Check and apply possible options
3082 // (see http://root.cern.ch/drupal/content/configuration-reference-guide#datadir)
3083 TString dataDirOpts = gEnv->GetValue("ProofServ.DataDirOpts","");
3084 if (!dataDirOpts.IsNull()) {
3085 // Do they apply to this server type
3086 Bool_t doit = kTRUE;
3087 if ((IsMaster() && !dataDirOpts.Contains("M")) ||
3088 (!IsMaster() && !dataDirOpts.Contains("W"))) doit = kFALSE;
3089 if (doit) {
3090 // Get the wanted mode
3091 UInt_t m = 0755;
3092 if (dataDirOpts.Contains("g")) m = 0775;
3093 if (dataDirOpts.Contains("a") || dataDirOpts.Contains("o")) m = 0777;
3094 if (gProofDebugLevel > 0)
3095 Info("SetupCommon", "requested mode for data directories is '%o'", m);
3096 // Loop over paths
3097 FileStat_t st;
3098 TString p, subp;
3099 Int_t from = 0;
3100 if (fDataDir.BeginsWith("/")) p = "/";
3101 while (fDataDir.Tokenize(subp, from, "/")) {
3102 if (subp.IsNull()) continue;
3103 p += subp;
3104 if (gSystem->GetPathInfo(p, st) == 0) {
3105 if (st.fUid == (Int_t) gSystem->GetUid() && st.fGid == (Int_t) gSystem->GetGid()) {
3106 if (gSystem->Chmod(p.Data(), m) != 0) {
3107 Warning("SetupCommon", "problems setting mode '%o' on path '%s' (errno: %d)",
3108 m, p.Data(), TSystem::GetErrno());
3109 break;
3110 }
3111 }
3112 p += "/";
3113 } else {
3114 Warning("SetupCommon", "problems stat-ing path '%s' (errno: %d; datadir: %s)",
3116 break;
3117 }
3118 }
3119 }
3120 }
3121
3122 // List of directories where to look for global packages
3123 TString globpack = gEnv->GetValue("Proof.GlobalPackageDirs","");
3124
3125 ResolveKeywords(globpack);
3126 Int_t nglb = TPackMgr::RegisterGlobalPath(globpack);
3127 Info("SetupCommon", " %d global package directories registered", nglb);
3128 FlushLogFile();
3129
3130 // Check the session dir
3136 Error("SetupCommon", "can not change to working directory '%s'",
3137 fSessionDir.Data());
3138 return -1;
3139 }
3140 }
3141 gSystem->Setenv("PROOF_SANDBOX", fSessionDir);
3142 if (gProofDebugLevel > 0)
3143 Info("SetupCommon", "session dir is '%s'", fSessionDir.Data());
3144
3145 // On masters, check and make sure that "queries" and "datasets"
3146 // directories exist
3147 if (IsMaster()) {
3148
3149 // Make sure that the 'queries' dir exist
3155 fQueryDir += TString("/session-") + fTopSessionTag;
3158 if (gProofDebugLevel > 0)
3159 Info("SetupCommon", "queries dir is %s", fQueryDir.Data());
3160
3161 // Create 'queries' locker instance and lock it
3162 fQueryLock = new TProofLockPath(TString::Format("%s/%s%s-%s",
3165 TString(fQueryDir).ReplaceAll("/","%").Data()));
3166 fQueryLock->Lock();
3167 // Create the query manager
3169 fQueryLock, 0);
3170 }
3171
3172 // Server image
3173 fImage = gEnv->GetValue("ProofServ.Image", "");
3174
3175 // Get the group priority
3176 if (IsMaster()) {
3177 // Send session tag to client
3179 m << fTopSessionTag << fGroup << fUser;
3180 fSocket->Send(m);
3181 // Group priority
3183 // Dataset manager instance via plug-in
3184 TPluginHandler *h = 0;
3185 TString dsms = gEnv->GetValue("Proof.DataSetManager", "");
3186 if (!dsms.IsNull()) {
3187 TString dsm;
3188 Int_t from = 0;
3189 while (dsms.Tokenize(dsm, from, ",")) {
3191 Warning("SetupCommon", "a valid dataset manager already initialized");
3192 Warning("SetupCommon", "support for multiple managers not yet available");
3193 break;
3194 }
3195 // Get plugin manager to load the appropriate TDataSetManager
3196 if (gROOT->GetPluginManager()) {
3197 // Find the appropriate handler
3198 h = gROOT->GetPluginManager()->FindHandler("TDataSetManager", dsm);
3199 if (h && h->LoadPlugin() != -1) {
3200 // make instance of the dataset manager
3202 reinterpret_cast<TDataSetManager*>(h->ExecPlugin(3, fGroup.Data(),
3203 fUser.Data(), dsm.Data()));
3204 }
3205 }
3206 }
3207 // Check the result of the dataset manager initialization
3209 Warning("SetupCommon", "dataset manager plug-in initialization failed");
3210 SendAsynMessage("TXProofServ::SetupCommon: dataset manager plug-in initialization failed");
3212 }
3213 } else {
3214 // Initialize the default dataset manager
3215 TString opts("Av:");
3216 TString dsetdir = gEnv->GetValue("ProofServ.DataSetDir", "");
3217 if (dsetdir.IsNull()) {
3218 // Use the default in the sandbox
3219 dsetdir.Form("%s/%s", fWorkDir.Data(), kPROOF_DataSetDir);
3222 opts += "Sb:";
3223 }
3224 // Find the appropriate handler
3225 if (!h) {
3226 h = gROOT->GetPluginManager()->FindHandler("TDataSetManager", "file");
3227 if (h && h->LoadPlugin() == -1) h = 0;
3228 }
3229 if (h) {
3230 // make instance of the dataset manager
3231 TString oo = TString::Format("dir:%s opt:%s", dsetdir.Data(), opts.Data());
3232 fDataSetManager = reinterpret_cast<TDataSetManager*>(h->ExecPlugin(3,
3233 fGroup.Data(), fUser.Data(), oo.Data()));
3234 }
3236 Warning("SetupCommon", "default dataset manager plug-in initialization failed");
3238 }
3239 }
3240 // Dataset manager for staging requests
3241 TString dsReqCfg = gEnv->GetValue("Proof.DataSetStagingRequests", "");
3242 if (!dsReqCfg.IsNull()) {
3243 TPMERegexp reReqDir("(^| )(dir:)?([^ ]+)( |$)");
3244
3245 if (reReqDir.Match(dsReqCfg) == 5) {
3246 TString dsDirFmt;
3247 dsDirFmt.Form("dir:%s perms:open", reReqDir[3].Data());
3248 fDataSetStgRepo = new TDataSetManagerFile("_stage_", "_stage_",
3249 dsDirFmt);
3250 if (fDataSetStgRepo &&
3252 Warning("SetupCommon",
3253 "failed init of dataset staging requests repository");
3255 }
3256 } else {
3257 Warning("SetupCommon",
3258 "specify, with [dir:]<path>, a valid path for staging requests");
3259 }
3260 } else if (gProofDebugLevel > 0) {
3261 Warning("SetupCommon", "no repository for staging requests available");
3262 }
3263 }
3264
3265 // Quotas
3266 TString quotas = gEnv->GetValue(TString::Format("ProofServ.UserQuotas.%s", fUser.Data()),"");
3267 if (quotas.IsNull())
3268 quotas = gEnv->GetValue(TString::Format("ProofServ.UserQuotasByGroup.%s", fGroup.Data()),"");
3269 if (quotas.IsNull())
3270 quotas = gEnv->GetValue("ProofServ.UserQuotas", "");
3271 if (!quotas.IsNull()) {
3272 // Parse it; format ("maxquerykept=10 hwmsz=800m maxsz=1g")
3273 TString tok;
3274 Ssiz_t from = 0;
3275 while (quotas.Tokenize(tok, from, " ")) {
3276 // Set max number of query results to keep
3277 if (tok.BeginsWith("maxquerykept=")) {
3278 tok.ReplaceAll("maxquerykept=","");
3279 if (tok.IsDigit())
3280 fMaxQueries = tok.Atoi();
3281 else
3282 Info("SetupCommon",
3283 "parsing 'maxquerykept' :ignoring token %s : not a digit", tok.Data());
3284 }
3285 // Set High-Water-Mark or max on the sandbox size
3286 const char *ksz[2] = {"hwmsz=", "maxsz="};
3287 for (Int_t j = 0; j < 2; j++) {
3288 if (tok.BeginsWith(ksz[j])) {
3289 tok.ReplaceAll(ksz[j],"");
3290 Long64_t fact = -1;
3291 if (!tok.IsDigit()) {
3292 // Parse (k, m, g)
3293 tok.ToLower();
3294 const char *s[3] = {"k", "m", "g"};
3295 Int_t i = 0, ki = 1024;
3296 while (fact < 0) {
3297 if (tok.EndsWith(s[i++]))
3298 fact = ki;
3299 else
3300 ki *= 1024;
3301 }
3302 tok.Remove(tok.Length()-1);
3303 }
3304 if (tok.IsDigit()) {
3305 if (j == 0)
3306 fHWMBoxSize = (fact > 0) ? tok.Atoi() * fact : tok.Atoi();
3307 else
3308 fMaxBoxSize = (fact > 0) ? tok.Atoi() * fact : tok.Atoi();
3309 } else {
3310 TString ssz(ksz[j], strlen(ksz[j])-1);
3311 Info("SetupCommon", "parsing '%s' : ignoring token %s", ssz.Data(), tok.Data());
3312 }
3313 }
3314 }
3315 }
3316 }
3317
3318 // Apply quotas, if any
3319 if (IsMaster() && fQMgr)
3321 Warning("SetupCommon", "problems applying fMaxQueries");
3322
3323 // Send "ROOTversion|ArchCompiler" flag
3324 if (fProtocol > 12) {
3325 TString vac = gROOT->GetVersion();
3326 vac += TString::Format(":%s", gROOT->GetGitCommit());
3327 TString rtag = gEnv->GetValue("ProofServ.RootVersionTag", "");
3328 if (rtag.Length() > 0)
3329 vac += TString::Format(":%s", rtag.Data());
3332 m << vac;
3333 fSocket->Send(m);
3334 }
3335
3336 // Set user vars in TProof
3337 TString all_vars(gSystem->Getenv("PROOF_ALLVARS"));
3338 TString name;
3339 Int_t from = 0;
3340 while (all_vars.Tokenize(name, from, ",")) {
3341 if (!name.IsNull()) {
3342 TString value = gSystem->Getenv(name);
3343 TProof::AddEnvVar(name, value);
3344 }
3345 }
3346
3347 if (fgLogToSysLog > 0) {
3348 // Set the syslog entity (all the information is available now)
3349 if (!(fUser.IsNull()) && !(fGroup.IsNull())) {
3350 fgSysLogEntity.Form("%s:%s", fUser.Data(), fGroup.Data());
3351 } else if (!(fUser.IsNull()) && fGroup.IsNull()) {
3352 fgSysLogEntity.Form("%s:default", fUser.Data());
3353 } else if (fUser.IsNull() && !(fGroup.IsNull())) {
3354 fgSysLogEntity.Form("undef:%s", fGroup.Data());
3355 }
3356 // Log the beginning of this session
3357 TString s;
3358 s.Form("%s 0 %.3f %.3f", fgSysLogEntity.Data(), fRealTime, fCpuTime);
3360 }
3361
3362 if (gProofDebugLevel > 0)
3363 Info("SetupCommon", "successfully completed");
3364
3365 // Done
3366 return 0;
3367}
3368
3369////////////////////////////////////////////////////////////////////////////////
3370/// Terminate the proof server.
3371
3373{
3374 if (fgLogToSysLog > 0) {
3375 TString s;
3376 s.Form("%s -1 %.3f %.3f %d", fgSysLogEntity.Data(), fRealTime, fCpuTime, status);
3378 }
3379
3380 // Notify the memory footprint
3381 ProcInfo_t pi;
3382 if (!gSystem->GetProcInfo(&pi)){
3383 Info("Terminate", "process memory footprint: %ld/%ld kB virtual, %ld/%ld kB resident ",
3385 }
3386
3387 // Cleanup session directory
3388 if (status == 0) {
3389 // make sure we remain in a "connected" directory
3391 // needed in case fSessionDir is on NFS ?!
3392 gSystem->MakeDirectory(fSessionDir+"/.delete");
3394 }
3395
3396 // Cleanup queries directory if empty
3397 if (IsMaster()) {
3398 if (!(fQMgr && fQMgr->Queries() && fQMgr->Queries()->GetSize())) {
3399 // make sure we remain in a "connected" directory
3401 // needed in case fQueryDir is on NFS ?!
3402 gSystem->MakeDirectory(fQueryDir+"/.delete");
3404 // Remove lock file
3405 if (fQueryLock)
3407 }
3408
3409 // Unlock the query dir owned by this session
3410 if (fQueryLock)
3411 fQueryLock->Unlock();
3412 }
3413
3414 // Cleanup data directory if empty
3417 Info("Terminate", "data directory '%s' has been removed", fDataDir.Data());
3418 }
3419
3420 // Remove input handler to avoid spurious signals in socket
3421 // selection for closing activities executed upon exit()
3423 TObject *fh = 0;
3424 while ((fh = next())) {
3425 TProofServInputHandler *ih = dynamic_cast<TProofServInputHandler *>(fh);
3426 if (ih)
3428 }
3429
3430 // Stop processing events
3431 gSystem->ExitLoop();
3432
3433 // Exit() is called in pmain
3434}
3435
3436////////////////////////////////////////////////////////////////////////////////
3437/// Scan recursively the datadir and unlink it if empty
3438/// Return kTRUE if it can be unlinked, kFALSE otherwise
3439
3441{
3442 if (!path || strlen(path) <= 0) return kFALSE;
3443
3444 Bool_t dorm = kTRUE;
3445 void *dirp = gSystem->OpenDirectory(path);
3446 if (dirp) {
3447 TString fpath;
3448 const char *ent = 0;
3449 while (dorm && (ent = gSystem->GetDirEntry(dirp))) {
3450 if (!strcmp(ent, ".") || !strcmp(ent, "..")) continue;
3451 fpath.Form("%s/%s", path, ent);
3452 FileStat_t st;
3453 if (gSystem->GetPathInfo(fpath, st) == 0 && R_ISDIR(st.fMode)) {
3454 dorm = UnlinkDataDir(fpath);
3455 } else {
3456 dorm = kFALSE;
3457 }
3458 }
3459 // Close the directory
3460 gSystem->FreeDirectory(dirp);
3461 } else {
3462 // Cannot open the directory
3463 dorm = kFALSE;
3464 }
3465
3466 // Do remove, if required
3467 if (dorm && gSystem->Unlink(path) != 0)
3468 Warning("UnlinkDataDir", "data directory '%s' is empty but could not be removed", path);
3469 // done
3470 return dorm;
3471}
3472
3473////////////////////////////////////////////////////////////////////////////////
3474/// Static function that returns kTRUE in case we are a PROOF server.
3475
3477{
3478 return gProofServ ? kTRUE : kFALSE;
3479}
3480
3481////////////////////////////////////////////////////////////////////////////////
3482/// Static function returning pointer to global object gProofServ.
3483/// Mainly for use via CINT, where the gProofServ symbol might be
3484/// deleted from the symbol table.
3485
3487{
3488 return gProofServ;
3489}
3490
3491////////////////////////////////////////////////////////////////////////////////
3492/// Setup authentication related stuff for old versions.
3493/// Provided for backward compatibility.
3494
3496{
3497 OldProofServAuthSetup_t oldAuthSetupHook = 0;
3498
3499 if (!oldAuthSetupHook) {
3500 // Load libraries needed for (server) authentication ...
3501 TString authlib = "libRootAuth";
3502 char *p = 0;
3503 // The generic one
3504 if ((p = gSystem->DynamicPathName(authlib, kTRUE))) {
3505 delete[] p;
3506 if (gSystem->Load(authlib) == -1) {
3507 Error("OldAuthSetup", "can't load %s",authlib.Data());
3508 return kFALSE;
3509 }
3510 } else {
3511 Error("OldAuthSetup", "can't locate %s",authlib.Data());
3512 return -1;
3513 }
3514 //
3515 // Locate OldProofServAuthSetup
3516 Func_t f = gSystem->DynFindSymbol(authlib,"OldProofServAuthSetup");
3517 if (f)
3518 oldAuthSetupHook = (OldProofServAuthSetup_t)(f);
3519 else {
3520 Error("OldAuthSetup", "can't find OldProofServAuthSetup");
3521 return -1;
3522 }
3523 }
3524 //
3525 // Setup
3526 return (*oldAuthSetupHook)(fSocket, IsMaster(), fProtocol,
3527 fUser, fOrdinal, conf);
3528}
3529
3530////////////////////////////////////////////////////////////////////////////////
3531/// Create a TProofQueryResult instance for this query.
3532
3534 const char *opt,
3535 TList *inlist, Long64_t fst,
3536 TDSet *dset, const char *selec,
3537 TObject *elist)
3538{
3539 // Increment sequential number
3540 Int_t seqnum = -1;
3541 if (fQMgr) {
3543 seqnum = fQMgr->SeqNum();
3544 }
3545
3546 // Locally we always use the current streamer
3547 Bool_t olds = (dset && dset->TestBit(TDSet::kWriteV3)) ? kTRUE : kFALSE;
3548 if (olds)
3549 dset->SetWriteV3(kFALSE);
3550
3551 // Create the instance and add it to the list
3552 TProofQueryResult *pqr = new TProofQueryResult(seqnum, opt, inlist, nent,
3553 fst, dset, selec, elist);
3554 // Title is the session identifier
3556
3557 // Restore old streamer info
3558 if (olds)
3559 dset->SetWriteV3(kTRUE);
3560
3561 return pqr;
3562}
3563
3564////////////////////////////////////////////////////////////////////////////////
3565/// Set query in running state.
3566
3568{
3569 // Record current position in the log file at start
3570 fflush(stdout);
3571 Int_t startlog = lseek(fileno(stdout), (off_t) 0, SEEK_END);
3572
3573 // Add some header to logs
3574 Printf(" ");
3575 Info("SetQueryRunning", "starting query: %d", pq->GetSeqNum());
3576
3577 // Build the list of loaded PAR packages
3578 TString parlist = "";
3579 fPackMgr->GetEnabledPackages(parlist);
3580
3581 if (fProof) {
3582 // Set in running state
3583 pq->SetRunning(startlog, parlist, fProof->GetParallel());
3584
3585 // Bytes and CPU at start (we will calculate the differential at end)
3586 pq->SetProcessInfo(pq->GetEntries(),
3588 } else {
3589 // Set in running state
3590 pq->SetRunning(startlog, parlist, -1);
3591
3592 // Bytes and CPU at start (we will calculate the differential at end)
3593 pq->SetProcessInfo(pq->GetEntries(), float(0.), 0);
3594 }
3595}
3596
3597////////////////////////////////////////////////////////////////////////////////
3598/// Handle archive request.
3599
3601{
3602 PDB(kGlobal, 1)
3603 Info("HandleArchive", "Enter");
3604
3605 TString queryref;
3606 TString path;
3607 (*mess) >> queryref >> path;
3608
3609 if (slb) slb->Form("%s %s", queryref.Data(), path.Data());
3610
3611 // If this is a set default action just save the default
3612 if (queryref == "Default") {
3613 fArchivePath = path;
3614 Info("HandleArchive",
3615 "default path set to %s", fArchivePath.Data());
3616 return;
3617 }
3618
3619 Int_t qry = -1;
3620 TString qdir;
3621 TProofQueryResult *pqr = fQMgr ? fQMgr->LocateQuery(queryref, qry, qdir) : 0;
3622 TProofQueryResult *pqm = pqr;
3623
3624 if (path.Length() <= 0) {
3625 if (fArchivePath.Length() <= 0) {
3626 Info("HandleArchive",
3627 "archive paths are not defined - do nothing");
3628 return;
3629 }
3630 if (qry > 0) {
3631 path.Form("%s/session-%s-%d.root",
3633 } else {
3634 path = queryref;
3635 path.ReplaceAll(":q","-");
3636 path.Insert(0, TString::Format("%s/",fArchivePath.Data()));
3637 path += ".root";
3638 }
3639 }
3640
3641 // Build file name for specific query
3642 if (!pqr || qry < 0) {
3643 TString fout = qdir;
3644 fout += "/query-result.root";
3645
3646 TFile *f = TFile::Open(fout,"READ");
3647 pqr = 0;
3648 if (f) {
3649 f->ReadKeys();
3650 TIter nxk(f->GetListOfKeys());
3651 TKey *k = 0;
3652 while ((k = (TKey *)nxk())) {
3653 if (!strcmp(k->GetClassName(), "TProofQueryResult")) {
3654 pqr = (TProofQueryResult *) f->Get(k->GetName());
3655 if (pqr)
3656 break;
3657 }
3658 }
3659 f->Close();
3660 delete f;
3661 } else {
3662 Info("HandleArchive",
3663 "file cannot be open (%s)",fout.Data());
3664 return;
3665 }
3666 }
3667
3668 if (pqr) {
3669
3670 PDB(kGlobal, 1) Info("HandleArchive",
3671 "archive path for query #%d: %s",
3672 qry, path.Data());
3673 TFile *farc = 0;
3674 if (gSystem->AccessPathName(path))
3675 farc = TFile::Open(path,"NEW");
3676 else
3677 farc = TFile::Open(path,"UPDATE");
3678 if (!farc || !(farc->IsOpen())) {
3679 Info("HandleArchive",
3680 "archive file cannot be open (%s)",path.Data());
3681 return;
3682 }
3683 farc->cd();
3684
3685 // Update query status
3686 pqr->SetArchived(path);
3687 if (pqm)
3688 pqm->SetArchived(path);
3689
3690 // Write to file
3691 pqr->Write();
3692
3693 // Update temporary files too
3694 if (qry > -1 && fQMgr)
3695 fQMgr->SaveQuery(pqr);
3696
3697 // Notify
3698 Info("HandleArchive",
3699 "results of query %s archived to file %s",
3700 queryref.Data(), path.Data());
3701 }
3702
3703 // Done
3704 return;
3705}
3706
3707////////////////////////////////////////////////////////////////////////////////
3708/// Get a map {server-name, list-of-files} for collection 'fc' to be used in
3709/// TPacketizerFile. Returns a pointer to the map (ownership of the caller).
3710/// Or (TMap *)0 and an error message in emsg.
3711
3713{
3714 TMap *fcmap = 0;
3715 emsg = "";
3716
3717 // Sanity checks
3718 if (!fc) {
3719 emsg.Form("file collection undefined!");
3720 return fcmap;
3721 }
3722
3723 // Prepare data set map
3724 fcmap = new TMap();
3725
3726 TIter nxf(fc->GetList());
3727 TFileInfo *fiind = 0;
3728 TString key;
3729 while ((fiind = (TFileInfo *)nxf())) {
3730 TUrl *xurl = fiind->GetCurrentUrl();
3731 // Find the key for this server
3732 key.Form("%s://%s", xurl->GetProtocol(), xurl->GetHostFQDN());
3733 if (xurl->GetPort() > 0)
3734 key += TString::Format(":%d", xurl->GetPort());
3735 // Get the map entry for this key
3736 TPair *ent = 0;
3737 THashList* l = 0;
3738 if ((ent = (TPair *) fcmap->FindObject(key.Data()))) {
3739 // Attach to the list
3740 l = (THashList *) ent->Value();
3741 } else {
3742 // Create list
3743 l = new THashList;
3744 l->SetOwner(kTRUE);
3745 // Add it to the map
3746 fcmap->Add(new TObjString(key.Data()), l);
3747 }
3748 // Add fileinfo with index to list
3749 l->Add(fiind);
3750 }
3751
3752 // Done
3753 return fcmap;
3754}
3755
3756////////////////////////////////////////////////////////////////////////////////
3757/// Handle processing request.
3758
3760{
3761 PDB(kGlobal, 1)
3762 Info("HandleProcess", "Enter");
3763
3764 // Nothing to do for slaves if we are not idle
3765 if (!IsTopMaster() && !IsIdle())
3766 return;
3767
3768 TDSet *dset;
3769 TString filename, opt;
3770 TList *input;
3772 TEventList *evl = 0;
3773 TEntryList *enl = 0;
3774 Bool_t sync;
3775
3776 (*mess) >> dset >> filename >> input >> opt >> nentries >> first >> evl >> sync;
3777 // Get entry list information, if any (support started with fProtocol == 15)
3778 if ((mess->BufferSize() > mess->Length()) && fProtocol > 14)
3779 (*mess) >> enl;
3780 Bool_t hasNoData = (!dset || dset->TestBit(TDSet::kEmpty)) ? kTRUE : kFALSE;
3781
3782 // Priority to the entry list
3783 TObject *elist = (enl) ? (TObject *)enl : (TObject *)evl;
3784 if (enl && evl)
3785 // Cannot specify both at the same time
3786 SafeDelete(evl);
3787 if ((!hasNoData) && elist)
3788 dset->SetEntryList(elist);
3789
3790 if (IsTopMaster()) {
3791
3792 TString emsg;
3793 // Make sure the dataset contains the information needed
3794 if ((!hasNoData) && dset->GetListOfElements()->GetSize() == 0) {
3795 if (TProof::AssertDataSet(dset, input, fDataSetManager, emsg) != 0) {
3796 SendAsynMessage(TString::Format("AssertDataSet on %s: %s",
3797 fPrefix.Data(), emsg.Data()));
3798 Error("HandleProcess", "AssertDataSet: %s", emsg.Data());
3799 // To terminate collection
3800 if (sync) SendLogFile();
3801 return;
3802 }
3803 } else if (hasNoData) {
3804 // Check if we are required to process with TPacketizerFile a registered dataset
3805 TNamed *ftp = dynamic_cast<TNamed *>(input->FindObject("PROOF_FilesToProcess"));
3806 if (ftp) {
3807 TString dsn(ftp->GetTitle());
3808 if (!dsn.Contains(":") || dsn.BeginsWith("dataset:")) {
3809 dsn.ReplaceAll("dataset:", "");
3810 // Get the map for TPacketizerFile
3811 // Make sure we have something in input and a dataset manager
3812 if (!fDataSetManager) {
3813 emsg.Form("dataset manager not initialized!");
3814 } else {
3815 TFileCollection *fc = 0;
3816 // Get the dataset
3817 if (!(fc = fDataSetManager->GetDataSet(dsn))) {
3818 emsg.Form("requested dataset '%s' does not exists", dsn.Data());
3819 } else {
3820 TMap *fcmap = GetDataSetNodeMap(fc, emsg);
3821 if (fcmap) {
3822 input->Remove(ftp);
3823 delete ftp;
3824 fcmap->SetOwner(kTRUE);
3825 fcmap->SetName("PROOF_FilesToProcess");
3826 input->Add(fcmap);
3827 }
3828 }
3829 }
3830 if (!emsg.IsNull()) {
3831 SendAsynMessage(TString::Format("HandleProcess on %s: %s",
3832 fPrefix.Data(), emsg.Data()));
3833 Error("HandleProcess", "%s", emsg.Data());
3834 // To terminate collection
3835 if (sync) SendLogFile();
3836 return;
3837 }
3838 }
3839 }
3840 }
3841
3842 TProofQueryResult *pq = 0;
3843
3844 // Create instance of query results; we set ownership of the input list
3845 // to the TQueryResult object, to avoid too many instantiations
3846 pq = MakeQueryResult(nentries, opt, 0, first, 0, filename, 0);
3847
3848 // Prepare the input list and transfer it into the TQueryResult object
3849 if (dset) input->Add(dset);
3850 if (elist) input->Add(elist);
3851 pq->SetInputList(input, kTRUE);
3852
3853 // Clear the list
3854 input->Clear("nodelete");
3855 SafeDelete(input);
3856
3857 // Save input data, if any
3858 if (TProof::SaveInputData(pq, fCacheDir.Data(), emsg) != 0)
3859 Warning("HandleProcess", "could not save input data: %s", emsg.Data());
3860
3861 // If not a draw action add the query to the main list
3862 if (!(pq->IsDraw())) {
3863 if (fQMgr) {
3864 if (fQMgr->Queries()) fQMgr->Queries()->Add(pq);
3865 // Also save it to queries dir
3866 fQMgr->SaveQuery(pq);
3867 }
3868 }
3869
3870 // Add anyhow to the waiting lists
3871 QueueQuery(pq);
3872
3873 // Call get Workers
3874 // if we are not idle the scheduler will just enqueue the query and
3875 // send a resume message later.
3876
3877 Bool_t enqueued = kFALSE;
3878 Int_t pc = 0;
3879 // if the session does not have workers and is in the dynamic mode
3880 if (fProof->UseDynamicStartup()) {
3881 // get the a list of workers and start them
3882 TList* workerList = new TList();
3883 EQueryAction retVal = GetWorkers(workerList, pc);
3884 if (retVal == TProofServ::kQueryStop) {
3885 Error("HandleProcess", "error getting list of worker nodes");
3886 // To terminate collection
3887 if (sync) SendLogFile();
3888 return;
3889 } else if (retVal == TProofServ::kQueryEnqueued) {
3890 // change to an asynchronous query
3891 enqueued = kTRUE;
3892 Info("HandleProcess", "query %d enqueued", pq->GetSeqNum());
3893 } else {
3894 Int_t ret = fProof->AddWorkers(workerList);
3895 if (ret < 0) {
3896 Error("HandleProcess", "Adding a list of worker nodes returned: %d",
3897 ret);
3898 // To terminate collection
3899 if (sync) SendLogFile();
3900 return;
3901 }
3902 }
3903 } else {
3904 EQueryAction retVal = GetWorkers(0, pc);
3905 if (retVal == TProofServ::kQueryStop) {
3906 Error("HandleProcess", "error getting list of worker nodes");
3907 // To terminate collection
3908 if (sync) SendLogFile();
3909 return;
3910 } else if (retVal == TProofServ::kQueryEnqueued) {
3911 // change to an asynchronous query
3912 enqueued = kTRUE;
3913 Info("HandleProcess", "query %d enqueued", pq->GetSeqNum());
3914 } else if (retVal != TProofServ::kQueryOK) {
3915 Error("HandleProcess", "unknown return value: %d", retVal);
3916 // To terminate collection
3917 if (sync) SendLogFile();
3918 return;
3919 }
3920 }
3921
3922 // If the client submission was asynchronous, signal the submission of
3923 // the query and communicate the assigned sequential number for later
3924 // identification
3926 if (!sync || enqueued) {
3927 m << pq->GetSeqNum() << kFALSE;
3928 fSocket->Send(m);
3929 }
3930
3931 // Nothing more to do if we are not idle
3932 if (!IsIdle()) {
3933 // Notify submission
3934 Info("HandleProcess",
3935 "query \"%s:%s\" submitted", pq->GetTitle(), pq->GetName());
3936 return;
3937 }
3938
3939 // Process
3940 // in the static mode, if a session is enqueued it will be processed after current query
3941 // (there is no way to enqueue if idle).
3942 // in the dynamic mode we will process here only if the session was idle and got workers!
3943 Bool_t doprocess = kFALSE;
3944 while (WaitingQueries() > 0 && !enqueued) {
3945 doprocess = kTRUE;
3946 //
3947 ProcessNext(slb);
3948 // avoid processing async queries sent during processing in dyn mode
3950 enqueued = kTRUE;
3951
3952 } // Loop on submitted queries
3953
3954 // Set idle
3955 SetIdle(kTRUE);
3956
3957 // Reset mergers
3959
3960 // kPROOF_SETIDLE sets the client to idle; in asynchronous mode clients monitor
3961 // TProof::IsIdle for to check the readiness of a query, so we need to send this
3962 // before to be sure thatn everything about a query is received by the client
3963 if (!sync) SendLogFile();
3964
3965 // Signal the client that we are idle
3966 if (doprocess) {
3967 m.Reset(kPROOF_SETIDLE);
3968 Bool_t waiting = (WaitingQueries() > 0) ? kTRUE : kFALSE;
3969 m << waiting;
3970 fSocket->Send(m);
3971 }
3972
3973 // In synchronous mode TProof::Collect is terminated by the reception of the
3974 // log file and subsequent submissions are controlled by TProof::IsIdle(), so
3975 // this must be last one to be sent
3976 if (sync) SendLogFile();
3977
3978 // Set idle
3979 SetIdle(kTRUE);
3980
3981 } else {
3982
3983 // Reset compute stopwatch: we include all what done from now on
3984 fCompute.Reset();
3985 fCompute.Start();
3986
3987 // Set not idle
3988 SetIdle(kFALSE);
3989
3990 // Cleanup the player
3991 Bool_t deleteplayer = kTRUE;
3992 MakePlayer();
3993
3994 // Setup data set
3995 if (dset && (dset->IsA() == TDSetProxy::Class()))
3996 ((TDSetProxy*)dset)->SetProofServ(this);
3997
3998 // Get input data, if any
3999 TString emsg;
4000 if (TProof::GetInputData(input, fCacheDir.Data(), emsg) != 0)
4001 Warning("HandleProcess", "could not get input data: %s", emsg.Data());
4002
4003 // Get query sequential number
4004 if (TProof::GetParameter(input, "PROOF_QuerySeqNum", fQuerySeqNum) != 0)
4005 Warning("HandleProcess", "could not get query sequential number!");
4006
4007 // Make the ordinal number available in the selector
4008 TObject *nord = 0;
4009 while ((nord = input->FindObject("PROOF_Ordinal")))
4010 input->Remove(nord);
4011 input->Add(new TNamed("PROOF_Ordinal", GetOrdinal()));
4012
4013 // Set input
4014 TIter next(input);
4015 TObject *o = 0;
4016 while ((o = next())) {
4017 PDB(kGlobal, 2) Info("HandleProcess", "adding: %s", o->GetName());
4018 fPlayer->AddInput(o);
4019 }
4020
4021 // Check if a TSelector object is passed via input list
4022 TObject *obj = 0;
4023 TSelector *selector_obj = 0;
4024 TIter nxt(input);
4025 while ((obj = nxt())){
4026 if (obj->InheritsFrom("TSelector")) {
4027 selector_obj = (TSelector *) obj;
4028 filename = selector_obj->ClassName();
4029 Info("HandleProcess", "selector obj for '%s' found", selector_obj->ClassName());
4030 break;
4031 }
4032 }
4033
4034 // Signal the master that we are starting processing
4036
4037 // Reset latency stopwatch
4038 fLatency.Reset();
4040
4041 // Process
4042 PDB(kGlobal, 1) Info("HandleProcess", "calling %s::Process()", fPlayer->IsA()->GetName());
4043
4044 if (selector_obj){
4045 Info("HandleProcess", "calling fPlayer->Process() with selector object: %s", selector_obj->ClassName());
4046 fPlayer->Process(dset, selector_obj, opt, nentries, first);
4047 }
4048 else {
4049 Info("HandleProcess", "calling fPlayer->Process() with selector name: %s", filename.Data());
4050 fPlayer->Process(dset, filename, opt, nentries, first);
4051 }
4052
4053 // Return number of events processed
4056 if (fProtocol > 18) {
4057 TProofProgressStatus* status =
4059 gPerfStats?gPerfStats->GetBytesRead():0);
4060 if (status)
4061 m << status << abort;
4062 if (slb)
4063 slb->Form("%d %lld %lld", fPlayer->GetExitStatus(),
4064 status->GetEntries(), status->GetBytesRead());
4065 SafeDelete(status);
4066 } else {
4067 m << fPlayer->GetEventsProcessed() << abort;
4068 if (slb)
4069 slb->Form("%d %lld -1", fPlayer->GetExitStatus(), fPlayer->GetEventsProcessed());
4070 }
4071
4072 fSocket->Send(m);
4073 PDB(kGlobal, 2)
4074 Info("TProofServ::Handleprocess",
4075 "worker %s has finished processing with %d objects in output list",
4077
4078 // Cleanup the input data set info
4079 SafeDelete(dset);
4080 SafeDelete(enl);
4081 SafeDelete(evl);
4082
4085 if (outok) {
4086 // Check if in controlled output sending mode or submerging
4087 Int_t cso = 0;
4088 Bool_t isSubMerging = kFALSE;
4089
4090 // Check if we are in merging mode (i.e. parameter PROOF_UseMergers exists)
4091 Int_t nm = 0;
4092 if (TProof::GetParameter(input, "PROOF_UseMergers", nm) == 0) {
4093 isSubMerging = (nm >= 0) ? kTRUE : kFALSE;
4094 }
4095 if (!isSubMerging) {
4096 cso = gEnv->GetValue("Proof.ControlSendOutput", 1);
4097 if (TProof::GetParameter(input, "PROOF_ControlSendOutput", cso) != 0)
4098 cso = gEnv->GetValue("Proof.ControlSendOutput", 1);
4099 }
4100
4101 if (cso > 0) {
4102
4103 // Control output sending mode: wait for the master to ask for the objects.
4104 // Allows controls of memory usage on the master.
4106 fSocket->Send(msg);
4107
4108 // Set idle
4109 SetIdle(kTRUE);
4110
4111 // Do not cleanup the player yet: it will be used in sending output activities
4112 deleteplayer = kFALSE;
4113
4114 PDB(kGlobal, 1)
4115 Info("HandleProcess", "controlled mode: worker %s has finished,"
4116 " sizes sent to master", fOrdinal.Data());
4117 } else {
4118
4119 // Check if we are in merging mode (i.e. parameter PROOF_UseMergers exists)
4121 if (isSubMerging)
4122 Info("HandleProcess", "submerging disabled because of high-memory case");
4123 isSubMerging = kFALSE;
4124 } else {
4125 PDB(kGlobal, 2) Info("HandleProcess", "merging mode check: %d", isSubMerging);
4126 }
4127
4128 if (!IsMaster() && isSubMerging) {
4129 // Worker in merging mode.
4130 //----------------------------
4131 // First, it reports only the size of its output to the master
4132 // + port on which it can possibly accept outputs from other workers if it becomes a merger
4133 // Master will later tell it where it should send the output (either to the master or to some merger)
4134 // or if it should become a merger
4135
4136 TMessage msg_osize(kPROOF_SUBMERGER);
4137 msg_osize << Int_t(TProof::kOutputSize);
4138 msg_osize << fPlayer->GetOutputList()->GetEntries();
4139
4141 Int_t merge_port = 0;
4142 if (fMergingSocket) {
4143 PDB(kGlobal, 2)
4144 Info("HandleProcess", "possible port for merging connections: %d",
4146 merge_port = fMergingSocket->GetLocalPort();
4147 }
4148 msg_osize << merge_port;
4149 fSocket->Send(msg_osize);
4150
4151 // Set idle
4152 SetIdle(kTRUE);
4153
4154 // Do not cleanup the player yet: it will be used in sub-merging activities
4155 deleteplayer = kFALSE;
4156
4157 PDB(kSubmerger, 2) Info("HandleProcess", "worker %s has finished", fOrdinal.Data());
4158
4159 } else {
4160 // Sub-master OR worker not in merging mode
4161 // ---------------------------------------------
4162 PDB(kGlobal, 2) Info("HandleProcess", "sending result directly to master");
4164 Warning("HandleProcess","problems sending output list");
4165
4166 // Masters reset the mergers, if any
4167 if (IsMaster()) fProof->ResetMergers();
4168
4169 // Signal the master that we are idle
4171
4172 // Set idle
4173 SetIdle(kTRUE);
4174
4175 // Notify the user
4176 SendLogFile();
4177 }
4178
4179
4180
4181 }
4182
4183 } else {
4184 // No output list
4186 Warning("HandleProcess","the output list is empty!");
4187 if (SendResults(fSocket) != 0)
4188 Warning("HandleProcess", "problems sending output list");
4189
4190 // Masters reset the mergers, if any
4191 if (IsMaster()) fProof->ResetMergers();
4192
4193 // Signal the master that we are idle
4195
4196 // Set idle
4197 SetIdle(kTRUE);
4198
4199 // Notify the user
4200 SendLogFile();
4201 }
4202
4203 // Prevent from double-deleting in input
4204 TIter nex(input);
4205 while ((obj = nex())) {
4206 if (obj->InheritsFrom("TSelector")) input->Remove(obj);
4207 }
4208
4209 // Make also sure the input list objects are deleted
4211
4212 // Remove possible inputs from a file and the file, if any
4213 TList *added = dynamic_cast<TList *>(input->FindObject("PROOF_InputObjsFromFile"));
4214 if (added) {
4215 if (added->GetSize() > 0) {
4216 // The file must be the last one
4217 TFile *f = dynamic_cast<TFile *>(added->Last());
4218 if (f) {
4219 added->Remove(f);
4220 TIter nxo(added);
4221 while ((o = nxo())) { input->Remove(o); }
4222 input->Remove(added);
4223 added->SetOwner(kFALSE);
4224 added->Clear();
4225 f->Close();
4226 delete f;
4227 }
4228 }
4229 SafeDelete(added);
4230 }
4231 input->SetOwner();
4232 SafeDelete(input);
4233
4234 // Cleanup if required
4235 if (deleteplayer) DeletePlayer();
4236 }
4237
4238 PDB(kGlobal, 1) Info("HandleProcess", "done");
4239
4240 // Done
4241 return;
4242}
4243
4244////////////////////////////////////////////////////////////////////////////////
4245/// Sends all objects from the given list to the specified socket
4246
4248{
4249 PDB(kOutput, 2) Info("SendResults", "enter");
4250
4251 TString msg;
4252 if (fProtocol > 23 && outlist) {
4253 // Send objects in bunches of max fMsgSizeHWM bytes to optimize transfer
4254 // Objects are merged one-by-one by the client
4255 // Messages for objects
4257 // Objects in the output list
4258 Int_t olsz = outlist->GetSize();
4259 if (IsTopMaster() && pq) {
4260 msg.Form("%s: merging output objects ... done ",
4261 fPrefix.Data());
4262 SendAsynMessage(msg.Data());
4263 // Message for the client
4264 msg.Form("%s: objects merged; sending output: %d objs", fPrefix.Data(), olsz);
4265 SendAsynMessage(msg.Data(), kFALSE);
4266 // Send light query info
4267 mbuf << (Int_t) 0;
4268 mbuf.WriteObject(pq);
4269 if (sock->Send(mbuf) < 0) return -1;
4270 }
4271 // Objects in the output list
4272 Int_t ns = 0, np = 0;
4273 TIter nxo(outlist);
4274 TObject *o = 0;
4275 Int_t totsz = 0, objsz = 0;
4276 mbuf.Reset();
4277 while ((o = nxo())) {
4278 if (mbuf.Length() > fMsgSizeHWM) {
4279 PDB(kOutput, 1)
4280 Info("SendResults",
4281 "message has %d bytes: limit of %lld bytes reached - sending ...",
4282 mbuf.Length(), fMsgSizeHWM);
4283 // Compress the message, if required; for these messages we do it already
4284 // here so we get the size; TXSocket does not do it twice.
4285 if (GetCompressionLevel() > 0) {
4287 mbuf.Compress();
4288 objsz = mbuf.CompLength();
4289 } else {
4290 objsz = mbuf.Length();
4291 }
4292 totsz += objsz;
4293 if (IsTopMaster()) {
4294 msg.Form("%s: objects merged; sending obj %d/%d (%d bytes) ",
4295 fPrefix.Data(), ns, olsz, objsz);
4296 SendAsynMessage(msg.Data(), kFALSE);
4297 }
4298 if (sock->Send(mbuf) < 0) return -1;
4299 // Reset the message
4300 mbuf.Reset();
4301 np = 0;
4302 }
4303 ns++;
4304 np++;
4305 mbuf << (Int_t) ((ns >= olsz) ? 2 : 1);
4306 mbuf << o;
4307 }
4308 if (np > 0) {
4309 // Compress the message, if required; for these messages we do it already
4310 // here so we get the size; TXSocket does not do it twice.
4311 if (GetCompressionLevel() > 0) {
4313 mbuf.Compress();
4314 objsz = mbuf.CompLength();
4315 } else {
4316 objsz = mbuf.Length();
4317 }
4318 totsz += objsz;
4319 if (IsTopMaster()) {
4320 msg.Form("%s: objects merged; sending obj %d/%d (%d bytes) ",
4321 fPrefix.Data(), ns, olsz, objsz);
4322 SendAsynMessage(msg.Data(), kFALSE);
4323 }
4324 if (sock->Send(mbuf) < 0) return -1;
4325 }
4326 if (IsTopMaster()) {
4327 // Send total size
4328 msg.Form("%s: grand total: sent %d objects, size: %d bytes ",
4329 fPrefix.Data(), olsz, totsz);
4330 SendAsynMessage(msg.Data());
4331 }
4332 } else if (fProtocol > 10 && outlist) {
4333
4334 // Send objects one-by-one to optimize transfer and merging
4335 // Messages for objects
4337 // Objects in the output list
4338 Int_t olsz = outlist->GetSize();
4339 if (IsTopMaster() && pq) {
4340 msg.Form("%s: merging output objects ... done ",
4341 fPrefix.Data());
4342 SendAsynMessage(msg.Data());
4343 // Message for the client
4344 msg.Form("%s: objects merged; sending output: %d objs", fPrefix.Data(), olsz);
4345 SendAsynMessage(msg.Data(), kFALSE);
4346 // Send light query info
4347 mbuf << (Int_t) 0;
4348 mbuf.WriteObject(pq);
4349 if (sock->Send(mbuf) < 0) return -1;
4350 }
4351
4352 Int_t ns = 0;
4353 Int_t totsz = 0, objsz = 0;
4354 TIter nxo(fPlayer->GetOutputList());
4355 TObject *o = 0;
4356 while ((o = nxo())) {
4357 ns++;
4358 mbuf.Reset();
4359 Int_t type = (Int_t) ((ns >= olsz) ? 2 : 1);
4360 mbuf << type;
4361 mbuf.WriteObject(o);
4362 // Compress the message, if required; for these messages we do it already
4363 // here so we get the size; TXSocket does not do it twice.
4364 if (GetCompressionLevel() > 0) {
4366 mbuf.Compress();
4367 objsz = mbuf.CompLength();
4368 } else {
4369 objsz = mbuf.Length();
4370 }
4371 totsz += objsz;
4372 if (IsTopMaster()) {
4373 msg.Form("%s: objects merged; sending obj %d/%d (%d bytes) ",
4374 fPrefix.Data(), ns, olsz, objsz);
4375 SendAsynMessage(msg.Data(), kFALSE);
4376 }
4377 if (sock->Send(mbuf) < 0) return -1;
4378 }
4379 // Total size
4380 if (IsTopMaster()) {
4381 // Send total size
4382 msg.Form("%s: grand total: sent %d objects, size: %d bytes ",
4383 fPrefix.Data(), olsz, totsz);
4384 SendAsynMessage(msg.Data());
4385 }
4386
4387 } else if (IsTopMaster() && fProtocol > 6 && outlist) {
4388
4389 // Buffer to be sent
4391 mbuf.WriteObject(pq);
4392 // Sizes
4393 Int_t blen = mbuf.CompLength();
4394 Int_t olsz = outlist->GetSize();
4395 // Message for the client
4396 msg.Form("%s: sending output: %d objs, %d bytes", fPrefix.Data(), olsz, blen);
4397 SendAsynMessage(msg.Data(), kFALSE);
4398 if (sock->Send(mbuf) < 0) return -1;
4399
4400 } else {
4401 if (outlist) {
4402 PDB(kGlobal, 2) Info("SendResults", "sending output list");
4403 } else {
4404 PDB(kGlobal, 2) Info("SendResults", "notifying failure or abort");
4405 }
4406 if (sock->SendObject(outlist, kPROOF_OUTPUTLIST) < 0) return -1;
4407 }
4408
4409 PDB(kOutput,2) Info("SendResults", "done");
4410
4411 // Done
4412 return 0;
4413}
4414
4415////////////////////////////////////////////////////////////////////////////////
4416/// process the next query from the queue of submitted jobs.
4417/// to be called on the top master only.
4418
4420{
4421 TDSet *dset = 0;
4422 TString filename, opt;
4423 TList *input = 0;
4424 Long64_t nentries = -1, first = 0;
4425
4426 // TObject *elist = 0;
4427 TProofQueryResult *pq = 0;
4428
4429 TObject* obj = 0;
4430 TSelector* selector_obj = 0;
4431
4432 // Process
4433
4434 // Reset compute stopwatch: we include all what done from now on
4435 fCompute.Reset();
4436 fCompute.Start();
4437
4438 // Get next query info (also removes query from the list)
4439 pq = NextQuery();
4440 if (pq) {
4441
4442 // Set not idle
4443 SetIdle(kFALSE);
4444 opt = pq->GetOptions();
4445 input = pq->GetInputList();
4446 nentries = pq->GetEntries();
4447 first = pq->GetFirst();
4448 filename = pq->GetSelecImp()->GetName();
4449 Ssiz_t id = opt.Last('#');
4450 if (id != kNPOS && id < opt.Length() - 1) {
4451 filename += opt(id + 1, opt.Length());
4452 // Remove it from 'opt' so user found on the workers what they specified
4453 opt.Remove(id);
4454 }
4455 // Attach to data set and entry- (or event-) list (if any)
4456 TObject *o = 0;
4457 if ((o = pq->GetInputObject("TDSet"))) {
4458 dset = (TDSet *) o;
4459 } else {
4460 // Should never get here
4461 Error("ProcessNext", "no TDset object: cannot continue");
4462 return;
4463 }
4464 // elist = 0;
4465 // if ((o = pq->GetInputObject("TEntryList")))
4466 // elist = o;
4467 // else if ((o = pq->GetInputObject("TEventList")))
4468 // elist = o;
4469
4470 // Expand selector files
4471 if (pq->GetSelecImp()) {
4472 gSystem->Exec(TString::Format("%s %s", kRM, pq->GetSelecImp()->GetName()));
4473 pq->GetSelecImp()->SaveSource(pq->GetSelecImp()->GetName());
4474 }
4475 if (pq->GetSelecHdr() &&
4476 !strstr(pq->GetSelecHdr()->GetName(), "TProofDrawHist")) {
4477 gSystem->Exec(TString::Format("%s %s", kRM, pq->GetSelecHdr()->GetName()));
4478 pq->GetSelecHdr()->SaveSource(pq->GetSelecHdr()->GetName());
4479 }
4480
4481 // Taking out a TSelector object from input list
4482 TIter nxt(input);
4483 while ((obj = nxt())){
4484 if (obj->InheritsFrom("TSelector") &&
4485 !strcmp(pq->GetSelecImp()->GetName(), obj->ClassName())) {
4486 selector_obj = (TSelector *) obj;
4487 Info("ProcessNext", "found object for selector '%s'", obj->ClassName());
4488 break;
4489 }
4490 }
4491
4492 } else {
4493 // Should never get here
4494 Error("ProcessNext", "empty waiting queries list!");
4495 return;
4496 }
4497
4498 // Set in running state
4499 SetQueryRunning(pq);
4500
4501 // Save to queries dir, if not standard draw
4502 if (fQMgr) {
4503 if (!(pq->IsDraw()))
4504 fQMgr->SaveQuery(pq);
4505 else
4507 fQMgr->ResetTime();
4508 }
4509
4510 // Signal the client that we are starting a new query
4512 m << TString(pq->GetSelecImp()->GetName())
4513 << dset->GetNumOfFiles()
4514 << pq->GetFirst() << pq->GetEntries();
4515 fSocket->Send(m);
4516
4517 // Create player
4518 MakePlayer();
4519
4520 // Add query results to the player lists
4522
4523 // Set query currently processed
4525
4526 // Setup data set
4527 if (dset->IsA() == TDSetProxy::Class())
4528 ((TDSetProxy*)dset)->SetProofServ(this);
4529
4530 // Add the unique query tag as TNamed object to the input list
4531 // so that it is available in TSelectors for monitoring
4532 TString qid = TString::Format("%s:%s",pq->GetTitle(),pq->GetName());
4533 input->Add(new TNamed("PROOF_QueryTag", qid.Data()));
4534 // ... and the sequential number
4535 fQuerySeqNum = pq->GetSeqNum();
4536 input->Add(new TParameter<Int_t>("PROOF_QuerySeqNum", fQuerySeqNum));
4537
4538 // Check whether we have to enforce the use of submergers, but only if the user did
4539 // not express itself on the subject
4540 if (gEnv->Lookup("Proof.UseMergers") && !input->FindObject("PROOF_UseMergers")) {
4541 Int_t smg = gEnv->GetValue("Proof.UseMergers",-1);
4542 if (smg >= 0) {
4543 input->Add(new TParameter<Int_t>("PROOF_UseMergers", smg));
4544 PDB(kSubmerger, 2) Info("ProcessNext", "PROOF_UseMergers set to %d", smg);
4545 if (gEnv->Lookup("Proof.MergersByHost")) {
4546 Int_t mbh = gEnv->GetValue("Proof.MergersByHost", 0);
4547 if (mbh != 0) {
4548 // Administrator settings have the priority
4549 TObject *o = 0;
4550 if ((o = input->FindObject("PROOF_MergersByHost"))) { input->Remove(o); delete o; }
4551 input->Add(new TParameter<Int_t>("PROOF_MergersByHost", mbh));
4552 PDB(kSubmerger, 2) Info("ProcessNext", "submergers setup by host/node");
4553 }
4554 }
4555 }
4556 }
4557
4558 // Set input
4559 TIter next(input);
4560 TObject *o = 0;
4561 while ((o = next())) {
4562 PDB(kGlobal, 2) Info("ProcessNext", "adding: %s", o->GetName());
4563 fPlayer->AddInput(o);
4564 }
4565
4566 // Remove the list of the missing files from the original list, if any
4567 if ((o = input->FindObject("MissingFiles"))) input->Remove(o);
4568
4569 // Process
4570 PDB(kGlobal, 1) Info("ProcessNext", "calling %s::Process()", fPlayer->IsA()->GetName());
4571 if (selector_obj){
4572 Info("ProcessNext", "calling fPlayer->Process() with selector object: %s", selector_obj->ClassName());
4573 fPlayer->Process(dset, selector_obj, opt, nentries, first);
4574 }
4575 else {
4576 Info("ProcessNext", "calling fPlayer->Process() with selector name: %s", filename.Data());
4577 fPlayer->Process(dset, filename, opt, nentries, first);
4578 }
4579
4580 // This is the end of merging
4582
4583 // Return number of events processed
4584 Bool_t abort =
4587 m.Reset(kPROOF_STOPPROCESS);
4588 // message sent from worker to the master
4589 if (fProtocol > 18) {
4591 m << status << abort;
4592 status = 0; // the status belongs to the player.
4593 } else if (fProtocol > 8) {
4594 m << fPlayer->GetEventsProcessed() << abort;
4595 } else {
4597 }
4598 fSocket->Send(m);
4599 }
4600
4601 // Register any dataset produced during this processing, if required
4603 TNamed *psr = (TNamed *) fPlayer->GetOutputList()->FindObject("PROOFSERV_RegisterDataSet");
4604 if (psr) {
4605 TString emsg;
4606 if (RegisterDataSets(input, fPlayer->GetOutputList(), fDataSetManager, emsg) != 0)
4607 Warning("ProcessNext", "problems registering produced datasets: %s", emsg.Data());
4608 do {
4609 fPlayer->GetOutputList()->Remove(psr);
4610 delete psr;
4611 } while ((psr = (TNamed *) fPlayer->GetOutputList()->FindObject("PROOFSERV_RegisterDataSet")));
4612 }
4613 }
4614
4615 // Complete filling of the TQueryResult instance
4616 if (fQMgr && !pq->IsDraw()) {
4617 if (!abort) fProof->AskStatistics();
4618 if (fQMgr->FinalizeQuery(pq, fProof, fPlayer))
4620 }
4621
4622 // If we were requested to save results on the master and we are not in save-to-file mode
4623 // then we save the results
4624 if (IsTopMaster() && fPlayer->GetOutputList()) {
4625 Bool_t save = kTRUE;
4626 TIter nxo(fPlayer->GetOutputList());
4627 TObject *xo = 0;
4628 while ((xo = nxo())) {
4629 if (xo->InheritsFrom("TProofOutputFile") && xo->TestBit(TProofOutputFile::kSwapFile)) {
4630 save = kFALSE;
4631 break;
4632 }
4633 }
4634 if (save) {
4635 TNamed *nof = (TNamed *) input->FindObject("PROOF_DefaultOutputOption");
4636 if (nof) {
4637 TString oopt(nof->GetTitle());
4638 if (oopt.BeginsWith("of:")) {
4639 oopt.Replace(0, 3, "");
4640 if (!oopt.IsNull()) fPlayer->SetOutputFilePath(oopt);
4642 }
4643 }
4644 }
4645 }
4646
4647 // Send back the results
4648 TQueryResult *pqr = pq->CloneInfo();
4649 // At least the TDSet name in the light object
4650 Info("ProcessNext", "adding info about dataset '%s' in the light query result", dset->GetName());
4651 TList rin;
4652 TDSet *ds = new TDSet(dset->GetName(), dset->GetObjName());
4653 rin.Add(ds);
4654 if (pqr) pqr->SetInputList(&rin, kTRUE);
4656 PDB(kGlobal, 2)
4657 Info("ProcessNext", "sending results");
4658 TQueryResult *xpq = (pqr && fProtocol > 10) ? pqr : pq;
4659 if (SendResults(fSocket, fPlayer->GetOutputList(), xpq) != 0)
4660 Warning("ProcessNext", "problems sending output list");
4661 if (slb) slb->Form("%d %lld %lld %.3f", fPlayer->GetExitStatus(), pq->GetEntries(),
4662 pq->GetBytes(), pq->GetUsedCPU());
4663 } else {
4665 Warning("ProcessNext","the output list is empty!");
4667 Warning("ProcessNext", "problems sending output list");
4668 if (slb) slb->Form("%d -1 -1 %.3f", fPlayer->GetExitStatus(), pq->GetUsedCPU());
4669 }
4670
4671 // Remove aborted queries from the list
4673 SafeDelete(pqr);
4674 if (fQMgr) fQMgr->RemoveQuery(pq);
4675 } else {
4676 // Keep in memory only light infor about a query
4677 if (!(pq->IsDraw()) && pqr) {
4678 if (fQMgr && fQMgr->Queries()) {
4679 fQMgr->Queries()->Add(pqr);
4680 // Remove from the fQueries list
4681 fQMgr->Queries()->Remove(pq);
4682 }
4683 // These removes 'pq' from the internal player list and
4684 // deletes it; in this way we do not attempt a double delete
4685 // when destroying the player
4687 pq->GetTitle(), pq->GetName()));
4688 }
4689 }
4690
4691 DeletePlayer();
4692 if (IsMaster() && fProof->UseDynamicStartup())
4693 // stop the workers
4695}
4696
4697////////////////////////////////////////////////////////////////////////////////
4698/// Register TFileCollections in 'out' as datasets according to the rules in 'in'
4699
4701 TDataSetManager *dsm, TString &msg)
4702{
4703 PDB(kDataset, 1)
4704 ::Info("TProofServ::RegisterDataSets",
4705 "enter: %d objs in the output list", (out ? out->GetSize() : -1));
4706
4707 if (!in || !out || !dsm) {
4708 ::Error("TProofServ::RegisterDataSets", "invalid inputs: %p, %p, %p", in, out, dsm);
4709 return 0;
4710 }
4711 msg = "";
4712 THashList tags;
4713 TList torm;
4714 TIter nxo(out);
4715 TObject *o = 0;
4716 while ((o = nxo())) {
4717 // Only file collections TFileCollection
4718 TFileCollection *ds = dynamic_cast<TFileCollection*> (o);
4719 if (ds) {
4720 // Origin of this dataset
4721 ds->SetTitle(gSystem->HostName());
4722 // The tag and register option
4723 TNamed *fcn = 0;
4724 TString tag = TString::Format("DATASET_%s", ds->GetName());
4725 if (!(fcn = (TNamed *) out->FindObject(tag))) continue;
4726 // If this tag is in the list of processed tags, flag it for removal
4727 if (tags.FindObject(tag)) {
4728 torm.Add(o);
4729 continue;
4730 }
4731 // Register option
4732 TString regopt(fcn->GetTitle());
4733 // Sort according to the internal index, if required
4734 if (regopt.Contains(":sortidx:")) {
4735 ds->Sort(kTRUE);
4736 regopt.ReplaceAll(":sortidx:", "");
4737 }
4738 // Register this dataset
4740 // Extract the list
4741 if (ds->GetList()->GetSize() > 0) {
4742 // Register the dataset (quota checks are done inside here)
4743 const char *vfmsg = regopt.Contains("V") ? " and verifying" : "";
4744 msg.Form("Registering%s dataset '%s' ... ", vfmsg, ds->GetName());
4745 // Always allow verification for this action
4747 if (regopt.Contains("V") && !allowVerify) dsm->SetBit(TDataSetManager::kAllowVerify);
4748 // Main action
4749 Int_t rc = dsm->RegisterDataSet(ds->GetName(), ds, regopt);
4750 // Reset to the previous state if needed
4751 if (regopt.Contains("V") && !allowVerify) dsm->ResetBit(TDataSetManager::kAllowVerify);
4752 if (rc != 0) {
4753 ::Warning("TProofServ::RegisterDataSets",
4754 "failure registering or verifying dataset '%s'", ds->GetName());
4755 msg.Form("Registering%s dataset '%s' ... failed! See log for more details", vfmsg, ds->GetName());
4756 } else {
4757 ::Info("TProofServ::RegisterDataSets", "dataset '%s' successfully registered%s",
4758 ds->GetName(), (strlen(vfmsg) > 0) ? " and verified" : "");
4759 msg.Form("Registering%s dataset '%s' ... OK", vfmsg, ds->GetName());
4760 // Add tag to the list of processed tags to avoid double processing
4761 // (there may be more objects with the same name, created by each worker)
4762 tags.Add(new TObjString(tag));
4763 }
4764 // Notify
4765 PDB(kDataset, 2) {
4766 ::Info("TProofServ::RegisterDataSets", "printing collection");
4767 ds->Print("F");
4768 }
4769 } else {
4770 ::Warning("TProofServ::RegisterDataSets", "collection '%s' is empty", o->GetName());
4771 }
4772 } else {
4773 ::Info("TProofServ::RegisterDataSets", "dataset registration not allowed");
4774 return -1;
4775 }
4776 }
4777 }
4778 // Cleanup all temporary stuff possibly created by each worker
4779 TIter nxrm(&torm);
4780 while ((o = nxrm())) out->Remove(o);
4781 torm.SetOwner(kTRUE);
4782 // Remove tags
4783 TIter nxtg(&tags);
4784 while((o = nxtg())) {
4785 TObject *oo = 0;
4786 while ((oo = out->FindObject(o->GetName()))) { out->Remove(oo); }
4787 }
4788 tags.SetOwner(kTRUE);
4789
4790 PDB(kDataset, 1) ::Info("TProofServ::RegisterDataSets", "exit");
4791 // Done
4792 return 0;
4793}
4794
4795////////////////////////////////////////////////////////////////////////////////
4796/// Handle request for list of queries.
4797
4799{
4800 PDB(kGlobal, 1)
4801 Info("HandleQueryList", "Enter");
4802
4803 Bool_t all;
4804 (*mess) >> all;
4805
4806 TList *ql = new TList;
4807 Int_t ntot = 0, npre = 0, ndraw= 0;
4808 if (fQMgr) {
4809 if (all) {
4810 // Rescan
4811 TString qdir = fQueryDir;
4812 Int_t idx = qdir.Index("session-");
4813 if (idx != kNPOS)
4814 qdir.Remove(idx);
4816 // Send also information about previous queries, if any
4817 if (fQMgr->PreviousQueries()) {
4818 TIter nxq(fQMgr->PreviousQueries());
4819 TProofQueryResult *pqr = 0;
4820 while ((pqr = (TProofQueryResult *)nxq())) {
4821 ntot++;
4822 pqr->fSeqNum = ntot;
4823 ql->Add(pqr);
4824 }
4825 }
4826 }
4827
4828 npre = ntot;
4829 if (fQMgr->Queries()) {
4830 // Add info about queries in this session
4831 TIter nxq(fQMgr->Queries());
4832 TProofQueryResult *pqr = 0;
4833 TQueryResult *pqm = 0;
4834 while ((pqr = (TProofQueryResult *)nxq())) {
4835 ntot++;
4836 if ((pqm = pqr->CloneInfo())) {
4837 pqm->fSeqNum = ntot;
4838 ql->Add(pqm);
4839 } else {
4840 Warning("HandleQueryList", "unable to clone TProofQueryResult '%s:%s'",
4841 pqr->GetName(), pqr->GetTitle());
4842 }
4843 }
4844 }
4845 // Number of draw queries
4846 ndraw = fQMgr->DrawQueries();
4847 }
4848
4850 m << npre << ndraw << ql;
4851 fSocket->Send(m);
4852 delete ql;
4853
4854 // Done
4855 return;
4856}
4857
4858////////////////////////////////////////////////////////////////////////////////
4859/// Handle remove request.
4860
4862{
4863 PDB(kGlobal, 1)
4864 Info("HandleRemove", "Enter");
4865
4866 TString queryref;
4867 (*mess) >> queryref;
4868
4869 if (slb) *slb = queryref;
4870
4871 if (queryref == "cleanupqueue") {
4872 // Remove pending requests
4874 // Notify
4875 Info("HandleRemove", "%d queries removed from the waiting list", pend);
4876 // We are done
4877 return;
4878 }
4879
4880 if (queryref == "cleanupdir") {
4881
4882 // Cleanup previous sessions results
4883 Int_t nd = (fQMgr) ? fQMgr->CleanupQueriesDir() : -1;
4884
4885 // Notify
4886 Info("HandleRemove", "%d directories removed", nd);
4887 // We are done
4888 return;
4889 }
4890
4891
4892 if (fQMgr) {
4893 TProofLockPath *lck = 0;
4894 if (fQMgr->LockSession(queryref, &lck) == 0) {
4895
4896 // Remove query
4897 TList qtorm;
4898 fQMgr->RemoveQuery(queryref, &qtorm);
4900
4901 // Unlock and remove the lock file
4902 if (lck) {
4903 gSystem->Unlink(lck->GetName());
4904 SafeDelete(lck);
4905 }
4906
4907 // We are done
4908 return;
4909 }
4910 } else {
4911 Warning("HandleRemove", "query result manager undefined!");
4912 }
4913
4914 // Notify failure
4915 Info("HandleRemove",
4916 "query %s could not be removed (unable to lock session)", queryref.Data());
4917
4918 // Done
4919 return;
4920}
4921
4922////////////////////////////////////////////////////////////////////////////////
4923/// Handle retrieve request.
4924
4926{
4927 PDB(kGlobal, 1)
4928 Info("HandleRetrieve", "Enter");
4929
4930 TString queryref;
4931 (*mess) >> queryref;
4932
4933 if (slb) *slb = queryref;
4934
4935 // Parse reference string
4936 Int_t qry = -1;
4937 TString qdir;
4938 if (fQMgr) fQMgr->LocateQuery(queryref, qry, qdir);
4939
4940 TString fout = qdir;
4941 fout += "/query-result.root";
4942
4943 TFile *f = TFile::Open(fout,"READ");
4944 TProofQueryResult *pqr = 0;
4945 if (f) {
4946 f->ReadKeys();
4947 TIter nxk(f->GetListOfKeys());
4948 TKey *k = 0;
4949 while ((k = (TKey *)nxk())) {
4950 if (!strcmp(k->GetClassName(), "TProofQueryResult")) {
4951 pqr = (TProofQueryResult *) f->Get(k->GetName());
4952 // For backward compatibility
4953 if (pqr && fProtocol < 13) {
4954 TDSet *d = 0;
4955 TObject *o = 0;
4956 TIter nxi(pqr->GetInputList());
4957 while ((o = nxi()))
4958 if ((d = dynamic_cast<TDSet *>(o)))
4959 break;
4960 d->SetWriteV3(kTRUE);
4961 }
4962 if (pqr) {
4963
4964 // Message for the client
4965 Float_t qsz = (Float_t) f->GetSize();
4966 Int_t ilb = 0;
4967 static const char *clb[4] = { "bytes", "KB", "MB", "GB" };
4968 while (qsz > 1000. && ilb < 3) {
4969 qsz /= 1000.;
4970 ilb++;
4971 }
4972 SendAsynMessage(TString::Format("%s: sending result of %s:%s (%.1f %s)",
4973 fPrefix.Data(), pqr->GetTitle(), pqr->GetName(),
4974 qsz, clb[ilb]));
4976 } else {
4977 Info("HandleRetrieve",
4978 "query not found in file %s",fout.Data());
4979 // Notify not found
4981 }
4982 break;
4983 }
4984 }
4985 f->Close();
4986 delete f;
4987 } else {
4988 Info("HandleRetrieve",
4989 "file cannot be open (%s)",fout.Data());
4990 // Notify not found
4992 return;
4993 }
4994
4995 // Done
4996 return;
4997}
4998
4999////////////////////////////////////////////////////////////////////////////////
5000/// Handle lib, inc search paths modification request
5001
5003{
5004 TString type;
5005 Bool_t add;
5006 TString path;
5007 Int_t rc = 1;
5008 (*mess) >> type >> add >> path;
5009 if (mess->BufferSize() > mess->Length()) (*mess) >> rc;
5010
5011 // Check type of action
5012 if ((type != "lib") && (type != "inc")) {
5013 Error("HandleLibIncPath","unknown action type: %s", type.Data());
5014 return rc;
5015 }
5016
5017 // Separators can be either commas or blanks
5018 path.ReplaceAll(","," ");
5019
5020 // Decompose lists
5021 TObjArray *op = 0;
5022 if (path.Length() > 0 && path != "-") {
5023 if (!(op = path.Tokenize(" "))) {
5024 Error("HandleLibIncPath","decomposing path %s", path.Data());
5025 return rc;
5026 }
5027 }
5028
5029 if (add) {
5030
5031 if (type == "lib") {
5032
5033 // Add libs
5034 TIter nxl(op, kIterBackward);
5035 TObjString *lib = 0;
5036 while ((lib = (TObjString *) nxl())) {
5037 // Expand path
5038 TString xlib = lib->GetName();
5039 gSystem->ExpandPathName(xlib);
5040 // Add to the dynamic lib search path if it exists and can be read
5041 if (!gSystem->AccessPathName(xlib, kReadPermission)) {
5042 TString newlibpath = gSystem->GetDynamicPath();
5043 // In the first position after the working dir
5044 Int_t pos = 0;
5045 if (newlibpath.BeginsWith(".:"))
5046 pos = 2;
5047 if (newlibpath.Index(xlib) == kNPOS) {
5048 newlibpath.Insert(pos,TString::Format("%s:", xlib.Data()));
5049 gSystem->SetDynamicPath(newlibpath);
5050 }
5051 } else {
5052 Info("HandleLibIncPath",
5053 "libpath %s does not exist or cannot be read - not added", xlib.Data());
5054 }
5055 }
5056
5057 // Forward the request, if required
5058 if (IsMaster())
5059 fProof->AddDynamicPath(path);
5060
5061 } else {
5062
5063 // Add incs
5064 TIter nxi(op);
5065 TObjString *inc = 0;
5066 while ((inc = (TObjString *) nxi())) {
5067 // Expand path
5068 TString xinc = inc->GetName();
5069 gSystem->ExpandPathName(xinc);
5070 // Add to the dynamic lib search path if it exists and can be read
5071 if (!gSystem->AccessPathName(xinc, kReadPermission)) {
5072 TString curincpath = gSystem->GetIncludePath();
5073 if (curincpath.Index(xinc) == kNPOS)
5074 gSystem->AddIncludePath(TString::Format("-I%s", xinc.Data()));
5075 } else
5076 Info("HandleLibIncPath",
5077 "incpath %s does not exist or cannot be read - not added", xinc.Data());
5078 }
5079
5080 // Forward the request, if required
5081 if (IsMaster())
5082 fProof->AddIncludePath(path);
5083 }
5084
5085
5086 } else {
5087
5088 if (type == "lib") {
5089
5090 // Remove libs
5091 TIter nxl(op);
5092 TObjString *lib = 0;
5093 while ((lib = (TObjString *) nxl())) {
5094 // Expand path
5095 TString xlib = lib->GetName();
5096 gSystem->ExpandPathName(xlib);
5097 // Remove from the dynamic lib search path
5098 TString newlibpath = gSystem->GetDynamicPath();
5099 newlibpath.ReplaceAll(TString::Format("%s:", xlib.Data()),"");
5100 gSystem->SetDynamicPath(newlibpath);
5101 }
5102
5103 // Forward the request, if required
5104 if (IsMaster())
5106
5107 } else {
5108
5109 // Remove incs
5110 TIter nxi(op);
5111 TObjString *inc = 0;
5112 while ((inc = (TObjString *) nxi())) {
5113 TString newincpath = gSystem->GetIncludePath();
5114 newincpath.ReplaceAll(TString::Format("-I%s", inc->GetName()),"");
5115 // Remove the interpreter path (added anyhow internally)
5116 newincpath.ReplaceAll(gInterpreter->GetIncludePath(),"");
5117 gSystem->SetIncludePath(newincpath);
5118 }
5119
5120 // Forward the request, if required
5121 if (IsMaster())
5123 }
5124 }
5125 // Done
5126 return rc;
5127}
5128
5129////////////////////////////////////////////////////////////////////////////////
5130/// Handle file checking request.
5131
5133{
5134 TString filenam;
5135 TMD5 md5;
5136 UInt_t opt = TProof::kUntar;
5137
5139
5140 // Parse message
5141 (*mess) >> filenam >> md5;
5142 if ((mess->BufferSize() > mess->Length()) && (fProtocol > 8))
5143 (*mess) >> opt;
5144
5145 if (slb) *slb = filenam;
5146
5147 if (filenam.BeginsWith("-")) {
5148 // install package:
5149 // compare md5's, untar, store md5 in PROOF-INF, remove par file
5150 Int_t st = 0;
5151 Bool_t err = kFALSE;
5152 filenam = filenam.Strip(TString::kLeading, '-');
5153 TString packnam = filenam;
5154 packnam.Remove(packnam.Length() - 4); // strip off ".par"
5155 // compare md5's to check if transmission was ok
5156 TMD5 *md5local = fPackMgr->GetMD5(packnam);
5157 if (md5local && md5 == (*md5local)) {
5158 if ((opt & TProof::kRemoveOld)) {
5159 if ((st = fPackMgr->Clean(packnam)))
5160 Error("HandleCheckFile", "failure cleaning %s", packnam.Data());
5161 }
5162 // Unpack
5163 st = fPackMgr->Unpack(packnam, md5local);
5164 if (st == 0) {
5165 // Notify the client
5166 reply << (Int_t)1;
5167 PDB(kPackage, 1)
5168 Info("HandleCheckFile",
5169 "package %s installed on node", filenam.Data());
5170 } else {
5171 if (st == -2) {
5172 Error("HandleCheckFile", "gunzip not found");
5173 } else {
5174 Error("HandleCheckFile", "package %s did not unpack into %s",
5175 filenam.Data(), packnam.Data());
5176 }
5177 reply << (Int_t)0;
5178 if (fProtocol <= 19) reply.Reset(kPROOF_FATAL);
5179 err = kTRUE;
5180 }
5181 } else {
5182 reply << (Int_t)0;
5183 if (fProtocol <= 19) reply.Reset(kPROOF_FATAL);
5184 err = kTRUE;
5185 PDB(kPackage, 1)
5186 Error("HandleCheckFile",
5187 "package %s not yet on node", filenam.Data());
5188 }
5189
5190 // Note: Originally an fPackageLock->Unlock() call was made
5191 // after the if-else statement below. With multilevel masters,
5192 // submasters still check to make sure the package exists with
5193 // the correct md5 checksum and need to do a read lock there.
5194 // As yet locking is not that sophisicated so the lock must
5195 // be released below before the call to fProof->UploadPackage().
5196 if (err) {
5197 // delete par file in case of error
5198 fPackMgr->Remove(filenam);
5199 } else if (IsMaster()) {
5200 // forward to workers
5201 TString parpath;
5202 fPackMgr->GetParPath(filenam, parpath);
5203 if (fProof->UploadPackage(parpath,
5204 (TProof::EUploadPackageOpt)opt) != 0)
5205 Info("HandleCheckFile",
5206 "problems uploading package %s", parpath.Data());
5207 }
5208 delete md5local;
5209 fSocket->Send(reply);
5210
5211 } else if (filenam.BeginsWith("+") || filenam.BeginsWith("=")) {
5212 filenam.Remove(0,1);
5213
5214 TString parname = filenam;
5215 // If remote install it from there
5216 TFile::EFileType ft = TFile::GetType(filenam);
5217 if (ft == TFile::kWeb || ft == TFile::kNet) {
5218 parname = gSystem->BaseName(filenam);
5219 if (fPackMgr->Install(filenam) < 0) {
5220 Warning("HandleCheckFile",
5221 "problems installing package %s", filenam.Data());
5222
5223 }
5224 }
5225
5226 // check file in package directory
5227 TMD5 *md5local = fPackMgr->ReadMD5(parname);
5228
5229 if (md5local && md5 == (*md5local)) {
5230 // package already on server, unlock directory
5231 reply << (Int_t)1;
5232 PDB(kPackage, 1)
5233 Info("HandleCheckFile",
5234 "package %s already on node", parname.Data());
5235 if (IsMaster()) {
5236 Int_t xrc = 0;
5237 TString par = filenam;
5238 if (ft != TFile::kWeb && ft != TFile::kNet) {
5239 xrc = fPackMgr->GetParPath(filenam, par);
5240 }
5241 if (xrc == 0) {
5242 if (fProof->UploadPackage(par) != 0)
5243 Warning("HandleCheckFile",
5244 "problems uploading package %s", par.Data());
5245 }
5246 }
5247
5248 } else {
5249 reply << (Int_t)0;
5250 if (fProtocol <= 19) reply.Reset(kPROOF_FATAL);
5251 PDB(kPackage, 1)
5252 Info("HandleCheckFile",
5253 "package %s not yet on node", filenam.Data());
5254 }
5255 delete md5local;
5256 fSocket->Send(reply);
5257
5258 } else {
5259 // check file in cache directory
5260 TString cachef = fCacheDir + "/" + filenam;
5261 fCacheLock->Lock();
5262 TMD5 *md5local = TMD5::FileChecksum(cachef);
5263
5264 if (md5local && md5 == (*md5local)) {
5265 reply << (Int_t)1;
5266 PDB(kCache, 1)
5267 Info("HandleCheckFile", "file %s already on node", filenam.Data());
5268 } else {
5269 reply << (Int_t)0;
5270 if (fProtocol <= 19) reply.Reset(kPROOF_FATAL);
5271 PDB(kCache, 1)
5272 Info("HandleCheckFile", "file %s not yet on node", filenam.Data());
5273 }
5274 delete md5local;
5275 fSocket->Send(reply);
5276 fCacheLock->Unlock();
5277 }
5278}
5279
5280////////////////////////////////////////////////////////////////////////////////
5281/// Handle here all cache and package requests.
5282
5284{
5285 PDB(kGlobal, 1)
5286 Info("HandleCache", "Enter");
5287
5288 Int_t status = 0;
5289 Int_t type = 0;
5290 Bool_t all = kFALSE;
5291 TMessage msg;
5292 Bool_t fromglobal = kFALSE;
5293 Int_t chkveropt = TPackMgr::kCheckROOT; // Default: check ROOT version
5294 TPackMgr *packmgr = 0;
5295
5296 // Notification message
5297 TString noth;
5298 const char *k = (IsMaster()) ? "Mst" : "Wrk";
5299 noth.Form("%s-%s", k, fOrdinal.Data());
5300
5301 TList *optls = 0;
5302 TString packagedir, package, pdir, ocwd, file;
5303 (*mess) >> type;
5304 switch (type) {
5305 case TProof::kShowCache:
5306 (*mess) >> all;
5307 printf("*** File cache %s:%s ***\n", gSystem->HostName(),
5308 fCacheDir.Data());
5309 fflush(stdout);
5310 PDB(kCache, 1) {
5311 gSystem->Exec(TString::Format("%s -a %s", kLS, fCacheDir.Data()));
5312 } else {
5314 }
5315 if (IsMaster() && all)
5316 fProof->ShowCache(all);
5317 LogToMaster();
5318 if (slb) slb->Form("%d %d", type, all);
5319 break;
5321 file = "";
5322 if ((mess->BufferSize() > mess->Length())) (*mess) >> file;
5323 fCacheLock->Lock();
5324 if (file.IsNull() || file == "*") {
5325 gSystem->Exec(TString::Format("%s %s/* %s/.*.binversion", kRM, fCacheDir.Data(), fCacheDir.Data()));
5326 } else {
5327 gSystem->Exec(TString::Format("%s %s/%s", kRM, fCacheDir.Data(), file.Data()));
5328 }
5329 fCacheLock->Unlock();
5330 if (IsMaster())
5332 if (slb) slb->Form("%d %s", type, file.Data());
5333 break;
5335 (*mess) >> all;
5336 fPackMgr->Show();
5337 if (IsMaster() && all)
5338 fProof->ShowPackages(all);
5339 LogToMaster();
5340 if (slb) slb->Form("%d %d", type, all);
5341 break;
5343 if ((status = fPackMgr->Unload(0)) == 0) {
5344 fPackMgr->Remove();
5345 if (IsMaster())
5346 status = fProof->ClearPackages();
5347 }
5348 if (slb) slb->Form("%d %d", type, status);
5349 break;
5351 (*mess) >> package;
5352 if ((status = fPackMgr->Unload(package)) == 0) {
5353 fPackMgr->Remove(package);
5354 if (IsMaster())
5355 status = fProof->ClearPackage(package);
5356 }
5357 if (slb) slb->Form("%d %s %d", type, package.Data(), status);
5358 break;
5360 (*mess) >> package;
5361 if ((mess->BufferSize() > mess->Length())) (*mess) >> chkveropt;
5362
5363 if (!(packmgr = TPackMgr::GetPackMgr(package.Data(), fPackMgr))) {
5364 // Package not found
5365 SendAsynMessage(TString::Format("%s: kBuildPackage: failure locating %s ...",
5366 noth.Data(), package.Data()));
5367 status = -1;
5368 break;
5369 }
5370 fromglobal = (packmgr == fPackMgr) ? kFALSE : kTRUE;
5371 packagedir = packmgr->GetTitle();
5372
5373 if (IsMaster() && !fromglobal) {
5374 // Make sure package is available on all slaves, even new ones
5375 TString par;
5376 Int_t xrc = packmgr->GetParPath(package, par);
5377 if (xrc != 0 || fProof->UploadPackage(par) != 0) {
5378 Warning("HandleCache",
5379 "kBuildPackage: problems forwarding package %s to workers", package.Data());
5380 SendAsynMessage(TString::Format("%s: kBuildPackage: problems forwarding package %s to workers ...",
5381 noth.Data(), package.Data()));
5382 }
5383 }
5384
5385 if (!status) {
5386
5387 PDB(kPackage, 1)
5388 Info("HandleCache",
5389 "kBuildPackage: package %s exists and has PROOF-INF directory", package.Data());
5390
5391 // Forward build command to slaves, but don't wait for results
5392 if (IsMaster())
5394
5395 // Build here
5396 status = packmgr->Build(package.Data(), chkveropt);
5397 }
5398
5399 if (status) {
5400 // Notify the upper level
5401 SendAsynMessage(TString::Format("%s: failure building %s ... (status: %d)", noth.Data(), package.Data(), status));
5402 } else {
5403 // collect built results from slaves
5404 if (IsMaster())
5406 PDB(kPackage, 1)
5407 Info("HandleCache", "package %s successfully built", package.Data());
5408 }
5409 if (slb) slb->Form("%d %s %d %d", type, package.Data(), status, chkveropt);
5410 break;
5411
5413 (*mess) >> package;
5414
5415 // Get argument, if any
5416 if ((mess->BufferSize() > mess->Length())) (*mess) >> optls;
5417 // Load the package
5418 if ((status = fPackMgr->Load(package.Data(), optls)) < 0) {
5419
5420 // Notify the upper level
5421 SendAsynMessage(TString::Format("%s: failure loading %s, args: %p (%d) ...",
5422 noth.Data(), package.Data(), optls,
5423 (optls && optls->GetSize() > 0) ? optls->GetSize() : 0));
5424
5425 } else {
5426
5427 if (IsMaster()) {
5428 if (optls && optls->GetSize() > 0) {
5429 // List argument
5430 status = fProof->LoadPackage(package, kFALSE, optls);
5431 } else {
5432 // No argument
5433 status = fProof->LoadPackage(package);
5434 }
5435 }
5436
5437 PDB(kPackage, 1)
5438 Info("HandleCache", "package %s successfully loaded", package.Data());
5439 }
5440
5441 if (slb) slb->Form("%d %s %d", type, package.Data(), status);
5442 break;
5443
5445 (*mess) >> all;
5446 { TString title("*** Enabled packages ***");
5447 if (!IsMaster() || all) {
5448 title.Form("*** Enabled packages on %s %s on %s",
5449 (IsMaster()) ? "master" : "worker",
5451 }
5452 fPackMgr->ShowEnabled(title);
5453 }
5454 if (IsMaster() && all)
5456 LogToMaster();
5457 if (slb) slb->Form("%d %d", type, all);
5458 break;
5460 (*mess) >> all;
5461 if (IsMaster() && all)
5462 fProof->ShowCache(all);
5463 LogToMaster();
5464 if (slb) slb->Form("%d %d", type, all);
5465 break;
5467 file = "";
5468 if ((mess->BufferSize() > mess->Length())) (*mess) >> file;
5469 if (IsMaster())
5471 if (slb) slb->Form("%d %s", type, file.Data());
5472 break;
5474 (*mess) >> all;
5475 if (IsMaster() && all)
5476 fProof->ShowPackages(all);
5477 LogToMaster();
5478 if (slb) slb->Form("%d %d", type, all);
5479 break;
5481 if (IsMaster())
5483 if (slb) slb->Form("%d", type);
5484 break;
5486 (*mess) >> package;
5487 if (IsMaster())
5488 fProof->DisablePackage(package);
5489 if (slb) slb->Form("%d %s", type, package.Data());
5490 break;
5492 (*mess) >> package;
5493 if ((mess->BufferSize() > mess->Length())) (*mess) >> chkveropt;
5494 if (IsMaster())
5495 fProof->BuildPackage(package, TProof::kBuildAll, chkveropt);
5496 if (slb) slb->Form("%d %s %d", type, package.Data(), chkveropt);
5497 break;
5499 (*mess) >> package;
5500 status = fPackMgr->Unload(package);
5501 if (IsMaster() && status == 0)
5502 status = fProof->UnloadPackage(package);
5503 if (slb) slb->Form("%d %s %d", type, package.Data(), status);
5504 break;
5506 (*mess) >> package;
5507 fPackMgr->Remove(package);
5508 if (IsMaster())
5509 fProof->DisablePackage(package);
5510 if (slb) slb->Form("%d %s", type, package.Data());
5511 break;
5513 status = fPackMgr->Unload(0);
5514 if (IsMaster() && status == 0)
5515 status = fProof->UnloadPackages();
5516 if (slb) slb->Form("%d %s %d", type, package.Data(), status);
5517 break;
5519 fPackMgr->Remove();
5520 if (IsMaster())
5522 if (slb) slb->Form("%d %s", type, package.Data());
5523 break;
5526 { TList *epl = fPackMgr->GetListOfEnabled();
5527 msg << type << epl;
5528 fSocket->Send(msg);
5529 epl->SetOwner();
5530 delete epl;
5531 }
5532 if (slb) slb->Form("%d", type);
5533 break;
5535 {
5536 TList *pack = fPackMgr->GetList();
5538 msg << type << pack;
5539 fSocket->Send(msg);
5540 pack->SetOwner(kTRUE);
5541 delete pack;
5542 }
5543 if (slb) slb->Form("%d", type);
5544 break;
5545 case TProof::kLoadMacro:
5546 {
5547 (*mess) >> package;
5548
5549 // By first forwarding the load command to the unique workers
5550 // and only then loading locally we load/build in parallel
5551 if (IsMaster())
5552 fProof->Load(package, kFALSE, kTRUE);
5553
5554 // Atomic action
5555 fCacheLock->Lock();
5556
5557 TString originalCwd = gSystem->WorkingDirectory();
5559
5560 // Load the macro
5561 TString pack(package);
5562 Ssiz_t from = 0;
5563 if ((from = pack.Index(",")) != kNPOS) pack.Remove(from);
5564 Info("HandleCache", "loading macro %s ...", pack.Data());
5565 gROOT->ProcessLine(TString::Format(".L %s", pack.Data()));
5566
5567 // Release atomicity
5568 gSystem->ChangeDirectory(originalCwd.Data());
5569 fCacheLock->Unlock();
5570
5571 // Now we collect the result from the unique workers and send the load request
5572 // to the other workers (no compilation)
5573 if (IsMaster())
5574 fProof->Load(package, kFALSE, kFALSE);
5575
5576 // Notify the upper level
5577 LogToMaster();
5578
5579 if (slb) slb->Form("%d %s", type, package.Data());
5580 }
5581 break;
5582 default:
5583 Error("HandleCache", "unknown type %d", type);
5584 break;
5585 }
5586
5587 // We are done
5588 return status;
5589}
5590
5591////////////////////////////////////////////////////////////////////////////////
5592/// Handle here all requests to modify worker lists
5593
5595{
5596 PDB(kGlobal, 1)
5597 Info("HandleWorkerLists", "Enter");
5598
5599 Int_t type = 0, rc = 0;
5600 TString ord;
5601
5602 (*mess) >> type;
5603
5604 switch (type) {
5606 (*mess) >> ord;
5607 if (ord != "*" && !ord.BeginsWith(GetOrdinal()) && ord != "restore") break;
5608 if (fProof) {
5610 Int_t nactmax = fProof->GetListOfSlaves()->GetSize() -
5612 if (nact < nactmax || !IsEndMaster()) {
5613 Int_t nwc = fProof->ActivateWorker(ord);
5614 Int_t nactnew = fProof->GetListOfActiveSlaves()->GetSize();
5615 if (ord == "*") {
5616 if (nactnew == nactmax) {
5617 PDB(kGlobal, 1) Info("HandleWorkerList", "all workers (re-)activated");
5618 } else {
5619 if (IsEndMaster())
5620 PDB(kGlobal, 1) Info("HandleWorkerList", "%d workers could not be (re-)activated", nactmax - nactnew);
5621 }
5622 } else if (ord == "restore") {
5623 if (nwc > 0) {
5624 PDB(kGlobal, 1) Info("HandleWorkerList","active worker(s) restored");
5625 } else {
5626 Error("HandleWorkerList", "some active worker(s) could not be restored; check logs");
5627 }
5628 } else {
5629 if (nactnew == (nact + nwc)) {
5630 if (nwc > 0)
5631 PDB(kGlobal, 1) Info("HandleWorkerList","worker(s) %s (re-)activated", ord.Data());
5632 } else {
5633 if (nwc != -2 && IsEndMaster()) {
5634 Error("HandleWorkerList", "some worker(s) could not be (re-)activated;"
5635 " # of actives: %d --> %d (nwc: %d)",
5636 nact, nactnew, nwc);
5637 }
5638 rc = (nwc < 0) ? nwc : -1;
5639 }
5640 }
5641 } else {
5642 PDB(kGlobal, 1) Info("HandleWorkerList","all workers are already active");
5643 }
5644 } else {
5645 Warning("HandleWorkerList","undefined PROOF session: protocol error?");
5646 }
5647 break;
5649 (*mess) >> ord;
5650 if (ord != "*" && !ord.BeginsWith(GetOrdinal()) && ord != "restore") break;
5651 if (fProof) {
5653 if (nact > 0) {
5654 Int_t nwc = fProof->DeactivateWorker(ord);
5655 Int_t nactnew = fProof->GetListOfActiveSlaves()->GetSize();
5656 if (ord == "*") {
5657 if (nactnew == 0) {
5658 PDB(kGlobal, 1) Info("HandleWorkerList","all workers deactivated");
5659 } else {
5660 if (IsEndMaster())
5661 PDB(kGlobal, 1) Info("HandleWorkerList","%d workers could not be deactivated", nactnew);
5662 }
5663 } else {
5664 if (nactnew == (nact - nwc)) {
5665 if (nwc > 0)
5666 PDB(kGlobal, 1) Info("HandleWorkerList","worker(s) %s deactivated", ord.Data());
5667 } else {
5668 if (nwc != -2 && IsEndMaster()) {
5669 Error("HandleWorkerList", "some worker(s) could not be deactivated:"
5670 " # of actives: %d --> %d (nwc: %d)",
5671 nact, nactnew, nwc);
5672 }
5673 rc = (nwc < 0) ? nwc : -1;
5674 }
5675 }
5676 } else {
5677 PDB(kGlobal, 1) Info("HandleWorkerList","all workers are already inactive");
5678 }
5679 } else {
5680 Warning("HandleWorkerList","undefined PROOF session: protocol error?");
5681 }
5682 break;
5683 default:
5684 Warning("HandleWorkerList","unknown action type (%d)", type);
5685 rc = -1;
5686 }
5687 // Done
5688 return rc;
5689}
5690
5691////////////////////////////////////////////////////////////////////////////////
5692/// Get list of workers to be used from now on.
5693/// The list must be provided by the caller.
5694
5696 Int_t & /* prioritychange */,
5697 Bool_t /* resume */)
5698{
5699 // Parse the config file
5700 TProofResourcesStatic *resources =
5702 fConfFile = resources->GetFileName(); // Update the global file name (with path)
5703 PDB(kGlobal,1)
5704 Info("GetWorkers", "using PROOF config file: %s", fConfFile.Data());
5705
5706 // Get the master
5707 TProofNodeInfo *master = resources->GetMaster();
5708 if (!master) {
5709 PDB(kAll,1)
5710 Info("GetWorkers",
5711 "no appropriate master line found in %s", fConfFile.Data());
5712 return kQueryStop;
5713 } else {
5714 // Set image if not yet done and available
5715 if (fImage.IsNull() && strlen(master->GetImage()) > 0)
5716 fImage = master->GetImage();
5717 }
5718
5719 // Fill submaster or worker list
5720 if (workers) {
5721 if (resources->GetSubmasters() && resources->GetSubmasters()->GetSize() > 0) {
5722 PDB(kAll,1)
5723 resources->GetSubmasters()->Print();
5724 TProofNodeInfo *ni = 0;
5725 TIter nw(resources->GetSubmasters());
5726 while ((ni = (TProofNodeInfo *) nw()))
5727 workers->Add(new TProofNodeInfo(*ni));
5728 } else if (resources->GetWorkers() && resources->GetWorkers()->GetSize() > 0) {
5729 PDB(kAll,1)
5730 resources->GetWorkers()->Print();
5731 TProofNodeInfo *ni = 0;
5732 TIter nw(resources->GetWorkers());
5733 while ((ni = (TProofNodeInfo *) nw()))
5734 workers->Add(new TProofNodeInfo(*ni));
5735 }
5736 }
5737
5738 // We are done
5739 return kQueryOK;
5740}
5741
5742////////////////////////////////////////////////////////////////////////////////
5743/// Set the file stream where to log (default stderr).
5744/// If ferr == 0 the default is restored.
5745/// Returns current setting.
5746
5748{
5749 FILE *oldferr = fgErrorHandlerFile;
5750 fgErrorHandlerFile = (ferr) ? ferr : stderr;
5751 return oldferr;
5752}
5753
5754////////////////////////////////////////////////////////////////////////////////
5755/// The PROOF error handler function. It prints the message on fgErrorHandlerFile and
5756/// if abort is set it aborts the application.
5757
5758void TProofServ::ErrorHandler(Int_t level, Bool_t abort, const char *location,
5759 const char *msg)
5760{
5761 if (gErrorIgnoreLevel == kUnset) {
5763 if (gEnv) {
5764 TString lvl = gEnv->GetValue("Root.ErrorIgnoreLevel", "Print");
5765 if (!lvl.CompareTo("Print", TString::kIgnoreCase))
5767 else if (!lvl.CompareTo("Info", TString::kIgnoreCase))
5769 else if (!lvl.CompareTo("Warning", TString::kIgnoreCase))
5771 else if (!lvl.CompareTo("Error", TString::kIgnoreCase))
5773 else if (!lvl.CompareTo("Break", TString::kIgnoreCase))
5775 else if (!lvl.CompareTo("SysError", TString::kIgnoreCase))
5777 else if (!lvl.CompareTo("Fatal", TString::kIgnoreCase))
5779 }
5780 }
5781
5782 if (level < gErrorIgnoreLevel)
5783 return;
5784
5785 // Always communicate errors via SendLogFile
5786 if (level >= kError && gProofServ)
5788
5789 Bool_t tosyslog = (fgLogToSysLog > 2) ? kTRUE : kFALSE;
5790
5791 const char *type = 0;
5792 ELogLevel loglevel = kLogInfo;
5793
5794 Int_t ipos = (location) ? strlen(location) : 0;
5795
5796 if (level >= kPrint) {
5797 loglevel = kLogInfo;
5798 type = "Print";
5799 }
5800 if (level >= kInfo) {
5801 loglevel = kLogInfo;
5802 char *ps = location ? (char *) strrchr(location, '|') : (char *)0;
5803 if (ps) {
5804 ipos = (int)(ps - (char *)location);
5805 type = "SvcMsg";
5806 } else {
5807 type = "Info";
5808 }
5809 }
5810 if (level >= kWarning) {
5811 loglevel = kLogWarning;
5812 type = "Warning";
5813 }
5814 if (level >= kError) {
5815 loglevel = kLogErr;
5816 type = "Error";
5817 }
5818 if (level >= kBreak) {
5819 loglevel = kLogErr;
5820 type = "*** Break ***";
5821 }
5822 if (level >= kSysError) {
5823 loglevel = kLogErr;
5824 type = "SysError";
5825 }
5826 if (level >= kFatal) {
5827 loglevel = kLogErr;
5828 type = "Fatal";
5829 }
5830
5831
5832 TString buf;
5833
5834 // Time stamp
5835 TTimeStamp ts;
5836 TString st(ts.AsString("lc"),19);
5837
5838 if (!location || ipos == 0 ||
5839 (level >= kPrint && level < kInfo) ||
5840 (level >= kBreak && level < kSysError)) {
5841 fprintf(fgErrorHandlerFile, "%s %5d %s | %s: %s\n", st(11,8).Data(),
5842 gSystem->GetPid(),
5843 (gProofServ ? gProofServ->GetPrefix() : "proof"),
5844 type, msg);
5845 if (tosyslog)
5846 buf.Form("%s: %s:%s", fgSysLogEntity.Data(), type, msg);
5847 } else {
5848 fprintf(fgErrorHandlerFile, "%s %5d %s | %s in <%.*s>: %s\n", st(11,8).Data(),
5849 gSystem->GetPid(),
5850 (gProofServ ? gProofServ->GetPrefix() : "proof"),
5851 type, ipos, location, msg);
5852 if (tosyslog)
5853 buf.Form("%s: %s:<%.*s>: %s", fgSysLogEntity.Data(), type, ipos, location, msg);
5854 }
5855 fflush(fgErrorHandlerFile);
5856
5857 if (tosyslog)
5858 gSystem->Syslog(loglevel, buf);
5859
5860#ifdef __APPLE__
5861 if (__crashreporter_info__)
5862 delete [] __crashreporter_info__;
5863 __crashreporter_info__ = StrDup(buf);
5864#endif
5865
5866 if (abort) {
5867
5868 static Bool_t recursive = kFALSE;
5869
5870 if (gProofServ != 0 && !recursive) {
5871 recursive = kTRUE;
5873 recursive = kFALSE;
5874 }
5875
5876 fprintf(fgErrorHandlerFile, "aborting\n");
5877 fflush(fgErrorHandlerFile);
5879 gSystem->Abort();
5880 }
5881}
5882
5883////////////////////////////////////////////////////////////////////////////////
5884/// Make player instance.
5885
5887{
5888 TVirtualProofPlayer *p = 0;
5889
5890 // Cleanup first
5891 DeletePlayer();
5892
5893 if (IsParallel()) {
5894 // remote mode
5895 p = fProof->MakePlayer();
5896 } else {
5897 // slave or sequential mode
5898 p = TVirtualProofPlayer::Create("slave", 0, fSocket);
5899 if (IsMaster())
5900 fProof->SetPlayer(p);
5901 }
5902
5903 // set player
5904 fPlayer = p;
5905}
5906
5907////////////////////////////////////////////////////////////////////////////////
5908/// Delete player instance.
5909
5911{
5912 if (IsMaster()) {
5913 PDB(kGlobal, 1) {
5914 fCompute.Stop();
5915 Printf(" +++ Latest processing times: %f s (CPU: %f s)",
5917 }
5918 if (fProof) fProof->SetPlayer(0);
5919 } else {
5921 }
5922 fPlayer = 0;
5923}
5924
5925////////////////////////////////////////////////////////////////////////////////
5926/// Get the processing priority for the group the user belongs too. This
5927/// priority is a number (0 - 100) determined by a scheduler (third
5928/// party process) based on some basic priority the group has, e.g.
5929/// we might want to give users in a specific group (e.g. promptana)
5930/// a higher priority than users in other groups, and on the analysis
5931/// of historical logging data (i.e. usage of CPU by the group in a
5932/// previous time slot, as recorded in TPerfStats::WriteQueryLog()).
5933///
5934/// Currently the group priority is obtained by a query in a SQL DB
5935/// table proofpriority, which has the format:
5936/// CREATE TABLE proofpriority (
5937/// id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
5938/// group VARCHAR(32) NOT NULL,
5939/// priority INT
5940///)
5941
5943{
5944 TString sqlserv = gEnv->GetValue("ProofServ.QueryLogDB","");
5945 TString sqluser = gEnv->GetValue("ProofServ.QueryLogUser","");
5946 TString sqlpass = gEnv->GetValue("ProofServ.QueryLogPasswd","");
5947
5948 Int_t priority = 100;
5949
5950 if (sqlserv == "")
5951 return priority;
5952
5953 TString sql;
5954 sql.Form("SELECT priority WHERE group='%s' FROM proofpriority", fGroup.Data());
5955
5956 // open connection to SQL server
5957 TSQLServer *db = TSQLServer::Connect(sqlserv, sqluser, sqlpass);
5958
5959 if (!db || db->IsZombie()) {
5960 Error("GetPriority", "failed to connect to SQL server %s as %s %s",
5961 sqlserv.Data(), sqluser.Data(), sqlpass.Data());
5962 printf("%s\n", sql.Data());
5963 } else {
5964 TSQLResult *res = db->Query(sql);
5965
5966 if (!res) {
5967 Error("GetPriority", "query into proofpriority failed");
5968 Printf("%s", sql.Data());
5969 } else {
5970 TSQLRow *row = res->Next(); // first row is header
5971 if (row) {
5972 priority = atoi(row->GetField(0));
5973 delete row;
5974 } else {
5975 Error("GetPriority", "first row is header is NULL");
5976 }
5977 }
5978 delete res;
5979 }
5980 delete db;
5981
5982 return priority;
5983}
5984
5985////////////////////////////////////////////////////////////////////////////////
5986/// Send an asychronous message to the master / client .
5987/// Masters will forward up the message to the client.
5988/// The client prints 'msg' of stderr and adds a '\n'/'\r' depending on
5989/// 'lf' being kTRUE (default) or kFALSE.
5990/// Returns the return value from TSocket::Send(TMessage &) .
5991
5992void TProofServ::SendAsynMessage(const char *msg, Bool_t lf)
5993{
5994 static TMessage m(kPROOF_MESSAGE);
5995
5996 // To leave a track in the output file ... if requested
5997 // (clients will be notified twice)
5998 PDB(kAsyn,1)
5999 Info("SendAsynMessage","%s", (msg ? msg : "(null)"));
6000
6001 if (fSocket && msg) {
6002 m.Reset(kPROOF_MESSAGE);
6003 m << TString(msg) << lf;
6004 if (fSocket->Send(m) <= 0)
6005 Warning("SendAsynMessage", "could not send message '%s'", msg);
6006 }
6007
6008 return;
6009}
6010
6011////////////////////////////////////////////////////////////////////////////////
6012/// Reposition the read pointer in the log file to the very end.
6013/// This allows to "hide" useful debug messages during normal operations
6014/// while preserving the possibility to have them in case of problems.
6015
6017{
6018 off_t lend = lseek(fileno(stdout), (off_t)0, SEEK_END);
6019 if (lend >= 0) lseek(fLogFileDes, lend, SEEK_SET);
6020}
6021
6022////////////////////////////////////////////////////////////////////////////////
6023/// Truncate the log file to the 80% of the required max size if this
6024/// is set.
6025
6027{
6028#ifndef WIN32
6029 TString emsg;
6030 if (fLogFileMaxSize > 0 && fLogFileDes > 0) {
6031 fflush(stdout);
6032 struct stat st;
6033 if (fstat(fLogFileDes, &st) == 0) {
6034 if (st.st_size >= fLogFileMaxSize) {
6035 off_t truncsz = (off_t) (( fLogFileMaxSize * 80 ) / 100 );
6036 if (truncsz < 100) {
6037 emsg.Form("+++ WARNING +++: %s: requested truncate size too small"
6038 " (%lld,%lld) - ignore ", fPrefix.Data(), (Long64_t) truncsz, fLogFileMaxSize);
6039 SendAsynMessage(emsg.Data());
6040 return;
6041 }
6043 while (ftruncate(fileno(stdout), truncsz) != 0 &&
6044 (TSystem::GetErrno() == EINTR)) {
6046 }
6047 if (TSystem::GetErrno() > 0) {
6048 Error("TruncateLogFile", "truncating to %lld bytes; file size is %lld bytes (errno: %d)",
6049 (Long64_t)truncsz, (Long64_t)st.st_size, TSystem::GetErrno());
6050 emsg.Form("+++ WARNING +++: %s: problems truncating log file to %lld bytes; file size is %lld bytes"
6051 " (errno: %d)", fPrefix.Data(), (Long64_t)truncsz, (Long64_t)st.st_size, TSystem::GetErrno());
6052 SendAsynMessage(emsg.Data());
6053 } else {
6054 Info("TruncateLogFile", "file truncated to %lld bytes (80%% of %lld); file size was %lld bytes ",
6055 (Long64_t)truncsz, fLogFileMaxSize, (Long64_t)st.st_size);
6056 emsg.Form("+++ WARNING +++: %s: log file truncated to %lld bytes (80%% of %lld)",
6057 fPrefix.Data(), (Long64_t)truncsz, fLogFileMaxSize);
6058 SendAsynMessage(emsg.Data());
6059 }
6060 }
6061 } else {
6062 emsg.Form("+++ WARNING +++: %s: could not stat log file descriptor"
6063 " for truncation (errno: %d)", fPrefix.Data(), TSystem::GetErrno());
6064 SendAsynMessage(emsg.Data());
6065 }
6066 }
6067#endif
6068}
6069
6070////////////////////////////////////////////////////////////////////////////////
6071/// Exception handler: we do not try to recover here, just exit.
6072
6074{
6075 Error("HandleException", "caugth exception triggered by signal '%d' %s %lld",
6076 sig, fgLastMsg.Data(), fgLastEntry);
6077 // Description
6078 TString emsg;
6079 emsg.Form("%s: caught exception triggered by signal '%d' %s %lld",
6081 // Try to warn the user
6082 SendAsynMessage(emsg.Data());
6083
6084 gSystem->Exit(sig);
6085}
6086
6087////////////////////////////////////////////////////////////////////////////////
6088/// Handle here requests about datasets.
6089
6091{
6092 if (gDebug > 0)
6093 Info("HandleDataSets", "enter");
6094
6095 // We need a dataset manager
6096 if (!fDataSetManager) {
6097 Warning("HandleDataSets", "no data manager is available to fullfil the request");
6098 return -1;
6099 }
6100
6101 // Used in most cases
6102 TString dsUser, dsGroup, dsName, dsTree, uri, opt;
6103 Int_t rc = 0;
6104
6105 // Invalid characters in dataset URI
6106 TPMERegexp reInvalid("[^A-Za-z0-9._-]"); // from ParseUri
6107
6108 // Message type
6109 Int_t type = 0;
6110 (*mess) >> type;
6111
6112 switch (type) {
6114 //
6115 // Check whether this dataset exist
6116 {
6117 (*mess) >> uri;
6118 if (slb) slb->Form("%d %s", type, uri.Data());
6120 // Dataset name does exist
6121 return -1;
6122 }
6123 break;
6125 // list size must be above 0
6126 {
6128 (*mess) >> uri;
6129 (*mess) >> opt;
6130 if (slb) slb->Form("%d %s %s", type, uri.Data(), opt.Data());
6131 // Extract the list
6132 TFileCollection *dataSet =
6133 dynamic_cast<TFileCollection*> ((mess->ReadObject(TFileCollection::Class())));
6134 if (!dataSet || dataSet->GetList()->GetSize() == 0) {
6135 Error("HandleDataSets", "can not save an empty list.");
6136 return -1;
6137 }
6138 // Register the dataset (quota checks are done inside here)
6139 rc = fDataSetManager->RegisterDataSet(uri, dataSet, opt);
6140 delete dataSet;
6141 return rc;
6142 } else {
6143 Info("HandleDataSets", "dataset registration not allowed");
6144 if (slb) slb->Form("%d notallowed", type);
6145 return -1;
6146 }
6147 }
6148 break;
6149
6151 {
6152 (*mess) >> uri; // TString
6153
6154 if (!fDataSetStgRepo) {
6155 Error("HandleDataSets",
6156 "no dataset staging request repository available");
6157 return -1;
6158 }
6159
6160 // Transform input URI in a valid dataset name
6161 TString validUri = uri;
6162 while (reInvalid.Substitute(validUri, "_")) {}
6163
6164 // Check if dataset exists beforehand: if it does, staging has
6165 // already been requested
6166 if (fDataSetStgRepo->ExistsDataSet(validUri.Data())) {
6167 Warning("HandleDataSets", "staging of %s already requested",
6168 uri.Data());
6169 return -1;
6170 }
6171
6172 // Try to get dataset from current manager
6174 if (!fc || (fc->GetNFiles() == 0)) {
6175 Error("HandleDataSets", "empty dataset or no dataset returned");
6176 if (fc) delete fc;
6177 return -1;
6178 }
6179
6180 // Reset all staged bits and remove unnecessary URLs (all but last)
6181 TIter it(fc->GetList());
6182 TFileInfo *fi;
6183 while ((fi = dynamic_cast<TFileInfo *>(it.Next()))) {
6185 Int_t nToErase = fi->GetNUrls() - 1;
6186 for (Int_t i=0; i<nToErase; i++)
6187 fi->RemoveUrlAt(0);
6188 }
6189
6190 fc->Update(); // absolutely necessary
6191
6192 // Save request
6193 fDataSetStgRepo->ParseUri(validUri, &dsGroup, &dsUser, &dsName);
6194 if (fDataSetStgRepo->WriteDataSet(dsGroup, dsUser,
6195 dsName, fc) == 0) {
6196 // Error, can't save dataset
6197 Error("HandleDataSets",
6198 "can't register staging request for %s", uri.Data());
6199 delete fc;
6200 return -1;
6201 }
6202
6203 Info("HandleDataSets",
6204 "Staging request registered for %s", uri.Data());
6205
6206 delete fc;
6207 return 0; // success (-1 == failure)
6208 }
6209 break;
6210
6212 {
6213 if (!fDataSetStgRepo) {
6214 Error("HandleDataSets",
6215 "no dataset staging request repository available");
6216 return -1;
6217 }
6218
6219 (*mess) >> uri; // TString
6220
6221 // Transform URI in a valid dataset name
6222 while (reInvalid.Substitute(uri, "_")) {}
6223
6224 // Get the list
6226 if (fc) {
6228 delete fc;
6229 return 0;
6230 }
6231 else {
6232 // No such dataset: not an error, but don't send message
6233 Info("HandleDataSets", "no pending staging request for %s",
6234 uri.Data());
6235 return 0;
6236 }
6237 }
6238 break;
6239
6241 {
6242 if (!fDataSetStgRepo) {
6243 Error("HandleDataSets",
6244 "no dataset staging request repository available");
6245 return -1;
6246 }
6247
6248 (*mess) >> uri;
6249
6250 // Transform URI in a valid dataset name
6251 while (reInvalid.Substitute(uri, "_")) {}
6252
6253 if (!fDataSetStgRepo->RemoveDataSet(uri.Data()))
6254 return -1; // failure
6255
6256 return 0; // success
6257 }
6258 break;
6259
6261 {
6262 (*mess) >> uri >> opt;
6263 if (slb) slb->Form("%d %s %s", type, uri.Data(), opt.Data());
6264 // Show content
6265 fDataSetManager->ShowDataSets(uri, opt);
6266 }
6267 break;
6268
6270 {
6271 (*mess) >> uri >> opt;
6272 if (slb) slb->Form("%d %s %s", type, uri.Data(), opt.Data());
6273 // Get the datasets and fill a map
6275 Ssiz_t kLite = opt.Index(":lite:", 0, TString::kIgnoreCase);
6276 if (kLite != kNPOS) {
6278 opt.Remove(kLite, strlen(":lite:"));
6279 }
6280 TMap *returnMap = fDataSetManager->GetDataSets(uri, omsk);
6281 // If defines, option gives the name of a server for which to extract the information
6282 if (returnMap && !opt.IsNull()) {
6283 // The return map will be in the form </group/user/datasetname> --> <dataset>
6284 TMap *rmap = new TMap;
6285 TObject *k = 0;
6286 TFileCollection *fc = 0, *xfc = 0;
6287 TIter nxd(returnMap);
6288 while ((k = nxd()) && (fc = (TFileCollection *) returnMap->GetValue(k))) {
6289 // Get subset on specified server, if any
6290 if ((xfc = fc->GetFilesOnServer(opt.Data()))) {
6291 rmap->Add(new TObjString(k->GetName()), xfc);
6292 }
6293 }
6294 returnMap->DeleteAll();
6295 if (rmap->GetSize() > 0) {
6296 returnMap = rmap;
6297 } else {
6298 Info("HandleDataSets", "no dataset found on server '%s'", opt.Data());
6299 delete rmap;
6300 returnMap = 0;
6301 }
6302 }
6303 if (returnMap) {
6304 // Send them back
6305 fSocket->SendObject(returnMap, kMESS_OK);
6306 returnMap->DeleteAll();
6307 } else {
6308 // Failure
6309 return -1;
6310 }
6311 }
6312 break;
6314 {
6315 (*mess) >> uri >> opt;
6316 if (slb) slb->Form("%d %s %s", type, uri.Data(), opt.Data());
6317 // Get the list
6318 TFileCollection *fileList = fDataSetManager->GetDataSet(uri,opt);
6319 if (fileList) {
6320 fSocket->SendObject(fileList, kMESS_OK);
6321 delete fileList;
6322 } else {
6323 // Failure
6324 return -1;
6325 }
6326 }
6327 break;
6329 {
6331 (*mess) >> uri;
6332 if (slb) slb->Form("%d %s", type, uri.Data());
6333 if (!fDataSetManager->RemoveDataSet(uri)) {
6334 // Failure
6335 return -1;
6336 }
6337 } else {
6338 Info("HandleDataSets", "dataset creation / removal not allowed");
6339 if (slb) slb->Form("%d notallowed", type);
6340 return -1;
6341 }
6342 }
6343 break;
6345 {
6347 (*mess) >> uri >> opt;
6348 if (slb) slb->Form("%d %s %s", type, uri.Data(), opt.Data());
6350 rc = fDataSetManager->ScanDataSet(uri, opt);
6351 // TODO: verify in parallel:
6352 // - dataset = GetDataSet(uri)
6353 // - TList flist; TDataSetManager::ScanDataSet(dataset, ..., &flist)
6354 // - fPlayer->Process( ... flist ...) // needs to be developed
6355 // - dataset->Integrate(flist) (perhaps automatic; flist object owned by dataset)
6356 // - RegisterDataSet(uri, dataset, "OT")
6357 } else {
6358 Info("HandleDataSets", "dataset verification not allowed");
6359 return -1;
6360 }
6361 }
6362 break;
6363 case TProof::kGetQuota:
6364 {
6366 if (slb) slb->Form("%d", type);
6367 TMap *groupQuotaMap = fDataSetManager->GetGroupQuotaMap();
6368 if (groupQuotaMap) {
6369 // Send result
6370 fSocket->SendObject(groupQuotaMap, kMESS_OK);
6371 } else {
6372 return -1;
6373 }
6374 } else {
6375 Info("HandleDataSets", "quota control disabled");
6376 if (slb) slb->Form("%d disabled", type);
6377 return -1;
6378 }
6379 }
6380 break;
6381 case TProof::kShowQuota:
6382 {
6384 if (slb) slb->Form("%d", type);
6385 (*mess) >> opt;
6386 // Display quota information
6388 } else {
6389 Info("HandleDataSets", "quota control disabled");
6390 if (slb) slb->Form("%d disabled", type);
6391 }
6392 }
6393 break;
6395 {
6397 (*mess) >> uri;
6398 if (slb) slb->Form("%d %s", type, uri.Data());
6400 } else {
6401 Info("HandleDataSets", "kSetDefaultTreeName: modification of dataset info not allowed");
6402 if (slb) slb->Form("%d notallowed", type);
6403 return -1;
6404 }
6405 }
6406 break;
6407 case TProof::kCache:
6408 {
6409 (*mess) >> uri >> opt;
6410 if (slb) slb->Form("%d %s %s", type, uri.Data(), opt.Data());
6411 if (opt == "show") {
6412 // Show cache content
6414 } else if (opt == "clear") {
6415 // Clear cache content
6417 } else {
6418 Error("HandleDataSets", "kCache: unknown action: %s", opt.Data());
6419 }
6420 }
6421 break;
6422 default:
6423 rc = -1;
6424 Error("HandleDataSets", "unknown type %d", type);
6425 break;
6426 }
6427
6428 // We are done
6429 return rc;
6430}
6431
6432////////////////////////////////////////////////////////////////////////////////
6433/// Handle a message of type kPROOF_SUBMERGER
6434
6436{
6437 // Message type
6438 Int_t type = 0;
6439 (*mess) >> type;
6440
6441 TString msg;
6442 switch (type) {
6444 break;
6445
6447 {
6448 Bool_t deleteplayer = kTRUE;
6449 if (!IsMaster()) {
6450 if (fMergingMonitor) {
6451 Info("HandleSubmerger", "kSendOutput: interrupting ...");
6453 }
6454 if (fMergingSocket) {
6458 }
6459
6460 TString name;
6461 Int_t port = 0;
6462 Int_t merger_id = -1;
6463 (*mess) >> merger_id >> name >> port;
6464 PDB(kSubmerger, 1)
6465 Info("HandleSubmerger","worker %s redirected to merger #%d %s:%d", fOrdinal.Data(), merger_id, name.Data(), port);
6466
6467 TSocket *t = 0;
6468 if (name.Length() > 0 && port > 0 && (t = new TSocket(name, port)) && t->IsValid()) {
6469
6470 PDB(kSubmerger, 2) Info("HandleSubmerger",
6471 "kSendOutput: worker asked for sending output to merger #%d %s:%d",
6472 merger_id, name.Data(), port);
6473
6474 if (SendResults(t, fPlayer->GetOutputList()) != 0) {
6475 msg.Form("worker %s cannot send results to merger #%d at %s:%d", GetPrefix(), merger_id, name.Data(), port);
6476 PDB(kSubmerger, 2) Info("HandleSubmerger",
6477 "kSendOutput: %s - inform the master", msg.Data());
6478 SendAsynMessage(msg);
6479 // Results not send
6481 answ << Int_t(TProof::kMergerDown);
6482 answ << merger_id;
6483 fSocket->Send(answ);
6484 } else {
6485 // Worker informs master that it had sent its output to the merger
6487 answ << Int_t(TProof::kOutputSent);
6488 answ << merger_id;
6489 fSocket->Send(answ);
6490
6491 PDB(kSubmerger, 2) Info("HandleSubmerger", "kSendOutput: worker sent its output");
6493 SetIdle(kTRUE);
6494 SendLogFile();
6495 }
6496 } else {
6497
6498 if (name == "master") {
6499 PDB(kSubmerger, 2) Info("HandleSubmerger",
6500 "kSendOutput: worker was asked for sending output to master");
6502 Warning("HandleSubmerger", "problems sending output list");
6503 // Signal the master that we are idle
6505 SetIdle(kTRUE);
6506 SendLogFile();
6507
6508 } else if (!t || !(t->IsValid())) {
6509 msg.Form("worker %s could not open a valid socket to merger #%d at %s:%d",
6510 GetPrefix(), merger_id, name.Data(), port);
6511 PDB(kSubmerger, 2) Info("HandleSubmerger",
6512 "kSendOutput: %s - inform the master", msg.Data());
6513 SendAsynMessage(msg);
6514 // Results not send
6516 answ << Int_t(TProof::kMergerDown);
6517 answ << merger_id;
6518 fSocket->Send(answ);
6519 deleteplayer = kFALSE;
6520 }
6521
6522 SafeDelete(t);
6523
6524 }
6525
6526 } else {
6527 Error("HandleSubmerger", "kSendOutput: received not on worker");
6528 }
6529
6530 // Cleanup
6531 if (deleteplayer) DeletePlayer();
6532 }
6533 break;
6534 case TProof::kBeMerger:
6535 {
6536 Bool_t deleteplayer = kTRUE;
6537 if (!IsMaster()) {
6538 Int_t merger_id = -1;
6539 //Int_t merger_port = 0;
6540 Int_t connections = 0;
6541 (*mess) >> merger_id >> connections;
6542 PDB(kSubmerger, 2)
6543 Info("HandleSubmerger", "worker %s established as merger", fOrdinal.Data());
6544
6545 PDB(kSubmerger, 2)
6546 Info("HandleSubmerger",
6547 "kBeMerger: worker asked for being merger #%d for %d connections",
6548 merger_id, connections);
6549
6550 TVirtualProofPlayer *mergerPlayer = TVirtualProofPlayer::Create("remote",fProof,0);
6551
6552 if (mergerPlayer) {
6553 PDB(kSubmerger, 2) Info("HandleSubmerger",
6554 "kBeMerger: mergerPlayer created (%p) ", mergerPlayer);
6555
6556 // This may be used internally
6558
6559 // Accept results from assigned workers
6560 if (AcceptResults(connections, mergerPlayer)) {
6561 PDB(kSubmerger, 2)
6562 Info("HandleSubmerger", "kBeMerger: all outputs from workers accepted");
6563
6564 PDB(kSubmerger, 2)
6565 Info("","adding own output to the list on %s", fOrdinal.Data());
6566
6567 // Add own results to the output list.
6568 // On workers the player does not own the output list, which is owned
6569 // by the selector and deleted in there
6570 // On workers the player does not own the output list, which is owned
6571 // by the selector and deleted in there
6572 TIter nxo(fPlayer->GetOutputList());
6573 TObject * o = 0;
6574 while ((o = nxo())) {
6575 if ((mergerPlayer->AddOutputObject(o) != 1)) {
6576 // Remove the object if it has not been merged: it is owned
6577 // now by the merger player (in its output list)
6578 if (fPlayer->GetOutputList()) {
6579 PDB(kSubmerger, 2)
6580 Info("HandleSocketInput", "removing merged object (%p)", o);
6582 }
6583 }
6584 }
6585 PDB(kSubmerger, 2) Info("HandleSubmerger","kBeMerger: own outputs added");
6586 PDB(kSubmerger, 2) Info("HandleSubmerger","starting delayed merging on %s", fOrdinal.Data());
6587
6588 // Delayed merging if neccessary
6589 mergerPlayer->MergeOutput(kTRUE);
6590
6591 PDB(kSubmerger, 2) mergerPlayer->GetOutputList()->Print("all");
6592
6593 PDB(kSubmerger, 2) Info("HandleSubmerger", "delayed merging on %s finished ", fOrdinal.Data());
6594 PDB(kSubmerger, 2) Info("HandleSubmerger", "%s sending results to master ", fOrdinal.Data());
6595 // Send merged results to master
6596 if (SendResults(fSocket, mergerPlayer->GetOutputList()) != 0)
6597 Warning("HandleSubmerger","kBeMerger: problems sending output list");
6598 if (mergerPlayer->GetOutputList())
6599 mergerPlayer->GetOutputList()->SetOwner(kTRUE);
6600
6601 PDB(kSubmerger, 2) Info("HandleSubmerger","kBeMerger: results sent to master");
6602 // Signal the master that we are idle
6604 SetIdle(kTRUE);
6605 SendLogFile();
6606 } else {
6607 // Results from all assigned workers not accepted
6609 answ << Int_t(TProof::kMergerDown);
6610 answ << merger_id;
6611 fSocket->Send(answ);
6612 deleteplayer = kFALSE;
6613 }
6614 // Reset
6615 SafeDelete(mergerPlayer);
6616
6617 } else {
6618 Warning("HandleSubmerger","kBeMerger: problems craeting the merger player!");
6619 // Results from all assigned workers not accepted
6621 answ << Int_t(TProof::kMergerDown);
6622 answ << merger_id;
6623 fSocket->Send(answ);
6624 deleteplayer = kFALSE;
6625 }
6626 } else {
6627 Error("HandleSubmerger","kSendOutput: received not on worker");
6628 }
6629
6630 // Cleanup
6631 if (deleteplayer) DeletePlayer();
6632 }
6633 break;
6634
6636 break;
6637
6639 {
6640 // Received only in case of forced termination of merger by master
6641 PDB(kSubmerger, 2) Info("HandleSubmerger", "kStopMerging");
6642 if (fMergingMonitor) {
6643 Info("HandleSubmerger", "kStopMerging: interrupting ...");
6645 }
6646 }
6647 break;
6648
6650 break;
6651 }
6652}
6653
6654////////////////////////////////////////////////////////////////////////////////
6655/// Cloning itself via fork. Not implemented
6656
6658{
6659 Info("HandleFork", "fork cloning not implemented");
6660}
6661
6662////////////////////////////////////////////////////////////////////////////////
6663/// Fork a child.
6664/// If successful, return 0 in the child process and the child pid in the parent
6665/// process. The child pid is registered for reaping.
6666/// Return <0 in the parent process in case of failure.
6667
6669{
6670#ifndef WIN32
6671 // Fork
6672 pid_t pid;
6673 if ((pid = fork()) < 0) {
6674 Error("Fork", "failed to fork");
6675 return pid;
6676 }
6677
6678 // Nothing else to do in the child
6679 if (!pid) return pid;
6680
6681 // Make sure that the reaper timer is started
6682 if (!fReaperTimer) {
6683 fReaperTimer = new TReaperTimer(1000);
6684 fReaperTimer->Start(-1);
6685 }
6686
6687 // Register the new child
6688 fReaperTimer->AddPid(pid);
6689
6690 // Done
6691 return pid;
6692#else
6693 Warning("Fork", "Functionality not provided under windows");
6694 return -1;
6695#endif
6696}
6697
6698////////////////////////////////////////////////////////////////////////////////
6699/// Replace <ord>, <user>, <u>, <group>, <stag>, <qnum>, <file>,
6700/// <rver> and <build> placeholders in fname.
6701/// Here, <rver> is the root version in integer form, e.g. 53403, and
6702/// <build> a string includign version, architecture and compiler version,
6703/// e.g. '53403_linuxx8664gcc_gcc46' .
6704
6705void TProofServ::ResolveKeywords(TString &fname, const char *path)
6706{
6707 // Replace <user>, if any
6708 if (fname.Contains("<user>")) {
6709 if (gProofServ && gProofServ->GetUser() && strlen(gProofServ->GetUser())) {
6710 fname.ReplaceAll("<user>", gProofServ->GetUser());
6711 } else if (gProof && gProof->GetUser() && strlen(gProof->GetUser())) {
6712 fname.ReplaceAll("<user>", gProof->GetUser());
6713 } else {
6714 fname.ReplaceAll("<user>", "nouser");
6715 }
6716 }
6717 // Replace <us>, if any
6718 if (fname.Contains("<u>")) {
6719 if (gProofServ && gProofServ->GetUser() && strlen(gProofServ->GetUser())) {
6720 TString u(gProofServ->GetUser()[0]);
6721 fname.ReplaceAll("<u>", u);
6722 } else if (gProof && gProof->GetUser() && strlen(gProof->GetUser())) {
6723 TString u(gProof->GetUser()[0]);
6724 fname.ReplaceAll("<u>", u);
6725 } else {
6726 fname.ReplaceAll("<u>", "n");
6727 }
6728 }
6729 // Replace <group>, if any
6730 if (fname.Contains("<group>")) {
6731 if (gProofServ && gProofServ->GetGroup() && strlen(gProofServ->GetGroup())) {
6732 fname.ReplaceAll("<group>", gProofServ->GetGroup());
6733 } else if (gProof && gProof->GetGroup() && strlen(gProof->GetGroup())) {
6734 fname.ReplaceAll("<group>", gProof->GetGroup());
6735 } else {
6736 fname.ReplaceAll("<group>", "default");
6737 }
6738 }
6739 // Replace <stag>, if any
6740 if (fname.Contains("<stag>")) {
6742 fname.ReplaceAll("<stag>", gProofServ->GetSessionTag());
6743 } else if (gProof && gProof->GetSessionTag() && strlen(gProof->GetSessionTag())) {
6744 fname.ReplaceAll("<stag>", gProof->GetSessionTag());
6745 } else {
6746 ::Warning("TProofServ::ResolveKeywords", "session tag undefined: ignoring");
6747 }
6748 }
6749 // Replace <ord>, if any
6750 if (fname.Contains("<ord>")) {
6751 if (gProofServ && gProofServ->GetOrdinal() && strlen(gProofServ->GetOrdinal()))
6752 fname.ReplaceAll("<ord>", gProofServ->GetOrdinal());
6753 else
6754 ::Warning("TProofServ::ResolveKeywords", "ordinal number undefined: ignoring");
6755 }
6756 // Replace <qnum>, if any
6757 if (fname.Contains("<qnum>")) {
6759 fname.ReplaceAll("<qnum>", TString::Format("%d", gProofServ->GetQuerySeqNum()).Data());
6760 else
6761 ::Warning("TProofServ::ResolveKeywords", "query seqeuntial number undefined: ignoring");
6762 }
6763 // Replace <file>, if any
6764 if (fname.Contains("<file>") && path && strlen(path) > 0) {
6765 fname.ReplaceAll("<file>", path);
6766 }
6767 // Replace <rver>, if any
6768 if (fname.Contains("<rver>")) {
6769 TString v = TString::Format("%d", gROOT->GetVersionInt());
6770 fname.ReplaceAll("<rver>", v);
6771 }
6772 // Replace <build>, if any
6773 if (fname.Contains("<build>")) {
6774 TString b = TString::Format("%d_%s_%s", gROOT->GetVersionInt(), gSystem->GetBuildArch(),
6776 fname.ReplaceAll("<build>", b);
6777 }
6778}
6779
6780////////////////////////////////////////////////////////////////////////////////
6781/// Return the status of this session:
6782/// 0 idle
6783/// 1 running
6784/// 2 being terminated (currently unused)
6785/// 3 queued
6786/// 4 idle timed-out (not set in here but in TIdleTOTimer::Notify)
6787/// This is typically run in the reader thread, so access needs to be protected
6788
6790{
6791 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6792 Int_t st = (fIdle) ? 0 : 1;
6793 if (fIdle && fWaitingQueries->GetSize() > 0) st = 3;
6794 return st;
6795}
6796
6797////////////////////////////////////////////////////////////////////////////////
6798/// Update the session status in the relevant file. The status is taken from
6799/// GetSessionStatus() unless xst >= 0, in which case xst is used.
6800/// Return 0 on success, -errno if the file could not be opened.
6801
6803{
6804 FILE *fs = fopen(fAdminPath.Data(), "w");
6805 if (fs) {
6806 Int_t st = (xst < 0) ? GetSessionStatus() : xst;
6807 fprintf(fs, "%d", st);
6808 fclose(fs);
6809 PDB(kGlobal, 2)
6810 Info("UpdateSessionStatus", "status (=%d) update in path: %s", st, fAdminPath.Data());
6811 } else {
6812 return -errno;
6813 }
6814 // Done
6815 return 0;
6816}
6817
6818////////////////////////////////////////////////////////////////////////////////
6819/// Return the idle status
6820
6822{
6823 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6824 return fIdle;
6825}
6826
6827////////////////////////////////////////////////////////////////////////////////
6828/// Change the idle status
6829
6831{
6832 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6833 fIdle = st;
6834}
6835
6836////////////////////////////////////////////////////////////////////////////////
6837/// Return kTRUE if the session is waiting for the OK to start processing
6838
6840{
6841 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6842 if (fIdle && fWaitingQueries->GetSize() > 0) return kTRUE;
6843 return kFALSE;
6844}
6845
6846////////////////////////////////////////////////////////////////////////////////
6847/// Return the number of waiting queries
6848
6850{
6851 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6852 return fWaitingQueries->GetSize();
6853}
6854
6855////////////////////////////////////////////////////////////////////////////////
6856/// Add a query to the waiting list
6857/// Returns the number of queries in the list
6858
6860{
6861 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6862 fWaitingQueries->Add(pq);
6863 return fWaitingQueries->GetSize();
6864}
6865
6866////////////////////////////////////////////////////////////////////////////////
6867/// Get the next query from the waiting list.
6868/// The query is removed from the list.
6869
6871{
6872 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6875 return pq;
6876}
6877
6878////////////////////////////////////////////////////////////////////////////////
6879/// Cleanup the waiting queries list. The objects are deleted if 'del' is true.
6880/// If 'qls' is non null, only objects in 'qls' are removed.
6881/// Returns the number of cleanup queries
6882
6884{
6885 std::lock_guard<std::recursive_mutex> lock(fQMtx);
6886 Int_t ncq = 0;
6887 if (qls) {
6888 TIter nxq(qls);
6889 TObject *o = 0;
6890 while ((o = nxq())) {
6891 if (fWaitingQueries->FindObject(o)) ncq++;
6893 if (del) delete o;
6894 }
6895 } else {
6896 ncq = fWaitingQueries->GetSize();
6899 }
6900 // Done
6901 return ncq;
6902}
6903
6904////////////////////////////////////////////////////////////////////////////////
6905/// Set the message to be sent back in case of exceptions
6906
6907void TProofServ::SetLastMsg(const char *lastmsg)
6908{
6909 fgLastMsg = lastmsg;
6910}
6911
6912////////////////////////////////////////////////////////////////////////////////
6913/// Set the last entry before exception
6914
6916{
6917 fgLastEntry = entry;
6918}
6919
6920////////////////////////////////////////////////////////////////////////////////
6921/// VirtMemMax getter
6922
6924{
6925 return fgVirtMemMax;
6926}
6927////////////////////////////////////////////////////////////////////////////////
6928/// ResMemMax getter
6929
6931{
6932 return fgResMemMax;
6933}
6934////////////////////////////////////////////////////////////////////////////////
6935/// MemHWM getter
6936
6938{
6939 return fgMemHWM;
6940}
6941////////////////////////////////////////////////////////////////////////////////
6942/// MemStop getter
6943
6945{
6946 return fgMemStop;
6947}
6948
6949////////////////////////////////////////////////////////////////////////////////
6950/// Extract LOCALDATASERVER info in 'dsrv'
6951
6953{
6954 // Check if a local data server has been specified
6955 if (gSystem->Getenv("LOCALDATASERVER")) {
6956 dsrv = gSystem->Getenv("LOCALDATASERVER");
6957 if (!dsrv.EndsWith("/")) dsrv += "/";
6958 }
6959
6960 // Done
6961 return;
6962}
6963
6964////////////////////////////////////////////////////////////////////////////////
6965/// If 'path' is local and 'dsrv' is Xrootd, apply 'path.Localroot' settings,
6966/// if any.
6967/// The final path via the server is dsrv+path.
6968
6969void TProofServ::FilterLocalroot(TString &path, const char *dsrv)
6970{
6971 TUrl u(path, kTRUE);
6972 if (!strcmp(u.GetProtocol(), "file")) {
6973 // Remove prefix, if any, if included and if Xrootd
6974 TString pfx = gEnv->GetValue("Path.Localroot","");
6975 if (!pfx.IsNull() && !strncmp(u.GetFile(), pfx.Data(), pfx.Length())) {
6976 TString srvp = TUrl(dsrv).GetProtocol();
6977 if (srvp == "root" || srvp == "xrd") path.Remove(0, pfx.Length());
6978 }
6979 }
6980
6981 // Done
6982 return;
6983}
6984
6985////////////////////////////////////////////////////////////////////////////////
6986/// Locks the directory. Waits if lock is hold by an other process.
6987/// Returns 0 on success, -1 in case of error.
6988
6990{
6991 const char *pname = GetName();
6992
6993 if (gSystem->AccessPathName(pname))
6994 fLockId = open(pname, O_CREAT|O_RDWR, 0644);
6995 else
6996 fLockId = open(pname, O_RDWR);
6997
6998 if (fLockId == -1) {
6999 SysError("Lock", "cannot open lock file %s", pname);
7000 return -1;
7001 }
7002
7003 PDB(kPackage, 2)
7004 Info("Lock", "%d: locking file %s ...", gSystem->GetPid(), pname);
7005 // lock the file
7006#if !defined(R__WIN32) && !defined(R__WINGCC)
7007 if (lockf(fLockId, F_LOCK, (off_t) 1) == -1) {
7008 SysError("Lock", "error locking %s", pname);
7009 close(fLockId);
7010 fLockId = -1;
7011 return -1;
7012 }
7013#endif
7014
7015 PDB(kPackage, 2)
7016 Info("Lock", "%d: file %s locked", gSystem->GetPid(), pname);
7017
7018 return 0;
7019}
7020
7021////////////////////////////////////////////////////////////////////////////////
7022/// Unlock the directory. Returns 0 in case of success,
7023/// -1 in case of error.
7024
7026{
7027 if (!IsLocked())
7028 return 0;
7029
7030 PDB(kPackage, 2)
7031 Info("Lock", "%d: unlocking file %s ...", gSystem->GetPid(), GetName());
7032 // unlock the file
7033 lseek(fLockId, 0, SEEK_SET);
7034#if !defined(R__WIN32) && !defined(R__WINGCC)
7035 if (lockf(fLockId, F_ULOCK, (off_t)1) == -1) {
7036 SysError("Unlock", "error unlocking %s", GetName());
7037 close(fLockId);
7038 fLockId = -1;
7039 return -1;
7040 }
7041#endif
7042
7043 PDB(kPackage, 2)
7044 Info("Unlock", "%d: file %s unlocked", gSystem->GetPid(), GetName());
7045
7046 close(fLockId);
7047 fLockId = -1;
7048
7049 return 0;
7050}
@ kPROOF_PROCESS
@ kPROOF_VALIDATE_DSET
@ kPROOF_PING
@ kMESS_OK
@ kPROOF_DATA_READY
@ kMESS_STRING
@ kPROOF_GETSTATS
@ kPROOF_GETTREEHEADER
@ kPROOF_STATUS
@ kPROOF_QUERYLIST
@ kPROOF_CHECKFILE
@ kPROOF_GOASYNC
@ kPROOF_PARALLEL
@ kPROOF_LOGLEVEL
@ kPROOF_SENDOUTPUT
@ kPROOF_SESSIONTAG
@ kPROOF_RETRIEVE
@ kPROOF_GETOBJECT
@ kMESS_OBJECT
@ kPROOF_STOPPROCESS
@ kPROOF_VERSARCHCOMP
@ kPROOF_LOGFILE
@ kPROOF_REMOVE
@ kMESS_ACK
@ kPROOF_FATAL
@ kPROOF_OUTPUTOBJECT
@ kPROOF_REALTIMELOG
@ kPROOF_SUBMERGER
@ kROOTD_PROTOCOL
@ kPROOF_QUERYSUBMITTED
@ kPROOF_ARCHIVE
@ kPROOF_SENDFILE
@ kPROOF_GETENTRIES
@ kPROOF_ECHO
@ kPROOF_GETPACKET
@ kPROOF_WORKERLISTS
@ kPROOF_OUTPUTLIST
@ kPROOF_RESET
@ kPROOF_GETPARALLEL
@ kPROOF_PRINT
@ kPROOF_LIB_INC_PATH
@ kPROOF_FORK
@ kPROOF_CACHE
@ kPROOF_MESSAGE
@ kPROOF_LOGDONE
@ kPROOF_DATASETS
@ kMESS_CINT
@ kPROOF_PACKAGE_LIST
@ kPROOF_GETOUTPUTLIST
@ kPROOF_SETIDLE
@ kPROOF_STARTPROCESS
@ kPROOF_GETSLAVEINFO
@ kPROOF_MAXQUERIES
@ kPROOF_CLEANUPSESSION
@ kPROOF_STOP
@ kPROOF_GROUPVIEW
ROOT::R::TRInterface & r
Definition Object.C:4
#define SafeDelete(p)
Definition RConfig.hxx:547
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
const Ssiz_t kNPOS
Definition RtypesCore.h:115
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:92
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
long long Long64_t
Definition RtypesCore.h:73
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
const Bool_t kIterBackward
Definition TCollection.h:41
#define gDirectory
Definition TDirectory.h:290
R__EXTERN TEnv * gEnv
Definition TEnv.h:171
@ kEnvChange
Definition TEnv.h:74
const Int_t kPrint
Definition TError.h:45
const Int_t kError
Definition TError.h:48
const Int_t kSysError
Definition TError.h:50
const Int_t kUnset
Definition TError.h:44
const Int_t kFatal
Definition TError.h:51
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
const Int_t kBreak
Definition TError.h:49
R__EXTERN Int_t gErrorAbortLevel
Definition TError.h:130
const Int_t kWarning
Definition TError.h:47
R__EXTERN Int_t gErrorIgnoreLevel
Definition TError.h:129
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
Definition TError.cxx:92
const Int_t kInfo
Definition TError.h:46
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
int nentries
float * q
#define gInterpreter
double log(double)
R__EXTERN TProofDebug::EProofDebugMask gProofDebugMask
Definition TProofDebug.h:53
#define PDB(mask, level)
Definition TProofDebug.h:56
R__EXTERN Int_t gProofDebugLevel
Definition TProofDebug.h:54
TApplication * GetTProofServ(Int_t *argc, char **argv, FILE *flog)
static volatile Int_t gProofServDebug
static void SendAsynMsg(const char *msg)
TProofServ * gProofServ
R__EXTERN TProofServ * gProofServ
Definition TProofServ.h:347
Int_t(* OldProofServAuthSetup_t)(TSocket *, Bool_t, Int_t, TString &, TString &, TString &)
Definition TProofServ.h:62
const char *const kPROOF_QueryDir
Definition TProof.h:128
const char *const kPROOF_DataSetDir
Definition TProof.h:129
const char *const kPROOF_DataDir
Definition TProof.h:130
const char *const kRM
Definition TProof.h:142
const char *const kPROOF_CacheLockFile
Definition TProof.h:131
const char *const kCP
Definition TProof.h:141
const char *const kPROOF_CacheDir
Definition TProof.h:125
const char *const kPROOF_PackDir
Definition TProof.h:126
const char *const kLS
Definition TProof.h:143
const char *const kPROOF_WorkDir
Definition TProof.h:124
const char *const kPROOF_QueryLockFile
Definition TProof.h:133
R__EXTERN TProof * gProof
Definition TProof.h:1077
const Int_t kPROOF_Protocol
Definition TProof.h:120
Int_t gDebug
Definition TROOT.cxx:590
#define gROOT
Definition TROOT.h:406
void Printf(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2510
@ kSigTermination
@ kSigPipe
@ kSigUrgent
@ kKeepAlive
Definition TSystem.h:219
@ kBytesToRead
Definition TSystem.h:225
@ kNoDelay
Definition TSystem.h:221
@ kProcessGroup
Definition TSystem.h:223
@ kAtMark
Definition TSystem.h:224
@ kOob
Definition TSystem.h:230
@ kReadPermission
Definition TSystem.h:47
@ kWritePermission
Definition TSystem.h:46
@ kLogLocal5
Definition TSystem.h:72
ELogLevel
Definition TSystem.h:55
@ kLogWarning
Definition TSystem.h:60
@ kLogNotice
Definition TSystem.h:61
@ kLogInfo
Definition TSystem.h:62
@ kLogErr
Definition TSystem.h:59
Bool_t R_ISDIR(Int_t mode)
Definition TSystem.h:115
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
@ kLogPid
Definition TSystem.h:51
@ kLogCons
Definition TSystem.h:52
#define gPerfStats
#define snprintf
Definition civetweb.c:1540
static struct mg_connection * fc(struct mg_context *ctx)
Definition civetweb.c:3728
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
Bool_t NoLogOpt() const
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a "....
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
TObject * ReadObject(const TClass *cl) override
Read object from I/O buffer.
char * ReadString(char *s, Int_t max) override
Read string from I/O buffer.
void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
Int_t BufferSize() const
Definition TBuffer.h:98
Int_t Length() const
Definition TBuffer.h:100
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
void SetName(const char *name)
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Manages an element of a TDSet.
Definition TDSet.h:66
This class implements a data set to be used for PROOF processing.
Definition TDSet.h:153
virtual void SetEntryList(TObject *aList)
Set entry (or event) list for this data set.
Definition TDSet.cxx:1894
static Long64_t GetEntries(Bool_t isTree, const char *filename, const char *path, TString &objname)
Returns number of entries in tree or objects in file.
Definition TDSet.cxx:1382
Int_t GetNumOfFiles()
Return the number of files in the dataset.
Definition TDSet.cxx:2019
void Validate()
Validate the TDSet by opening files.
Definition TDSet.cxx:1590
void SetWriteV3(Bool_t on=kTRUE)
Set/Reset the 'OldStreamer' bit in this instance and its elements.
Definition TDSet.cxx:1875
TList * GetListOfElements() const
Definition TDSet.h:231
const char * GetObjName() const
Definition TDSet.h:229
@ kEmpty
Definition TDSet.h:159
@ kWriteV3
Definition TDSet.h:158
Int_t WriteDataSet(const char *group, const char *user, const char *dsName, TFileCollection *dataset, UInt_t option=0, TMD5 *checksum=0)
Writes indicated dataset.
TFileCollection * GetDataSet(const char *uri, const char *srv=0)
Utility function used in various methods for user dataset upload.
Bool_t ExistsDataSet(const char *group, const char *user, const char *dsName)
Checks if the indicated dataset exits.
Bool_t RemoveDataSet(const char *group, const char *user, const char *dsName)
Removes the indicated dataset.
virtual TFileCollection * GetDataSet(const char *uri, const char *server=0)
Utility function used in various methods for user dataset upload.
Int_t ScanDataSet(const char *uri, const char *opt)
Scans the dataset indicated by 'uri' following the 'opts' directives.
virtual TMap * GetDataSets(const char *uri, UInt_t=TDataSetManager::kExport)
Returns all datasets for the <group> and <user> specified by <uri>.
virtual Bool_t ExistsDataSet(const char *uri)
Checks if the indicated dataset exits.
virtual TMap * GetGroupQuotaMap()
virtual void ShowDataSets(const char *uri="*", const char *opt="")
Prints formatted information about the dataset 'uri'.
virtual void ShowQuota(const char *opt)
Display quota information.
virtual Bool_t RemoveDataSet(const char *uri)
Removes the indicated dataset.
Bool_t ParseUri(const char *uri, TString *dsGroup=0, TString *dsUser=0, TString *dsName=0, TString *dsTree=0, Bool_t onlyCurrent=kFALSE, Bool_t wildcards=kFALSE)
Parses a (relative) URI that describes a DataSet on the cluster.
virtual Int_t ClearCache(const char *uri)
Clear cached information matching uri.
virtual Int_t RegisterDataSet(const char *uri, TFileCollection *dataSet, const char *opt)
Register a dataset, perfoming quota checkings, if needed.
virtual Int_t ShowCache(const char *uri)
Show cached information matching uri.
Bool_t cd(const char *path=nullptr) override
Change current directory to "this" directory.
A List of entry numbers in a TTree or TChain.
Definition TEntryList.h:26
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition TEnv.cxx:592
virtual TEnvRec * Lookup(const char *n) const
Loop over all resource records and return the one with name.
Definition TEnv.cxx:547
A TEventList object is a list of selected events (entries) in a TTree.
Definition TEventList.h:31
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
THashList * GetList()
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
void SetFd(int fd)
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
Class describing a generic file including meta information.
Definition TFileInfo.h:39
Bool_t RemoveUrlAt(Int_t i)
Remove URL at given position. Returns kTRUE on success, kFALSE on error.
Int_t GetNUrls() const
Definition TFileInfo.h:75
TUrl * GetCurrentUrl() const
Return the current url.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
Definition TFile.cxx:4464
virtual Bool_t IsOpen() const
Returns kTRUE in case file is open and kFALSE if file is not open.
Definition TFile.cxx:1385
static EFileType GetType(const char *name, Option_t *option="", TString *prefix=nullptr)
Resolve the file type as a function of the protocol field in 'name'.
Definition TFile.cxx:4711
EFileType
File type.
Definition TFile.h:194
@ kWeb
Definition TFile.h:194
@ kNet
Definition TFile.h:194
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3997
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
TObject * FindObject(const char *name) const
Find object using its name.
Bool_t Notify()
Handle expiration of the idle timer. The session will just be terminated.
TProofServ * fProofServ
Definition TProofServ.h:445
This class represents an Internet Protocol (IP) address.
TObject * Next()
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual const char * GetClassName() const
Definition TKey.h:76
A doubly linked list.
Definition TList.h:44
virtual void Add(TObject *obj)
Definition TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition TList.cxx:822
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:357
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:693
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:659
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition TList.cxx:402
This code implements the MD5 message-digest algorithm.
Definition TMD5.h:44
static TMD5 * FileChecksum(const char *file)
Returns checksum of specified file.
Definition TMD5.cxx:474
Class supporting a collection of lines with C++ code.
Definition TMacro.h:31
virtual Int_t ReadFile(const char *filename)
Read lines in filename in this macro.
Definition TMacro.cxx:338
void SaveSource(FILE *fp)
Save macro source in file pointer fp.
Definition TMacro.cxx:383
TList * GetListOfLines() const
Definition TMacro.h:51
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
void DeleteAll()
Remove all (key,value) pairs from the map AND delete the keys AND values when they are allocated on t...
Definition TMap.cxx:168
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition TMap.cxx:54
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:236
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:215
static void EnableSchemaEvolutionForAll(Bool_t enable=kTRUE)
Static function enabling or disabling the automatic schema evolution.
Definition TMessage.cxx:116
UInt_t What() const
Definition TMessage.h:75
void Reset() override
Reset the message buffer so we can use (i.e. fill) it again.
Definition TMessage.cxx:179
void SetCompressionSettings(Int_t settings=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Set compression settings.
Definition TMessage.cxx:288
Int_t Compress()
Compress the message.
Definition TMessage.cxx:306
Int_t CompLength() const
Definition TMessage.h:90
TClass * GetClass() const
Definition TMessage.h:71
virtual void RemoveAll()
Remove all sockets from the monitor.
Definition TMonitor.cxx:241
TSocket * Select()
Return pointer to socket for which an event is waiting.
Definition TMonitor.cxx:322
virtual void Add(TSocket *sock, Int_t interest=kRead)
Add socket to the monitor's active list.
Definition TMonitor.cxx:168
Int_t GetActive(Long_t timeout=-1) const
Return number of sockets in the active list.
Definition TMonitor.cxx:438
virtual void DeActivateAll()
De-activate all activated sockets.
Definition TMonitor.cxx:302
TList * GetListOfDeActives() const
Returns a list with all de-active sockets.
Definition TMonitor.cxx:515
virtual void Remove(TSocket *sock)
Remove a socket from the monitor.
Definition TMonitor.cxx:214
void Interrupt()
Definition TMonitor.h:71
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:37
Collectable string class.
Definition TObjString.h:28
const char * GetName() const
Returns name of object.
Definition TObjString.h:38
Mother of all ROOT objects.
Definition TObject.h:37
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:798
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:187
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition TObject.cxx:907
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:149
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:921
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition TObject.cxx:552
void ResetBit(UInt_t f)
Definition TObject.h:186
@ kInvalidObject
if object ctor succeeded but object should not be used
Definition TObject.h:68
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:867
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition TPRegexp.h:97
Int_t Substitute(TString &s, const TString &r, Bool_t doDollarSubst=kTRUE)
Substitute matching part of s with r, dollar back-ref substitution is performed if doDollarSubst is t...
Definition TPRegexp.cxx:874
Int_t Match(const TString &s, UInt_t start=0)
Runs a match on s against the regex 'this' was created with.
Definition TPRegexp.cxx:708
The PROOF package manager contains tools to manage packages.
Definition TPackMgr.h:37
void SetLogger(TPackMgrLog_t logger)
Definition TPackMgr.h:67
Bool_t IsInDir(const char *path)
Method to check if 'path' is in the managed directory Return kTRUE or kFALSE.
Definition TPackMgr.cxx:478
@ kCheckROOT
Definition TPackMgr.h:39
void Show(const char *title=0)
Show available packages.
Definition TPackMgr.cxx:548
void GetEnabledPackages(TString &packlist)
Method to get a semi-colon separated list with the names of the enabled packages.
Definition TPackMgr.cxx:501
Int_t Build(const char *pack, Int_t opt=TPackMgr::kCheckROOT)
Method to build a package.
Definition TPackMgr.cxx:87
Int_t Install(const char *par, Bool_t rmold=kFALSE)
Install package from par (unpack the file in the directory); par can be an URL for remote retrieval.
Definition TPackMgr.cxx:766
Int_t GetParPath(const char *pack, TString &path)
Method to get the path of the PAR file for package 'pack'.
Definition TPackMgr.cxx:521
Int_t Unpack(const char *pack, TMD5 *sum=0)
Read MD5 checksum of the PAR file from the PROOF-INF/md5.txt file.
Definition TPackMgr.cxx:723
TMD5 * GetMD5(const char *pack)
Get MD5 checksum of the PAR file corresponding to given package Returns a pointer to a TMD5 object,...
Definition TPackMgr.cxx:692
void ShowEnabled(const char *title=0)
Show enabled packages.
Definition TPackMgr.cxx:662
TList * GetList() const
Get list of available packages Returns a pointer to a TList object, transferring ownership to the cal...
Definition TPackMgr.cxx:621
Int_t Clean(const char *pack)
Clean dir for package 'pack' Return -1 in case of error, 0 otherwise.
Definition TPackMgr.cxx:576
static Int_t RegisterGlobalPath(const char *paths)
Parse one or more paths as possible sources of packages Returns number of paths added; or -1 in case ...
Definition TPackMgr.cxx:872
Int_t Load(const char *pack, TList *optls=0)
Method to load a package taking an option list Return -1 on error, 0 otherwise.
Definition TPackMgr.cxx:220
Int_t Unload(const char *pack)
Method to unload a package.
Definition TPackMgr.cxx:411
TList * GetListOfEnabled() const
Get list of enabled packages Returns a pointer to a TList object, transferring ownership to the calle...
Definition TPackMgr.cxx:644
static TPackMgr * GetPackMgr(const char *pack, TPackMgr *packmgr=nullptr)
Get the package manager having 'pack'; priority is given to packmgr, if defined.
Definition TPackMgr.cxx:912
void SetPrefix(const char *pfx)
Definition TPackMgr.h:68
Int_t Remove(const char *pack=0, Bool_t dolock=kTRUE)
Remove package 'pack' If 'pack' is null or empty all packages are cleared.
Definition TPackMgr.cxx:593
TMD5 * ReadMD5(const char *pack)
Read MD5 checksum of the PAR file from the PROOF-INF/md5.txt file.
Definition TPackMgr.cxx:708
const char * GetTitle() const
Returns title of object.
Definition TPackMgr.h:63
Class used by TMap to store (key,value) pairs.
Definition TMap.h:102
TObject * Value() const
Definition TMap.h:121
Named parameter, streamable and storable.
Definition TParameter.h:35
const AParamType & GetVal() const
Definition TParameter.h:67
This class implements a plugin library manager.
TPluginHandler * FindHandler(const char *base, const char *uri=0)
Returns the handler if there exists a handler for the specified URI.
Bool_t IsLocked() const
Definition TProofServ.h:360
Int_t Unlock()
Unlock the directory.
Int_t Lock()
Locks the directory.
The purpose of this class is to provide a complete node description for masters, submasters and worke...
const TString & GetImage() const
const TString & GetWorkDir() const
Container class for processing statistics.
void Print(Option_t *option="") const
Dump the content.
Long64_t GetEntries() const
void SetLearnTime(Double_t learnTime)
void IncCPUTime(Double_t procTime)
void IncProcTime(Double_t procTime)
Long64_t GetBytesRead() const
TQueryResult version adapted to PROOF neeeds.
void SetRunning(Int_t startlog, const char *par, Int_t nwrks)
Call when running starts.
The purpose of this class is to provide a standard interface to static config files.
TProofNodeInfo * GetMaster()
Get the master node.
TList * GetSubmasters()
Get the list of submaster nodes.
TList * GetWorkers()
Get the list of worker nodes.
virtual Bool_t IsValid() const
TProofServLogHandlerGuard(const char *cmd, TSocket *s, const char *pfx="", Bool_t on=kTRUE)
Init a guard for executing a command in a pipe.
TProofServLogHandler * fExecHandler
Definition TProofServ.h:404
virtual ~TProofServLogHandlerGuard()
Close a guard for executing a command in a pipe.
Bool_t Notify()
Handle available message in the open file.
virtual ~TProofServLogHandler()
Handle available message in the open file.
TProofServLogHandler(const char *cmd, TSocket *s, const char *pfx="")
Execute 'cmd' in a pipe and handle output messages from the related file.
static Int_t fgCmdRtn
Definition TProofServ.h:382
static TString fgPfx
Definition TProofServ.h:381
static Int_t GetCmdRtn()
Static method to get the return code from the execution of a command via the pipe.
static void SetDefaultPrefix(const char *pfx)
Static method to set the default prefix.
Class providing the PROOF server.
Definition TProofServ.h:66
Float_t fCpuTime
Definition TProofServ.h:114
TString fQueryDir
Definition TProofServ.h:88
const char * GetOrdinal() const
Definition TProofServ.h:253
TPackMgr * fPackMgr
Definition TProofServ.h:86
virtual ~TProofServ()
Cleanup.
void SetIdle(Bool_t st=kTRUE)
Change the idle status.
const char * GetConfDir() const
Definition TProofServ.h:239
Int_t fProtocol
Definition TProofServ.h:103
void Interrupt()
Definition TProofServ.h:291
void TruncateLogFile()
Truncate the log file to the 80% of the required max size if this is set.
Int_t CatMotd()
Print message of the day (in the file pointed by the env PROOFMOTD or from fConfDir/etc/proof/motd).
TString fArchivePath
Definition TProofServ.h:96
Int_t GetPriority()
Get the processing priority for the group the user belongs too.
Int_t fGroupId
Definition TProofServ.h:105
void SendStatistics()
Send statistics of slave server to master or client.
const char * GetImage() const
Definition TProofServ.h:244
virtual Int_t CreateServer()
Finalize the server setup.
Int_t fLogLevel
Definition TProofServ.h:107
FILE * fLogFile
Definition TProofServ.h:100
virtual EQueryAction GetWorkers(TList *workers, Int_t &prioritychange, Bool_t resume=kFALSE)
Get list of workers to be used from now on.
Int_t GetQuerySeqNum() const
Definition TProofServ.h:260
Bool_t IsWaiting()
Return kTRUE if the session is waiting for the OK to start processing.
TString fDataDir
Definition TProofServ.h:90
void Print(Option_t *option="") const
Print status of slave server.
static void ErrorHandler(Int_t level, Bool_t abort, const char *location, const char *msg)
The PROOF error handler function.
static Long_t fgResMemMax
Definition TProofServ.h:160
TString fSessionDir
Definition TProofServ.h:85
TMonitor * fMergingMonitor
Definition TProofServ.h:150
TString fAdminPath
Definition TProofServ.h:92
const char * GetUser() const
Definition TProofServ.h:241
virtual void HandleProcess(TMessage *mess, TString *slb=0)
Handle processing request.
void FlushLogFile()
Reposition the read pointer in the log file to the very end.
Int_t CleanupWaitingQueries(Bool_t del=kTRUE, TList *qls=0)
Cleanup the waiting queries list.
static FILE * fgErrorHandlerFile
Definition TProofServ.h:168
static Bool_t IsActive()
Static function that returns kTRUE in case we are a PROOF server.
static TProofServ * This()
Static function returning pointer to global object gProofServ.
TString fService
Definition TProofServ.h:76
static void GetLocalServer(TString &dsrv)
Extract LOCALDATASERVER info in 'dsrv'.
virtual void HandleRemove(TMessage *mess, TString *slb=0)
Handle remove request.
static void SetLastEntry(Long64_t lastentry)
Set the last entry before exception.
virtual void HandleArchive(TMessage *mess, TString *slb=0)
Handle archive request.
static Float_t GetMemHWM()
MemHWM getter.
Int_t fLogFileDes
Definition TProofServ.h:101
Bool_t IsParallel() const
True if in parallel mode.
TProofLockPath * fQueryLock
Definition TProofServ.h:95
static void FilterLocalroot(TString &path, const char *url="root://dum/")
If 'path' is local and 'dsrv' is Xrootd, apply 'path.Localroot' settings, if any.
Long64_t fMsgSizeHWM
Definition TProofServ.h:166
static FILE * SetErrorHandlerFile(FILE *ferr)
Set the file stream where to log (default stderr).
virtual void HandleFork(TMessage *mess)
Cloning itself via fork. Not implemented.
virtual void HandleSigPipe()
Called when the client is not alive anymore (i.e.
void RedirectOutput(const char *dir=0, const char *mode="w")
Redirect stdout to a log file.
static void SetLastMsg(const char *lastmsg)
Set the message to be sent back in case of exceptions.
TStopwatch fLatency
Definition TProofServ.h:115
virtual void DeletePlayer()
Delete player instance.
virtual void ProcessNext(TString *slb=0)
process the next query from the queue of submitted jobs.
Bool_t fMasterServ
Definition TProofServ.h:111
TSocket * GetSocket() const
Definition TProofServ.h:257
virtual void HandleUrgentData()
Handle Out-Of-Band data sent by the master or client.
void SetQueryRunning(TProofQueryResult *pq)
Set query in running state.
TProofQueryResult * NextQuery()
Get the next query from the waiting list.
TSocket * fSocket
Definition TProofServ.h:97
Int_t fCompressMsg
Definition TProofServ.h:142
Int_t SetupCommon()
Common part (between TProofServ and TXProofServ) of the setup phase.
Int_t SendResults(TSocket *sock, TList *outlist=0, TQueryResult *pq=0)
Sends all objects from the given list to the specified socket.
TString fDataSetDir
Definition TProofServ.h:89
TString fPrefix
Definition TProofServ.h:134
const char * GetGroup() const
Definition TProofServ.h:242
TDSetElement * GetNextPacket(Long64_t totalEntries=-1)
Get next range of entries to be processed on this server.
Bool_t IsEndMaster() const
Definition TProofServ.h:292
void SendAsynMessage(const char *msg, Bool_t lf=kTRUE)
Send an asychronous message to the master / client .
static void ResolveKeywords(TString &fname, const char *path=0)
Replace <ord>, <user>, <u>, <group>, <stag>, <qnum>, <file>, <rver> and <build> placeholders in fname...
Int_t ReceiveFile(const char *file, Bool_t bin, Long64_t size)
Receive a file, either sent by a client or a master server.
virtual Int_t HandleWorkerLists(TMessage *mess)
Handle here all requests to modify worker lists.
static Int_t RegisterDataSets(TList *in, TList *out, TDataSetManager *dsm, TString &e)
Register TFileCollections in 'out' as datasets according to the rules in 'in'.
TVirtualProofPlayer * fPlayer
Definition TProofServ.h:99
TString fSessionTag
Definition TProofServ.h:83
virtual void HandleQueryList(TMessage *mess)
Handle request for list of queries.
Bool_t IsMaster() const
Definition TProofServ.h:293
const char * GetDataDir() const
Definition TProofServ.h:250
Bool_t fSendLogToMaster
Definition TProofServ.h:147
virtual void HandleCheckFile(TMessage *mess, TString *slb=0)
Handle file checking request.
static Float_t fgMemStop
Definition TProofServ.h:163
TProofLockPath * fCacheLock
Definition TProofServ.h:94
TProof * fProof
Definition TProofServ.h:98
TString fOrdinal
Definition TProofServ.h:104
TProofServ(Int_t *argc, char **argv, FILE *flog=0)
Main constructor.
Bool_t fEndMaster
Definition TProofServ.h:110
Long64_t fLogFileMaxSize
Definition TProofServ.h:102
virtual Int_t HandleCache(TMessage *mess, TString *slb=0)
Handle here all cache and package requests.
std::recursive_mutex fQMtx
Definition TProofServ.h:130
virtual void HandleSocketInput()
Handle input coming from the client or from the master server.
TString fWorkDir
Definition TProofServ.h:81
virtual void MakePlayer()
Make player instance.
virtual void HandleSubmerger(TMessage *mess)
Handle a message of type kPROOF_SUBMERGER.
virtual Int_t HandleLibIncPath(TMessage *mess)
Handle lib, inc search paths modification request.
TShutdownTimer * fShutdownTimer
Definition TProofServ.h:138
TString fCacheDir
Definition TProofServ.h:87
Bool_t IsIdle()
Return the idle status.
Int_t fNcmd
Definition TProofServ.h:108
TDataSetManagerFile * fDataSetStgRepo
Definition TProofServ.h:145
Int_t GetSessionStatus()
Return the status of this session: 0 idle 1 running 2 being terminated (currently unused) 3 queued 4 ...
virtual Int_t HandleDataSets(TMessage *mess, TString *slb=0)
Handle here requests about datasets.
TServerSocket * fMergingSocket
Definition TProofServ.h:149
Bool_t fInterrupt
Definition TProofServ.h:112
Int_t fActSessions
Definition TProofServ.h:121
TList * fQueuedMsg
Definition TProofServ.h:132
TString fGroup
Definition TProofServ.h:78
Bool_t fRealTimeLog
Definition TProofServ.h:136
void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
virtual Int_t Setup()
Print the ProofServ logo on standard output.
TStopwatch fCompute
Definition TProofServ.h:116
static Long_t fgVirtMemMax
Definition TProofServ.h:159
Int_t fMergedWorkers
Definition TProofServ.h:151
TString fImage
Definition TProofServ.h:82
TString fTopSessionTag
Definition TProofServ.h:84
TFileHandler * fInputHandler
Definition TProofServ.h:124
void SendParallel(Bool_t async=kFALSE)
Send number of parallel nodes to master or client.
Int_t GetCompressionLevel() const
Definition TProofServ.h:464
static Float_t fgMemHWM
Definition TProofServ.h:162
Float_t fEffSessions
Definition TProofServ.h:122
static Long_t GetResMemMax()
ResMemMax getter.
Long64_t fHWMBoxSize
Definition TProofServ.h:156
TString fConfDir
Definition TProofServ.h:79
Int_t QueueQuery(TProofQueryResult *pq)
Add a query to the waiting list Returns the number of queries in the list.
TIdleTOTimer * fIdleTOTimer
Definition TProofServ.h:140
static Int_t fgLogToSysLog
Definition TProofServ.h:172
static TString fgLastMsg
Definition TProofServ.h:228
virtual Int_t Fork()
Fork a child.
Int_t fMaxQueries
Definition TProofServ.h:154
static Long_t GetVirtMemMax()
VirtMemMax getter.
Bool_t UnlinkDataDir(const char *path)
Scan recursively the datadir and unlink it if empty Return kTRUE if it can be unlinked,...
Int_t GetProtocol() const
Definition TProofServ.h:252
TString fConfFile
Definition TProofServ.h:80
Int_t fTotSessions
Definition TProofServ.h:120
Int_t fGroupSize
Definition TProofServ.h:106
Bool_t AcceptResults(Int_t connections, TVirtualProofPlayer *mergerPlayer)
Accept and merge results from a set of workers.
TDataSetManager * fDataSetManager
Definition TProofServ.h:144
TString fUser
Definition TProofServ.h:77
static Int_t fgRecursive
Definition TProofServ.h:169
TQueryResultManager * fQMgr
Definition TProofServ.h:126
TList * fWaitingQueries
Definition TProofServ.h:128
void Reset(const char *dir)
Reset PROOF environment to be ready for execution of next command.
virtual void Terminate(Int_t status)
Terminate the proof server.
virtual void HandleException(Int_t sig)
Exception handler: we do not try to recover here, just exit.
Int_t OldAuthSetup(TString &wconf)
Setup authentication related stuff for old versions.
static TString fgSysLogEntity
Definition TProofServ.h:174
TString fDataDirOpts
Definition TProofServ.h:91
Int_t WaitingQueries()
Return the number of waiting queries.
void Run(Bool_t retrn=kFALSE)
Main server eventloop.
Long64_t fMaxBoxSize
Definition TProofServ.h:155
const char * GetWorkDir() const
Definition TProofServ.h:243
const char * GetPrefix() const
Definition TProofServ.h:276
static TString fgSysLogService
Definition TProofServ.h:173
void LogToMaster(Bool_t on=kTRUE)
Definition TProofServ.h:322
Int_t fGroupPriority
Definition TProofServ.h:109
TReaperTimer * fReaperTimer
Definition TProofServ.h:139
static Long64_t fgLastEntry
Definition TProofServ.h:229
const char * GetSessionTag() const
Definition TProofServ.h:245
virtual void SendLogFile(Int_t status=0, Int_t start=-1, Int_t end=-1)
Send log file to master.
Float_t fRealTime
Definition TProofServ.h:113
static Float_t GetMemStop()
MemStop getter.
Bool_t IsTopMaster() const
Definition TProofServ.h:295
void RestartComputeTime()
Reset the compute time.
Int_t fQuerySeqNum
Definition TProofServ.h:118
TProofQueryResult * MakeQueryResult(Long64_t nentries, const char *opt, TList *inl, Long64_t first, TDSet *dset, const char *selec, TObject *elist)
Create a TProofQueryResult instance for this query.
virtual void HandleRetrieve(TMessage *mess, TString *slb=0)
Handle retrieve request.
TStopwatch fSaveOutput
Definition TProofServ.h:117
Int_t UpdateSessionStatus(Int_t xst=-1)
Update the session status in the relevant file.
Bool_t fIdle
Definition TProofServ.h:129
TObject * Get(const char *namecycle)
Get object with name "name;cycle" (e.g.
static TMap * GetDataSetNodeMap(TFileCollection *fc, TString &emsg)
Get a map {server-name, list-of-files} for collection 'fc' to be used in TPacketizerFile.
const char * GetService() const
Definition TProofServ.h:238
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition TProof.h:316
const char * GetSessionTag() const
Definition TProof.h:909
void ShowPackages(Bool_t all=kFALSE, Bool_t redirlog=kFALSE)
List contents of package directory.
Definition TProof.cxx:7760
@ kShutdownInterrupt
Definition TProof.h:398
@ kHardInterrupt
Definition TProof.h:396
@ kSoftInterrupt
Definition TProof.h:397
Bool_t IsEndMaster() const
Definition TProof.h:664
Int_t UploadPackage(const char *par, EUploadPackageOpt opt=kUntar, TList *workers=0)
Upload a PROOF archive (PAR file).
Definition TProof.cxx:8431
Int_t SendCurrentState(ESlaves list=kActive)
Transfer the current state of the master to the active slave servers.
Definition TProof.cxx:6748
TList * GetListOfSlaves() const
Definition TProof.h:654
@ kDeactivateWorker
Definition TProof.h:451
@ kActivateWorker
Definition TProof.h:450
Int_t DisablePackages()
Remove all packages.
Definition TProof.cxx:7932
@ kCollectBuildResults
Definition TProof.h:457
@ kBuildOnSlavesNoWait
Definition TProof.h:455
@ kBuildAll
Definition TProof.h:456
static Int_t SaveInputData(TQueryResult *qr, const char *cachedir, TString &emsg)
Save input data file from 'cachedir' into the sandbox or create a the file with input data objects.
Definition TProof.cxx:12301
Int_t BuildPackage(const char *package, EBuildPackageOpt opt=kBuildAll, Int_t chkveropt=TPackMgr::kCheckROOT, TList *workers=0)
Build specified package.
Definition TProof.cxx:7980
virtual void Print(Option_t *option="") const
Print status of PROOF cluster.
Definition TProof.cxx:4793
TList * GetListOfInactiveSlaves() const
Definition TProof.h:655
static Int_t GetInputData(TList *input, const char *cachedir, TString &emsg)
Get the input data from the file defined in the input list.
Definition TProof.cxx:12403
Bool_t IsParallel() const
Definition TProof.h:939
TVirtualProofPlayer * GetPlayer() const
Definition TProof.h:716
void AskParallel()
Ask the for the number of parallel slaves.
Definition TProof.cxx:2067
virtual void ClearCache(const char *file=0)
Remove file from all file caches.
Definition TProof.cxx:7704
Int_t ActivateWorker(const char *ord, Bool_t save=kTRUE)
Make sure that the worker identified by the ordinal number 'ord' is in the active list.
Definition TProof.cxx:11343
TObject * GetParameter(const char *par) const
Get specified parameter.
Definition TProof.cxx:9908
void SetRunStatus(ERunStatus rst)
Definition TProof.h:672
static void AssertMacroPath(const char *macro)
Make sure that the directory path contained by macro is in the macro path.
Definition TProof.cxx:8589
@ kRunning
Definition TProof.h:371
Int_t AddIncludePath(const char *incpath, Bool_t onClient=kFALSE, TList *wrks=0, Bool_t doCollect=kTRUE)
Add 'incpath' to the inc path search.
Definition TProof.cxx:8878
virtual void ShowCache(Bool_t all=kFALSE)
List contents of file cache.
Definition TProof.cxx:7681
Bool_t IsValid() const
Definition TProof.h:937
Int_t SetParallel(Int_t nodes=-1, Bool_t random=kFALSE)
Tell PROOF how many slaves to use in parallel.
Definition TProof.cxx:7130
@ kStopMerging
Definition TProof.h:381
@ kOutputSent
Definition TProof.h:382
@ kMergerDown
Definition TProof.h:380
@ kSendOutput
Definition TProof.h:378
@ kOutputSize
Definition TProof.h:377
@ kBeMerger
Definition TProof.h:379
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:11750
static Bool_t GetFileInCmd(const char *cmd, TString &fn)
Static method to extract the filename (if any) form a CINT command.
Definition TProof.cxx:6485
Float_t GetCpuTime() const
Definition TProof.h:931
void SetPlayer(TVirtualProofPlayer *player)
Set a new PROOF player.
Definition TProof.cxx:10189
Int_t ClearPackage(const char *package)
Remove a specific package.
Definition TProof.cxx:7847
Int_t AddWorkers(TList *wrks)
Works on the master node only.
Definition TProof.cxx:1310
Int_t ClearPackages()
Remove all packages.
Definition TProof.cxx:7830
void SetActive(Bool_t=kTRUE)
Definition TProof.h:988
EUploadPackageOpt
Definition TProof.h:366
@ kUntar
Definition TProof.h:367
@ kRemoveOld
Definition TProof.h:368
Int_t RemoveIncludePath(const char *incpath, Bool_t onClient=kFALSE)
Remove 'incpath' from the inc path search.
Definition TProof.cxx:8957
Int_t GetParallel() const
Returns number of slaves active in parallel mode.
Definition TProof.cxx:2294
Int_t UnloadPackage(const char *package)
Unload specified package.
Definition TProof.cxx:8104
Long64_t GetBytesRead() const
Definition TProof.h:929
void AskStatistics()
Ask the for the statistics of the slaves.
Definition TProof.cxx:2012
Int_t DeactivateWorker(const char *ord, Bool_t save=kTRUE)
Remove the worker identified by the ordinal number 'ord' from the the active list.
Definition TProof.cxx:11360
@ kRemoveDataSet
Definition TProof.h:430
@ kRegisterDataSet
Definition TProof.h:427
@ kShowQuota
Definition TProof.h:434
@ kGetQuota
Definition TProof.h:433
@ kStagingStatus
Definition TProof.h:438
@ kShowDataSets
Definition TProof.h:432
@ kCache
Definition TProof.h:436
@ kSetDefaultTreeName
Definition TProof.h:435
@ kRequestStaging
Definition TProof.h:437
@ kGetDataSets
Definition TProof.h:426
@ kCheckDataSetName
Definition TProof.h:425
@ kVerifyDataSet
Definition TProof.h:429
@ kCancelStaging
Definition TProof.h:439
@ kGetDataSet
Definition TProof.h:428
void SetRealTimeLog(Bool_t on=kTRUE)
Switch ON/OFF the real-time logging facility.
Definition TProof.cxx:7086
Int_t Ping(ESlaves list)
Ping PROOF slaves. Returns the number of slaves that responded.
Definition TProof.cxx:4742
Int_t UnloadPackages()
Unload all packages.
Definition TProof.cxx:8137
virtual TVirtualProofPlayer * MakePlayer(const char *player=0, TSocket *s=0)
Construct a TProofPlayer object.
Definition TProof.cxx:10201
TList * GetListOfActiveSlaves() const
Definition TProof.h:723
virtual Int_t Load(const char *macro, Bool_t notOnClient=kFALSE, Bool_t uniqueOnly=kTRUE, TList *wrks=0)
Load the specified macro on master, workers and, if notOnClient is kFALSE, on the client.
Definition TProof.cxx:8618
Int_t AddDynamicPath(const char *libpath, Bool_t onClient=kFALSE, TList *wrks=0, Bool_t doCollect=kTRUE)
Add 'libpath' to the lib path search.
Definition TProof.cxx:8833
Int_t RemoveWorkers(TList *wrks)
Used for shuting down the workres after a query is finished.
Definition TProof.cxx:1587
Int_t RemoveDynamicPath(const char *libpath, Bool_t onClient=kFALSE)
Remove 'libpath' from the lib path search.
Definition TProof.cxx:8923
TList * GetOutputList()
Get list with all object created during processing (see Process()).
Definition TProof.cxx:9798
void StopProcess(Bool_t abort, Int_t timeout=-1)
Send STOPPROCESS message to master and workers.
Definition TProof.cxx:6214
Int_t SendFile(const char *file, Int_t opt=(kBinary|kForward|kCp|kCpBin), const char *rfile=0, TSlave *sl=0)
Send a file to master or slave servers.
Definition TProof.cxx:6884
static Int_t AssertDataSet(TDSet *dset, TList *input, TDataSetManager *mgr, TString &emsg)
Make sure that dataset is in the form to be processed.
Definition TProof.cxx:12004
void Interrupt(EUrgent type, ESlaves list=kActive)
Send interrupt to master or slave servers.
Definition TProof.cxx:2266
virtual Int_t Echo(const TObject *obj)
Sends an object to master and workers and expect them to send back a message with the output of its T...
Definition TProof.cxx:7018
Int_t SendCommand(const char *cmd, ESlaves list=kActive)
Send command to be executed on the PROOF master and/or slaves.
Definition TProof.cxx:6621
TList * GetListOfSlaveInfos()
Returns list of TSlaveInfo's. In case of error return 0.
Definition TProof.cxx:2311
virtual void ValidateDSet(TDSet *dset)
Validate a TDSet.
Definition TProof.cxx:9370
@ kDisableSubPackage
Definition TProof.h:413
@ kClearPackages
Definition TProof.h:404
@ kShowSubPackages
Definition TProof.h:411
@ kShowEnabledPackages
Definition TProof.h:408
@ kListEnabledPackages
Definition TProof.h:420
@ kClearPackage
Definition TProof.h:405
@ kLoadMacro
Definition TProof.h:421
@ kShowSubCache
Definition TProof.h:409
@ kDisablePackage
Definition TProof.h:416
@ kDisablePackages
Definition TProof.h:418
@ kLoadPackage
Definition TProof.h:407
@ kBuildPackage
Definition TProof.h:406
@ kListPackages
Definition TProof.h:419
@ kUnloadPackages
Definition TProof.h:417
@ kUnloadPackage
Definition TProof.h:415
@ kShowCache
Definition TProof.h:401
@ kClearSubCache
Definition TProof.h:410
@ kBuildSubPackage
Definition TProof.h:414
@ kClearCache
Definition TProof.h:402
@ kShowPackages
Definition TProof.h:403
@ kDisableSubPackages
Definition TProof.h:412
const char * GetUser() const
Definition TProof.h:906
void TerminateWorker(TSlave *wrk)
Ask an active worker 'wrk' to terminate, i.e. to shutdown.
Definition TProof.cxx:4686
Int_t LoadPackage(const char *package, Bool_t notOnClient=kFALSE, TList *loadopts=0, TList *workers=0)
Load specified package.
Definition TProof.cxx:8059
@ kBinary
Definition TProof.h:443
@ kCp
Definition TProof.h:447
@ kForward
Definition TProof.h:445
void SetLogLevel(Int_t level, UInt_t mask=TProofDebug::kAll)
Set server logging level.
Definition TProof.cxx:7069
TList * GetListOfBadSlaves() const
Definition TProof.h:657
Int_t DisablePackage(const char *package)
Remove a specific package.
Definition TProof.cxx:7875
void ShowEnabledPackages(Bool_t all=kFALSE)
List which packages are enabled.
Definition TProof.cxx:7808
Bool_t UseDynamicStartup() const
Definition TProof.h:921
void ResetMergers()
Definition TProof.h:691
Bool_t IsDataReady(Long64_t &totalbytes, Long64_t &bytesready)
See if the data is ready to be analyzed.
Definition TProof.cxx:2230
const char * GetGroup() const
Definition TProof.h:907
Class managing the query-result area.
void SaveQuery(TProofQueryResult *qr, const char *fout=0)
Save current status of query 'qr' to file name fout.
Bool_t FinalizeQuery(TProofQueryResult *pq, TProof *proof, TVirtualProofPlayer *player)
Final steps after Process() to complete the TQueryResult instance.
void RemoveQuery(TQueryResult *qr, Bool_t soft=kFALSE)
Remove everything about query qr.
TList * PreviousQueries() const
Int_t CleanupQueriesDir()
Remove all queries results referring to previous sessions.
Int_t ApplyMaxQueries(Int_t mxq)
Scan the queries directory and remove the oldest ones (and relative dirs, if empty) in such a way onl...
TProofQueryResult * LocateQuery(TString queryref, Int_t &qry, TString &qdir)
Locate query referenced by queryref.
Int_t CleanupSession(const char *sessiontag)
Cleanup query dir qdir.
Int_t LockSession(const char *sessiontag, TProofLockPath **lck)
Try locking query area of session tagged sessiontag.
void ScanPreviousQueries(const char *dir)
Scan the queries directory for the results of previous queries.
A container class for query results.
Long64_t GetEntries() const
Int_t GetSeqNum() const
void SetArchived(const char *archfile)
Set (or update) query in archived state.
TMacro * GetSelecImp() const
TQueryResult * CloneInfo()
Return an instance of TQueryResult containing only the local info fields, i.e.
virtual void SetProcessInfo(Long64_t ent, Float_t cpu=0., Long64_t siz=-1, Float_t inittime=0., Float_t proctime=0.)
Set processing info.
virtual void SetInputList(TList *in, Bool_t adopt=kTRUE)
Set / change the input list.
TObject * GetInputObject(const char *classname) const
Return first instance of class 'classname' in the input list.
TMacro * GetSelecHdr() const
const char * GetOptions() const
Long64_t GetFirst() const
Bool_t IsDraw() const
TList * GetInputList()
Int_t fSeqNum
query unique sequential number
Float_t GetUsedCPU() const
Long64_t GetBytes() const
static const TString & GetBinDir()
Get the binary directory in the installation. Static utility function.
Definition TROOT.cxx:2917
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition TROOT.cxx:2723
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition TROOT.cxx:2826
Bool_t Notify()
Check if any of the registered children has changed its state.
TList * fChildren
Definition TProofServ.h:431
void AddPid(Int_t pid)
Add an entry for 'pid' in the internal list.
virtual ~TReaperTimer()
Destructor.
virtual TSQLRow * Next()=0
virtual const char * GetField(Int_t field)=0
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
The db should be of the form: <dbms>://<host>[:<port>][/<database>], e.g.: mysql://pcroot....
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition TSelector.h:31
virtual Int_t GetLocalPort()
Get port # to which server socket is bound. In case of error returns -1.
virtual TSocket * Accept(UChar_t Opt=0)
Accept a connection on a server socket.
TShutdownTimer(TProofServ *p, Int_t delay)
Construtor.
Bool_t Notify()
Handle expiration of the shutdown timer.
TProofServ * fProofServ
Definition TProofServ.h:418
virtual Bool_t Notify()
Notify when signal occurs.
void SetSysInfo(SysInfo_t si)
Setter for fSysInfo.
Definition TProof.cxx:262
Option_t * GetOption() const
Definition TSocket.h:98
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
Definition TSocket.cxx:1013
TTimeStamp GetLastUsage()
Definition TSocket.h:129
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:818
virtual void Close(Option_t *opt="")
Close the socket.
Definition TSocket.cxx:389
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition TSocket.cxx:898
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Definition TSocket.cxx:620
virtual Int_t SendObject(const TObject *obj, Int_t kind=kMESS_OBJECT)
Send an object.
Definition TSocket.cxx:600
void SetCompressionSettings(Int_t settings=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Used to specify the compression level and algorithm: settings = 100 * algorithm + level.
Definition TSocket.cxx:1098
virtual Bool_t IsValid() const
Definition TSocket.h:132
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:522
Stopwatch class.
Definition TStopwatch.h:28
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Int_t Counter() const
Definition TStopwatch.h:50
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
void Reset()
Definition TStopwatch.h:52
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
void ToLower()
Change string to lower-case.
Definition TString.cxx:1145
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:438
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:649
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1941
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2197
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1126
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:682
const char * Data() const
Definition TString.h:369
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition TString.cxx:1783
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
@ kLeading
Definition TString.h:267
@ kTrailing
Definition TString.h:267
@ kIgnoreCase
Definition TString.h:268
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:912
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2217
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
Bool_t IsNull() const
Definition TString.h:407
TString & Remove(Ssiz_t pos)
Definition TString.h:673
TString & Append(const char *cs)
Definition TString.h:564
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2331
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2309
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
virtual int Umask(Int_t mask)
Set the process file creation mode mask.
Definition TSystem.cxx:1513
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
Definition TSystem.cxx:555
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr)
Redirect standard output (stdout, stderr) to the specified file.
Definition TSystem.cxx:1711
virtual const char * GetBuildCompilerVersion() const
Return the build compiler version.
Definition TSystem.cxx:3874
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition TSystem.cxx:2313
virtual Func_t DynFindSymbol(const char *module, const char *entry)
Find specific entry point in specified library.
Definition TSystem.cxx:2040
virtual void Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
Definition TSystem.cxx:1682
static void ResetErrno()
Static function resetting system error number.
Definition TSystem.cxx:277
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1272
virtual void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
Definition TSystem.cxx:1673
static Int_t GetErrno()
Static function returning system error number.
Definition TSystem.cxx:261
virtual void AddIncludePath(const char *includePath)
Add a directory to the already set include path.
Definition TSystem.cxx:4138
virtual int Chmod(const char *file, UInt_t mode)
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
Definition TSystem.cxx:1504
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:844
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition TSystem.cxx:835
virtual int GetPid()
Get process id.
Definition TSystem.cxx:708
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1661
virtual const char * GetIncludePath()
Get the list of include path.
Definition TSystem.cxx:3956
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition TSystem.cxx:905
virtual int MakeDirectory(const char *name)
Make a directory.
Definition TSystem.cxx:826
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:654
virtual int GetSysInfo(SysInfo_t *info) const
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
Definition TSystem.cxx:2462
virtual void SetIncludePath(const char *includePath)
IncludePath should contain the list of compiler flags to indicate where to find user defined header f...
Definition TSystem.cxx:4173
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Definition TSystem.cxx:565
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1853
virtual TSeqCollection * GetListOfFileHandlers() const
Definition TSystem.h:381
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition TSystem.cxx:663
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition TSystem.cxx:1396
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:1294
virtual FILE * TempFileName(TString &base, const char *dir=nullptr)
Create a secure temporary file by appending a unique 6 letter string to base.
Definition TSystem.cxx:1495
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:852
virtual void ExitLoop()
Exit from event loop.
Definition TSystem.cxx:393
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:861
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition TSystem.cxx:2493
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition TSystem.cxx:672
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:933
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Definition TSystem.cxx:533
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition TSystem.cxx:1791
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition TSystem.cxx:717
virtual Int_t GetGid(const char *group=nullptr)
Returns the group's id. If group = 0, returns current user's group.
Definition TSystem.cxx:1577
virtual const char * HostName()
Return the system's host name.
Definition TSystem.cxx:304
virtual Int_t GetUid(const char *user=nullptr)
Returns the user's id. If user = 0, returns current user's id.
Definition TSystem.cxx:1558
virtual void SetDynamicPath(const char *pathname)
Set the dynamic path to a new value.
Definition TSystem.cxx:1802
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:438
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:870
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1544
virtual void Setenv(const char *name, const char *value)
Set environment variable.
Definition TSystem.cxx:1645
virtual const char * GetBuildArch() const
Return the build architecture.
Definition TSystem.cxx:3858
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
Definition TSystem.cxx:886
virtual void Abort(int code=0)
Abort the application.
Definition TSystem.cxx:725
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1030
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1379
virtual void StackTrace()
Print a stack trace.
Definition TSystem.cxx:733
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition TSystem.cxx:1597
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition TSystem.cxx:1480
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition TSystem.cxx:2016
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:71
time_t GetSec() const
Definition TTimeStamp.h:135
Int_t GetNanoSec() const
Definition TTimeStamp.h:136
const char * AsString(const Option_t *option="") const
Return the date & time as a string.
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void Start(Long_t milliSec=-1, Bool_t singleShot=kFALSE)
Starts the timer with a milliSec timeout.
Definition TTimer.cxx:211
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:241
TTime fTime
Definition TTimer.h:54
void Reset()
Reset the timer.
Definition TTimer.cxx:157
virtual void Stop()
Definition TTimer.h:93
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetFile() const
Definition TUrl.h:69
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition TUrl.cxx:471
const char * GetProtocol() const
Definition TUrl.h:64
Int_t GetPort() const
Definition TUrl.h:78
Abstract interface for the PROOF player.
virtual void AddInput(TObject *inp)=0
virtual TQueryResult * GetCurrentQuery() const =0
virtual Int_t GetLearnEntries()=0
virtual TList * GetInputList() const =0
virtual void UpdateProgressInfo()=0
virtual Long64_t GetEventsProcessed() const =0
virtual void SetMerging(Bool_t on=kTRUE)=0
virtual EExitStatus GetExitStatus() const =0
virtual void AddQueryResult(TQueryResult *q)=0
virtual void MergeOutput(Bool_t=kFALSE)=0
static TVirtualProofPlayer * Create(const char *player, TProof *p, TSocket *s=0)
Create a PROOF player.
virtual Int_t AddOutputObject(TObject *obj)=0
virtual void HandleGetTreeHeader(TMessage *mess)=0
virtual void RemoveQueryResult(const char *ref)=0
virtual Int_t SavePartialResults(Bool_t queryend=kFALSE, Bool_t force=kFALSE)=0
virtual void StopProcess(Bool_t abort, Int_t timeout=-1)=0
virtual Long64_t Process(TDSet *set, const char *selector, Option_t *option="", Long64_t nentries=-1, Long64_t firstentry=0)=0
virtual TProofProgressStatus * GetProgressStatus() const =0
virtual void SetOutputFilePath(const char *fp)=0
virtual TList * GetOutputList() const =0
virtual void SetCurrentQuery(TQueryResult *q)=0
virtual Long64_t GetCacheSize()=0
TLine * line
const Int_t n
Definition legend1.C:16
Definition file.py:1
Definition first.py:1
Definition test.py:1
static const char * what
Definition stlLoader.cc:6
Int_t fMode
Definition TSystem.h:127
Int_t fGid
Definition TSystem.h:129
Int_t fUid
Definition TSystem.h:128
Long_t fMemVirtual
Definition TSystem.h:196
Long_t fMemResident
Definition TSystem.h:195
TString fUser
Definition TSystem.h:141
auto * m
Definition textangle.C:8
auto * l
Definition textangle.C:4