// @(#)root/proof:$Id: 5d579564fccbadad9cd6f81ccb7726dddea80e0d $
// Author: G. Ganis   31/08/06

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TProofLog
#define ROOT_TProofLog

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofLog                                                            //
//                                                                      //
// Implementation of the PROOF session log handler                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TDatime
#include "TDatime.h"
#endif
#ifndef ROOT_TNamed
#include "TNamed.h"
#endif
#ifndef ROOT_TQObject
#include "TQObject.h"
#endif

class TMacro;
class TProofLogElem;
class TProofMgr;


class TProofLog : public TNamed, public TQObject {

friend class TProofLogElem;
friend class TProofMgrLite;
friend class TXProofMgr;

private:
   TProofMgr  *fMgr;   // parent TProofMgr
   void       *fFILE;  // pointer logging file, if any
   TList      *fElem;  // list of TProofLogElem objects
   TDatime     fStartTime; // Time at which this session started

   TProofLogElem *Add(const char *ord, const char *url);

public:
   // Screen or GUI box logging
   enum ELogLocationBit {
      kLogToBox = BIT(16)
   };
   enum ERetrieveOpt   { kLeading = 0x1, kTrailing = 0x2,
                         kAll = 0x3, kGrep = 0x4 };

   TProofLog(const char *stag, const char *url, TProofMgr *mgr);
   virtual ~TProofLog();

   void   Display(const char *ord = "*", Int_t from = -10, Int_t to = -1);
   TList *GetListOfLogs() const { return fElem; }
   Int_t  Grep(const char *txt, Int_t from = 0);
   void   Print(Option_t *opt = 0) const;
   void   Prt(const char *what, Bool_t newline = kTRUE);
   Int_t  Retrieve(const char *ord = "*",
                  TProofLog::ERetrieveOpt opt = TProofLog::kTrailing,
                  const char *fname = 0, const char *pattern = 0);
   Int_t  Save(const char *ord = "*", const char *fname = 0, Option_t *opt="w");

   TDatime StartTime() { return fStartTime; }

   // Where to log
   void SetLogToBox(Bool_t lgbox = kFALSE) { SetBit(kLogToBox, lgbox); }
   Bool_t LogToBox() { return (TestBit(kLogToBox)) ? kTRUE : kFALSE; }

   static void SetMaxTransferSize(Long64_t maxsz);

   ClassDef(TProofLog,0)  // PROOF session log handler
};


class TProofLogElem : public TNamed {

private:
   TProofLog *fLogger;  // parent TProofLog
   TMacro    *fMacro;   // container for the log lines
   Long64_t   fSize;    // best knowledge of the log file size
   Long64_t   fFrom;    // starting offset of the current content
   Long64_t   fTo;      // end offset of the current content
   TString    fRole;    // role (master-submaster-worker)

   static Long64_t fgMaxTransferSize;

   //the name of TProofLogElem is the ordinal number of the corresp. worker
   //the title is the url

public:
   TProofLogElem(const char *ord, const char *url,
                 TProofLog *logger);
   virtual ~TProofLogElem();

   void    Display(Int_t from = 0, Int_t to = -1);
   TMacro *GetMacro() const { return fMacro; }
   const char *    GetRole() { return fRole.Data(); }
   Int_t   Grep(const char *txt, TString &res, Int_t from = 0);
   Bool_t  IsMaster() const { return (fRole == "master") ? kTRUE : kFALSE; }
   Bool_t  IsSubMaster() const { return (fRole == "submaster") ? kTRUE : kFALSE; }
   Bool_t  IsWorker() const { return (fRole == "worker") ? kTRUE : kFALSE; }
   void    Print(Option_t *opt = 0) const;
   void    Prt(const char *what);
   Int_t   Retrieve(TProofLog::ERetrieveOpt opt = TProofLog::kTrailing,
                    const char *pattern = 0);

   static Long64_t GetMaxTransferSize();
   static void     SetMaxTransferSize(Long64_t maxsz);

   ClassDef(TProofLogElem,0)  // PROOF session log element
};

#endif
 TProofLog.h:1
 TProofLog.h:2
 TProofLog.h:3
 TProofLog.h:4
 TProofLog.h:5
 TProofLog.h:6
 TProofLog.h:7
 TProofLog.h:8
 TProofLog.h:9
 TProofLog.h:10
 TProofLog.h:11
 TProofLog.h:12
 TProofLog.h:13
 TProofLog.h:14
 TProofLog.h:15
 TProofLog.h:16
 TProofLog.h:17
 TProofLog.h:18
 TProofLog.h:19
 TProofLog.h:20
 TProofLog.h:21
 TProofLog.h:22
 TProofLog.h:23
 TProofLog.h:24
 TProofLog.h:25
 TProofLog.h:26
 TProofLog.h:27
 TProofLog.h:28
 TProofLog.h:29
 TProofLog.h:30
 TProofLog.h:31
 TProofLog.h:32
 TProofLog.h:33
 TProofLog.h:34
 TProofLog.h:35
 TProofLog.h:36
 TProofLog.h:37
 TProofLog.h:38
 TProofLog.h:39
 TProofLog.h:40
 TProofLog.h:41
 TProofLog.h:42
 TProofLog.h:43
 TProofLog.h:44
 TProofLog.h:45
 TProofLog.h:46
 TProofLog.h:47
 TProofLog.h:48
 TProofLog.h:49
 TProofLog.h:50
 TProofLog.h:51
 TProofLog.h:52
 TProofLog.h:53
 TProofLog.h:54
 TProofLog.h:55
 TProofLog.h:56
 TProofLog.h:57
 TProofLog.h:58
 TProofLog.h:59
 TProofLog.h:60
 TProofLog.h:61
 TProofLog.h:62
 TProofLog.h:63
 TProofLog.h:64
 TProofLog.h:65
 TProofLog.h:66
 TProofLog.h:67
 TProofLog.h:68
 TProofLog.h:69
 TProofLog.h:70
 TProofLog.h:71
 TProofLog.h:72
 TProofLog.h:73
 TProofLog.h:74
 TProofLog.h:75
 TProofLog.h:76
 TProofLog.h:77
 TProofLog.h:78
 TProofLog.h:79
 TProofLog.h:80
 TProofLog.h:81
 TProofLog.h:82
 TProofLog.h:83
 TProofLog.h:84
 TProofLog.h:85
 TProofLog.h:86
 TProofLog.h:87
 TProofLog.h:88
 TProofLog.h:89
 TProofLog.h:90
 TProofLog.h:91
 TProofLog.h:92
 TProofLog.h:93
 TProofLog.h:94
 TProofLog.h:95
 TProofLog.h:96
 TProofLog.h:97
 TProofLog.h:98
 TProofLog.h:99
 TProofLog.h:100
 TProofLog.h:101
 TProofLog.h:102
 TProofLog.h:103
 TProofLog.h:104
 TProofLog.h:105
 TProofLog.h:106
 TProofLog.h:107
 TProofLog.h:108
 TProofLog.h:109
 TProofLog.h:110
 TProofLog.h:111
 TProofLog.h:112
 TProofLog.h:113
 TProofLog.h:114
 TProofLog.h:115
 TProofLog.h:116
 TProofLog.h:117
 TProofLog.h:118
 TProofLog.h:119
 TProofLog.h:120
 TProofLog.h:121
 TProofLog.h:122
 TProofLog.h:123