ChipConfiguration.h

00001 #ifndef SCTDATA_CHIPCONFIGURATION_H
00002 #define SCTDATA_CHIPCONFIGURATION_H
00003 
00004 #include <string>
00005 #include <climits>
00006 #include <Sct/AbcdModule.h>
00007 #include "Sct/Streamable.h"
00008 #include "Sct/SctParameters.h"
00009 #include "Sct/Exception.h"
00010 #include "Sct/OutOfRangeError.h"
00011 
00012 using Sct::LogicError;
00013 using Sct::OutOfRangeError;
00014 namespace SctData {
00015   
00022 class ChipConfiguration : public virtual Sct::Streamable {
00023 public:
00024     ChipConfiguration(ABCDChip& chipConfig) throw();
00025     virtual ~ChipConfiguration() throw() {}
00026     virtual std::string getClassName() const throw();
00027     
00029     bool isActive() const throw();
00031     void setActive(const bool active) throw();
00035     unsigned char getAddress() const throw();
00037     unsigned char getTrimTarget() const throw();
00039     void setTrimTarget(const unsigned char target) throw(LogicError);
00041     unsigned char getTrim(unsigned int channel) const throw(LogicError);
00043     void setTrim(const unsigned channel, const unsigned char trim) throw(LogicError);
00045     unsigned char getThreshold() const throw();
00047     void setThreshold(const unsigned char threshold) throw(LogicError);
00049     unsigned char getCalCharge() const throw();
00051     void setCalCharge(const unsigned char calCharge) throw();
00053     unsigned char getStrobeDelay() const throw();
00055     void setStrobeDelay(const unsigned char strobeDelay) throw(LogicError);
00057     void resetMask() throw();
00059     void setMask(const unsigned ichannel, const bool value) throw(LogicError);
00061     void mask(const unsigned ichannel) throw(LogicError);
00063     void unmask(const unsigned ichannel) throw(LogicError);
00065     bool isMasked(const unsigned ichannel) const throw(LogicError);
00066 
00067     unsigned char getTrimRange() const throw(); 
00068     void setTrimRange(const unsigned char) throw(LogicError);
00069      /* A functional representation of the response
00070      * curve (equivalent threshold as a function of charge)
00071      * so that one may request ROD to set the threshold to
00072      * a value specified in fC. @{ get the index (type) of the RC function
00073      *  @return 0 - no calibration information
00074      *  1 - second order polynomial
00075      *  2 - "grillo" function
00076      *  3 - exponential
00077      *  4 - straight line fit */
00078     char getRcFunctionIndex() const throw();
00080     void setRcFunctionIndex(const char) throw(LogicError);
00082     double getRcParam(const unsigned ipar) const throw(LogicError);
00087     void setRcParam(const unsigned ipar, const double val) const throw(LogicError);
00089 
00094     void setCalFactor(const float factor) throw();
00096     float getCalFactor() const throw();
00097     
00098     void setMaster(bool value) throw();
00099     void setEnd(bool value) throw();
00100     void setFeedThrough(bool value) throw();
00101     void setInputBypass(bool value) throw();
00102     void setOutputBypass(bool value) throw();
00103 
00104     bool isMaster() const throw();
00105     bool isEnd() const throw();
00106     bool isFeedThrough() const throw();
00107     bool isInputBypass() const throw();
00108     bool isOutputBypass() const throw();
00109 
00111     const ABCDChip& getConfig() const{ return config;}
00113     ABCDChip& getConfig() { return config;}
00114 private:
00115     ABCDChip& config;
00116 };
00117 
00118 //INLINES
00119 
00120    inline bool ChipConfiguration::isMasked(const unsigned ichannel)const throw(LogicError) {
00121        return !( config.basic.mask[ichannel/32] & (1 << ichannel%32) );
00122    }
00123     
00124     inline void ChipConfiguration::setMask(const unsigned ichannel, const bool value) throw(LogicError){
00125     if (value) { mask(ichannel); } else { unmask(ichannel); }
00126     }
00127     
00128     inline void ChipConfiguration::unmask(const unsigned ichannel) throw(LogicError){
00130 #ifndef NDEBUG
00131     if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::mask", __FILE__, __LINE__, ichannel,0,Sct::nChannelChip-1);
00132 #endif
00133     config.basic.mask[ichannel/32] |= (1<<ichannel%32);
00134     }
00135 
00136     inline void ChipConfiguration::mask(const unsigned ichannel) throw(LogicError){
00137 #ifndef NDEBUG
00138     if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::unmask", __FILE__, __LINE__, ichannel,0,Sct::nChannelModule-1);
00139 #endif
00140     config.basic.mask[ichannel/32] &= ~(1<<ichannel%32);
00141     }
00142     
00143     inline void ChipConfiguration::resetMask() throw(){
00144     for (short i=0; i<4; ++i){
00145         config.basic.mask[i]=ULONG_MAX;
00146     }
00147     }
00148 
00149     inline bool ChipConfiguration::isActive() const throw() {
00150     return config.active;
00151 }
00152     
00153     inline void ChipConfiguration::setActive(const bool active) throw() {
00154     config.active = active;
00155     }
00156     
00157     inline unsigned char ChipConfiguration::getAddress() const throw() {
00158     return config.address;
00159     }
00160     
00161     inline unsigned char ChipConfiguration::getTrimTarget() const throw() {
00162     return config.target;
00163     }
00164 
00165     inline void ChipConfiguration::setTrimTarget(const unsigned char target) throw(LogicError) {
00166     config.target = target;
00167     }
00168 
00169     inline unsigned char ChipConfiguration::getThreshold() const throw() {
00170     return config.basic.vthr;
00171     }
00172 
00173     inline void ChipConfiguration::setThreshold(const unsigned char threshold) throw(LogicError) {
00174 #ifndef NDEBUG
00175     if (threshold>=256) throw OutOfRangeError<unsigned>("ChipConfiguration::setThreshold", __FILE__, __LINE__, threshold,0,255);
00176 #endif
00177     config.basic.vthr = threshold;
00178     }
00179     
00180     inline double ChipConfiguration::getRcParam(const unsigned ipar) const throw(LogicError) {
00181 #ifndef NDEBUG
00182     if (ipar>=3) throw OutOfRangeError<unsigned>("ChipConfiguration::getRcParam", __FILE__, __LINE__, ipar,0,2);
00183 #endif
00184     return config.caldata.rc_params[ipar];
00185     }
00186     
00187     inline void ChipConfiguration::setRcParam(const unsigned ipar, const double val) const throw(LogicError) {
00188 #ifndef NDEBUG
00189     if (ipar>=3)  throw OutOfRangeError<unsigned>("ChipConfiguration::setRcParam", __FILE__, __LINE__, ipar,0,2);
00190 #endif  
00191     config.caldata.rc_params[ipar]=val;
00192     }
00193 
00194     inline char ChipConfiguration::getRcFunctionIndex() const throw(){
00195     return config.caldata.rc_function;
00196     }
00197 
00198     inline void ChipConfiguration::setRcFunctionIndex(const char index) throw(LogicError){
00199 #ifndef NDEBUG
00200       if (index>=5) throw OutOfRangeError<unsigned>("ChipConfiguration::setFunctionIndex", __FILE__, __LINE__, index,0,4);
00201 #endif
00202     config.caldata.rc_function=index;
00203     }
00204     
00205     inline unsigned char ChipConfiguration::getCalCharge() const throw() {
00206     return config.basic.vcal;
00207     }
00208     
00209     inline void ChipConfiguration::setCalCharge(const unsigned char calCharge) throw() {
00210 #ifndef NDEBUG
00211       if (calCharge>=256) throw OutOfRangeError<unsigned>("ChipConfiguration::setCalCharge", __FILE__, __LINE__, calCharge,0,255);
00212 #endif
00213     config.basic.vcal = calCharge;
00214     }
00215     
00216     inline unsigned char ChipConfiguration::getStrobeDelay() const throw() {
00217     return config.basic.delay;
00218     }
00219     
00220     inline void ChipConfiguration::setStrobeDelay(const unsigned char strobeDelay) throw(LogicError) {
00221 #ifndef NDEBUG
00222       if (strobeDelay>=64) throw OutOfRangeError<unsigned>("ChipConfiguration::setStrobeDelay", __FILE__, __LINE__, strobeDelay,0,63);
00223 #endif
00224     config.basic.delay = strobeDelay;
00225     }
00226 
00227     inline ChipConfiguration::ChipConfiguration(ABCDChip& chipConfig) throw () : config(chipConfig) {}
00228 
00229     inline std::string ChipConfiguration::getClassName() const throw() {
00230     return "SctData::ChipConfiguration";
00231     }
00232 
00233     inline void ChipConfiguration::setCalFactor(const float factor) throw(){
00234     config.caldata.c_factor=factor;
00235     }
00236 
00237     inline float ChipConfiguration::getCalFactor() const throw(){
00238     return config.caldata.c_factor;
00239     }
00240   
00241   inline unsigned char ChipConfiguration::getTrim(unsigned ichannel) const throw(LogicError){
00242 #ifndef NDEBUG
00243     if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::getTrim", __FILE__, __LINE__, ichannel,0,Sct::nChannelChip-1);
00244 #endif
00245     return config.trim[ichannel];
00246   }
00247   inline void ChipConfiguration::setTrim(unsigned ichannel, unsigned char value) throw(LogicError){
00248 #ifndef NDEBUG
00249     if (ichannel>=Sct::nChannelChip) throw OutOfRangeError<unsigned>("ChipConfiguration::setTrim channel", __FILE__, __LINE__, ichannel,0,Sct::nChannelChip-1);
00250     if (value>=16) throw OutOfRangeError<unsigned>("ChipConfiguration::setTrim value", __FILE__, __LINE__, value,0,15);
00251 #endif
00252     config.trim[ichannel]=value;
00253   }
00254   
00255   inline void ChipConfiguration::setTrimRange(unsigned char value) throw(LogicError) {
00256 #ifndef NDEBUG
00257     if (value>=4) throw OutOfRangeError<unsigned>("ChipConfiguration::setTrimRange value", __FILE__, __LINE__, value,0,3);
00258 #endif
00259     config.basic.config.trimRange=value;
00260   }
00261   inline unsigned char ChipConfiguration::getTrimRange() const throw() {
00262     return config.basic.config.trimRange;
00263   }
00264     
00265     inline void ChipConfiguration::setMaster(bool value) throw(){
00266     config.basic.config.master = value ? 1 : 0;
00267     }
00268     inline void ChipConfiguration::setEnd(bool value) throw(){
00269     config.basic.config.end = value ? 1 : 0;
00270     }
00271     inline void ChipConfiguration::setFeedThrough(bool value) throw(){
00272     config.basic.config.feedThrough = value ? 1 : 0;
00273     }
00274     inline void ChipConfiguration::setInputBypass(bool value) throw(){
00275     config.basic.config.inputBypass = value ? 1 : 0;
00276     }
00277     inline void ChipConfiguration::setOutputBypass(bool value) throw(){
00278     config.basic.config.outputBypass = value ? 1 : 0;
00279     }
00280     
00281     inline bool ChipConfiguration::isMaster() const throw(){
00282     return config.basic.config.master;
00283     }
00284     inline bool ChipConfiguration::isEnd() const throw(){
00285     return config.basic.config.end;
00286     }
00287     inline bool ChipConfiguration::isFeedThrough() const throw(){
00288     return config.basic.config.feedThrough;
00289     }
00290     inline bool ChipConfiguration::isInputBypass() const throw(){
00291     return config.basic.config.inputBypass;
00292     }
00293     inline bool ChipConfiguration::isOutputBypass() const throw(){
00294     return config.basic.config.outputBypass;
00295     }
00296     
00297 }
00298 
00299 #endif //#ifndef SCTDATA_CHIPCONFIGURATION_H

Generated on Mon Feb 6 14:01:17 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6