1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
/**
\file
test file for DTChamberId, DTSuperLayerId, DTLayerId and DTWireId
\author S. Argiro' & G. Cerminara
\date 27 Jul 2005
*/
//#define TEST_FORBIDDEN_CTORS
#include <cppunit/extensions/HelperMacros.h>
#include <DataFormats/MuonDetId/interface/DTChamberId.h>
#include <DataFormats/MuonDetId/interface/DTSuperLayerId.h>
#include <DataFormats/MuonDetId/interface/DTLayerId.h>
#include <DataFormats/MuonDetId/interface/DTWireId.h>
#include <FWCore/Utilities/interface/Exception.h>
#include <iostream>
using namespace std;
class testDTDetIds : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(testDTDetIds);
CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST(testFail);
CPPUNIT_TEST(testMemberOperators);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testConstructors();
void testFail();
void testMemberOperators();
};
///registration of the test so that the runner can find it
CPPUNIT_TEST_SUITE_REGISTRATION(testDTDetIds);
// Try every possible constructor
void testDTDetIds::testConstructors() {
for (int wheel = DTWireId::minWheelId; wheel <= DTWireId::maxWheelId; ++wheel) {
for (int station = DTWireId::minStationId; station <= DTWireId::maxStationId; ++station) {
for (int sector = DTWireId::minSectorId; sector <= DTWireId::maxSectorId; ++sector) {
// Build a DTChamberId
DTChamberId chamberId(wheel, station, sector);
CPPUNIT_ASSERT(chamberId.wheel() == wheel);
CPPUNIT_ASSERT(chamberId.station() == station);
CPPUNIT_ASSERT(chamberId.sector() == sector);
// Test constructor from id
int chId = chamberId.rawId();
DTChamberId newChamberId(chId);
CPPUNIT_ASSERT(newChamberId == chamberId);
// Test DTChamberId copy constructor
DTChamberId copyChamberId(newChamberId);
CPPUNIT_ASSERT(copyChamberId == newChamberId);
for (int slayer = DTWireId::minSuperLayerId; slayer <= DTWireId::maxSuperLayerId; ++slayer) {
// Build a DTSuperLayerId
DTSuperLayerId slId(wheel, station, sector, slayer);
CPPUNIT_ASSERT(slId.wheel() == wheel);
CPPUNIT_ASSERT(slId.station() == station);
CPPUNIT_ASSERT(slId.sector() == sector);
CPPUNIT_ASSERT(slId.superlayer() == slayer);
// Test constructor from id
int sId = slId.rawId();
DTSuperLayerId newSlId(sId);
CPPUNIT_ASSERT(newSlId == slId);
// Test constructor from chamberId and sl number
DTSuperLayerId anotherSLId(chamberId, slayer);
CPPUNIT_ASSERT(anotherSLId == slId);
// Test DTChamberId copy constructor
DTChamberId copyChamberIdFromSl(slId);
CPPUNIT_ASSERT(copyChamberIdFromSl == chamberId);
// Test DTSuperLayerId constructor from raw SL Id
DTChamberId copyChamberIdFromRawSl(sId);
CPPUNIT_ASSERT(copyChamberIdFromRawSl == chamberId);
// Test DTSuperLayerId copy constructor
DTSuperLayerId copySlId(slId);
CPPUNIT_ASSERT(slId == copySlId);
for (int layer = DTWireId::minLayerId; layer <= DTWireId::maxLayerId; ++layer) {
// Build a DTLayerId
DTLayerId layerId(wheel, station, sector, slayer, layer);
CPPUNIT_ASSERT(layerId.wheel() == wheel);
CPPUNIT_ASSERT(layerId.station() == station);
CPPUNIT_ASSERT(layerId.sector() == sector);
CPPUNIT_ASSERT(layerId.superlayer() == slayer);
CPPUNIT_ASSERT(layerId.layer() == layer);
// Test constructor from id
int lId = layerId.rawId();
DTLayerId newLayerId(lId);
CPPUNIT_ASSERT(newLayerId == layerId);
// Test constructor from chamberId, sl and layer numbers
DTLayerId anotherLayerId(chamberId, slayer, layer);
CPPUNIT_ASSERT(anotherLayerId == layerId);
// Test constructor from slId and layer number
DTLayerId anotherLayerId1(slId, layer);
CPPUNIT_ASSERT(anotherLayerId1 == layerId);
// Test DTChamberId copy constructor
DTChamberId copyChamberIdFromLayer(layerId);
CPPUNIT_ASSERT(copyChamberIdFromLayer == chamberId);
// Test DTSuperLayerId constructor from raw layer Id
DTChamberId copyChamberIdFromRawLayer(lId);
CPPUNIT_ASSERT(copyChamberIdFromRawLayer == chamberId);
// Test DTSuperLayerId copy constructor
DTSuperLayerId copySlIdFromLayer(layerId);
CPPUNIT_ASSERT(copySlIdFromLayer == slId);
// Test DTSuperLayerId constructor from raw layer Id
DTSuperLayerId copySlIdFromRawLayer(lId);
CPPUNIT_ASSERT(copySlIdFromRawLayer == slId);
// Test DTLayerId copy constructor
DTLayerId copyLayerId(layerId);
CPPUNIT_ASSERT(copyLayerId == layerId);
for (int wire = DTWireId::minWireId; wire <= DTWireId::maxWireId; ++wire) {
// Build a wireId
DTWireId wireId(wheel, station, sector, slayer, layer, wire);
CPPUNIT_ASSERT(wireId.wheel() == wheel);
CPPUNIT_ASSERT(wireId.station() == station);
CPPUNIT_ASSERT(wireId.sector() == sector);
CPPUNIT_ASSERT(wireId.superlayer() == slayer);
CPPUNIT_ASSERT(wireId.layer() == layer);
CPPUNIT_ASSERT(wireId.wire() == wire);
// Test constructor from id
int myId = wireId.rawId();
DTWireId newWireId(myId);
CPPUNIT_ASSERT(wireId == newWireId);
// Test constructor from chamberId, sl, layer and wire numbers
DTWireId anotherWireId(chamberId, slayer, layer, wire);
CPPUNIT_ASSERT(anotherWireId == wireId);
// Test constructor from slId and layer and wire numbers
DTWireId anotherWireId1(slId, layer, wire);
CPPUNIT_ASSERT(anotherWireId1 == wireId);
// Test constructor from layerId and wire number
DTWireId anotherWireId2(layerId, wire);
CPPUNIT_ASSERT(anotherWireId2 == wireId);
// Test DTChamberId copy constructor
DTChamberId copyChamberIdFromWire(wireId);
CPPUNIT_ASSERT(copyChamberIdFromWire == chamberId);
// Test DTChamberId constructor from raw wireId
DTChamberId copyChamberIdFromRawWire(myId);
CPPUNIT_ASSERT(copyChamberIdFromRawWire == chamberId);
// Test DTSuperLayerId copy constructor
DTSuperLayerId copySlIdFromWire(wireId);
CPPUNIT_ASSERT(copySlIdFromWire == slId);
// Test DTSuperLayerId constructor from raw wireId
DTSuperLayerId copySlIdFromRawWire(myId);
CPPUNIT_ASSERT(copySlIdFromRawWire == slId);
// Test DTLayerId copy constructor
DTLayerId copyLayerIdFromWire(wireId);
CPPUNIT_ASSERT(copyLayerIdFromWire == layerId);
// Test DTLayerId constructor from raw wireId
DTLayerId copyLayerIdFromRawWire(myId);
CPPUNIT_ASSERT(copyLayerIdFromRawWire == layerId);
// Test DTWireId copy constructor
DTWireId copyWireId(wireId);
CPPUNIT_ASSERT(copyWireId == wireId);
}
}
}
}
}
}
}
void testDTDetIds::testFail() {
// Contruct a DTChamberId using an invalid input index
try {
// Invalid sector
DTChamberId detid(0, 1, 15);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTChamberId using an invalid input id
try {
DTChamberId detid(3211);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTSuperLayerId using an invalid input index
try {
// Invalid superlayer
DTSuperLayerId detid(0, 1, 1, 5);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTSuperLayerId using an invalid input id
try {
DTSuperLayerId detid(3211);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTLayerId using an invalid input index
try {
// Invalid layer
DTLayerId detid(0, 1, 1, 1, 7);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTLayerId using an invalid input id
try {
DTLayerId detid(3211);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTWireId using an invalid input index
try {
// Invalid wire
DTWireId wireId(0, 1, 1, 1, 1, 1000);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
wireId.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// Contruct a DTWireId using an invalid input id
try {
DTWireId wireId(3211);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
wireId.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
}
void testDTDetIds::testMemberOperators() {
int wheel = 2;
int station = 3;
int sector = 8;
int sl = 1;
int layer = 4;
int wire = 15;
// Test assignement operators from same type
DTChamberId chamber1(wheel, station, sector);
DTChamberId chamber2;
chamber2 = chamber1;
CPPUNIT_ASSERT(chamber2 == chamber1);
DTSuperLayerId superlayer1(wheel, station, sector, sl);
DTSuperLayerId superlayer2;
superlayer2 = superlayer1;
CPPUNIT_ASSERT(superlayer2 == superlayer1);
DTLayerId layer1(wheel, station, sector, sl, layer);
DTLayerId layer2;
layer2 = layer1;
CPPUNIT_ASSERT(layer2 == layer1);
DTWireId wire1(wheel, station, sector, sl, layer, wire);
DTWireId wire2;
wire2 = wire1;
CPPUNIT_ASSERT(wire2 == wire1);
// Test getter of base id
DTChamberId chamber3 = superlayer1.chamberId();
CPPUNIT_ASSERT(chamber3 == chamber1);
DTChamberId chamber4 = layer1.chamberId();
CPPUNIT_ASSERT(chamber4 == chamber1);
DTChamberId chamber5 = wire1.chamberId();
CPPUNIT_ASSERT(chamber5 == chamber1);
DTSuperLayerId superlayer3 = layer1.superlayerId();
CPPUNIT_ASSERT(superlayer3 == superlayer1);
DTSuperLayerId superlayer4 = wire1.superlayerId();
CPPUNIT_ASSERT(superlayer4 == superlayer1);
DTLayerId layer3 = wire1.layerId();
CPPUNIT_ASSERT(layer3 == layer1);
// Test assignement operators from derived objects
DTChamberId chamber6 = superlayer1;
CPPUNIT_ASSERT(chamber6 == chamber3);
DTSuperLayerId superlayer6 = layer1;
CPPUNIT_ASSERT(superlayer6 == superlayer3);
DTLayerId layer6 = wire1;
CPPUNIT_ASSERT(layer6 == layer3);
#ifdef TEST_FORBIDDEN_CTORS
// Forbidden constructors. None of these should be accepted by the compiler!!!
// It should not be allowed to create a derived from a base
// (it would result in invalid IDs)
DTSuperLayerId s(chamber1);
DTLayerId l(superlayer1);
DTWireId w(layer1);
// It is not currently allowed to build any DT id directly from a Detid
// (would allow the above ones and may prevent proper slicing)
DetId d;
DTChamberId c(d);
DTSuperLayerId s1(d);
DTLayerId l1(d);
DTWireId w1(d);
// It is not allowed to copy a derived to a base.
DTChamberId chamber7 = d;
DTSuperLayerId superlayer7 = chamber1;
DTLayerId layer7 = superlayer1;
DTWireId wire7 = layer1;
#endif
}
|