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