CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CaloOnlineTools/HcalOnlineDb/src/RooGKCounter.cc

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