Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:09

0001 /**
0002    \file
0003    test file for CSCTriggerNumbering
0004 
0005    \author Lindsey GRAY
0006    \date 27 Jul 2005
0007 */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0011 #include <FWCore/Utilities/interface/Exception.h>
0012 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
0013 
0014 #include <iostream>
0015 using namespace std;
0016 
0017 class testCSCTriggerNumbering : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testCSCTriggerNumbering);
0019 
0020   CPPUNIT_TEST(testNumbering);
0021   CPPUNIT_TEST(testFail);
0022 
0023   CPPUNIT_TEST_SUITE_END();
0024 
0025 public:
0026   void setUp() {}
0027   void tearDown() {}
0028   void testNumbering();
0029   void testFail();
0030 };
0031 
0032 ///registration of the test so that the runner can find it
0033 CPPUNIT_TEST_SUITE_REGISTRATION(testCSCTriggerNumbering);
0034 
0035 // run a self consistency check
0036 void testCSCTriggerNumbering::testNumbering() {
0037   for (int endcap = CSCDetId::minEndcapId(); endcap <= CSCDetId::maxEndcapId(); ++endcap)
0038     for (int station = CSCDetId::minStationId(); station <= CSCDetId::maxStationId(); ++station)
0039       for (int sector = CSCTriggerNumbering::minTriggerSectorId(); sector <= CSCTriggerNumbering::maxTriggerSectorId();
0040            ++sector)
0041         for (int cscid = CSCTriggerNumbering::minTriggerCscId(); cscid <= CSCTriggerNumbering::maxTriggerCscId();
0042              ++cscid) {
0043           if (station == 1)
0044             for (int subs = CSCTriggerNumbering::minTriggerSubSectorId();
0045                  subs <= CSCTriggerNumbering::maxTriggerSubSectorId();
0046                  subs++) {
0047               int tcscid = CSCTriggerNumbering::triggerCscIdFromLabels(
0048                   station,
0049                   CSCTriggerNumbering::ringFromTriggerLabels(station, cscid),
0050                   CSCTriggerNumbering::chamberFromTriggerLabels(sector, subs, station, cscid));
0051               CPPUNIT_ASSERT(tcscid == cscid);
0052 
0053               int tsubs = CSCTriggerNumbering::triggerSubSectorFromLabels(
0054                   station, CSCTriggerNumbering::chamberFromTriggerLabels(sector, subs, station, cscid));
0055 
0056               CPPUNIT_ASSERT(tsubs == subs);
0057 
0058               int tsector = CSCTriggerNumbering::triggerSectorFromLabels(
0059                   station,
0060                   CSCTriggerNumbering::ringFromTriggerLabels(station, cscid),
0061                   CSCTriggerNumbering::chamberFromTriggerLabels(sector, subs, station, cscid));
0062               CPPUNIT_ASSERT(tsector == sector);
0063             }
0064           else {
0065             int tcscid = CSCTriggerNumbering::triggerCscIdFromLabels(
0066                 station,
0067                 CSCTriggerNumbering::ringFromTriggerLabels(station, cscid),
0068                 CSCTriggerNumbering::chamberFromTriggerLabels(sector, 0, station, cscid));
0069             CPPUNIT_ASSERT(tcscid == cscid);
0070 
0071             int tsector = CSCTriggerNumbering::triggerSectorFromLabels(
0072                 station,
0073                 CSCTriggerNumbering::ringFromTriggerLabels(station, cscid),
0074                 CSCTriggerNumbering::chamberFromTriggerLabels(sector, 0, station, cscid));
0075             CPPUNIT_ASSERT(tsector == sector);
0076           }
0077         }
0078 }
0079 
0080 void testCSCTriggerNumbering::testFail() {
0081   // Give triggerSectorFromLabels a bad input
0082   try {
0083     CSCTriggerNumbering::triggerSectorFromLabels(0, 1, 2);
0084     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0085   } catch (cms::Exception& e) {
0086   } catch (...) {
0087     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0088   }
0089 
0090   // Give triggerSubSectorFromLabels a bad input
0091 
0092   try {
0093     CSCTriggerNumbering::triggerSubSectorFromLabels(0, 34);
0094     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0095   } catch (cms::Exception& e) {
0096   } catch (...) {
0097     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0098   }
0099 
0100   // Give triggerCscIdFromLabels a bad input
0101 
0102   try {
0103     CSCTriggerNumbering::triggerCscIdFromLabels(0, 1, 2);
0104     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0105   } catch (cms::Exception& e) {
0106   } catch (...) {
0107     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0108   }
0109 
0110   // Give ringFromTriggerLabels a bad input
0111   try {
0112     CSCTriggerNumbering::ringFromTriggerLabels(0, 2);
0113     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0114   } catch (cms::Exception& e) {
0115   } catch (...) {
0116     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0117   }
0118 
0119   // Give ringFromTriggerLabels a bad input
0120   try {
0121     CSCTriggerNumbering::chamberFromTriggerLabels(0, 1, 2, 9);
0122     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0123   } catch (cms::Exception& e) {
0124   } catch (...) {
0125     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0126   }
0127 }