// @(#)root/proof:$Id$
// Author: Jan Iwaszkiewicz    08/08/08

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

#include "TProofProgressStatus.h"
#include "TObject.h"
#include "TString.h"
#include "TSystem.h"
#include "TTime.h"

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProofProgressStatus                                                 //
//                                                                      //
// Small class including processing statistics                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

ClassImp(TProofProgressStatus)

//______________________________________________________________________________
TProofProgressStatus::TProofProgressStatus(Long64_t entries,
                                           Long64_t bytesRead,
                                           Long64_t readCalls,
                                           Double_t procTime,
                                           Double_t cpuTime): TObject()
{
   // Main and default constructor

   fLastEntries = 0;
   fEntries = entries;
   fBytesRead = bytesRead;
   fReadCalls = readCalls;
   fLearnTime = 0.;
   fLastProcTime = 0;
   fProcTime = procTime;
   fCPUTime = cpuTime;
   SetLastUpdate();
}

//______________________________________________________________________________
TProofProgressStatus& TProofProgressStatus::operator+=(const TProofProgressStatus &st)
{
   // '+=' operator

   fLastEntries += st.fEntries;
   fEntries += st.fEntries;
   fBytesRead += st.fBytesRead;
   fReadCalls += st.fReadCalls;
   if (st.fLearnTime > fLearnTime)
      fLearnTime = st.fLearnTime;
   fLastProcTime = st.fProcTime;
   fProcTime += st.fProcTime;
   fCPUTime += st.fCPUTime;
   SetLastUpdate();
   return *this;
}

//______________________________________________________________________________
TProofProgressStatus& TProofProgressStatus::operator-=(const TProofProgressStatus &st)
{
   // '-=' operator

   fEntries -= st.fEntries;
   fBytesRead -= st.fBytesRead;
   fReadCalls -= st.fReadCalls;
   if (st.fLearnTime < fLearnTime)
      fLearnTime = st.fLearnTime;
   fProcTime -= st.fProcTime;
   fCPUTime -= st.fCPUTime;
   SetLastUpdate();
   return *this;
}

//______________________________________________________________________________
TProofProgressStatus TProofProgressStatus::operator-(TProofProgressStatus &st)
{
   // '-' operator

   return TProofProgressStatus(*this) -= st;
}

//______________________________________________________________________________
void TProofProgressStatus::Print(Option_t*option) const
{
   // Dump the content

   Printf("TProofProgressStatus:%s: Ents:(%lld,%lld), Bytes:%lld, Calls:%lld,"
          " Learn:%.3g s, Proc:(%.3g,%.3g) s, CPU:%.3g s",
          option, fEntries, fLastEntries, fBytesRead, fReadCalls,
          fLearnTime, fProcTime, fLastProcTime, fCPUTime);
}

//______________________________________________________________________________
void TProofProgressStatus::SetLastUpdate(Double_t updtTime)
{
   // Update time stamp either with the passed value (if > 0) or with
   // the current time

   if (updtTime > 0) {
      fLastUpdate = updtTime;
   } else {
      TTime tnow = gSystem->Now();
      fLastUpdate = (Double_t) (Long64_t(tnow)) / (Double_t)1000.;
   }
}

//______________________________________________________________________________
Double_t TProofProgressStatus::GetCurrentRate() const
{
   // Get current rate. Rteunr the average rate if the current is not defined

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