ChipCounterTest.h

00001 #ifndef SCTCALIBRATIONCONTROLLER_CHIPCOUNTERTEST_H
00002 #define SCTCALIBRATIONCONTROLLER_CHIPCOUNTERTEST_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/StdExceptionWrapper.h"
00013 #include "Sct/LogicErrors.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 ChipCounterTest : public TestRequestImpl {
00031 private:
00032    static const bool registeredInTestLibrary;
00033 
00034 public:
00035    static Sct_CalibrationController::TestRequest_ptr instance() {
00036     static ChipCounterTest rt;
00037     rt.setFitAlgorithm("NONE");
00038     rt.setAnalysisAlgorithm("ChipCounterTest");
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 = "ChipCounterTest";
00046      testVariable = ST_ELAPSED;
00047      nScans = 1;
00048      testPoints.push_back(nTriggers);
00049      softResetAllModules();
00050    }
00051    
00052    virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00053      Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00054 
00055      // dont reset between scan points - only at start of test!
00056      const bool issueSoftReset = false;
00057      Sct_CalibrationController::ScanRequest_ptr request = sl->rawScan(nTriggers, issueSoftReset);
00058      Sct_SctApi::Scan_var scan = request->getScanCorba();
00059        // Number of bytes to read from the conf register: There should be about 210 ish bytes.  We will read a few more just so we have some elbow room.  Rather arbitrarily, then we chose to read 256 bits:
00060      const int bitsToRead = 64;
00061      request->setWidthCorba(bitsToRead);
00062      
00063      // This next two executable lines (which disables data
00064      // mode, and thus enables SendConfRegister mode) 
00065      // is the second line which (beyond the test names!) 
00066      // should be the source of difference between THIS
00067      // test and the usual RxThresholdTest:
00068      APICALL(scan, setOption(Sct_SctApi::Scan::enableDataMode, 1), "Failed to disable dataMode (failed to enable SendConfRegIDMode)")
00069        
00070      APICALL(scan, configure(ST_ELAPSED, 0, 127, 1), "Failed to set Scan information")
00071      return request;
00072    }
00073     
00074     virtual bool canFeedbackRealImpl() {
00075     return false;
00076     }
00077     
00078     virtual void endTestRealImpl() {
00079       api = Sct_SctApi::SctApiIPC::_nil();
00080     }
00081 
00082     virtual void softResetAllModules(){
00083       using std::list;
00084       try{
00085     boost::shared_ptr<SctConfiguration::Configuration> config(new SctConfiguration::ConfigIPC);
00086     
00087     Sct_SctApi::Trigger_var trig;    
00088     APIRETCALL(api, trig, createTrigger(), "ChipCounterTest: Couldn't create trigger")
00089     APICALL(trig, soft(), "Failed to set trigger type")
00090         APICALL(trig, setSource(::Sct_SctApi::Trigger::SOURCE_ROD), "Failed to set trigger source")
00091 
00092     //send to all modules
00093     list<unsigned> partitions=config->listPartitions();
00094     for (list<unsigned>::const_iterator p=partitions.begin(); p!=partitions.end(); ++p){
00095       list<unsigned> crates=config->listCratesInPartition(*p);
00096       for (list<unsigned>::const_iterator c=crates.begin(); c!=crates.end(); ++c){
00097         std::cout << "ChipCounterTest : sendTriggers ("<<*p<<", "<<*c<<",soft)"<<std::endl;
00098         APICALL(api, sendTriggers(*p, *c, trig, 1, 0), "ChipCounterTest Could not send trigger");
00099       }
00100         }
00101        }catch (std::exception& e){
00102      throw Sct::StdExceptionWrapper(e, __FILE__, __LINE__);
00103        }
00104     }  
00105  private:
00106     ChipCounterTest() {}
00107     Sct_SctApi::SctApiIPC_var api;    
00108     static const int nTriggers = 1;
00109 };
00110 }
00111 }
00112 #endif //SCTCALIBRATIONCONTROLLER_CHIPCOUNTERTEST_H

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