Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

TrimRangeTest.h

00001 #ifndef TRIMRANGETEST_H
00002 #define TRIMRANGETEST_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 <CommonWithDsp/ABCD/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 TrimRangeTest : public TestRequestImpl {
00029 private:
00030    static const bool registeredInTestLibrary;
00031 
00032 public: 
00033     static Sct_CalibrationController::TestRequest_ptr instance() {
00034     static TrimRangeTest tr;
00035     return tr._this();
00036     }
00037     
00038     virtual void startTestRealImpl(Sct_SctApi::SctApiIPC_ptr inapi, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {    
00039     this->api = Sct_SctApi::SctApiIPC::_duplicate(inapi);
00040 
00041         // Compression mode X1X
00042         APICALL(api, modifyABCDVar(ST_COMPRESSION, 1), "TrimRangeTest::startTest can't set compression")
00043 
00044         // Edge detect off
00045         APICALL(api, modifyABCDVar(ST_EDGE_DETECT, 0), "TrimRangeTest::startTest can't set edge detect")
00046 
00047         // No masked channels
00048         APICALL(api, modifyABCDVar(ST_SEND_MASK, 0), "TrimRangeTest::startTest can't set send mask")
00049 
00050         // QCAL (fC)
00051         APICALL(api, modifyABCDVar(ST_QCAL, 1), "TrimRangeTest::startTest can't set qcal")
00052 
00053     name = "TrimRangeTest";
00054     testVariable=ST_TRIM_RANGE;
00055     for (unsigned int i=0; i<28; ++i) {
00056         testPoints.push_back(getValue(i));
00057     }
00058     nScans = testPoints.size();
00059     }
00060 
00061     virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00062     if (isFirstPoint(index)) {
00063             // set trim range
00064         APICALL(api, modifyABCDVar(ST_TRIM_RANGE, getRange(index)), "TrimRangeTest::getNextScan")
00065     }
00066         // set trim value
00067     APICALL(api, modifyABCDVar(ST_TRIM, getValue(index)), "TrimRangeTest::getNextScan")
00068 
00069     Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00070     double offset = ranges[getRange(index)] * getValue(index);
00071     return sl->thresholdScanfCOffset(400, 1.0, offset);  // trim at 1 fC
00072     }
00073 
00074     unsigned int getRange(unsigned int index) {
00075     if (index<16) return 0;
00076     else return (index-16)/4+1;
00077     }
00078     
00079     bool isFirstPoint(unsigned int index) {
00080     return (index-16)%4 == 0;
00081     }
00082     
00083     unsigned int getValue(unsigned int index) {
00084     if (index < 16) return index;
00085     unsigned int pointInRange = (index-16)%4;
00086     return (pointInRange+1)*4-1;
00087     }
00088     
00089     virtual bool canFeedbackRealImpl() {
00090     return true;
00091     }    
00092 
00093     virtual void endTestRealImpl() {
00094     api = Sct_SctApi::SctApiIPC::_nil();
00095     }
00096         
00097 private:
00098     TrimRangeTest() {}
00099     Sct_SctApi::SctApiIPC_var api;
00100     static double ranges[4];
00101 };
00102 }
00103 }
00104 #endif //TRIMRANGETEST_H

Generated on Fri Sep 16 18:02:03 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5