1 |
//
|
2 |
#include "LJMet/MultivariateAnalysis/interface/RooGKCounter.h"
|
3 |
|
4 |
#include <iostream>
|
5 |
#include <math.h>
|
6 |
using std::cout;
|
7 |
using std::endl;
|
8 |
using std::ostream;
|
9 |
|
10 |
//ClassImp(RooGKCounter)
|
11 |
|
12 |
RooGKCounter::RooGKCounter(){
|
13 |
init();
|
14 |
}
|
15 |
|
16 |
RooGKCounter::RooGKCounter( const char *message ){
|
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 |
_count_double_type = 0.0;
|
53 |
_firstCount = 0;
|
54 |
_divider = 1;
|
55 |
printCount = false;
|
56 |
firstCountEntry = true;
|
57 |
_message = "processing entry #";
|
58 |
_newLine = true;
|
59 |
|
60 |
initTime = time( NULL );
|
61 |
firstTickTime = 1;
|
62 |
lastTickTime = 1;
|
63 |
lastPrintTime = 1;
|
64 |
|
65 |
}
|
66 |
|
67 |
void RooGKCounter::count( void ){
|
68 |
|
69 |
_count++;
|
70 |
|
71 |
double _number;
|
72 |
double _freq;
|
73 |
double _limit = 1./(double)_divider;
|
74 |
|
75 |
_number = (double)_count;
|
76 |
_freq = (double)_divider;
|
77 |
|
78 |
if (firstCountEntry){
|
79 |
if ( printCount ) cout << "Counter is on:" << endl;
|
80 |
firstCountEntry = false;
|
81 |
firstTickTime = time( NULL );
|
82 |
}
|
83 |
|
84 |
if ( printCount ){
|
85 |
if ( fmod( _number, _freq ) < _limit ){
|
86 |
double averageTimeSinceLastPrint = 0.0;
|
87 |
double averageTimeSinceFirstTick = 0.0;
|
88 |
if ( lastPrintTime > 1 )
|
89 |
{
|
90 |
averageTimeSinceLastPrint = ( time( NULL ) - lastPrintTime ) / (double)_divider;
|
91 |
}
|
92 |
if ( _count > _firstCount )
|
93 |
{
|
94 |
averageTimeSinceFirstTick = ( time( NULL ) - firstTickTime ) / (double)( _count - _firstCount );
|
95 |
}
|
96 |
if ( !_newLine )
|
97 |
{
|
98 |
cout << char(13) << _message . c_str() << _count;
|
99 |
if ( _count > _firstCount ) cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
|
100 |
fflush(stdout);
|
101 |
}
|
102 |
else
|
103 |
{
|
104 |
cout << _message . c_str() << _count;
|
105 |
if ( _count > _firstCount ) cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
|
106 |
cout << endl;
|
107 |
}
|
108 |
lastPrintTime = time( NULL );
|
109 |
}
|
110 |
}
|
111 |
|
112 |
lastTickTime = time( NULL );
|
113 |
}
|
114 |
|
115 |
unsigned long int RooGKCounter::getCount( void ){
|
116 |
return _count;
|
117 |
}
|
118 |
|
119 |
double RooGKCounter::getCountDouble( void ){
|
120 |
return _count_double_type;
|
121 |
}
|
122 |
|
123 |
void RooGKCounter::increment( long int _incr ){
|
124 |
_count += _incr;
|
125 |
}
|
126 |
|
127 |
void RooGKCounter::incrementDouble( double _incr ){
|
128 |
_count_double_type += _incr;
|
129 |
}
|
130 |
|
131 |
RooGKCounter::~RooGKCounter(){
|
132 |
}
|