GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Ratemeter.cxx
Go to the documentation of this file.
1 // $Id: TGo4Ratemeter.cxx 1631 2015-06-24 07:31:58Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4Ratemeter.h"
15 
16 const Double_t TGo4Ratemeter::fgdUPDATEINTERVAL= 1.0; // time in s
17 
18 
20  TNamed(),
21  fbRunning(kFALSE),
22  fuCurrentCount(0),
23  fdRate(0),
24  fdTime(0),
25  fxDateString(),
26  fxEventSource(),
27  fuLastCount(0),
28  fLastTm(),
29  fbUpdateDone(kFALSE),
30  fuNextCheckCnt(0),
31  fuCheckInterval(1),
32  fdUpdateInterval(fgdUPDATEINTERVAL)
33 {
34 }
35 
37 {
38 }
39 
41 {
42  // update only persistent members
43 
44  if (r==0) return;
45  fbRunning = r->fbRunning;
47  fdRate = r->fdRate;
48  fdTime = r->fdTime;
51 }
52 
54 {
55  fbRunning = kFALSE;
56  fdTime = 0;
57  fdRate = 0;
58  fuLastCount = 0;
59  fuCurrentCount = 0;
60 
61  fLastTm.Set();
62  fbUpdateDone = kFALSE;
63  fuNextCheckCnt = 0;
64  fuCheckInterval = 1; // in the beginning check every event
65 }
66 
67 Bool_t TGo4Ratemeter::Update(Int_t increment)
68 {
69  if(increment<0) {
70  if(increment==-2)
71  fdRate=1; // first update after start: dummy rate
72  else
73  fdRate=0; // case of stopped analysis: zero rate
74  // keep last values of time, average rate, eventnumber
75  fbUpdateDone = kTRUE; // tell watch thread we did the update
76  return kTRUE;
77  }
78 
79  fuCurrentCount += (UInt_t) increment;
80 
81  // check time if update count specified as 0
82  if ((increment>0) && (fuCurrentCount < fuNextCheckCnt)) return kFALSE;
83 
84  TTimeStamp now;
85 
86  Double_t dist = now.AsDouble() - fLastTm.AsDouble();
87 
88  if (dist<fdUpdateInterval) {
90  return kFALSE;
91  }
92 
93  fdRate = (fuCurrentCount - fuLastCount) / dist;
94 
95  // accumulate running time only when running flag set
96  if (fbRunning)
97  fdTime += dist;
98 
99  fLastTm = now;
101 
102  double check = fdRate * fdUpdateInterval * 0.1; // check about 10 times before next update
103  if (check<2) fuCheckInterval = 1; else
104  if (check>1000) fuCheckInterval = 1000; else fuCheckInterval = (ULong64_t) check;
105 
107 
108  fbUpdateDone = kTRUE; // tell watch thread we did the update
109  return kTRUE;
110 }
111 
113 {
114  Bool_t rev = fbUpdateDone;
115  fbUpdateDone = kFALSE;
116  return rev;
117 }
static const Double_t fgdUPDATEINTERVAL
Configured interval in seconds before two updates.
Definition: TGo4Ratemeter.h:41
void UpdateFrom(const TGo4Ratemeter *r)
Bool_t TestUpdate()
ULong64_t fuCheckInterval
Next counter value when time will be checked.
Definition: TGo4Ratemeter.h:38
ULong64_t fuLastCount
Definition: TGo4Ratemeter.h:33
TString fxEventSource
Definition: TGo4Ratemeter.h:31
ULong64_t fuNextCheckCnt
True if update has been performed since last TestZero call.
Definition: TGo4Ratemeter.h:37
Bool_t fbRunning
Definition: TGo4Ratemeter.h:26
Double_t fdTime
Definition: TGo4Ratemeter.h:29
Double_t fdRate
Definition: TGo4Ratemeter.h:28
ULong64_t fuCurrentCount
Definition: TGo4Ratemeter.h:27
Double_t fdUpdateInterval
How often time should be checked.
Definition: TGo4Ratemeter.h:39
Bool_t fbUpdateDone
Time when last rate measurement was done.
Definition: TGo4Ratemeter.h:35
Bool_t Update(Int_t increment=1)
virtual ~TGo4Ratemeter()
TTimeStamp fLastTm
Number of events processed at last ratemeter update.
Definition: TGo4Ratemeter.h:34
TString fxDateString
Definition: TGo4Ratemeter.h:30