QuickTrimTest.h

00001 #ifndef QUICKTRIMTEST_H
00002 #define QUICKTRIMTEST_H
00003 
00004 #include "../ipc/TestRequest.h"
00005 #include "../ipc/CalibrationController.h"
00006 #include "../ipc/ScanLibrary.h"
00007 #include "../ipc/CalibrationController.hh"
00008 #include "../CalibrationControllerImpl.h"
00009 
00010 #include "../SctApiAccessException.h"
00011 #include "Sct/LogicErrors.h"
00012 #include "../SctApiCall.h"
00013 
00014 #include <Sct/AbcdScans.h>
00015 #include <iostream>
00016 #include <vector>
00017 
00018 using namespace std;
00019 using namespace SctCalibrationController::Ipc;
00020 using namespace SctCalibrationController;
00021 using namespace Sct;
00022 
00023 namespace SctCalibrationController {
00024 namespace Scripts {
00025 
00028 class QuickTrimTest : public TestRequestImpl {
00029 private:
00030    static const bool registeredInTestLibrary;
00031 
00032 public: 
00033     static Sct_CalibrationController::TestRequest_ptr instance() {
00034     static QuickTrimTest tr;
00035     tr.setFitAlgorithm("Threshold");
00036     tr.setAnalysisAlgorithm("TrimRangeTest");
00037     return tr._this();
00038     }
00039     
00040     virtual void startTestRealImpl(Sct_SctApi::SctApiIPC_ptr inapi, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {    
00041     this->api = Sct_SctApi::SctApiIPC::_duplicate(inapi);
00042 
00043         // Compression mode X1X
00044         APICALL(api, modifyABCDVar(ST_COMPRESSION, 1), "QuickTrimTest::startTest can't set compression")
00045 
00046         // Edge detect off
00047         APICALL(api, modifyABCDVar(ST_EDGE_DETECT, 0), "QuickTrimTest::startTest can't set edge detect")
00048 
00049         // No masked channels
00050         APICALL(api, modifyABCDVar(ST_SEND_MASK, 0), "QuickTrimTest::startTest can't set send mask")
00051 
00052         // QCAL (fC)
00053         APICALL(api, modifyABCDVar(ST_QCAL, 1), "QuickTrimTest::startTest can't set qcal")
00054 
00055     name = "TrimRangeTest";
00056     testVariable=ST_TRIM_RANGE;
00057     for (unsigned int i=0; i<13; ++i) {
00058         testPoints.push_back(getValue(i));
00059     }
00060     nScans = testPoints.size();
00061     }
00062 
00063     virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00064       if (isFirstPoint(index)) {
00065     // set trim range
00066       APICALL(api, modifyABCDVar(ST_TRIM_RANGE, getRange(index)), "QuickTrimTest::getNextScan")
00067       APICALL(api, modifyABCDVarROD(ST_TRIM_RANGE, getRange(index), Sct_SctApi::SCAN_CONFIG), "QuickTrimTest::getNextScan")
00068     }
00069         // set trim value
00070     APICALL(api, modifyABCDVar(ST_TRIM, getValue(index)), "QuickTrimTest::getNextScan")
00071     APICALL(api, modifyABCDVarROD(ST_TRIM, getValue(index), Sct_SctApi::SCAN_CONFIG), "QuickTrimTest::getNextScan")
00072 
00073     Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00074     double offset = ranges[getRange(index)] * getValue(index);
00075     return sl->thresholdScanfCOffset(1000, 1.0, offset);  // trim at 1 fC
00076     }
00077 
00078     unsigned int getRange(unsigned int index) {
00079     if (index<4) return 0;
00080     else return (index-1)/3+1;
00081     }
00082     
00083     bool isFirstPoint(unsigned int index) {
00084       return (index==0 || (index-1)%3) == 0;
00085     }
00086     
00087     unsigned int getValue(unsigned int index) {
00088     if (index ==0 ) return 0;
00089     switch ((index-1)%3){
00090     case 0: return 2;
00091     case 1: return 5;
00092     case 2: return 8;
00093     default:
00094       throw IllegalStateError("This index should never happen!", __FILE__, __LINE__);
00095     }
00096     }
00097     
00098     virtual bool canFeedbackRealImpl() {
00099     return true;
00100     }    
00101 
00102     virtual void endTestRealImpl() {
00103     api = Sct_SctApi::SctApiIPC::_nil();
00104     }
00105         
00106 private:
00107     QuickTrimTest() {}
00108     Sct_SctApi::SctApiIPC_var api;
00109     static double ranges[4];
00110 };
00111 double QuickTrimTest::ranges[4] = {3.5, 6.5, 10, 13};
00112 }
00113 }
00114 #endif //QUICKTRIMTEST_H

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