00001 // $Id: TGo4Ratemeter.cxx 828 2011-12-20 12:37:57Z linev $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "TGo4Ratemeter.h" 00015 00016 const Double_t TGo4Ratemeter::fgdUPDATEINTERVAL= 1.0; // time in s 00017 00018 00019 TGo4Ratemeter::TGo4Ratemeter() : 00020 TObject(), 00021 fuCurrentCount(0), 00022 fuLastCount(0), 00023 fdRate(0), 00024 fdTime(0), 00025 fLastTm(), 00026 fbUpdateDone(kFALSE), 00027 fuNextCheckCnt(0), 00028 fuCheckInterval(1), 00029 fdUpdateInterval(fgdUPDATEINTERVAL) 00030 { 00031 } 00032 00033 TGo4Ratemeter::~TGo4Ratemeter() 00034 { 00035 } 00036 00037 void TGo4Ratemeter::Reset() 00038 { 00039 fdTime = 0; 00040 fdRate = 0; 00041 fuLastCount = 0; 00042 fuCurrentCount = 0; 00043 00044 fLastTm.Set(); 00045 fbUpdateDone = kFALSE; 00046 fuNextCheckCnt = 0; 00047 fuCheckInterval = 1; // in the beginning check every event 00048 } 00049 00050 Bool_t TGo4Ratemeter::Update(Int_t increment) 00051 { 00052 if(increment<0) { 00053 if(increment==-2) 00054 fdRate=1; // first update after start: dummy rate 00055 else 00056 fdRate=0; // case of stopped analysis: zero rate 00057 // keep last values of time, average rate, eventnumber 00058 fbUpdateDone = kTRUE; // tell watch thread we did the update 00059 return kTRUE; 00060 } 00061 00062 fuCurrentCount += (UInt_t) increment; 00063 00064 // check time if update count specified as 0 00065 if ((increment>0) && (fuCurrentCount < fuNextCheckCnt)) return kFALSE; 00066 00067 TTimeStamp now; 00068 00069 Double_t dist = now.AsDouble() - fLastTm.AsDouble(); 00070 00071 if (dist<fdUpdateInterval) { 00072 fuNextCheckCnt = fuCurrentCount + fuCheckInterval; 00073 return kFALSE; 00074 } 00075 00076 fdRate = (fuCurrentCount - fuLastCount) / dist; 00077 00078 fdTime += dist; 00079 00080 fLastTm = now; 00081 fuLastCount = fuCurrentCount; 00082 00083 double check = fdRate * fdUpdateInterval * 0.1; // check about 10 times before next update 00084 if (check<2) fuCheckInterval = 1; else 00085 if (check>1000) fuCheckInterval = 1000; else fuCheckInterval = (ULong64_t) check; 00086 00087 fuNextCheckCnt = fuCurrentCount + fuCheckInterval; 00088 00089 fbUpdateDone = kTRUE; // tell watch thread we did the update 00090 return kTRUE; 00091 } 00092 00093 Bool_t TGo4Ratemeter::TestUpdate() 00094 { 00095 Bool_t rev = fbUpdateDone; 00096 fbUpdateDone = kFALSE; 00097 return rev; 00098 }