00001 // ===================================================================== 00021 // ===================================================================== 00022 #ifndef __TSOFTWARESCALERMODULE_HH 00023 #define __TSOFTWARESCALERMODULE_HH 00024 00025 #include "Tglobals.h" 00026 #include "TSoftwareModule.hh" 00027 #include "TChannel.hh" 00028 00029 class TDataSegment; 00030 class TDataElement; 00031 00032 00052 class TSoftwareScalerModule 00053 : public TSoftwareModule 00054 { 00055 00056 protected: 00057 enum { tDefaultChannel = 8 }; 00058 00059 protected: 00060 TChannel theChannel; 00061 00062 public: 00063 TSoftwareScalerModule( Tint nchannel = tDefaultChannel ); 00064 TSoftwareScalerModule( const TSoftwareScalerModule& right ); 00065 virtual ~TSoftwareScalerModule(); 00066 00067 public: 00068 virtual Tint Clear(); 00069 virtual Tint Update(); 00070 virtual Tint Initialize(); 00071 virtual Tvoid FillData( TDataElement& element, Tint channel ); 00072 00073 public: 00074 virtual Tint Increase( Tint channel ); 00075 virtual Tint Increase(); 00076 virtual Tint Decrease( Tint channel ); 00077 virtual Tint Decrease(); 00078 virtual Tint GetData( Tint channel ) const; 00079 virtual Tvoid SetData( Tint channel, Tint data ); 00080 00081 public: 00082 virtual const TSoftwareScalerModule& operator=( const TSoftwareScalerModule& right ); 00083 virtual Tbool operator==( const TSoftwareScalerModule& right ) const; 00084 virtual Tbool operator!=( const TSoftwareScalerModule& right ) const; 00085 00086 public: 00087 virtual const TChannel& GetChannel() const; 00088 virtual Tvoid SetChannel( const TChannel& channels ); 00089 00090 }; 00091 00092 inline Tint TSoftwareScalerModule::GetData( Tint channel ) const 00093 { 00094 if ( channel < 0 || channel >= theNumberOfChannels ) { 00095 Tcerr << "TSoftwareScalerModule::GetData: invalid ID" << Tendl; 00096 return -EFAULT; 00097 } else { 00098 return theChannel[ channel ]; 00099 } 00100 } 00101 00102 inline Tvoid TSoftwareScalerModule::SetData( Tint channel, Tint data ) 00103 { 00104 if ( channel < 0 || channel >= theNumberOfChannels ) { 00105 Tcerr << "TSoftwareScalerModule::SetData: invalid ID" << Tendl; 00106 return; 00107 } else { 00108 theChannel[ channel ] = data; 00109 return; 00110 } 00111 } 00112 00113 inline const TChannel& TSoftwareScalerModule::GetChannel() const 00114 { 00115 return theChannel; 00116 } 00117 00118 inline Tvoid TSoftwareScalerModule::SetChannel( const TChannel& channels ) 00119 { 00120 theChannel = channels; 00121 return; 00122 } 00123 00124 inline Tint TSoftwareScalerModule::Increase( Tint channel ) 00125 { 00126 if ( channel < 0 || channel >= theNumberOfChannels ) { 00127 Tcerr << "TSoftwareScalerModule::Increase: invalid ID" << Tendl; 00128 return theStatus = -EFAULT; 00129 } else { 00130 Tint data = GetData( channel ); 00131 SetData( channel, ++ data ); 00132 return theStatus = tStatusSuccess; 00133 } 00134 } 00135 00136 inline Tint TSoftwareScalerModule::Decrease( Tint channel ) 00137 { 00138 if ( channel < 0 || channel >= theNumberOfChannels ) { 00139 Tcerr << "TSoftwareScalerModule::Decrease: invalid ID" << Tendl; 00140 return theStatus = -EFAULT; 00141 } else { 00142 Tint data = GetData( channel ); 00143 SetData( channel, -- data ); 00144 return theStatus = tStatusSuccess; 00145 } 00146 } 00147 00148 inline Tint TSoftwareScalerModule::Increase() 00149 { 00150 Tint ret = tStatusSuccess; 00151 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) 00152 ret &= Increase( i ); 00153 return ret; 00154 } 00155 00156 inline Tint TSoftwareScalerModule::Decrease() 00157 { 00158 Tint ret = tStatusSuccess; 00159 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) 00160 ret &= Decrease( i ); 00161 return ret; 00162 } 00163 00164 inline Tint TSoftwareScalerModule::Clear() 00165 { 00166 for ( Tint i = 0; i < theNumberOfChannels; i ++ ) 00167 theChannel[ i ] = 0; 00168 return theStatus = tStatusSuccess; 00169 } 00170 00171 inline Tint TSoftwareScalerModule::Update() 00172 { 00173 return Increase(); 00174 } 00175 00176 inline Tint TSoftwareScalerModule::Initialize() 00177 { 00178 return Clear(); 00179 } 00180 00181 #endif