00001 #include "Sct/IS/IOManagerIS.h"
00002 #include "Sct/Exception.h"
00003 #include "Sct/LogicErrors.h"
00004 #include "Sct/SctNames.h"
00005 #include "Sct/SctParameters.h"
00006 #include "SctData/NoiseOccupancyTestResult.h"
00007 #include <is/isinfo.h>
00008 #include <boost/shared_ptr.hpp>
00009 #include <iostream>
00010
00011 using namespace Sct;
00012 using namespace Sct::IS;
00013 using namespace boost;
00014 using namespace SctData;
00015 using namespace std;
00016
00017 string testName = "TestData.SctData::NoiseOccupancyTestResult.551.54.SCTTestAPI_PseudoModule";
00018 double compData[] = {1469, 1440, 1482, 1453, 1426, 1453, 1459, 1462, 1451, 1441, 1412, 1461};
00019 double tolerance = 2;
00020 bool debug = false;
00021
00022 void waitFor(string name, int nsecs) {
00023 int tries = 0;
00024 while (!SctNames::getISDictionary().contains(name.c_str()) && tries < nsecs) {
00025 if (!sleep(1))
00026 ++tries;
00027 }
00028 if (tries == nsecs) {
00029 throw IllegalStateError("Didn't wait long enough", __FILE__, __LINE__);
00030 }
00031 if (debug) {
00032 cout << "Waited for " << tries << " secs" << endl;
00033 }
00034 }
00035
00036 bool compare(shared_ptr<NoiseOccupancyTestResult> result) {
00037 bool retVal = true;
00038 for (unsigned int i=0; i<nChipModule; ++i) {
00039 if (fabs(result->getChipResult(i).getNoise() - compData[i]) > tolerance) {
00040 cout << "Comparison failed at chip: " << i << " Noise: " << result->getChipResult(i).getNoise() << " wanted: " << compData[i] << " to: " << tolerance << endl;
00041 retVal = false;
00042 } else if (debug) {
00043 cout << "Comparison successful for chip: " << i << " Noise: " << result->getChipResult(i).getNoise() << " SCTDAQ noise: " << compData[i] << " Tolerance: " << tolerance << endl;
00044 }
00045 }
00046 return retVal;
00047 }
00048
00049 int main(int argc, char** argv) {
00050 Sct::setExceptionHandlers(argv[0]);
00051 try {
00052 waitFor(testName, 20);
00053 shared_ptr<Serializable> ob = IOManagerIS::instance().read(testName);
00054 shared_ptr<NoiseOccupancyTestResult> result = dynamic_pointer_cast<NoiseOccupancyTestResult>(ob);
00055 if (!result)
00056 throw IllegalStateError("Failed to read test result: " + testName, __FILE__, __LINE__);
00057 if (compare(result)) {
00058 if (debug) cout << "Success!" << endl;
00059 return 0;
00060 }
00061 else {
00062 cout << "Failed" << endl;
00063 return 1;
00064 }
00065
00066 } catch (Throwable& e) {
00067 e.sendToMrs(MRS_FATAL);
00068 return 1;
00069 }
00070 }