00001 #ifndef ANALYSISALGORITHM_H 00002 #define ANALYSISALGORITHM_H 00003 00004 #include <string> 00005 #include <vector> 00006 #include <boost/thread.hpp> 00007 #include <boost/shared_ptr.hpp> 00008 #include "Sct/IoExceptions.h" 00009 #include "Sct/LogicErrors.h" 00010 00011 namespace SctData { 00012 class TestResult; 00013 class RawScanResult; 00014 class FitScanResult; 00015 } 00016 namespace Sct { 00017 class IOName; 00018 } 00019 00020 class TestData; 00021 00022 using std::string; 00023 using std::vector; 00024 using boost::shared_ptr; 00025 00026 namespace SctAnalysis { 00027 00033 class AnalysisAlgorithm { 00034 public: 00038 virtual ~AnalysisAlgorithm() throw(); 00042 const TestData& getTestData() const throw() {return m_test;} 00043 00047 const std::string getModuleName() const throw() {return m_modulename;} 00048 00053 virtual boost::shared_ptr<AnalysisAlgorithm> clone(const TestData& testData, const string& moduleName) const throw() =0; 00059 void addFitScanResult(shared_ptr<Sct::IOName> name); 00065 void addRawScanResult(shared_ptr<Sct::IOName> name); 00071 void checkTestResultExists(); 00075 bool isDone() const throw() {return m_done;} 00076 00081 void finish(); 00082 00086 boost::shared_ptr<SctData::TestResult> getTestResult() const{return m_result;} 00087 00091 boost::recursive_mutex& getMutex() const {return m_access;} 00092 00097 virtual bool canAnalyze() const = 0; 00098 00105 virtual void analyze() = 0; 00106 00112 virtual void loadData() = 0; 00113 00117 00121 void addFailure(); 00125 void addPass(); 00131 void addIOTime(double ioTime); 00132 00137 void addAnalysisTime(double time); 00138 00143 void addOverheadTime(double time); 00144 00148 string getStatus() const; 00150 00151 protected: 00155 AnalysisAlgorithm(const TestData& testData, const string& moduleName, const AnalysisAlgorithm& prototype) throw(); 00156 00161 virtual shared_ptr<SctData::TestResult> createTestResult() const = 0; 00166 void loadAllFits(); 00171 void loadAllRaws(); 00172 00177 bool hasAllRaws() const; 00182 bool hasAllFits() const; 00183 00188 shared_ptr<SctData::RawScanResult> getRaw(unsigned int index) const; 00189 00194 shared_ptr<SctData::FitScanResult> getFit(unsigned int index) const; 00195 00196 00202 void mergeDefects(); 00203 00204 AnalysisAlgorithm() ; 00205 00206 private: 00212 void initializeTestResult(); 00213 00214 class ScanData { 00215 public: 00216 ScanData(); 00217 bool rawAvailable; 00218 bool fitAvailable; 00219 string rawName; 00220 string fitName; 00221 shared_ptr<SctData::RawScanResult> raw; 00222 shared_ptr<SctData::FitScanResult> fit; 00223 }; 00224 00225 const string m_modulename; 00226 shared_ptr<SctData::TestResult> m_result; 00227 const TestData& m_test; 00228 vector<ScanData> scanData; 00229 bool m_done; 00230 mutable boost::recursive_mutex m_access; 00231 00232 //Timing stuff 00233 mutable boost::recursive_mutex m_status_access; 00234 const AnalysisAlgorithm& prototype; 00235 mutable double ioTime; 00236 mutable double analysisTime; 00237 mutable double overheadTime; 00238 mutable unsigned int nCalls; 00239 mutable unsigned int nAnalyses; 00240 mutable unsigned int nPassed; 00241 mutable unsigned int nFailed; 00242 }; 00243 00244 inline void AnalysisAlgorithm::addPass(){ 00245 boost::recursive_mutex::scoped_lock lock(m_status_access); 00246 ++prototype.nPassed; 00247 } 00248 00249 inline void AnalysisAlgorithm::addFailure(){ 00250 boost::recursive_mutex::scoped_lock lock(m_status_access); 00251 ++prototype.nFailed; 00252 } 00253 00254 inline void AnalysisAlgorithm::addIOTime(double ioTime) { 00255 boost::recursive_mutex::scoped_lock lock(m_status_access); 00256 prototype.ioTime += ioTime; 00257 } 00258 00259 inline void AnalysisAlgorithm::addAnalysisTime(double time) { 00260 boost::recursive_mutex::scoped_lock lock(m_status_access); 00261 prototype.analysisTime += time; 00262 ++prototype.nAnalyses; 00263 } 00264 00265 inline void AnalysisAlgorithm::addOverheadTime(double time) { 00266 boost::recursive_mutex::scoped_lock lock(m_status_access); 00267 prototype.overheadTime += time; 00268 ++prototype.nCalls; 00269 } 00270 00271 } 00272 00273 #endif //#ifndef ANALYSISALGORITHM_H