1x90ResEdgeTests.cpp

Go to the documentation of this file.
00001 // Template for a test suite.
00002 #include <config.h>
00003 #include <cppunit/extensions/HelperMacros.h>
00004 #include <cppunit/Asserter.h>
00005 #include "Asserts.h"
00006 #include "CCAENV1x90.h"
00007 #include "DesignByContract.h"
00008 
00009 
00010 #ifdef HAVE_STD_NAMESPACE
00011 using namespace std;
00012 #endif
00013 
00014 using namespace DesignByContract;
00015 
00016 extern long ModuleBase;
00017 
00018 class ResEdgeTests : public CppUnit::TestFixture {
00019   CPPUNIT_TEST_SUITE(ResEdgeTests);
00020   CPPUNIT_TEST(LSBTest);
00021   CPPUNIT_TEST(EdgeTest);
00022   CPPUNIT_TEST(PairTest);
00023   CPPUNIT_TEST(DeadTimeTest);
00024   CPPUNIT_TEST_SUITE_END();
00025 
00026 
00027 private:
00028   CCAENV1x90* m_pModule;
00029 
00030   void CheckResolution(CCAENV1x90::Resolution res);
00031   void CheckEdge(CCAENV1x90::EdgeMode nmode);
00032   void CheckPair(CCAENV1x90::LEResolution leRes,
00033                  CCAENV1x90::PWResolution pwRes);
00034   void CheckDead(CCAENV1x90::DeadTime dt);
00035 
00036 public:
00037   // Construct a module in powered up condition:
00038 
00039   void setUp() {
00040     m_pModule = new CCAENV1x90(1, 0, ModuleBase);
00041     m_pModule->Reset();
00042   }
00043   // Delete the module to prevent resource leaks.
00044 
00045   void tearDown() {
00046     delete m_pModule;
00047   }
00048 protected:
00049   void LSBTest();
00050   void EdgeTest();
00051   void PairTest();
00052   void DeadTimeTest();
00053 
00054 };
00055 
00056 CPPUNIT_TEST_SUITE_REGISTRATION(ResEdgeTests);
00057 
00058 
00059 CCAENV1x90::LEResolution les[] = {CCAENV1x90::LE_100ps,
00060                                   CCAENV1x90::LE_200ps,
00061                                   CCAENV1x90::LE_400ps,
00062                                   CCAENV1x90::LE_800ps,
00063                                   CCAENV1x90::LE_1600ps,
00064                                   CCAENV1x90::LE_3120ps,
00065                                   CCAENV1x90::LE_6250ps,
00066                                   CCAENV1x90::LE_12500ps
00067 };
00068 unsigned const int nLEResolutions=sizeof(les)/
00069                                   sizeof(CCAENV1x90::LEResolution);
00070                               
00071 CCAENV1x90::PWResolution pws[]  = { CCAENV1x90::PW_100ps, 
00072                                   CCAENV1x90::PW_200ps,
00073                                   CCAENV1x90::PW_400ps,
00074                                   CCAENV1x90::PW_800ps,
00075                                   CCAENV1x90::PW_1600ps,
00076                                   CCAENV1x90::PW_3200ps,
00077                                   CCAENV1x90::PW_6250ps,
00078                                   CCAENV1x90::PW_12500ps,
00079                                   CCAENV1x90::PW_25ns,
00080                                   CCAENV1x90::PW_50ns,
00081                                   CCAENV1x90::PW_100ns,
00082                                   CCAENV1x90::PW_200ns,
00083                                   CCAENV1x90::PW_400ns,
00084                                   CCAENV1x90::PW_800ns };
00085 unsigned const int nPWResolutions = sizeof(pws) /
00086                                     sizeof(CCAENV1x90::PWResolution);
00087 
00088 void 
00089 ResEdgeTests::CheckResolution(CCAENV1x90::Resolution res)
00090 {
00091     m_pModule->SetIndividualLSB(res);
00092     unsigned short nRes = m_pModule->GetResolution();
00093     EQ(res, m_pModule->InterpretEdgeResolution(nRes));
00094 }
00095 
00096 void
00097 ResEdgeTests::CheckEdge(CCAENV1x90::EdgeMode nmode)
00098 {
00099   m_pModule->SetEdgeDetectMode(nmode);
00100   EQ(nmode, m_pModule->GetEdgeDetectMode()); 
00101 
00102 }
00103 
00104 void
00105 ResEdgeTests::CheckPair(CCAENV1x90::LEResolution leres,
00106                         CCAENV1x90::PWResolution pwres)
00107 {
00108   m_pModule->SetPairResolutions(leres, pwres);
00109   unsigned short res = m_pModule->GetResolution();
00110 
00111 
00112   EQ(leres, m_pModule->InterpretLEResolution(res));
00113   EQ(pwres, m_pModule->InterpretWidthResolution(res));
00114 
00115 }
00116 
00117 void
00118 ResEdgeTests::CheckDead(CCAENV1x90::DeadTime dead)
00119 {
00120   m_pModule->SetDoubleHitResolution(dead);
00121   EQ(dead, m_pModule->GetDoubleHitResolution());
00122 
00123 }
00124 
00125 // Test ability to set/get resolution of the LSB.
00126 
00127 void
00128 ResEdgeTests::LSBTest()
00129 {
00130 
00131   // Check 25 ps:
00132 
00133   if(m_pModule->getModel() == 1190) { // 1190 doesn't support this...
00134     EXCEPTION(m_pModule->SetIndividualLSB(CCAENV1x90::Res_25ps),
00135               Require);
00136   } 
00137   else {                        // 1290 does support 25ps.
00138 
00139     CheckResolution(CCAENV1x90::Res_25ps);
00140 
00141   }
00142 
00143   // Check 100ps, 200ps, 800ps:
00144 
00145   CheckResolution(CCAENV1x90::Res_100ps);
00146   CheckResolution(CCAENV1x90::Res_200ps);
00147   CheckResolution(CCAENV1x90::Res_800ps);
00148 
00149 
00150 }
00151 // Check edge detection modes.
00152 
00153 void
00154 ResEdgeTests::EdgeTest()
00155 {
00156   m_pModule->SetIndividualLSB(CCAENV1x90::Res_100ps); // Pair mode good.
00157 
00158   CheckEdge(CCAENV1x90::EdgeMode_Pair);
00159   CheckEdge(CCAENV1x90::EdgeMode_Trailing);
00160   CheckEdge(CCAENV1x90::EdgeMode_Leading);
00161   CheckEdge(CCAENV1x90::EdgeMode_Both);
00162 
00163   // If a 1290, setting to 25ps resolution should cause]
00164   // pair mode to throw:
00165 
00166   if(m_pModule->getModel() == 1290) {
00167     m_pModule->SetIndividualLSB(CCAENV1x90::Res_25ps);
00168     EXCEPTION(m_pModule->SetEdgeDetectMode(CCAENV1x90::EdgeMode_Pair),
00169               Require);
00170   }
00171   
00172 }
00173 
00174 // Check pulse width resolution modes:
00175 
00176 void
00177 ResEdgeTests::PairTest()
00178 {
00179   // Set up the module in pair mode (must be 100ps or worse resolution)
00180 
00181   m_pModule->SetIndividualLSB(CCAENV1x90::Res_100ps);
00182   m_pModule->SetEdgeDetectMode(CCAENV1x90::EdgeMode_Pair);
00183 
00184   for (int le  = 0; le < nLEResolutions; le++) {
00185     for (int pw = 0; pw < nPWResolutions; pw++) {
00186       CheckPair(les[le],
00187                 pws[pw]);
00188     }
00189   }
00190 }
00191 //  Check dead times:
00192 
00193 void
00194 ResEdgeTests::DeadTimeTest()
00195 {
00196   CheckDead(CCAENV1x90::DT_5ns);
00197   CheckDead(CCAENV1x90::DT_10ns);
00198   CheckDead(CCAENV1x90::DT_30ns);
00199   CheckDead(CCAENV1x90::DT_100ns);
00200 
00201 
00202 }

Generated on Wed Sep 17 08:38:09 2008 for NSCL Device support. by  doxygen 1.5.1