00001 // ===================================================================== 00024 // ===================================================================== 00025 #ifndef CLDAQ__TSOFTWAREADCMODULE_HH 00026 #define CLDAQ__TSOFTWAREADCMODULE_HH 00027 00028 #include "Tglobals.h" 00029 #include "TSoftwareModule.hh" 00030 #include "TChannel.hh" 00031 #include "TRandomEngine.hh" 00032 #include "TRandomFlat.hh" 00033 #include "TRandomGaussian.hh" 00034 00035 class TDataSegment; 00036 class TDataElement; 00037 00038 00058 class TSoftwareAdcModule 00059 : public TSoftwareModule 00060 { 00061 protected: 00062 enum { tDataOverFlow = -1 }; 00063 enum { tDefaultScale = 4096 }; 00064 enum { tDefaultChannel = 16 }; 00065 00066 protected: 00067 Tint theScale; 00068 TintList theMean; 00069 TintList theSigma; 00070 TChannel theChannel; 00071 Trandom_t theRandomType; 00072 00073 protected: 00074 static Tint theSeed; 00075 static TRandomEngine theRandomEngine; 00076 00077 public: 00078 TSoftwareAdcModule( Tint nchannel = tDefaultChannel, Tint scale = tDefaultScale, Trandom_t randtype = tRandomGaussian ); 00079 TSoftwareAdcModule( const TSoftwareAdcModule& right ); 00080 virtual ~TSoftwareAdcModule(); 00081 00082 public: 00083 virtual Tint Clear(); 00084 virtual Tint Update(); 00085 virtual Tint Initialize(); 00086 virtual Tvoid FillData( TDataElement& element, Tint channel ); 00087 00088 public: 00089 virtual const TSoftwareAdcModule& operator=( const TSoftwareAdcModule& right ); 00090 virtual Tbool operator==( const TSoftwareAdcModule& right ) const; 00091 virtual Tbool operator!=( const TSoftwareAdcModule& right ) const; 00092 00093 public: 00094 virtual Tint GetScale() const; 00095 virtual const TintList& GetMean() const; 00096 virtual Tint GetMean( Tint channel ) const; 00097 virtual const TintList& GetSigma() const; 00098 virtual Tint GetSigma( Tint channel ) const; 00099 virtual const TChannel& GetChannel() const; 00100 virtual Tint GetData( Tint channel ) const; 00101 virtual Trandom_t GetRandomType() const; 00102 virtual Tvoid SetScale( Tint scale ); 00103 virtual Tvoid SetMean( const TintList& meanlist ); 00104 virtual Tvoid SetMean( Tint channel, Tint mean ); 00105 virtual Tvoid SetSigma( const TintList& sigmalist ); 00106 virtual Tvoid SetSigma( Tint channel, Tint sigma ); 00107 virtual Tvoid SetChannel( const TChannel& channels ); 00108 virtual Tvoid SetData( Tint channel, Tint data ); 00109 virtual Tvoid GetRandomType( Trandom_t randomtype ); 00110 00111 public: 00112 static Tint GetSeed(); 00113 static const TRandomEngine& GetRandomEngine(); 00114 static Tvoid SetSeed( Tint seed ); 00115 static Tvoid SetRandomEngine( const TRandomEngine& engine ); 00116 00117 protected: 00118 virtual Tvoid setParameters(); 00119 virtual Tvoid fillGaussian(); 00120 00121 }; 00122 00123 inline Tint TSoftwareAdcModule::GetScale() const 00124 { 00125 return theScale; 00126 } 00127 00128 inline const TintList& TSoftwareAdcModule::GetMean() const 00129 { 00130 return theMean; 00131 } 00132 00133 inline Tint TSoftwareAdcModule::GetMean( Tint channel ) const 00134 { 00135 if ( channel < 0 || channel >= theNumberOfChannels ) { 00136 Tcerr << "TSoftwareAdcModule::GetMean: invalid ID" << Tendl; 00137 return -EFAULT; 00138 } else { 00139 return theMean[ channel ]; 00140 } 00141 } 00142 00143 inline const TintList& TSoftwareAdcModule::GetSigma() const 00144 { 00145 return theSigma; 00146 } 00147 00148 inline Tint TSoftwareAdcModule::GetSigma( Tint channel ) const 00149 { 00150 if ( channel < 0 || channel >= theNumberOfChannels ) { 00151 Tcerr << "TSoftwareAdcModule::GetSigma: invalid ID" << Tendl; 00152 return -EFAULT; 00153 } else { 00154 return theSigma[ channel ]; 00155 } 00156 } 00157 00158 inline const TChannel& TSoftwareAdcModule::GetChannel() const 00159 { 00160 return theChannel; 00161 } 00162 00163 inline Tint TSoftwareAdcModule::GetData( Tint channel ) const 00164 { 00165 if ( channel < 0 || channel >= theNumberOfChannels ) { 00166 Tcerr << "TSoftwareAdcModule::GetData: invalid ID" << Tendl; 00167 return -EFAULT; 00168 } else { 00169 return theChannel[ channel ]; 00170 } 00171 } 00172 00173 inline Trandom_t TSoftwareAdcModule::GetRandomType() const 00174 { 00175 return theRandomType; 00176 } 00177 00178 inline Tvoid TSoftwareAdcModule::SetScale( Tint scale ) 00179 { 00180 theScale = scale; 00181 return; 00182 } 00183 00184 inline Tvoid TSoftwareAdcModule::SetMean( const TintList& meanlist ) 00185 { 00186 theMean = meanlist; 00187 return; 00188 } 00189 00190 inline Tvoid TSoftwareAdcModule::SetMean( Tint channel, Tint mean ) 00191 { 00192 if ( channel < 0 || channel >= theNumberOfChannels ) 00193 Tcerr << "TSoftwareAdc::SetMean: invalid ID" << Tendl; 00194 else 00195 theMean[ channel ] = mean; 00196 return; 00197 } 00198 00199 inline Tvoid TSoftwareAdcModule::SetSigma( const TintList& sigmalist ) 00200 { 00201 theSigma = sigmalist; 00202 return; 00203 } 00204 00205 inline Tvoid TSoftwareAdcModule::SetSigma( Tint channel, Tint sigma ) 00206 { 00207 if ( channel < 0 || channel >= theNumberOfChannels ) 00208 Tcerr << "TSoftwareAdc::SetSigma: invalid ID" << Tendl; 00209 else 00210 theSigma[ channel ] = sigma; 00211 return; 00212 } 00213 00214 inline Tvoid TSoftwareAdcModule::SetChannel( const TChannel& channels ) 00215 { 00216 theChannel = channels; 00217 return; 00218 } 00219 00220 inline Tvoid TSoftwareAdcModule::SetData( Tint channel, Tint data ) 00221 { 00222 if ( channel < 0 || channel >= theNumberOfChannels ) 00223 Tcerr << "TSoftwareAdc::SetData: invalid ID" << Tendl; 00224 else 00225 theChannel[ channel ] = data; 00226 return; 00227 } 00228 00229 inline Tvoid TSoftwareAdcModule::GetRandomType( Trandom_t randomtype ) 00230 { 00231 theRandomType = randomtype; 00232 return; 00233 } 00234 00235 inline Tint TSoftwareAdcModule::GetSeed() 00236 { 00237 return TSoftwareAdcModule::theSeed; 00238 } 00239 00240 inline const TRandomEngine& TSoftwareAdcModule::GetRandomEngine() 00241 { 00242 return TSoftwareAdcModule::theRandomEngine; 00243 } 00244 00245 inline Tvoid TSoftwareAdcModule::SetSeed( Tint seed ) 00246 { 00247 TSoftwareAdcModule::theSeed = seed; 00248 return; 00249 } 00250 00251 inline Tvoid TSoftwareAdcModule::SetRandomEngine( const TRandomEngine& engine ) 00252 { 00253 TSoftwareAdcModule::theRandomEngine = engine; 00254 return; 00255 } 00256 00257 #endif