Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:47

0001 /**
0002    \file
0003    test file for RPCDetId
0004 
0005    \author Stefano ARGIRO
0006    \date 27 Jul 2005
0007 */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0011 #include "DataFormats/MuonDetId/interface/RPCCompDetId.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 
0014 #include <iomanip>
0015 #include <iostream>
0016 
0017 using namespace std;
0018 
0019 class testRPCDetId : public CppUnit::TestFixture {
0020   CPPUNIT_TEST_SUITE(testRPCDetId);
0021   CPPUNIT_TEST(testOne);
0022   CPPUNIT_TEST(testGasId);
0023   CPPUNIT_TEST(testFail);
0024   CPPUNIT_TEST(testMemberOperators);
0025   CPPUNIT_TEST_SUITE_END();
0026 
0027 public:
0028   void setUp();
0029   void tearDown() {}
0030 
0031   void testOne();
0032   void testGasId();
0033   void testFail();
0034   void testMemberOperators();
0035 
0036 private:
0037   RPCCompDetId rpcgasid_;
0038 };
0039 
0040 ///registration of the test so that the runner can find it
0041 CPPUNIT_TEST_SUITE_REGISTRATION(testRPCDetId);
0042 
0043 void testRPCDetId::setUp() { rpcgasid_ = RPCCompDetId("WM2_S04_RB4R", 0); }
0044 
0045 void testRPCDetId::testOne() {
0046   for (int region = RPCDetId::minRegionId; region <= RPCDetId::maxRegionId; ++region) {
0047     const int minRing(0 != region ? RPCDetId::minRingForwardId : RPCDetId::minRingBarrelId);
0048     const int maxRing(0 != region ? RPCDetId::maxRingForwardId : RPCDetId::maxRingBarrelId);
0049     const int minSector(0 != region ? RPCDetId::minSectorForwardId : RPCDetId::minSectorBarrelId);
0050     const int maxSector(0 != region ? RPCDetId::maxSectorForwardId : RPCDetId::maxSectorBarrelId);
0051     const int minSubSector(0 != region ? RPCDetId::minSubSectorForwardId : RPCDetId::minSubSectorBarrelId);
0052     const int maxSubSector(0 != region ? RPCDetId::maxSubSectorForwardId : RPCDetId::maxSubSectorBarrelId);
0053 
0054     for (int ring = minRing; ring <= maxRing; ++ring)
0055       for (int station = RPCDetId::minStationId; station <= RPCDetId::maxStationId; ++station)
0056         for (int sector = minSector; sector <= maxSector; ++sector)
0057           for (int layer = RPCDetId::minLayerId; layer <= RPCDetId::maxLayerId; ++layer)
0058             for (int subSector = minSubSector; subSector <= maxSubSector; ++subSector)
0059               for (int roll = RPCDetId::minRollId; roll <= RPCDetId::maxRollId; ++roll) {
0060                 RPCDetId detid(region, ring, station, sector, layer, subSector, roll);
0061 
0062                 CPPUNIT_ASSERT(detid.region() == region);
0063                 CPPUNIT_ASSERT(detid.ring() == ring);
0064                 CPPUNIT_ASSERT(detid.station() == station);
0065                 CPPUNIT_ASSERT(detid.sector() == sector);
0066                 CPPUNIT_ASSERT(detid.layer() == layer);
0067                 CPPUNIT_ASSERT(detid.subsector() == subSector);
0068                 CPPUNIT_ASSERT(detid.roll() == roll);
0069 
0070                 //  test constructor from id
0071                 int myId = detid.rawId();
0072                 RPCDetId anotherId(myId);
0073                 CPPUNIT_ASSERT(detid == anotherId);
0074               }
0075   }
0076 }
0077 
0078 void testRPCDetId::testGasId() {
0079   std::cout << rpcgasid_ << " rawid = " << rpcgasid_.rawId() << std::endl;
0080   std::cout << "Region = " << rpcgasid_.region() << std::endl;
0081   std::cout << "Ring or Wheel = " << rpcgasid_.ring() << " - Wheel = " << rpcgasid_.wheel() << std::endl;
0082   std::cout << "Station or Disk = " << rpcgasid_.station() << " - Disk = " << rpcgasid_.disk() << std::endl;
0083   std::cout << "Sector = " << rpcgasid_.sector() << std::endl;
0084   std::cout << "Layer = " << rpcgasid_.layer() << std::endl;
0085   std::cout << "SubSector = " << rpcgasid_.subsector() << std::endl;
0086   std::cout << std::setw(100) << std::setfill('-') << std::endl;
0087   std::cout << "ok" << std::endl;
0088   RPCCompDetId check(rpcgasid_.rawId());
0089   std::cout << check << " rawid = " << check.rawId() << std::endl;
0090   std::cout << "Region = " << check.region() << std::endl;
0091   std::cout << "Ring or Wheel = " << check.ring() << " - Wheel = " << check.wheel() << std::endl;
0092   std::cout << "Station or Disk = " << check.station() << " - Disk = " << check.disk() << std::endl;
0093   std::cout << "Sector = " << check.sector() << std::endl;
0094   std::cout << "Layer = " << check.layer() << std::endl;
0095   std::cout << "SubSector = " << check.subsector() << std::endl;
0096 }
0097 
0098 void testRPCDetId::testFail() {
0099   // contruct using an invalid input index
0100   try {
0101     // Station number too high
0102     RPCDetId detid(0, 1, 7, 2, 2, 1, 1);
0103     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0104     detid.rawId();  // avoid compiler warning
0105   } catch (cms::Exception& e) {
0106     // OK
0107   } catch (...) {
0108     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0109   }
0110 
0111   // contruct using an invalid input id
0112   try {
0113     RPCDetId detid(100);
0114     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0115     detid.rawId();  // avoid compiler warning
0116   } catch (cms::Exception& e) {
0117     // OK
0118   } catch (...) {
0119     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0120   }
0121 }
0122 
0123 void testRPCDetId::testMemberOperators() {
0124   RPCDetId unit1(0, -2, 1, 2, 2, 1, 1);
0125   RPCDetId unit2 = unit1;
0126 
0127   CPPUNIT_ASSERT(unit2 == unit1);
0128 
0129   RPCDetId chamber = unit1.chamberId();
0130   RPCDetId unit3(0, -2, 1, 2, 2, 1, 0);
0131 
0132   CPPUNIT_ASSERT(chamber == unit3);
0133 }