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

ArchModuleDefects.cpp

00001 #include "ArchModuleDefects.h"
00002 #include <boost/shared_ptr.hpp>
00003 #include "SctData/ModuleDefect.h"
00004 #include "TObjString.h"
00005 #include "TVectorD.h"
00006 #include "TVector.h"
00007 #include <string>
00008 #include <map>
00009 
00010 //using namespace SctData;
00011 //using namespace Sct;
00012 using namespace boost;
00013 using boost::shared_ptr;
00014 
00015 
00016 ArchModuleDefects::ArchModuleDefects(vector<shared_ptr<const ModuleDefect> > testDefects ) {
00017 
00018   
00019   
00020   defects = testDefects;
00021 
00022   for (unsigned int i=0; i<defects.size(); ++i) {    //loop on the number of all kinds of defects per module
00023     
00024     
00025     //TObjString* name =  new TObjString(defects[i]->getName().c_str());
00026     
00027     
00028     double first = defects[i]->getModuleElement().getFirst();
00029     double Nchannels = defects[i]->getModuleElement().getNChannels();
00030     double chipDefect = defects[i]->isChipDefect();
00031     double linkDefect = defects[i]->isLinkDefect();
00032     double unfittable = defects[i]->isUnfittable();
00033     double unusable = defects[i]->isUnuseable();
00034     double dodgy = defects[i]->isDodgy();
00035 
00036     
00037     TVector* vthisDefect = new TVector(0,7,0,first,Nchannels,chipDefect,linkDefect,unfittable,unusable,dodgy,"END"); 
00038     //cout << "defects = "<<first<<" "<<Nchannels<<" "<<chipDefect<<" "<<linkDefect<<" "<<unfittable<<" "<<unusable<<" "<<dodgy<<endl; 
00039     
00040     
00041       
00042 
00043        //Check if this kind of defect already exists
00044 
00045        if (IsInMap(defects[i]->getName().c_str()) == true) {
00046       
00047       
00048      float index = IndexInMap(defects[i]->getName().c_str());
00049 
00050      //get the TObjArray defectList and add this defect, i, to the TObjArray defectList      
00051      TObjArray* tmp_obj[defectList.size()];
00052      for(int ii= 0;ii<defectList.size(); ++ii) { 
00053        tmp_obj[ii] = (defectList[ii]).get();
00054        TObjString* this_name = dynamic_cast<TObjString*>(tmp_obj[ii]->First());
00055        const char *tmp_this_name = this_name->GetName();
00056        if (IndexInMap(tmp_this_name) == index) {
00057          //cout<< "Name = " <<tmp_this_name<<endl;
00058          tmp_obj[ii]->Add(vthisDefect);
00059        }
00060        
00061        
00062      }
00063        
00064        
00065 
00066        
00067        } else {
00068       
00069 
00070      //if this kind of defect is new, i.e. not in the defect map:
00071      //Add this defect to map
00072      if (addToMap(defects[i]->getName().c_str()) == true) { 
00073 
00074        //get the TObjArray defectList and add this defect, i, to the TObjArray defectList
00075        TObjString* name =  new TObjString(defects[i]->getName().c_str());
00076 
00077        TObjArray* obj = new TObjArray();       
00078        obj->Add(name);
00079        obj->Add(vthisDefect);   
00080        defectList.push_back(obj);
00081     
00082      } else { 
00083        cerr<<"ERROR in Adding Defect to map"<<endl;
00084      }
00085      
00086        }    
00087     
00088 
00089  
00090 
00091   }
00092 
00093 
00094 
00095 } 
00096 
00097 
00098 bool ArchModuleDefects::IsInMap(const string& defectName) throw() {
00099   
00100   if (defectMap.find(defectName) == defectMap.end()) {
00101     ostringstream os; os <<"ArchModuleDefects::isInMap couldn't find defect `"<< defectName<<"'";
00102     cerr << os.str() << endl;
00103     cerr << "There are " << defectMap.size() << " known defect types: ";
00104     for (map<string, int>::const_iterator it = defectMap.begin();it != defectMap.end() ; ++it)
00105       {
00106     cerr << (*it).first << endl;
00107       }
00108     //throw InvalidArgumentError(os.str(), __FILE__, __LINE__);
00109     return false;
00110   }
00111   
00112   
00113   return true;
00114 
00115 }
00116 
00117 
00118 int ArchModuleDefects::IndexInMap(const string& defectName) throw(LogicError) {
00119   
00120   if (defectMap.find(defectName) == defectMap.end()) {
00121   ostringstream os; os <<"ArchModuleDefects::IndexInMap couldn't find defect `"<< defectName<<"'";
00122     cerr << os.str() << endl;
00123     cerr << "There are " << defectMap.size() << " known response defect types: ";
00124     for (map<string, int>::const_iterator it = defectMap.begin();it != defectMap.end() ; ++it)
00125       {
00126     cerr << (*it).first << endl;
00127 
00128       }
00129     throw InvalidArgumentError(os.str(), __FILE__, __LINE__);
00130   }
00131   return (*defectMap.find(defectName)).second;
00132 
00133 
00134 
00135 }
00136 
00137     
00138 
00139 bool ArchModuleDefects::addToMap(const string& defectName) throw() {
00140   //if this defectName is already in the map return false
00141   //cout<<"I am in AddToMap"<<endl;
00142   if (defectMap.find(defectName) != defectMap.end()) {
00143     cout<<" Defect already in map"<<endl;
00144     return false;
00145   }
00146 
00147   //cout<<" Adding Defect to map..."<<endl;
00148   int size = defectMap.size();
00149   defectMap[defectName] = size+1;
00150   return true;
00151 }
00152  
00153 
00154 
00155 
00156 vector< shared_ptr<TObjArray> > ArchModuleDefects::getDefects() {
00157 
00158  return defectList;
00159 
00160 
00161 }
00162 
00163 map <string, int> ArchModuleDefects::getMap() {
00164 
00165  return defectMap;
00166 
00167 
00168 
00169 }

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