00001 #ifndef MODULEDEFECT_H
00002 #define MODULEDEFECT_H
00003
00004 #include "Sct/Streamable.h"
00005 #include <cstdio>
00006 #include <string>
00007 #include <memory>
00008 #include <map>
00009 #include "Sct/LogicErrors.h"
00010 #include "Sct/SctParameters.h"
00011 #include "ModuleElement.h"
00012
00013 using namespace std;
00014 using Sct::Streamable;
00015
00016 namespace SctData {
00017
00026 class ModuleDefect : public Streamable {
00027 public:
00028
00030
00032
00033 static const ModuleDefect STUCKON;
00034 static const ModuleDefect OVER;
00035 static const ModuleDefect UNDER;
00036 static const ModuleDefect NOINIT;
00037 static const ModuleDefect FIT_UNDER;
00038 static const ModuleDefect FIT_OVER;
00039 static const ModuleDefect SIG_UNDER;
00040 static const ModuleDefect SIG_OVER;
00042
00043 static const ModuleDefect SD_LO;
00044 static const ModuleDefect SD_HI;
00045
00046
00047 static const ModuleDefect LO_GAIN;
00048 static const ModuleDefect HI_GAIN;
00049 static const ModuleDefect LO_OFFSET;
00050 static const ModuleDefect HI_OFFSET;
00051 static const ModuleDefect UNBONDED;
00052 static const ModuleDefect PARTBONDED;
00053 static const ModuleDefect NOISY;
00054
00055
00056 static const ModuleDefect TR_RANGE;
00057 static const ModuleDefect TR_STEP;
00058 static const ModuleDefect TR_OFFSET;
00059 static const ModuleDefect TR_NOTRIM;
00060
00061
00062 static const ModuleDefect NO_HI;
00063 static const ModuleDefect MEAN_ERROR;
00064 static const ModuleDefect SIG_ERROR;
00065 static const ModuleDefect STUCK_CELL;
00066 static const ModuleDefect DEAD_CELL;
00067 static const ModuleDefect TOKEN;
00068 static const ModuleDefect RTOKEN;
00069 static const ModuleDefect TW_HI;
00070 static const ModuleDefect TW_LO;
00071
00072
00073
00077 ModuleDefect(const ModuleDefect & prototype, const ModuleElement& element) throw () ;
00082 virtual ~ModuleDefect() throw() {
00083 }
00084
00088 bool isSevere() const throw() ;
00092 const ModuleElement& getModuleElement() const throw(LogicError);
00096 bool isPrototype() const throw() ;
00097
00101 bool isChipDefect() const throw() ;
00102
00106 bool isLinkDefect() const throw() ;
00107
00111 bool isUnfittable() const throw() ;
00112
00116 bool isUnuseable() const throw() ;
00117
00121 bool isDodgy() const throw() ;
00122
00126 const string& getName() const throw() ;
00127
00131 const string & getDescription() const throw() ;
00132
00136 double getParameter() const throw() ;
00137
00143 bool isOfTheSameTypeAs(const ModuleDefect & defect) const throw() ;
00149 bool operator ==(const ModuleDefect & defect) const throw(LogicError) ;
00150
00151
00152 virtual string getClassName() const throw() ;
00153
00154 private:
00158 ModuleDefect(int id, bool severe, const string& name, const string & d, double parameter) throw() ;
00163 ModuleDefect(int id, bool severe, const string& name, const char* d, double parameter) throw() ;
00164
00168
00169
00170
00171 int id;
00172 bool severe;
00173 string name;
00174 string description;
00175 double parameter;
00176 auto_ptr<ModuleElement> element;
00177
00178
00179 friend class ModuleDefectIOHelper;
00180 static map <int, ModuleDefect*> defectMap;
00181 };
00182
00183
00184 inline ModuleDefect::ModuleDefect(int id, bool severe, const string& name, const string & d, double parameter) throw()
00185 :id(id), severe(severe), name(name), description(d), parameter(parameter), element(0) {
00186
00187 defectMap[id] = this;
00188 }
00189
00190 inline ModuleDefect::ModuleDefect(int id, bool severe, const string& name, const char* d, double parameter) throw()
00191 :id(id), severe(severe), name(name), description(""), parameter(parameter), element(0) {
00192
00193 defectMap[id] = this;
00194
00196 char temp[100];
00197 sprintf(temp, d, parameter);
00198 description = temp;
00199 }
00200
00201 inline ModuleDefect::ModuleDefect(const ModuleDefect & prototype, const ModuleElement& el) throw()
00202 :id(prototype.id), severe(prototype.severe), name(prototype.name), description(prototype.description), parameter(prototype.parameter), element(new ModuleElement(el)) {
00203 }
00204
00205 inline double ModuleDefect::getParameter() const throw() {
00206 return parameter;
00207 }
00208
00209 inline bool ModuleDefect::isPrototype() const throw() {
00210 return (element.get()==0);
00211 }
00212
00213 inline bool ModuleDefect::operator ==(const ModuleDefect & defect) const throw(LogicError) {
00214 return (id == defect.id && getModuleElement() == defect.getModuleElement() );
00215 }
00216 inline bool ModuleDefect::isOfTheSameTypeAs(const ModuleDefect & defect) const throw() {
00217 return (id == defect.id);
00218 }
00219 inline const ModuleElement& ModuleDefect::getModuleElement() const throw(LogicError) {
00220 if (element.get()==0){
00221 throw IllegalStateError("ModuleDefect::getModuleElement not available for prototype", __FILE__, __LINE__);
00222 }
00223 return *element;
00224 }
00225
00226 inline bool ModuleDefect::isChipDefect() const throw() {
00227 return getModuleElement().isChip();
00228 }
00229
00230 inline bool ModuleDefect::isLinkDefect() const throw() {
00231 return getModuleElement().isLink();
00232 }
00233
00234 inline bool ModuleDefect::isSevere() const throw() {
00235 return severe;
00236 }
00237
00238 inline bool ModuleDefect::isUnfittable() const throw() {
00239 return (isOfTheSameTypeAs(OVER) || isOfTheSameTypeAs(UNDER) ||
00240 isOfTheSameTypeAs(STUCKON) );
00241 }
00242
00243 inline bool ModuleDefect::isUnuseable() const throw() {
00244 return (isOfTheSameTypeAs(DEAD) || isOfTheSameTypeAs(STUCKON) );
00245 }
00246
00247 inline bool ModuleDefect::isDodgy() const throw() {
00248 return !(isOfTheSameTypeAs(DEAD) || isOfTheSameTypeAs(STUCKON) );
00249 }
00250
00251 inline const string& ModuleDefect::getName() const throw() {
00252 return name;
00253 }
00254
00255 inline const string & ModuleDefect::getDescription() const throw() {
00256 return description;
00257 }
00258
00259 inline string ModuleDefect::getClassName() const throw() {
00260 return "SctData::ModuleDefect";
00261 }
00262 }
00263 #endif //#ifndef MODULEDEFECT_H