Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:15:09

0001 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
0002 
0003 #include <iostream>
0004 #include <cmath>
0005 #include <cstdio>
0006 using std::cout;
0007 using std::endl;
0008 using std::ostream;
0009 
0010 //ClassImp(RooGKCounter)
0011 
0012 RooGKCounter::RooGKCounter() { init(); }
0013 
0014 RooGKCounter::RooGKCounter(const char *message) {
0015   init();
0016   _message = message;
0017   if (_message.length() == 0)
0018     printCount = false;
0019 }
0020 
0021 RooGKCounter::RooGKCounter(unsigned long int theFirst, unsigned long int theDivider) {
0022   init();
0023   _count = theFirst;
0024   _firstCount = theFirst;
0025   _divider = theDivider;
0026   printCount = true;
0027 }
0028 
0029 void RooGKCounter::setCounter(unsigned long int theCount) { _count = theCount; }
0030 
0031 void RooGKCounter::setDivider(unsigned int theDivider) { _divider = theDivider; }
0032 
0033 void RooGKCounter::setPrintCount(bool _printCount) { printCount = _printCount; }
0034 
0035 void RooGKCounter::setNewLine(bool newLine) { _newLine = newLine; }
0036 
0037 void RooGKCounter::setMessage(const char *message) { _message = message; }
0038 
0039 void RooGKCounter::init(void) {
0040   _count = 0;
0041   _firstCount = 0;
0042   _divider = 1;
0043   printCount = false;
0044   firstCountEntry = true;
0045   _message = "processing entry #";
0046   _newLine = true;
0047 
0048   initTime = time(nullptr);
0049   firstTickTime = 1;
0050   lastTickTime = 1;
0051   lastPrintTime = 1;
0052 }
0053 
0054 void RooGKCounter::count(void) {
0055   _count++;
0056 
0057   double _number;
0058   double _freq;
0059   double _limit = 1. / (double)_divider;
0060 
0061   _number = (double)_count;
0062   _freq = (double)_divider;
0063 
0064   if (firstCountEntry) {
0065     if (printCount)
0066       std::cout << "Counter is on:" << std::endl;
0067     firstCountEntry = false;
0068     firstTickTime = time(nullptr);
0069   }
0070 
0071   if (printCount) {
0072     if (fmod(_number, _freq) < _limit) {
0073       double averageTimeSinceFirstTick = 0.0;
0074       if (_count > _firstCount) {
0075         averageTimeSinceFirstTick = (time(nullptr) - firstTickTime) / (double)(_count - _firstCount);
0076       }
0077       if (!_newLine) {
0078         std::cout << char(13) << _message.c_str() << _count;
0079         if (_count > _firstCount)
0080           std::cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
0081         fflush(stdout);
0082       } else {
0083         std::cout << _message.c_str() << _count;
0084         if (_count > _firstCount)
0085           std::cout << ", average time per count, sec: " << averageTimeSinceFirstTick;
0086         std::cout << std::endl;
0087       }
0088       lastPrintTime = time(nullptr);
0089     }
0090   }
0091 
0092   lastTickTime = time(nullptr);
0093 }
0094 
0095 unsigned long int RooGKCounter::getCount(void) { return _count; }
0096 
0097 void RooGKCounter::increment(long int _incr) { _count += _incr; }
0098 
0099 RooGKCounter::~RooGKCounter() {}