CaloOnlineTools
HcalOnlineDb
src
RooGKCounter.cc
Go to the documentation of this file.
1
#include "
CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h
"
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
12
RooGKCounter::RooGKCounter
() {
init
(); }
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
99
RooGKCounter::~RooGKCounter
() {}
RooGKCounter::firstCountEntry
bool firstCountEntry
Definition:
RooGKCounter.h:31
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
RooGKCounter::printCount
bool printCount
Definition:
RooGKCounter.h:30
RooGKCounter::increment
void increment(long int _incr)
Definition:
RooGKCounter.cc:97
RooGKCounter::firstTickTime
time_t firstTickTime
Definition:
RooGKCounter.h:35
protons_cff.time
time
Definition:
protons_cff.py:39
RooGKCounter::_message
std::string _message
Definition:
RooGKCounter.h:32
RooGKCounter::init
void init(void)
Definition:
RooGKCounter.cc:39
RooGKCounter::setMessage
void setMessage(const char *)
Definition:
RooGKCounter.cc:37
RooGKCounter.h
RooGKCounter::lastTickTime
time_t lastTickTime
Definition:
RooGKCounter.h:35
RooGKCounter::lastPrintTime
time_t lastPrintTime
Definition:
RooGKCounter.h:35
RooGKCounter::_divider
unsigned int _divider
Definition:
RooGKCounter.h:29
mps_setup.stdout
stdout
Definition:
mps_setup.py:250
RooGKCounter::initTime
time_t initTime
Definition:
RooGKCounter.h:35
RooGKCounter::setDivider
void setDivider(unsigned int)
Definition:
RooGKCounter.cc:31
RooGKCounter::_newLine
bool _newLine
Definition:
RooGKCounter.h:33
RooGKCounter::setCounter
void setCounter(unsigned long int)
Definition:
RooGKCounter.cc:29
RooGKCounter::getCount
unsigned long int getCount(void)
Definition:
RooGKCounter.cc:95
RooGKCounter::setPrintCount
void setPrintCount(bool _printCount)
Definition:
RooGKCounter.cc:33
RooGKCounter::setNewLine
void setNewLine(bool newLine)
Definition:
RooGKCounter.cc:35
RooGKCounter::count
void count(void)
Definition:
RooGKCounter.cc:54
RooGKCounter::_firstCount
unsigned long int _firstCount
Definition:
RooGKCounter.h:28
RooGKCounter::_count
unsigned long int _count
Definition:
RooGKCounter.h:27
RooGKCounter::RooGKCounter
RooGKCounter()
Definition:
RooGKCounter.cc:12
RooGKCounter::~RooGKCounter
~RooGKCounter()
Definition:
RooGKCounter.cc:99
Generated for CMSSW Reference Manual by
1.8.16