CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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 averageTimeSinceFirstTick = 0.0;
00086       if ( _count > _firstCount )
00087         {
00088           averageTimeSinceFirstTick = ( time( NULL ) - firstTickTime ) / (double)( _count - _firstCount );
00089         }
00090       if ( !_newLine )
00091         {
00092           std::cout << char(13) << _message . c_str() << _count;
00093           if ( _count > _firstCount ) std::cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
00094           fflush(stdout);
00095         }
00096       else
00097         {
00098           std::cout << _message . c_str() << _count;
00099           if ( _count > _firstCount ) std::cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
00100           std::cout << std::endl;
00101         }
00102       lastPrintTime = time( NULL );
00103     }
00104   }
00105   
00106   lastTickTime = time( NULL );
00107 }
00108 
00109 unsigned long int RooGKCounter::getCount( void ){
00110   return _count;
00111 }
00112 
00113 void RooGKCounter::increment( long int _incr ){
00114   _count += _incr;
00115 }
00116 
00117 RooGKCounter::~RooGKCounter(){
00118 }