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); 00071 void checkForZeroTriggerBins(); 00077 void checkTestResultExists(); 00081 bool isDone() const throw() {return m_done;} 00082 00087 void finish(); 00088 00092 boost::shared_ptr<SctData::TestResult> getTestResult() const{return m_result;} 00093 00097 boost::recursive_mutex& getMutex() const {return m_access;} 00098 00103 virtual bool canAnalyze() const = 0; 00104 00111 virtual void analyze() = 0; 00112 00118 virtual void loadData() = 0; 00119 00123 00127 void addFailure(); 00131 void addPass(); 00137 void addIOTime(double ioTime); 00138 00143 void addAnalysisTime(double time); 00144 00149 void addOverheadTime(double time); 00150 00154 string getStatus() const; 00156 00160 void setFit(unsigned index, const std::string& fit); 00164 void setRaw(unsigned index, const std::string& raw); 00165 protected: 00169 AnalysisAlgorithm(shared_ptr<const TestData> testData, const string& moduleName, const AnalysisAlgorithm& prototype) throw(); 00170 00175 virtual shared_ptr<SctData::TestResult> createTestResult() const = 0; 00180 void loadAllFits(); 00185 void loadAllRaws(); 00186 00191 bool hasAllRaws() const; 00196 bool hasAllFits() const; 00197 00202 shared_ptr<SctData::RawScanResult> getRaw(unsigned int index) const; 00203 00208 shared_ptr<SctData::FitScanResult> getFit(unsigned int index) const; 00209 00210 00216 void mergeDefects(); 00217 00218 AnalysisAlgorithm() ; 00219 00220 private: 00226 void initializeTestResult(); 00227 00228 class ScanData { 00229 public: 00230 ScanData(); 00231 bool rawAvailable; 00232 bool fitAvailable; 00233 string rawName; 00234 string fitName; 00235 shared_ptr<SctData::RawScanResult> raw; 00236 shared_ptr<SctData::FitScanResult> fit; 00237 }; 00238 00239 const string m_modulename; 00240 shared_ptr<SctData::TestResult> m_result; 00241 shared_ptr<const TestData> m_test; 00242 vector<ScanData> scanData; 00243 bool m_done; 00244 mutable boost::recursive_mutex m_access; 00245 00246 //Timing stuff 00247 mutable boost::recursive_mutex m_status_access; 00248 const AnalysisAlgorithm& prototype; 00249 mutable double ioTime; 00250 mutable double analysisTime; 00251 mutable double overheadTime; 00252 mutable unsigned int nCalls; 00253 mutable unsigned int nAnalyses; 00254 mutable unsigned int nPassed; 00255 mutable unsigned int nFailed; 00256 }; 00257 00258 inline void AnalysisAlgorithm::addPass(){ 00259 boost::recursive_mutex::scoped_lock lock(m_status_access); 00260 ++prototype.nPassed; 00261 } 00262 00263 inline void AnalysisAlgorithm::addFailure(){ 00264 boost::recursive_mutex::scoped_lock lock(m_status_access); 00265 ++prototype.nFailed; 00266 } 00267 00268 inline void AnalysisAlgorithm::addIOTime(double ioTime) { 00269 boost::recursive_mutex::scoped_lock lock(m_status_access); 00270 prototype.ioTime += ioTime; 00271 } 00272 00273 inline void AnalysisAlgorithm::addAnalysisTime(double time) { 00274 boost::recursive_mutex::scoped_lock lock(m_status_access); 00275 prototype.analysisTime += time; 00276 ++prototype.nAnalyses; 00277 } 00278 00279 inline void AnalysisAlgorithm::addOverheadTime(double time) { 00280 boost::recursive_mutex::scoped_lock lock(m_status_access); 00281 prototype.overheadTime += time; 00282 ++prototype.nCalls; 00283 } 00284 00285 } 00286 00287 #endif //#ifndef ANALYSISALGORITHM_H