Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

DefectList.cpp

00001 #include "DefectList.h"
00002 #include "DefectPrototype.h"
00003 #include "Defect.h"
00004 
00005 namespace SctData {
00006 
00007 DefectList::DefectList() {}
00008 
00009 string DefectList::getClassName() const throw() {
00010     return "SctData::DefectList";
00011 }
00012 
00013 void DefectList::addDefect(Defect defect) {
00014   DefectCollection::iterator i=defectList.begin();
00015   while(i!=defectList.end()){
00016 
00017     const ModuleElement& ei = (*i).getModuleElement();
00018     const ModuleElement& ej = defect.getModuleElement();
00019     const DefectPrototype& pi = (*i).getPrototype();
00020     const DefectPrototype& pj = defect.getPrototype();
00021     
00022     // if the defect is of the same type:
00023     if ( pi==pj ){
00024       // if new defect already contaned, then redundant:
00025       if ( ei.contains(ej) ) return;
00026       // if new defect contains existing one, replace:
00027       if ( ej.contains(ei) ) {
00028     *i=defect;
00029     return;
00030       }
00031       
00032       // if they overlap or are adjacent, replace with combined defect:
00033       if ( ei.overlaps(ej) || ei.adjacentTo(ej) ){
00034     unsigned first = ei.getFirst() < ej.getFirst() ? ei.getFirst() : ej.getFirst();
00035     unsigned last  = ei.getLast() > ej.getLast() ? ei.getLast() : ej.getLast();
00036     i=defectList.erase(i);
00037     defectList.push_back(Defect(pi,ModuleElement(first,last)));
00038     return;
00039       }
00040     }
00041     ++i;
00042   }
00043   defectList.push_back(defect);
00044 }
00045 
00046 const DefectList::DefectCollection& DefectList::getAllDefects() const {
00047     return defectList;
00048 }
00049 
00050 auto_ptr<DefectList> DefectList::getDefectsAffectingElement(ModuleElement element) const {
00051     auto_ptr<DefectList> newDefects(new DefectList());
00052     for (DefectCollection::const_iterator i=defectList.begin(); 
00053      i!=defectList.end(); 
00054      ++i) {
00055       if ( (*i).getModuleElement().overlaps(element))
00056     newDefects->addDefect(*i);
00057     }
00058     return newDefects;
00059 }
00060 
00061 DefectSeverity DefectList::defectSeverityAffectingElement(ModuleElement element) const {
00062     DefectSeverity s = NONE;
00063     for (DefectCollection::const_iterator i=defectList.begin(); 
00064      i!=defectList.end(); 
00065      ++i) {
00066         if ( (*i).getModuleElement().overlaps(element) && (*i).getPrototype().getSeverity() > s)
00067       s = (*i).getPrototype().getSeverity();
00068     };
00069     return s;
00070 }
00071 
00072 auto_ptr<DefectList> DefectList::getDefectsEncompassingElement(ModuleElement element) const {
00073     auto_ptr<DefectList> newDefects(new DefectList());
00074     for (DefectCollection::const_iterator i=defectList.begin(); 
00075      i!=defectList.end(); 
00076      ++i) {
00077       if ( (*i).getModuleElement().contains(element))
00078     newDefects->addDefect(*i);
00079     }
00080     return newDefects;
00081 }
00082 
00083 DefectSeverity DefectList::defectSeverityEncompassingElement(ModuleElement element) const {
00084     DefectSeverity s = NONE;
00085     for (DefectCollection::const_iterator i=defectList.begin(); 
00086      i!=defectList.end(); 
00087      ++i) {
00088       if ((*i).getModuleElement().contains(element) && (*i).getPrototype().getSeverity() > s)
00089     s = (*i).getPrototype().getSeverity();
00090     };
00091     return s;
00092 }
00093   
00094 DefectList& DefectList::operator +=(const DefectList& toadd) {
00095     for (DefectCollection::const_iterator i=toadd.defectList.begin(); 
00096      i!=toadd.defectList.end(); 
00097      ++i) {
00098       if (!this->containsDefect(*i))
00099     this->addDefect(*i);
00100     }
00101     return *this;
00102 }
00103 
00104 bool DefectList::containsDefect(Defect defect) const {
00105   for (DefectCollection::const_iterator i=defectList.begin(); 
00106      i!=defectList.end(); 
00107      ++i) {
00108     if (*i == defect) return true;
00109   }
00110   return false;
00111 }
00112 
00113 }
00114 

Generated on Thu Jul 15 09:50:45 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5