CMS 3D CMS Logo

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