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(); 00044 shared_ptr<const TestData> getTestData() const; 00045 00049 const std::string getModuleName() const throw() {return m_modulename;} 00050 00055 virtual boost::shared_ptr<AnalysisAlgorithm> clone(shared_ptr<const TestData> testData, const string& moduleName) const throw() =0; 00061 void addFitScanResult(shared_ptr<Sct::IOName> name); 00067 void addRawScanResult(shared_ptr<Sct::IOName> name); 00073 void checkTestResultExists(); 00077 bool isDone() const throw() {return m_done;} 00078 00083 void finish(); 00084 00088 boost::shared_ptr<SctData::TestResult> getTestResult() const{return m_result;} 00089 00093 boost::recursive_mutex& getMutex() const {return m_access;} 00094 00099 virtual bool canAnalyze() const = 0; 00100 00107 virtual void analyze() = 0; 00108 00114 virtual void loadData() = 0; 00115 00119 00123 void addFailure(); 00127 void addPass(); 00133 void addIOTime(double ioTime); 00134 00139 void addAnalysisTime(double time); 00140 00145 void addOverheadTime(double time); 00146 00150 string getStatus() const; 00152 00156 void setFit(unsigned index, const std::string& fit); 00160 void setRaw(unsigned index, const std::string& raw); 00161 protected: 00165 AnalysisAlgorithm(shared_ptr<const TestData> testData, const string& moduleName, const AnalysisAlgorithm& prototype) throw(); 00166 00171 virtual shared_ptr<SctData::TestResult> createTestResult() const = 0; 00176 void loadAllFits(); 00181 void loadAllRaws(); 00182 00187 bool hasAllRaws() const; 00192 bool hasAllFits() const; 00193 00198 shared_ptr<SctData::RawScanResult> getRaw(unsigned int index) const; 00199 00204 shared_ptr<SctData::FitScanResult> getFit(unsigned int index) const; 00205 00206 00212 void mergeDefects(); 00213 00214 AnalysisAlgorithm() ; 00215 00216 private: 00222 void initializeTestResult(); 00223 00224 class ScanData { 00225 public: 00226 ScanData(); 00227 bool rawAvailable; 00228 bool fitAvailable; 00229 string rawName; 00230 string fitName; 00231 shared_ptr<SctData::RawScanResult> raw; 00232 shared_ptr<SctData::FitScanResult> fit; 00233 }; 00234 00235 const string m_modulename; 00236 shared_ptr<SctData::TestResult> m_result; 00237 shared_ptr<const TestData> m_test; 00238 vector<ScanData> scanData; 00239 bool m_done; 00240 mutable boost::recursive_mutex m_access; 00241 00242 //Timing stuff 00243 mutable boost::recursive_mutex m_status_access; 00244 const AnalysisAlgorithm& prototype; 00245 mutable double ioTime; 00246 mutable double analysisTime; 00247 mutable double overheadTime; 00248 mutable unsigned int nCalls; 00249 mutable unsigned int nAnalyses; 00250 mutable unsigned int nPassed; 00251 mutable unsigned int nFailed; 00252 }; 00253 00254 inline void AnalysisAlgorithm::addPass(){ 00255 boost::recursive_mutex::scoped_lock lock(m_status_access); 00256 ++prototype.nPassed; 00257 } 00258 00259 inline void AnalysisAlgorithm::addFailure(){ 00260 boost::recursive_mutex::scoped_lock lock(m_status_access); 00261 ++prototype.nFailed; 00262 } 00263 00264 inline void AnalysisAlgorithm::addIOTime(double ioTime) { 00265 boost::recursive_mutex::scoped_lock lock(m_status_access); 00266 prototype.ioTime += ioTime; 00267 } 00268 00269 inline void AnalysisAlgorithm::addAnalysisTime(double time) { 00270 boost::recursive_mutex::scoped_lock lock(m_status_access); 00271 prototype.analysisTime += time; 00272 ++prototype.nAnalyses; 00273 } 00274 00275 inline void AnalysisAlgorithm::addOverheadTime(double time) { 00276 boost::recursive_mutex::scoped_lock lock(m_status_access); 00277 prototype.overheadTime += time; 00278 ++prototype.nCalls; 00279 } 00280 00281 } 00282 00283 #endif //#ifndef ANALYSISALGORITHM_H