File indexing completed on 2024-04-06 12:04:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <cppunit/extensions/HelperMacros.h>
0012 #include <DataFormats/MuonDetId/interface/DTChamberId.h>
0013 #include <DataFormats/MuonDetId/interface/DTSuperLayerId.h>
0014 #include <DataFormats/MuonDetId/interface/DTLayerId.h>
0015 #include <DataFormats/MuonDetId/interface/DTWireId.h>
0016 #include <FWCore/Utilities/interface/Exception.h>
0017
0018 #include <iostream>
0019 using namespace std;
0020
0021 class testDTDetIds : public CppUnit::TestFixture {
0022 CPPUNIT_TEST_SUITE(testDTDetIds);
0023 CPPUNIT_TEST(testConstructors);
0024 CPPUNIT_TEST(testFail);
0025 CPPUNIT_TEST(testMemberOperators);
0026 CPPUNIT_TEST_SUITE_END();
0027
0028 public:
0029 void setUp() {}
0030 void tearDown() {}
0031
0032 void testConstructors();
0033 void testFail();
0034 void testMemberOperators();
0035 };
0036
0037
0038 CPPUNIT_TEST_SUITE_REGISTRATION(testDTDetIds);
0039
0040
0041 void testDTDetIds::testConstructors() {
0042 for (int wheel = DTWireId::minWheelId; wheel <= DTWireId::maxWheelId; ++wheel) {
0043 for (int station = DTWireId::minStationId; station <= DTWireId::maxStationId; ++station) {
0044 for (int sector = DTWireId::minSectorId; sector <= DTWireId::maxSectorId; ++sector) {
0045
0046 DTChamberId chamberId(wheel, station, sector);
0047 CPPUNIT_ASSERT(chamberId.wheel() == wheel);
0048 CPPUNIT_ASSERT(chamberId.station() == station);
0049 CPPUNIT_ASSERT(chamberId.sector() == sector);
0050
0051
0052 int chId = chamberId.rawId();
0053 DTChamberId newChamberId(chId);
0054 CPPUNIT_ASSERT(newChamberId == chamberId);
0055
0056
0057 DTChamberId copyChamberId(newChamberId);
0058 CPPUNIT_ASSERT(copyChamberId == newChamberId);
0059
0060 for (int slayer = DTWireId::minSuperLayerId; slayer <= DTWireId::maxSuperLayerId; ++slayer) {
0061
0062 DTSuperLayerId slId(wheel, station, sector, slayer);
0063 CPPUNIT_ASSERT(slId.wheel() == wheel);
0064 CPPUNIT_ASSERT(slId.station() == station);
0065 CPPUNIT_ASSERT(slId.sector() == sector);
0066 CPPUNIT_ASSERT(slId.superlayer() == slayer);
0067
0068
0069 int sId = slId.rawId();
0070 DTSuperLayerId newSlId(sId);
0071 CPPUNIT_ASSERT(newSlId == slId);
0072
0073
0074 DTSuperLayerId anotherSLId(chamberId, slayer);
0075 CPPUNIT_ASSERT(anotherSLId == slId);
0076
0077
0078 DTChamberId copyChamberIdFromSl(slId);
0079 CPPUNIT_ASSERT(copyChamberIdFromSl == chamberId);
0080
0081
0082 DTChamberId copyChamberIdFromRawSl(sId);
0083 CPPUNIT_ASSERT(copyChamberIdFromRawSl == chamberId);
0084
0085
0086 DTSuperLayerId copySlId(slId);
0087 CPPUNIT_ASSERT(slId == copySlId);
0088
0089 for (int layer = DTWireId::minLayerId; layer <= DTWireId::maxLayerId; ++layer) {
0090
0091 DTLayerId layerId(wheel, station, sector, slayer, layer);
0092 CPPUNIT_ASSERT(layerId.wheel() == wheel);
0093 CPPUNIT_ASSERT(layerId.station() == station);
0094 CPPUNIT_ASSERT(layerId.sector() == sector);
0095 CPPUNIT_ASSERT(layerId.superlayer() == slayer);
0096 CPPUNIT_ASSERT(layerId.layer() == layer);
0097
0098
0099 int lId = layerId.rawId();
0100 DTLayerId newLayerId(lId);
0101 CPPUNIT_ASSERT(newLayerId == layerId);
0102
0103
0104 DTLayerId anotherLayerId(chamberId, slayer, layer);
0105 CPPUNIT_ASSERT(anotherLayerId == layerId);
0106
0107
0108 DTLayerId anotherLayerId1(slId, layer);
0109 CPPUNIT_ASSERT(anotherLayerId1 == layerId);
0110
0111
0112 DTChamberId copyChamberIdFromLayer(layerId);
0113 CPPUNIT_ASSERT(copyChamberIdFromLayer == chamberId);
0114
0115
0116 DTChamberId copyChamberIdFromRawLayer(lId);
0117 CPPUNIT_ASSERT(copyChamberIdFromRawLayer == chamberId);
0118
0119
0120 DTSuperLayerId copySlIdFromLayer(layerId);
0121 CPPUNIT_ASSERT(copySlIdFromLayer == slId);
0122
0123
0124 DTSuperLayerId copySlIdFromRawLayer(lId);
0125 CPPUNIT_ASSERT(copySlIdFromRawLayer == slId);
0126
0127
0128 DTLayerId copyLayerId(layerId);
0129 CPPUNIT_ASSERT(copyLayerId == layerId);
0130
0131 for (int wire = DTWireId::minWireId; wire <= DTWireId::maxWireId; ++wire) {
0132
0133 DTWireId wireId(wheel, station, sector, slayer, layer, wire);
0134 CPPUNIT_ASSERT(wireId.wheel() == wheel);
0135 CPPUNIT_ASSERT(wireId.station() == station);
0136 CPPUNIT_ASSERT(wireId.sector() == sector);
0137 CPPUNIT_ASSERT(wireId.superlayer() == slayer);
0138 CPPUNIT_ASSERT(wireId.layer() == layer);
0139 CPPUNIT_ASSERT(wireId.wire() == wire);
0140
0141
0142 int myId = wireId.rawId();
0143 DTWireId newWireId(myId);
0144 CPPUNIT_ASSERT(wireId == newWireId);
0145
0146
0147 DTWireId anotherWireId(chamberId, slayer, layer, wire);
0148 CPPUNIT_ASSERT(anotherWireId == wireId);
0149
0150
0151 DTWireId anotherWireId1(slId, layer, wire);
0152 CPPUNIT_ASSERT(anotherWireId1 == wireId);
0153
0154
0155 DTWireId anotherWireId2(layerId, wire);
0156 CPPUNIT_ASSERT(anotherWireId2 == wireId);
0157
0158
0159 DTChamberId copyChamberIdFromWire(wireId);
0160 CPPUNIT_ASSERT(copyChamberIdFromWire == chamberId);
0161
0162
0163 DTChamberId copyChamberIdFromRawWire(myId);
0164 CPPUNIT_ASSERT(copyChamberIdFromRawWire == chamberId);
0165
0166
0167 DTSuperLayerId copySlIdFromWire(wireId);
0168 CPPUNIT_ASSERT(copySlIdFromWire == slId);
0169
0170
0171 DTSuperLayerId copySlIdFromRawWire(myId);
0172 CPPUNIT_ASSERT(copySlIdFromRawWire == slId);
0173
0174
0175 DTLayerId copyLayerIdFromWire(wireId);
0176 CPPUNIT_ASSERT(copyLayerIdFromWire == layerId);
0177
0178
0179 DTLayerId copyLayerIdFromRawWire(myId);
0180 CPPUNIT_ASSERT(copyLayerIdFromRawWire == layerId);
0181
0182
0183 DTWireId copyWireId(wireId);
0184 CPPUNIT_ASSERT(copyWireId == wireId);
0185 }
0186 }
0187 }
0188 }
0189 }
0190 }
0191 }
0192
0193 void testDTDetIds::testFail() {
0194
0195 try {
0196
0197 DTChamberId detid(0, 1, 15);
0198 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0199 detid.rawId();
0200 } catch (cms::Exception& e) {
0201
0202 } catch (...) {
0203 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0204 }
0205
0206
0207 try {
0208 DTChamberId detid(3211);
0209 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0210 detid.rawId();
0211 } catch (cms::Exception& e) {
0212
0213 } catch (...) {
0214 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0215 }
0216
0217
0218 try {
0219
0220 DTSuperLayerId detid(0, 1, 1, 5);
0221 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0222 detid.rawId();
0223 } catch (cms::Exception& e) {
0224
0225 } catch (...) {
0226 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0227 }
0228
0229
0230 try {
0231 DTSuperLayerId detid(3211);
0232 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0233 detid.rawId();
0234 } catch (cms::Exception& e) {
0235
0236 } catch (...) {
0237 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0238 }
0239
0240
0241 try {
0242
0243 DTLayerId detid(0, 1, 1, 1, 7);
0244 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0245 detid.rawId();
0246 } catch (cms::Exception& e) {
0247
0248 } catch (...) {
0249 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0250 }
0251
0252
0253 try {
0254 DTLayerId detid(3211);
0255 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0256 detid.rawId();
0257 } catch (cms::Exception& e) {
0258
0259 } catch (...) {
0260 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0261 }
0262
0263
0264 try {
0265
0266 DTWireId wireId(0, 1, 1, 1, 1, 1000);
0267 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0268 wireId.rawId();
0269 } catch (cms::Exception& e) {
0270
0271 } catch (...) {
0272 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0273 }
0274
0275
0276 try {
0277 DTWireId wireId(3211);
0278 CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0279 wireId.rawId();
0280 } catch (cms::Exception& e) {
0281
0282 } catch (...) {
0283 CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0284 }
0285 }
0286
0287 void testDTDetIds::testMemberOperators() {
0288 int wheel = 2;
0289 int station = 3;
0290 int sector = 8;
0291 int sl = 1;
0292 int layer = 4;
0293 int wire = 15;
0294
0295
0296 DTChamberId chamber1(wheel, station, sector);
0297 DTChamberId chamber2;
0298 chamber2 = chamber1;
0299 CPPUNIT_ASSERT(chamber2 == chamber1);
0300
0301 DTSuperLayerId superlayer1(wheel, station, sector, sl);
0302 DTSuperLayerId superlayer2;
0303 superlayer2 = superlayer1;
0304 CPPUNIT_ASSERT(superlayer2 == superlayer1);
0305
0306 DTLayerId layer1(wheel, station, sector, sl, layer);
0307 DTLayerId layer2;
0308 layer2 = layer1;
0309 CPPUNIT_ASSERT(layer2 == layer1);
0310
0311 DTWireId wire1(wheel, station, sector, sl, layer, wire);
0312 DTWireId wire2;
0313 wire2 = wire1;
0314 CPPUNIT_ASSERT(wire2 == wire1);
0315
0316
0317 DTChamberId chamber3 = superlayer1.chamberId();
0318 CPPUNIT_ASSERT(chamber3 == chamber1);
0319
0320 DTChamberId chamber4 = layer1.chamberId();
0321 CPPUNIT_ASSERT(chamber4 == chamber1);
0322
0323 DTChamberId chamber5 = wire1.chamberId();
0324 CPPUNIT_ASSERT(chamber5 == chamber1);
0325
0326 DTSuperLayerId superlayer3 = layer1.superlayerId();
0327 CPPUNIT_ASSERT(superlayer3 == superlayer1);
0328
0329 DTSuperLayerId superlayer4 = wire1.superlayerId();
0330 CPPUNIT_ASSERT(superlayer4 == superlayer1);
0331
0332 DTLayerId layer3 = wire1.layerId();
0333 CPPUNIT_ASSERT(layer3 == layer1);
0334
0335
0336 DTChamberId chamber6 = superlayer1;
0337 CPPUNIT_ASSERT(chamber6 == chamber3);
0338
0339 DTSuperLayerId superlayer6 = layer1;
0340 CPPUNIT_ASSERT(superlayer6 == superlayer3);
0341
0342 DTLayerId layer6 = wire1;
0343 CPPUNIT_ASSERT(layer6 == layer3);
0344
0345 #ifdef TEST_FORBIDDEN_CTORS
0346
0347
0348
0349
0350 DTSuperLayerId s(chamber1);
0351 DTLayerId l(superlayer1);
0352 DTWireId w(layer1);
0353
0354
0355
0356 DetId d;
0357 DTChamberId c(d);
0358 DTSuperLayerId s1(d);
0359 DTLayerId l1(d);
0360 DTWireId w1(d);
0361
0362
0363 DTChamberId chamber7 = d;
0364 DTSuperLayerId superlayer7 = chamber1;
0365 DTLayerId layer7 = superlayer1;
0366 DTWireId wire7 = layer1;
0367 #endif
0368 }