CMS 3D CMS Logo

RooGKCounter.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <math.h>
5 #include <cstdio>
6 using std::cout;
7 using std::endl;
8 using std::ostream;
9 
10 //ClassImp(RooGKCounter)
11 
13  init();
14 }
15 
17  init();
18  _message = message;
19  if ( _message . length() == 0 ) printCount = false;
20 }
21 
22 RooGKCounter::RooGKCounter( unsigned long int theFirst, unsigned long int theDivider ){
23  init();
24  _count = theFirst;
25  _firstCount = theFirst;
26  _divider = theDivider;
27  printCount = true;
28 }
29 
30 void RooGKCounter::setCounter( unsigned long int theCount ){
31  _count = theCount;
32 }
33 
34 void RooGKCounter::setDivider( unsigned int theDivider ){
35  _divider = theDivider;
36 }
37 
38 void RooGKCounter::setPrintCount( bool _printCount ){
39  printCount = _printCount;
40 }
41 
42 void RooGKCounter::setNewLine( bool newLine ){
43  _newLine = newLine;
44 }
45 
46 void RooGKCounter::setMessage( const char *message ){
47  _message = message;
48 }
49 
50 void RooGKCounter::init( void ){
51  _count = 0;
52  _firstCount = 0;
53  _divider = 1;
54  printCount = false;
55  firstCountEntry = true;
56  _message = "processing entry #";
57  _newLine = true;
58 
59  initTime = time( NULL );
60  firstTickTime = 1;
61  lastTickTime = 1;
62  lastPrintTime = 1;
63 
64 }
65 
66 void RooGKCounter::count( void ){
67 
68  _count++;
69 
70  double _number;
71  double _freq;
72  double _limit = 1./(double)_divider;
73 
74  _number = (double)_count;
75  _freq = (double)_divider;
76 
77  if (firstCountEntry){
78  if ( printCount ) std::cout << "Counter is on:" << std::endl;
79  firstCountEntry = false;
80  firstTickTime = time( NULL );
81  }
82 
83  if ( printCount ){
84  if ( fmod( _number, _freq ) < _limit ){
85  double averageTimeSinceFirstTick = 0.0;
86  if ( _count > _firstCount )
87  {
88  averageTimeSinceFirstTick = ( time( NULL ) - firstTickTime ) / (double)( _count - _firstCount );
89  }
90  if ( !_newLine )
91  {
92  std::cout << char(13) << _message . c_str() << _count;
93  if ( _count > _firstCount ) std::cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
94  fflush(stdout);
95  }
96  else
97  {
98  std::cout << _message . c_str() << _count;
99  if ( _count > _firstCount ) std::cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
100  std::cout << std::endl;
101  }
102  lastPrintTime = time( NULL );
103  }
104  }
105 
106  lastTickTime = time( NULL );
107 }
108 
109 unsigned long int RooGKCounter::getCount( void ){
110  return _count;
111 }
112 
113 void RooGKCounter::increment( long int _incr ){
114  _count += _incr;
115 }
116 
118 }
unsigned int _divider
Definition: RooGKCounter.h:30
void setPrintCount(bool _printCount)
Definition: RooGKCounter.cc:38
unsigned long int _firstCount
Definition: RooGKCounter.h:29
#define NULL
Definition: scimark2.h:8
unsigned long int getCount(void)
time_t firstTickTime
Definition: RooGKCounter.h:36
void setNewLine(bool newLine)
Definition: RooGKCounter.cc:42
bool firstCountEntry
Definition: RooGKCounter.h:32
time_t lastTickTime
Definition: RooGKCounter.h:36
void setCounter(unsigned long int)
Definition: RooGKCounter.cc:30
void increment(long int _incr)
unsigned long int _count
Definition: RooGKCounter.h:28
void count(void)
Definition: RooGKCounter.cc:66
void init(void)
Definition: RooGKCounter.cc:50
void setDivider(unsigned int)
Definition: RooGKCounter.cc:34
std::string _message
Definition: RooGKCounter.h:33
void setMessage(const char *)
Definition: RooGKCounter.cc:46
time_t initTime
Definition: RooGKCounter.h:36
time_t lastPrintTime
Definition: RooGKCounter.h:36