CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/SiPixelRawToDigi/interface/R2DTimerObserver.h

Go to the documentation of this file.
00001 #ifndef SiPixelRawToDigi_R2DTimerObserver_H 
00002 #define SiPixelRawToDigi_R2DTimerObserver_H
00003 
00004 #include <string>
00005 #include "Utilities/Timing/interface/TimingReport.h"
00006 
00007 class R2DTimerObserver :  public TimingReport::ItemObserver {
00015 
00016 
00017 private:
00018 
00019   typedef TimingReport::ItemObserver::event TimerState;
00020 
00021   class LastMeasurement {
00022   public:
00023     LastMeasurement(double real=0., double cpu=0.) : real_(real), cpu_(cpu) { }
00024     double real() const { return real_;}
00025     double cpu() const { return cpu_;}
00026   private:
00027     double real_,cpu_;
00028   };
00029  
00030   TimingReport::Item * timer_item;
00031   TimerState lastState;
00032   LastMeasurement theMeasurement;
00033 
00035   virtual void operator()(const TimerState & timerState) {
00036     theMeasurement = LastMeasurement(timerState.first-lastState.first,
00037                                      timerState.second-lastState.second);
00038     lastState = timerState;
00039   }
00040 
00041 public:
00042 
00043   void init(const std::string & name) {
00044     timer_item = &(*TimingReport::current())[name];
00045     timer_item->switchCPU(false);
00046     timer_item->setObs(this);
00047   }
00048 
00049   R2DTimerObserver() : timer_item(0), lastState(0,0) { }
00050   R2DTimerObserver(const std::string name) : lastState(0,0) { init( name) ; }
00051 
00052   const LastMeasurement & lastMeasurement() { return theMeasurement; }
00053   TimingReport::Item & item() { return *timer_item; }
00054 
00055   void start() { timer_item->start(); }
00056   void stop() { timer_item->stop(); }
00057 
00058 };
00059 
00060 #endif