DefectList.cpp

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

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