TPeriodicClass.cxx

Go to the documentation of this file.
00001 #include "TPeriodicClass.hxx"
00002 #include <sys/time.h>
00003 #include <assert.h>
00004 
00005 
00006 double GetTimeSec()
00007 {
00008   struct timeval tv;
00009   gettimeofday(&tv,NULL);
00010   return tv.tv_sec + 0.000001*tv.tv_usec;
00011 }
00012 
00013 TPeriodicClass::TPeriodicClass(int period_msec,TimerHandler handler)
00014 {
00015   assert(handler != NULL);
00016   fPeriod_msec = period_msec;
00017   fHandler  = handler;
00018   fLastTime = GetTimeSec();
00019   Start(period_msec,kTRUE);
00020 }
00021 
00022 Bool_t TPeriodicClass::Notify()
00023 {
00024   double t = GetTimeSec();
00025   //printf("timer notify, period %f should be %f!\n",t-fLastTime,fPeriod_msec*0.001);
00026   
00027   if (t - fLastTime >= 0.9*fPeriod_msec*0.001)
00028     {
00029       //printf("timer: call handler %p\n",fHandler);
00030       if (fHandler)
00031         (*fHandler)();
00032       
00033       fLastTime = t;
00034     }
00035   
00036   Reset();
00037   return kTRUE;
00038 }

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1