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 00154 void setFit(unsigned index, const std::string& fit); 00158 void setRaw(unsigned index, const std::string& raw); 00159 protected: 00163 AnalysisAlgorithm(const TestData& testData, const string& moduleName, const AnalysisAlgorithm& prototype) throw(); 00164 00169 virtual shared_ptr<SctData::TestResult> createTestResult() const = 0; 00174 void loadAllFits(); 00179 void loadAllRaws(); 00180 00185 bool hasAllRaws() const; 00190 bool hasAllFits() const; 00191 00196 shared_ptr<SctData::RawScanResult> getRaw(unsigned int index) const; 00197 00202 shared_ptr<SctData::FitScanResult> getFit(unsigned int index) const; 00203 00204 00210 void mergeDefects(); 00211 00212 AnalysisAlgorithm() ; 00213 00214 private: 00220 void initializeTestResult(); 00221 00222 class ScanData { 00223 public: 00224 ScanData(); 00225 bool rawAvailable; 00226 bool fitAvailable; 00227 string rawName; 00228 string fitName; 00229 shared_ptr<SctData::RawScanResult> raw; 00230 shared_ptr<SctData::FitScanResult> fit; 00231 }; 00232 00233 const string m_modulename; 00234 shared_ptr<SctData::TestResult> m_result; 00235 const TestData& m_test; 00236 vector<ScanData> scanData; 00237 bool m_done; 00238 mutable boost::recursive_mutex m_access; 00239 00240 //Timing stuff 00241 mutable boost::recursive_mutex m_status_access; 00242 const AnalysisAlgorithm& prototype; 00243 mutable double ioTime; 00244 mutable double analysisTime; 00245 mutable double overheadTime; 00246 mutable unsigned int nCalls; 00247 mutable unsigned int nAnalyses; 00248 mutable unsigned int nPassed; 00249 mutable unsigned int nFailed; 00250 }; 00251 00252 inline void AnalysisAlgorithm::addPass(){ 00253 boost::recursive_mutex::scoped_lock lock(m_status_access); 00254 ++prototype.nPassed; 00255 } 00256 00257 inline void AnalysisAlgorithm::addFailure(){ 00258 boost::recursive_mutex::scoped_lock lock(m_status_access); 00259 ++prototype.nFailed; 00260 } 00261 00262 inline void AnalysisAlgorithm::addIOTime(double ioTime) { 00263 boost::recursive_mutex::scoped_lock lock(m_status_access); 00264 prototype.ioTime += ioTime; 00265 } 00266 00267 inline void AnalysisAlgorithm::addAnalysisTime(double time) { 00268 boost::recursive_mutex::scoped_lock lock(m_status_access); 00269 prototype.analysisTime += time; 00270 ++prototype.nAnalyses; 00271 } 00272 00273 inline void AnalysisAlgorithm::addOverheadTime(double time) { 00274 boost::recursive_mutex::scoped_lock lock(m_status_access); 00275 prototype.overheadTime += time; 00276 ++prototype.nCalls; 00277 } 00278 00279 } 00280 00281 #endif //#ifndef ANALYSISALGORITHM_H