00001 // ===================================================================== 00002 // $Id: TSoftwareScalerModule.hh,v 1.1.1.1 2003/06/27 02:56:41 goiwai Exp $ 00003 // $Name: CLDAQ-1-06-00 $ 00004 // ===================================================================== 00005 #ifndef __TSOFTWARESCALERMODULE_HH 00006 #define __TSOFTWARESCALERMODULE_HH 00007 00008 #include "Tglobals.h" 00009 #include "TSoftwareModule.hh" 00010 #include "TChannel.hh" 00011 00012 class TDataSegment; 00013 class TDataElement; 00014 00015 class TSoftwareScalerModule 00016 : public TSoftwareModule 00017 { 00018 00019 protected: 00020 enum { tDefaultChannel = 8 }; 00021 00022 protected: 00023 TChannel theChannel; 00024 00025 public: 00026 TSoftwareScalerModule( Tint nchannel = tDefaultChannel ); 00027 TSoftwareScalerModule( const TSoftwareScalerModule& right ); 00028 virtual ~TSoftwareScalerModule(); 00029 00030 public: 00031 virtual Tint Clear(); 00032 virtual Tint Update(); 00033 virtual Tint Initialize(); 00034 virtual Tvoid FillData( TDataElement& element, Tint channel ); 00035 00036 public: 00037 virtual Tint Increase( Tint channel ); 00038 virtual Tint Increase(); 00039 virtual Tint Decrease( Tint channel ); 00040 virtual Tint Decrease(); 00041 virtual Tint GetData( Tint channel ) const; 00042 virtual Tvoid SetData( Tint channel, Tint data ); 00043 00044 public: 00045 virtual const TSoftwareScalerModule& operator=( const TSoftwareScalerModule& right ); 00046 virtual Tbool operator==( const TSoftwareScalerModule& right ) const; 00047 virtual Tbool operator!=( const TSoftwareScalerModule& right ) const; 00048 00049 public: 00050 virtual const TChannel& GetChannel() const; 00051 virtual Tvoid SetChannel( const TChannel& channels ); 00052 00053 }; 00054 00055 inline Tint TSoftwareScalerModule::GetData( Tint channel ) const 00056 { 00057 if ( channel < 0 || channel >= theNumberOfChannels ) { 00058 Tcerr << "TSoftwareScalerModule::GetData: invalid ID" << Tendl; 00059 return( -EFAULT ); 00060 } else { 00061 return( theChannel[ channel ] ); 00062 } 00063 } 00064 00065 inline Tvoid TSoftwareScalerModule::SetData( Tint channel, Tint data ) 00066 { 00067 if ( channel < 0 || channel >= theNumberOfChannels ) { 00068 Tcerr << "TSoftwareScalerModule::SetData: invalid ID" << Tendl; 00069 return; 00070 } else { 00071 theChannel[ channel ] = data; 00072 return; 00073 } 00074 } 00075 00076 inline const TChannel& TSoftwareScalerModule::GetChannel() const 00077 { 00078 return( theChannel ); 00079 } 00080 00081 inline Tvoid TSoftwareScalerModule::SetChannel( const TChannel& channels ) 00082 { 00083 theChannel = channels; 00084 return; 00085 } 00086 00087 inline Tint TSoftwareScalerModule::Increase( Tint channel ) 00088 { 00089 if ( channel < 0 || channel >= theNumberOfChannels ) { 00090 Tcerr << "TSoftwareScalerModule::Increase: invalid ID" << Tendl; 00091 return( theStatus = -EFAULT ); 00092 } else { 00093 Tint data = GetData( channel ); 00094 SetData( channel, ++ data ); 00095 return( theStatus = tStatusSuccess ); 00096 } 00097 } 00098 00099 inline Tint TSoftwareScalerModule::Decrease( Tint channel ) 00100 { 00101 if ( channel < 0 || channel >= theNumberOfChannels ) { 00102 Tcerr << "TSoftwareScalerModule::Decrease: invalid ID" << Tendl; 00103 return( theStatus = -EFAULT ); 00104 } else { 00105 Tint data = GetData( channel ); 00106 SetData( channel, -- data ); 00107 return( theStatus = tStatusSuccess ); 00108 } 00109 } 00110 00111 inline Tint TSoftwareScalerModule::Increase() 00112 { 00113 Tint ret = tStatusSuccess; 00114 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) 00115 ret &= Increase( i ); 00116 return( ret ); 00117 } 00118 00119 inline Tint TSoftwareScalerModule::Decrease() 00120 { 00121 Tint ret = tStatusSuccess; 00122 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) 00123 ret &= Decrease( i ); 00124 return( ret ); 00125 } 00126 00127 inline Tint TSoftwareScalerModule::Clear() 00128 { 00129 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) 00130 theChannel[ i ] = 0; 00131 return( theStatus = tStatusSuccess ); 00132 } 00133 00134 inline Tint TSoftwareScalerModule::Update() 00135 { 00136 return( Increase() ); 00137 } 00138 00139 inline Tint TSoftwareScalerModule::Initialize() 00140 { 00141 return( Clear() ); 00142 } 00143 00144 #endif