![]() |
![]() |
00001 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h" 00002 00003 #include <iostream> 00004 #include <math.h> 00005 using std::cout; 00006 using std::endl; 00007 using std::ostream; 00008 00009 //ClassImp(RooGKCounter) 00010 00011 RooGKCounter::RooGKCounter(){ 00012 init(); 00013 } 00014 00015 RooGKCounter::RooGKCounter( const char *message ){ 00016 init(); 00017 _message = message; 00018 if ( _message . length() == 0 ) printCount = false; 00019 } 00020 00021 RooGKCounter::RooGKCounter( unsigned long int theFirst, unsigned long int theDivider ){ 00022 init(); 00023 _count = theFirst; 00024 _firstCount = theFirst; 00025 _divider = theDivider; 00026 printCount = true; 00027 } 00028 00029 void RooGKCounter::setCounter( unsigned long int theCount ){ 00030 _count = theCount; 00031 } 00032 00033 void RooGKCounter::setDivider( unsigned int theDivider ){ 00034 _divider = theDivider; 00035 } 00036 00037 void RooGKCounter::setPrintCount( bool _printCount ){ 00038 printCount = _printCount; 00039 } 00040 00041 void RooGKCounter::setNewLine( bool newLine ){ 00042 _newLine = newLine; 00043 } 00044 00045 void RooGKCounter::setMessage( const char *message ){ 00046 _message = message; 00047 } 00048 00049 void RooGKCounter::init( void ){ 00050 _count = 0; 00051 _firstCount = 0; 00052 _divider = 1; 00053 printCount = false; 00054 firstCountEntry = true; 00055 _message = "processing entry #"; 00056 _newLine = true; 00057 00058 initTime = time( NULL ); 00059 firstTickTime = 1; 00060 lastTickTime = 1; 00061 lastPrintTime = 1; 00062 00063 } 00064 00065 void RooGKCounter::count( void ){ 00066 00067 _count++; 00068 00069 double _number; 00070 double _freq; 00071 double _limit = 1./(double)_divider; 00072 00073 _number = (double)_count; 00074 _freq = (double)_divider; 00075 00076 if (firstCountEntry){ 00077 if ( printCount ) cout << "Counter is on:" << endl; 00078 firstCountEntry = false; 00079 firstTickTime = time( NULL ); 00080 } 00081 00082 if ( printCount ){ 00083 if ( fmod( _number, _freq ) < _limit ){ 00084 double averageTimeSinceLastPrint = 0.0; 00085 double averageTimeSinceFirstTick = 0.0; 00086 if ( lastPrintTime > 1 ) 00087 { 00088 averageTimeSinceLastPrint = ( time( NULL ) - lastPrintTime ) / (double)_divider; 00089 } 00090 if ( _count > _firstCount ) 00091 { 00092 averageTimeSinceFirstTick = ( time( NULL ) - firstTickTime ) / (double)( _count - _firstCount ); 00093 } 00094 if ( !_newLine ) 00095 { 00096 cout << char(13) << _message . c_str() << _count; 00097 if ( _count > _firstCount ) cout << ", average time per count, sec: " << averageTimeSinceFirstTick; 00098 fflush(stdout); 00099 } 00100 else 00101 { 00102 cout << _message . c_str() << _count; 00103 if ( _count > _firstCount ) cout << ", average time per count, sec: " << averageTimeSinceFirstTick; 00104 cout << endl; 00105 } 00106 lastPrintTime = time( NULL ); 00107 } 00108 } 00109 00110 lastTickTime = time( NULL ); 00111 } 00112 00113 unsigned long int RooGKCounter::getCount( void ){ 00114 return _count; 00115 } 00116 00117 void RooGKCounter::increment( long int _incr ){ 00118 _count += _incr; 00119 } 00120 00121 RooGKCounter::~RooGKCounter(){ 00122 }