MarkSpaceRatioTest.h

00001 #ifndef SCTCALIBRATIONCONTROLLER_MARKSPACERATIOTEST_H
00002 #define SCTCALIBRATIONCONTROLLER_MARKSPACERATIOTEST_H
00003 
00004 #include "../ipc/TestRequest.h"
00005 #include "../ipc/CalibrationController.h"
00006 #include "../ipc/ScanLibrary.h"
00007 #include "../ipc/CalibrationController.hh"
00008 
00009 #include "../SctApiAccessException.h"
00010 #include "../SctApiCall.h"
00011 #include "../CalibrationControllerImpl.h"
00012 #include "Sct/LogicErrors.h"
00013 #include "Sct/StdExceptionWrapper.h"
00014 #include "SctApi/extraScans.h"
00015 
00016 #include "sctConfIPC/configipc.h"
00017 
00018 #include <Sct/AbcdScans.h>
00019 #include <iostream>
00020 #include <vector>
00021 
00022 using namespace Sct;
00023 using namespace std;
00024 using namespace SctCalibrationController::Ipc;
00025 using namespace SctCalibrationController;
00026 
00027 namespace SctCalibrationController {
00028 namespace Scripts {
00029     
00030 class MarkSpaceRatioTest : public TestRequestImpl {
00031 private:
00032    static const bool registeredInTestLibrary;
00033 
00034 public:
00035    static Sct_CalibrationController::TestRequest_ptr instance() {
00036     static MarkSpaceRatioTest rt;
00037     rt.setFitAlgorithm("NONE");
00038     rt.setAnalysisAlgorithm("MarkSpaceRatioTest");
00039     return rt._this();
00040     }
00041    
00042    virtual void startTestRealImpl(Sct_SctApi::SctApiIPC_ptr the_api, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {   
00043      this->api = Sct_SctApi::SctApiIPC::_duplicate(the_api);
00044      // No masked channels
00045      name = "MarkSpaceRatioTest";
00046      testVariable = ST_TX_MARKSPACE;
00047      
00048      for (unsigned i=0; i<31; i+=2){
00049        register_values.push_back(i);
00050      }
00051 
00052      nScans = 0;
00053 
00054      // do twice - before and after bit-flip.
00055      for (unsigned i=0; i<2; ++i){
00056        for (vector<int>::const_iterator value=register_values.begin(); 
00057         value!= register_values.end(); ++value){
00058      ++nScans;
00059      testPoints.push_back(*value);
00060        }
00061      }
00062      Sct_SctApi::BankList banks;
00063      banks.length(1);
00064      banks[0]=Sct_SctApi::SCAN_CONFIG;
00065      APICALL(api, modifyABCDVar(ST_FEEDTHROUGH, 0), "MarkSpaceRatioTest:startTest error setting feedthrough on API");
00066      APICALL(api, setABCDModules(banks),"MarkSpaceRatioTest:startTest error setting feedthrough on ROD"); 
00067      APICALL(api, sendABCDModules(Sct_SctApi::SCAN_CONFIG), "MarkSpaceRatioTest:startTest error setting feedthrough to MODULES");
00068    }
00069    
00070    virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00071      Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00072      const bool issueSoftReset = false;
00073      Sct_CalibrationController::ScanRequest_ptr request = sl->rawScan(nTriggers, issueSoftReset);
00074 
00075      request->setWidthCorba(1024);
00076      request->setConfigureModulesCorba(false);
00077 
00078      Sct_SctApi::Scan_var scan = request->getScanCorba();
00079      Sct_SctApi::Trigger_var t;
00080 
00081      APICALL(scan, setOption(Sct_SctApi::Scan::enableDataMode, 0), "MarkSpaceRatioTest : failed to disable dataMode")
00082      APIRETCALL(scan, t, getTrigger1(), "Failed to get Trigger1")       
00083      APICALL(t, singleL1A(), "Failed to set trigger type")
00084 
00085      float msr = register_values[index%register_values.size()];
00086      APICALL(api, modifyABCDVar(ST_TX_MARKSPACE, msr), "MarkSpaceRatioTest coulndt set MSR");
00087 
00088      APICALL(scan, configure(ST_RX_DELAY, 0, 24, 1), "Failed to set Scan information")
00089 
00090      // half-way through send a bit-flip
00091      if (index==register_values.size()) sendOddNumberOfBits();
00092 
00093      return request;
00094    }
00095     
00096     virtual bool canFeedbackRealImpl() {
00097     return true;
00098     }
00099     
00100     virtual void endTestRealImpl() {
00101       
00102       APICALL(api, modifyABCDVar(ST_FEEDTHROUGH, 1), "MarkSpaceRatioTest:endTest error unsetting feedthrough on API");
00103       Sct_SctApi::BankList banks;
00104       banks.length(1);
00105       banks[0]=Sct_SctApi::SCAN_CONFIG;
00106       APICALL(api, setABCDModules(banks),"MarkSpaceRatioTest:endTest error unsetting feedthrough on ROD"); 
00107       APICALL(api, sendABCDModules(Sct_SctApi::SCAN_CONFIG), "MarkSpaceRatioTest:endTest error unsetting feedthrough to MODULES");
00108 
00109       api = Sct_SctApi::SctApiIPC::_nil();
00110       register_values.clear();
00111     }
00112 
00113     virtual void sendOddNumberOfBits(){
00114       using std::list;
00115       try{
00116     boost::shared_ptr<SctConfiguration::Configuration> config(new SctConfiguration::ConfigIPC);
00117     
00118     Sct_SctApi::Trigger_var trig;    
00119     APIRETCALL(api, trig, createTrigger(), "MarkSpaceRatioTest: Couldn't create trigger")
00120     APICALL(trig, soft(), "Failed to set trigger type")
00121         APICALL(trig, setSource(::Sct_SctApi::Trigger::SOURCE_ROD), "Failed to set trigger source")
00122 
00123     //send to all modules
00124     list<unsigned> partitions=config->listPartitions();
00125     for (list<unsigned>::const_iterator p=partitions.begin(); p!=partitions.end(); ++p){
00126       list<unsigned> crates=config->listCratesInPartition(*p);
00127       for (list<unsigned>::const_iterator c=crates.begin(); c!=crates.end(); ++c){
00128         std::cout << "MarkSpaceRatio: sendTriggers ("<<*p<<", "<<*c<<",soft)"<<std::endl;
00129         APICALL(api, sendTriggers(*p, *c, trig, 1, 0), "MarkSpaceRatioTest Could not send trigger");
00130       }
00131     }
00132       }catch (std::exception& e){
00133     throw Sct::StdExceptionWrapper(e, __FILE__, __LINE__);
00134       }
00135     }
00136 
00137 private:
00138     vector<int> register_values;
00139     MarkSpaceRatioTest() {}
00140     Sct_SctApi::SctApiIPC_var api;    
00141     static const int nTriggers = 1;
00142 };
00143 }
00144 }
00145 #endif //SCTCALIBRATIONCONTROLLER_MARKSPACERATIOTEST_H

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