AnalysisAlgorithm.h

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     void setTestData(shared_ptr<const TestData> testdata);
00053     const std::string getModuleName() const throw() {return m_modulename;}
00054 
00059     virtual boost::shared_ptr<AnalysisAlgorithm> clone(shared_ptr<const TestData> testData, const string& moduleName) const throw() =0;
00065     void addFitScanResult(shared_ptr<Sct::IOName> name);
00071     void addRawScanResult(shared_ptr<Sct::IOName> name);
00075    void checkForZeroTriggerBins();
00081     void checkTestResultExists();
00085     bool isDone() const throw() {return m_done;}
00090     void finish();
00091     
00095     boost::shared_ptr<SctData::TestResult> getTestResult() const{return m_result;}
00096     
00100     boost::recursive_mutex& getMutex() const {return m_access;}
00101     
00106     virtual bool canAnalyze() const = 0;
00107     
00114     virtual void analyze() = 0;
00115     
00121     virtual void loadData() = 0;
00122     
00126 
00130     void addFailure();
00134     void addPass();
00140     void addIOTime(double ioTime);
00141     
00146     void addAnalysisTime(double time);
00147     
00152     void addOverheadTime(double time);
00153     
00157     string getStatus() const;
00159     
00163     void setFit(unsigned index, const std::string& fit);
00167     void setRaw(unsigned index, const std::string&  raw);
00168 protected:
00172     AnalysisAlgorithm(shared_ptr<const TestData> testData, const string& moduleName, const AnalysisAlgorithm& prototype) throw();
00173     
00178     virtual shared_ptr<SctData::TestResult> createTestResult() const = 0;
00183     void loadAllFits();
00188     void loadAllRaws();
00189     
00194     bool hasAllRaws() const;
00199     bool hasAllFits() const;
00200     
00205     shared_ptr<SctData::RawScanResult> getRaw(unsigned int index) const;
00206     
00211     shared_ptr<SctData::FitScanResult> getFit(unsigned int index) const;
00212 
00213     
00219     void mergeDefects();
00220     
00221     AnalysisAlgorithm() ;
00222 
00223 private:
00229     void initializeTestResult();
00230     
00231     class ScanData {
00232     public:
00233     ScanData();
00234     bool rawAvailable;
00235     bool fitAvailable;
00236     string rawName;
00237     string fitName;
00238         shared_ptr<SctData::RawScanResult> raw;
00239         shared_ptr<SctData::FitScanResult> fit;
00240     };
00241 
00242     const string m_modulename;              
00243     shared_ptr<SctData::TestResult> m_result;  
00244     shared_ptr<const TestData> m_test;      
00245     vector<ScanData> scanData;          
00246     bool m_done;                      
00247     mutable boost::recursive_mutex m_access;      
00248     
00249     //Timing stuff
00250     mutable boost::recursive_mutex m_status_access;      
00251     const AnalysisAlgorithm& prototype;         
00252     mutable double ioTime;                  
00253     mutable double analysisTime;                
00254     mutable double overheadTime;                
00255     mutable unsigned int nCalls;                
00256     mutable unsigned int nAnalyses;             
00257     mutable unsigned int nPassed;                            
00258     mutable unsigned int nFailed;                           
00259 };
00260 
00261 inline void AnalysisAlgorithm::addPass(){
00262   boost::recursive_mutex::scoped_lock lock(m_status_access);
00263   ++prototype.nPassed;
00264 }
00265 
00266 inline void AnalysisAlgorithm::addFailure(){
00267   boost::recursive_mutex::scoped_lock lock(m_status_access);
00268     ++prototype.nFailed;
00269 }
00270 
00271 inline void AnalysisAlgorithm::addIOTime(double ioTime) {
00272   boost::recursive_mutex::scoped_lock lock(m_status_access);
00273     prototype.ioTime += ioTime;
00274 }
00275     
00276 inline void AnalysisAlgorithm::addAnalysisTime(double time) {
00277   boost::recursive_mutex::scoped_lock lock(m_status_access);
00278     prototype.analysisTime += time;
00279     ++prototype.nAnalyses;
00280 }
00281     
00282 inline void AnalysisAlgorithm::addOverheadTime(double time) {
00283   boost::recursive_mutex::scoped_lock lock(m_status_access);
00284     prototype.overheadTime += time;
00285     ++prototype.nCalls;
00286 }
00287 
00288 }
00289 
00290 #endif //#ifndef ANALYSISALGORITHM_H

Generated on Mon Feb 6 14:01:16 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6