00001 #ifndef SCTDATA_CHIPCONFIGURATION_H
00002 #define SCTDATA_CHIPCONFIGURATION_H
00003
00004 #include <string>
00005 #include <CommonWithDsp/sctStructure.h>
00006 #include "Sct/Streamable.h"
00007 #include "Sct/SctParameters.h"
00008 #include "Sct/Exception.h"
00009 #include "Sct/OutOfRangeError.h"
00010
00011 using Sct::LogicError;
00012 using Sct::OutOfRangeError;
00013 namespace SctData {
00014
00021 class ChipConfiguration : public virtual Sct::Streamable {
00022 public:
00023 ChipConfiguration(ABCDChip& chipConfig) throw();
00024 virtual ~ChipConfiguration() throw() {}
00025 virtual std::string getClassName() const throw();
00026
00028 bool isActive() const throw();
00030 void setActive(const bool active) throw();
00034 unsigned char getAddress() const throw();
00036 unsigned char getTrimTarget() const throw();
00038 void setTrimTarget(const unsigned char target) throw(LogicError);
00040 unsigned char getTrim(unsigned int channel) const throw(LogicError);
00042 void setTrim(const unsigned channel, const unsigned char trim) throw(LogicError);
00044 unsigned char getThreshold() const throw();
00046 void setThreshold(const unsigned char threshold) throw(LogicError);
00048 unsigned char getCalCharge() const throw();
00050 void setCalCharge(const unsigned char calCharge) throw();
00052 unsigned char getStrobeDelay() const throw();
00054 void setStrobeDelay(const unsigned char strobeDelay) throw(LogicError);
00056 void resetMask() throw();
00058 void setMask(const unsigned ichannel, const bool value) throw(LogicError);
00060 void mask(const unsigned ichannel) throw(LogicError);
00062 void unmask(const unsigned ichannel) throw(LogicError);
00064 bool isMasked(const unsigned ichannel) const throw(LogicError);
00065
00066 unsigned char getTrimRange() const throw();
00067 void setTrimRange(const unsigned char) throw(LogicError);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 char getRcFunctionIndex() const throw();
00079 void setRcFunctionIndex(const char) throw(LogicError);
00081 double getRcParam(const unsigned ipar) const throw(LogicError);
00086 void setRcParam(const unsigned ipar, const double val) const throw(LogicError);
00088
00093 void setCalFactor(const float factor) throw();
00095 float getCalFactor() throw();
00096
00097 void setMaster(bool value) throw();
00098 void setEnd(bool value) throw();
00099 void setFeedThrough(bool value) throw();
00100 void setInputBypass(bool value) throw();
00101 void setOutputBypass(bool value) throw();
00102
00103 bool isMaster() const throw();
00104 bool isEnd() const throw();
00105 bool isFeedThrough() const throw();
00106 bool isInputBypass() const throw();
00107 bool isOutputBypass() const throw();
00108
00109 private:
00110 ABCDChip& config;
00111 };
00112
00113
00114
00115 inline bool ChipConfiguration::isMasked(const unsigned ichannel)const throw(LogicError) {
00116 return !( config.basic.mask[ichannel/32] & (1 << ichannel%32) );
00117 }
00118
00119 inline void ChipConfiguration::setMask(const unsigned ichannel, const bool value) throw(LogicError){
00120 if (value) { mask(ichannel); } else { unmask(ichannel); }
00121 }
00122
00123 inline void ChipConfiguration::unmask(const unsigned ichannel) throw(LogicError){
00125 #ifndef NDEBUG
00126 if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::mask", __FILE__, __LINE__, ichannel,0,Sct::nChannelChip-1);
00127 #endif
00128 config.basic.mask[ichannel/32] |= (1<<ichannel%32);
00129 }
00130
00131 inline void ChipConfiguration::mask(const unsigned ichannel) throw(LogicError){
00132 #ifndef NDEBUG
00133 if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::unmask", __FILE__, __LINE__, ichannel,0,Sct::nChannelModule-1);
00134 #endif
00135 config.basic.mask[ichannel/32] &= ~(1<<ichannel%32);
00136 }
00137
00138 inline void ChipConfiguration::resetMask() throw(){
00139 for (short i=0; i<4; ++i){
00140 config.basic.mask[i]=0;
00141 }
00142 }
00143
00144 inline bool ChipConfiguration::isActive() const throw() {
00145 return config.active;
00146 }
00147
00148 inline void ChipConfiguration::setActive(const bool active) throw() {
00149 config.active = active;
00150 }
00151
00152 inline unsigned char ChipConfiguration::getAddress() const throw() {
00153 return config.address;
00154 }
00155
00156 inline unsigned char ChipConfiguration::getTrimTarget() const throw() {
00157 return config.target;
00158 }
00159
00160 inline void ChipConfiguration::setTrimTarget(const unsigned char target) throw(LogicError) {
00161 config.target = target;
00162 }
00163
00164 inline unsigned char ChipConfiguration::getThreshold() const throw() {
00165 return config.basic.vthr;
00166 }
00167
00168 inline void ChipConfiguration::setThreshold(const unsigned char threshold) throw(LogicError) {
00169 #ifndef NDEBUG
00170 if (threshold>=256) throw OutOfRangeError<unsigned>("ChipConfiguration::setThreshold", __FILE__, __LINE__, threshold,0,255);
00171 #endif
00172 config.basic.vthr = threshold;
00173 }
00174
00175 inline double ChipConfiguration::getRcParam(const unsigned ipar) const throw(LogicError) {
00176 #ifndef NDEBUG
00177 if (ipar>=3) throw OutOfRangeError<unsigned>("ChipConfiguration::getRcParam", __FILE__, __LINE__, ipar,0,2);
00178 #endif
00179 return config.caldata.rc_params[ipar];
00180 }
00181
00182 inline void ChipConfiguration::setRcParam(const unsigned ipar, const double val) const throw(LogicError) {
00183 #ifndef NDEBUG
00184 if (ipar>=3) throw OutOfRangeError<unsigned>("ChipConfiguration::setRcParam", __FILE__, __LINE__, ipar,0,2);
00185 #endif
00186 config.caldata.rc_params[ipar]=val;
00187 }
00188
00189 inline char ChipConfiguration::getRcFunctionIndex() const throw(){
00190 return config.caldata.rc_function;
00191 }
00192
00193 inline void ChipConfiguration::setRcFunctionIndex(const char index) throw(LogicError){
00194 #ifndef NDEBUG
00195 if (index>=5) throw OutOfRangeError<unsigned>("ChipConfiguration::setFunctionIndex", __FILE__, __LINE__, index,0,4);
00196 #endif
00197 config.caldata.rc_function=index;
00198 }
00199
00200 inline unsigned char ChipConfiguration::getCalCharge() const throw() {
00201 return config.basic.vcal;
00202 }
00203
00204 inline void ChipConfiguration::setCalCharge(const unsigned char calCharge) throw() {
00205 #ifndef NDEBUG
00206 if (calCharge>=256) throw OutOfRangeError<unsigned>("ChipConfiguration::setCalCharge", __FILE__, __LINE__, calCharge,0,255);
00207 #endif
00208 config.basic.vcal = calCharge;
00209 }
00210
00211 inline unsigned char ChipConfiguration::getStrobeDelay() const throw() {
00212 return config.basic.delay;
00213 }
00214
00215 inline void ChipConfiguration::setStrobeDelay(const unsigned char strobeDelay) throw(LogicError) {
00216 #ifndef NDEBUG
00217 if (strobeDelay>=64) throw OutOfRangeError<unsigned>("ChipConfiguration::setStrobeDelay", __FILE__, __LINE__, strobeDelay,0,63);
00218 #endif
00219 config.basic.delay = strobeDelay;
00220 }
00221
00222 inline ChipConfiguration::ChipConfiguration(ABCDChip& chipConfig) throw () : config(chipConfig) {}
00223
00224 inline std::string ChipConfiguration::getClassName() const throw() {
00225 return "SctData::ChipConfiguration";
00226 }
00227
00228 inline void ChipConfiguration::setCalFactor(const float factor) throw(){
00229 config.caldata.c_factor=factor;
00230 }
00231
00232 inline float ChipConfiguration::getCalFactor() throw(){
00233 return config.caldata.c_factor;
00234 }
00235
00236 inline unsigned char ChipConfiguration::getTrim(unsigned ichannel) const throw(LogicError){
00237 #ifndef NDEBUG
00238 if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::getTrim", __FILE__, __LINE__, ichannel,0,Sct::nChannelChip-1);
00239 #endif
00240 return config.trim[ichannel];
00241 }
00242 inline void ChipConfiguration::setTrim(unsigned ichannel, unsigned char value) throw(LogicError){
00243 #ifndef NDEBUG
00244 if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::setTrim channel", __FILE__, __LINE__, ichannel,0,Sct::nChannelChip-1);
00245 if (value>=16) throw OutOfRangeError<unsigned>("ChipConfiguration::setTrim value", __FILE__, __LINE__, value,0,15);
00246 #endif
00247 config.trim[ichannel]=value;
00248 }
00249
00250 inline void ChipConfiguration::setTrimRange(unsigned char value) throw(LogicError) {
00251 #ifndef NDEBUG
00252 if (value>=4) throw OutOfRangeError<unsigned>("ChipConfiguration::setTrimRange value", __FILE__, __LINE__, value,0,3);
00253 #endif
00254 config.basic.config.trimRange=value;
00255 }
00256 inline unsigned char ChipConfiguration::getTrimRange() const throw() {
00257 return config.basic.config.trimRange;
00258 }
00259
00260 inline void ChipConfiguration::setMaster(bool value) throw(){
00261 config.basic.config.master = value ? 1 : 0;
00262 }
00263 inline void ChipConfiguration::setEnd(bool value) throw(){
00264 config.basic.config.end = value ? 1 : 0;
00265 }
00266 inline void ChipConfiguration::setFeedThrough(bool value) throw(){
00267 config.basic.config.feedThrough = value ? 1 : 0;
00268 }
00269 inline void ChipConfiguration::setInputBypass(bool value) throw(){
00270 config.basic.config.inputBypass = value ? 1 : 0;
00271 }
00272 inline void ChipConfiguration::setOutputBypass(bool value) throw(){
00273 config.basic.config.outputBypass = value ? 1 : 0;
00274 }
00275
00276 inline bool ChipConfiguration::isMaster() const throw(){
00277 return config.basic.config.master;
00278 }
00279 inline bool ChipConfiguration::isEnd() const throw(){
00280 return config.basic.config.end;
00281 }
00282 inline bool ChipConfiguration::isFeedThrough() const throw(){
00283 return config.basic.config.feedThrough;
00284 }
00285 inline bool ChipConfiguration::isInputBypass() const throw(){
00286 return config.basic.config.inputBypass;
00287 }
00288 inline bool ChipConfiguration::isOutputBypass() const throw(){
00289 return config.basic.config.outputBypass;
00290 }
00291
00292 }
00293
00294 #endif //#ifndef SCTDATA_CHIPCONFIGURATION_H