// =====================================================================
//  $Id: TSoftwareTimerModule.hh,v 1.2 2003/06/27 10:00:18 goiwai Exp $
//  $Name: CLDAQ-1-06-02 $
// =====================================================================
#ifndef __TSOFTWARETIMERMODULE_HH
#define __TSOFTWARETIMERMODULE_HH

#include "Tglobals.h"
#include "TSoftwareModule.hh"
#include "TSystemTimer.hh"

class TDataElement;
class TSystemTimer;

class TSoftwareTimerModule
  : public TSoftwareModule
{

  public:
    enum { 
      tRealElapsedTime,
      tRealElapsedTimeTotal,
      tSystemElapsedTime,
      tUserElapsedTime,
      tUnit,
      tNumberOfChannels
    };

  private:
    TSystemTimer theSystemTimer;
    Tdouble theRealElapsedTimeTotal;

  public:
    TSoftwareTimerModule( Tint nchannel = tNumberOfChannels, const Tstring& unit = Tmsec );
    TSoftwareTimerModule( const Tstring& unit, Tint nchannel = tNumberOfChannels );
    TSoftwareTimerModule( const TSoftwareTimerModule& right );
    ~TSoftwareTimerModule();

  public:
    Tint Clear();
    Tint Update();
    Tint Initialize();
    Tvoid FillData( TDataElement& element, Tint channel );

  public:
    Tvoid Start();
    Tvoid Pause();
    Tvoid Stop();
    Tvoid Lap();
    Tvoid Restart();

  public:
    const TSystemTimer& GetSystemTimer() const;
    TSystemTimer& GetSystemTimer();
    Tvoid SetSystemTimer( const TSystemTimer& timer );
    Tdouble GetRealElapsedTimeTotal() const;
    Tvoid SetRealElapsedTimeTotal( Tdouble time );

  public:
    const TSoftwareTimerModule& operator=( const TSoftwareTimerModule& right );
    Tbool operator==( const TSoftwareTimerModule& right ) const;
    Tbool operator!=( const TSoftwareTimerModule& right ) const;

};

inline const TSystemTimer& TSoftwareTimerModule::GetSystemTimer() const
{
  return( theSystemTimer );
}

inline TSystemTimer& TSoftwareTimerModule::GetSystemTimer()
{
  return( theSystemTimer );
}

inline Tvoid TSoftwareTimerModule::SetSystemTimer( const TSystemTimer& timer )
{
  theSystemTimer = timer;
  return;
}

inline Tvoid TSoftwareTimerModule::Start()
{
  theSystemTimer.Start();
  return;
}

inline Tvoid TSoftwareTimerModule::Pause()
{
  theSystemTimer.Pause();
  return;
}

inline Tvoid TSoftwareTimerModule::Stop()
{
  theSystemTimer.Stop();
  theRealElapsedTimeTotal += theSystemTimer.GetRealElapsedTime();
  return;
}

inline Tvoid TSoftwareTimerModule::Lap()
{
  theSystemTimer.Lap();
  return;
}

inline Tvoid TSoftwareTimerModule::Restart()
{
  theSystemTimer.Restart();
  return;
}

inline Tdouble TSoftwareTimerModule::GetRealElapsedTimeTotal() const
{
  return( theRealElapsedTimeTotal );
}

inline Tvoid TSoftwareTimerModule::SetRealElapsedTimeTotal( Tdouble time )
{
  theRealElapsedTimeTotal = time;
  return;
}

#endif
