00001 #include "TestResult.h"
00002 #include "FitScanResult.h"
00003 #include "RawScanResult.h"
00004 #include "ConfigurationVariable.h"
00005 #include "NullVariable.h"
00006 #include "Sct/SctNames.h"
00007 #include "Sct/IS/IOManagerIS.h"
00008 #include "Sct/IS/IONameIS.h"
00009 #include <algorithm>
00010 #include <sstream>
00011
00012 using namespace std;
00013 using namespace Sct;
00014 using namespace Sct::IS;
00015 using namespace boost;
00016
00017 namespace SctData {
00018
00019 TestResult::TestResult(const unsigned int runNumber, const string & moduleName,
00020 const ConfigurationVariable& testVariable, const ConfigurationVariable& scanVariable) throw ()
00021 : runNumber(runNumber), moduleName(moduleName), testVariable(&testVariable),
00022 scanVariable(&scanVariable), passed(false), problem(false) {
00023 }
00024
00025
00026 TestResult::TestResult() throw() : runNumber(0), moduleName(""), testVariable(&NullVariable::instance()),
00027 scanVariable(&NullVariable::instance()), passed(false), problem(false) {
00028
00029 }
00030
00031 void TestResult::setRunNumber(unsigned int runNumber) throw() {
00032 this->runNumber = runNumber;
00033 }
00034
00035 void TestResult::setModuleName(string name) throw() {
00036 this->moduleName = name;
00037 }
00038
00039 const ModuleDefectList& TestResult::getDefects() const throw() {
00040 return defects;
00041 }
00042
00043 ModuleDefectList& TestResult::getDefects() throw() {
00044 return defects;
00045 }
00046
00047 const ConfigurationVariable& TestResult::getScanVariable() const throw() {
00048 return *scanVariable;
00049 }
00050
00051 void TestResult::setScanVariable(const ConfigurationVariable& scanVariable) throw() {
00052 this->scanVariable = &scanVariable;
00053 }
00054
00055 const ConfigurationVariable& TestResult::getTestVariable() const throw() {
00056 return *testVariable;
00057 }
00058
00059 void TestResult::setTestVariable(const ConfigurationVariable& testVariable) throw() {
00060 this->testVariable = &testVariable;
00061 }
00062
00063 bool TestResult::getPassed() const throw() {
00064 return passed;
00065 }
00066
00067 void TestResult::setPassed(bool passed) throw() {
00068 this->passed = passed;
00069 }
00070
00071 bool TestResult::getProblem() const throw() {
00072 return problem;
00073 }
00074
00075 void TestResult::setProblem(bool problem) throw() {
00076 this->problem = problem;
00077 }
00078
00079 vector<string> TestResult::getComments() const throw() {
00080 return comments;
00081 }
00082
00083 void TestResult::addComment(string comment) throw() {
00084 comments.push_back(comment);
00085 }
00086
00087 void TestResult::addScan(const unsigned int scanNumber, const double testPoint) throw(LogicError) {
00088 data.push_back(ScanData(scanNumber, testPoint));
00089 sort(data.begin(), data.end());
00090 }
00091
00092 string TestResult::getUniqueID() const throw(LogicError) {
00093 if (data.size() > 0) {
00094 return ScanHeader::getUniqueID(runNumber, data[0].scanNumber, moduleName);
00095 }
00096 throw IllegalStateError("TestResult::getUniqueID() : empty test result", __FILE__, __LINE__);
00097 }
00098
00099 unsigned TestResult::getScanNumberAt(unsigned int i) const throw(LogicError) {
00100 if ( i>=data.size() )
00101 throw OutOfRangeError<unsigned>("TestPoint::getScanNumberAt", __FILE__, __LINE__,i,0,data.size()-1);
00102 return data[i].scanNumber;
00103 }
00104
00105 double TestResult::getTestPointAt(unsigned int i) const throw(LogicError) {
00106 if ( i>=data.size() )
00107 throw OutOfRangeError<unsigned>("TestPoint::getTestPointAt", __FILE__, __LINE__,i,0,data.size()-1);
00108 return data[i].testPoint;
00109 }
00110
00111 const ModuleConfiguration& TestResult::getUpdatedConfiguration() const throw() {
00112 return updatedConfig;
00113 }
00114
00115 ModuleConfiguration& TestResult::getUpdatedConfiguration() throw() {
00116 return updatedConfig;
00117 }
00118
00119 shared_ptr<const FitScanResult> TestResult::getFit(unsigned int index) const throw(LogicError,IoError) {
00120 return data[index].fit;
00121 }
00122
00123 shared_ptr<const RawScanResult> TestResult::getRaw(unsigned int index) const throw(LogicError,IoError) {
00124 return data[index].raw;
00125 }
00126
00127 void TestResult::addFit(shared_ptr<const FitScanResult> fit) throw (LogicError){
00128 unsigned index = getIndex( fit->getHeader().getScanNumber() );
00129 data[index].fit=fit;
00130 }
00131
00132 void TestResult::addRaw(shared_ptr<const RawScanResult> raw) throw (LogicError){
00133 unsigned index = getIndex( raw->getHeader().getScanNumber() );
00134 data[index].raw=raw;
00135 }
00136
00137 bool TestResult::hasAllFits() const throw() {
00138 for (unsigned i=0; i<data.size(); ++i){
00139 if (data[i].fit.get()==0) return false;
00140 }
00141 return true;
00142 }
00143
00144 bool TestResult::hasAllRaws() const throw() {
00145 for (unsigned i=0; i<data.size(); ++i){
00146 if (data[i].raw.get()==0) return false;
00147 }
00148 return true;
00149 }
00150
00151 unsigned int TestResult::getIndex(unsigned int scanNumber) const throw(LogicError) {
00152 vector<ScanData>::const_iterator i=find(data.begin(), data.end(), scanNumber);
00153 if (i==data.end() ) {
00154 ostringstream text;
00155 text << "TestResult::findScanData scan not found scanNumber="<< scanNumber;
00156 throw InvalidArgumentError( text.str(), __FILE__, __LINE__ );
00157 }
00158 return i-data.begin();
00159 }
00160
00162 TestResult::ScanData::ScanData(const unsigned int scanNumber, const double testPoint,
00163 shared_ptr<const RawScanResult> raw, shared_ptr<const FitScanResult> fit ) throw()
00164 : scanNumber(scanNumber), testPoint(testPoint), raw(raw), fit(fit) {}
00165
00166 TestResult::ScanData::ScanData(const unsigned int scanNumber, const double testPoint) throw()
00167 : scanNumber(scanNumber), testPoint(testPoint) {}
00168
00169 bool TestResult::ScanData::operator<(const ScanData& s) const throw() {
00170 if (this->scanNumber<s.scanNumber)
00171 return true;
00172 return false;
00173 }
00174
00175 bool TestResult::ScanData::operator>(const ScanData& s) const throw() {
00176 if (this->scanNumber>s.scanNumber)
00177 return true;
00178 return false;
00179 }
00180
00181 bool TestResult::ScanData::operator==(const unsigned int aScanNumber) const throw() {
00182 if (this->scanNumber==aScanNumber)
00183 return true;
00184 return false;
00185 }
00186 }