Belle II Software development
fullSecID.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <framework/logging/Logger.h>
9#include <tracking/dataobjects/FullSecID.h>
10#include <iostream>
11#include <gtest/gtest.h>
12#include <vector>
13
14namespace Belle2 {
21 class FullSecIDTest : public ::testing::Test {
22 protected:
23 };
24
26 TEST_F(FullSecIDTest, constructorAndGetterTests)
27 {
28 // first, we need a useful vxdID:
29 VxdID vxdID = VxdID(34624); // this should be a sensor on layer 4
30 int vxdIDInt = vxdID;
31
32 EXPECT_EQ(4, vxdID.getLayerNumber());
33
34 // now we are using the constructor with a VxdID, a subLayerID and a sectorID
35 bool subLayerID = true;
36 unsigned short sectorID = 15;
37 FullSecID aFullSecID = FullSecID(vxdID, subLayerID, sectorID);
38
39 EXPECT_EQ(4, aFullSecID.getLayerID());
40
41 EXPECT_EQ(subLayerID, aFullSecID.getSubLayerID());
42
43 EXPECT_EQ(vxdID, aFullSecID.getVxdID());
44
45 EXPECT_EQ(vxdIDInt, aFullSecID.getUniID());
46
47 EXPECT_EQ(sectorID, aFullSecID.getSecID());
48
49 // now we are using the second constructor using an encoded fullSecID (int) as input:
50
51 FullSecID anotherFullSecID = FullSecID(aFullSecID.getFullSecID());
52
53 EXPECT_EQ(4, anotherFullSecID.getLayerID());
54
55 EXPECT_EQ(subLayerID, anotherFullSecID.getSubLayerID());
56
57 EXPECT_EQ(vxdID, anotherFullSecID.getVxdID());
58
59 EXPECT_EQ(vxdIDInt, anotherFullSecID.getUniID());
60
61 EXPECT_EQ(aFullSecID.getSecID(), anotherFullSecID.getSecID());
62
63 EXPECT_EQ(aFullSecID.getFullSecID(), anotherFullSecID.getFullSecID());
64
65 // now we are using the third constructor using an encoded fullSecID (string) as input:
66 std::stringstream aSecIDString;
67 aSecIDString << aFullSecID.getLayerID() << aFullSecID.getSubLayerID() << "_" << int(aFullSecID.getVxdID()) << "_" <<
68 aFullSecID.getSecID();
69
70 FullSecID aThirdFullSecID = FullSecID(aSecIDString.str());
71
72 EXPECT_EQ(4, aThirdFullSecID.getLayerID());
73
74 EXPECT_EQ(subLayerID, aThirdFullSecID.getSubLayerID());
75
76 EXPECT_EQ(vxdID, aThirdFullSecID.getVxdID());
77
78 EXPECT_EQ(vxdIDInt, aThirdFullSecID.getUniID());
79
80 EXPECT_EQ(aFullSecID.getSecID(), aThirdFullSecID.getSecID());
81
82 EXPECT_EQ(aFullSecID.getFullSecID(), aThirdFullSecID.getFullSecID());
83
84 EXPECT_EQ(aSecIDString.str(), aThirdFullSecID.getFullSecString());
85
86 // now we are using the third constructor again using an encoded short fullSecID (string, used by filterCalculator) as input:
87 std::stringstream aSecIDString2;
88 aSecIDString2 << aFullSecID.getLayerID() << "_" << int(aFullSecID.getVxdID()) << "_" << aFullSecID.getSecID();
89
90 FullSecID aFourthFullSecID = FullSecID(aSecIDString2.str());
91
92 EXPECT_EQ(4, aFourthFullSecID.getLayerID());
93
94 EXPECT_FALSE(aFourthFullSecID.getSubLayerID());
95
96 EXPECT_EQ(vxdID, aFourthFullSecID.getVxdID());
97
98 EXPECT_EQ(vxdIDInt, aFourthFullSecID.getUniID());
99
100 EXPECT_EQ(FullSecID(vxdID, false, sectorID).getSecID(), aFourthFullSecID.getSecID());
101
102 EXPECT_NE(aSecIDString2.str(), aFourthFullSecID.getFullSecString()); // they should not be the same any more...
103
104
105 // testing copy constructor (and C++11 range based for-loops):
106 std::vector<FullSecID> testVector;
107 for (int i = 0; i < 5; ++i) {
108 testVector.push_back(aFullSecID);
109 }
110 for (auto aSecID : testVector) {
111 EXPECT_EQ(aFullSecID, aSecID);
112 }
113 }
114
115
117 TEST_F(FullSecIDTest, overloadedOperatorTests)
118 {
119 //preparing stuff (procedures copied from constructorAndGetterTest):
120 VxdID vxdID = VxdID(34624); // this should be a sensor on layer 4
121 bool subLayerID = true;
122 unsigned short sectorID = 15;
123 FullSecID aFullSecID = FullSecID(vxdID, subLayerID, sectorID);
124 std::stringstream aSecIDString;
125 aSecIDString << aFullSecID.getLayerID() << aFullSecID.getSubLayerID() << "_" << int(aFullSecID.getVxdID()) << "_" <<
126 aFullSecID.getSecID();
127
128 FullSecID aFullSecID2 = FullSecID(aSecIDString.str());
129
130 // now the checks:
131 EXPECT_EQ(static_cast<unsigned int>(aFullSecID), aFullSecID2); // directly comparing to an int
132
133 EXPECT_EQ(aSecIDString.str(), std::string(aFullSecID2)); // directly comparing to an string - testing string cast
134
135 EXPECT_EQ(aFullSecID, aFullSecID2); // direct comparison
136
137
138 std::stringstream aSecIDStream, aSecIDStream2;
139 aSecIDStream << aFullSecID2;
140 aSecIDStream2 << aSecIDString.str();
141
142 EXPECT_EQ(aSecIDString.str(), aSecIDStream.str()); // testing stream operator overloading after string-conversion
143
144 FullSecID aFullSecID3 = FullSecID(vxdID, false, sectorID); // same ID as above but now, the sublayerID is false instead of true
145
146 EXPECT_GT(aFullSecID2, aFullSecID3); // aFullSecID2 > aFullSecID3
147
148 for (int l1 = 7; l1 != 0; --l1) { // testing layerIDs
149 int l2 = l1;
150 l2--;
151 FullSecID biggerOne = FullSecID(l1, false, 0, 0);
152 FullSecID smallerOne = FullSecID(l2, false, 0, 0);
153 EXPECT_GT(biggerOne, smallerOne);
154 }
155 for (int s1 = 255; s1 != 0; --s1) { // testing sectorIDs
156 int s2 = s1;
157 s2--;
158 FullSecID biggerOne = FullSecID(6, false, 0, s1);
159 FullSecID smallerOne = FullSecID(6, false, 0, s2);
160 EXPECT_GT(biggerOne, smallerOne); // aFullSecID2 > aFullSecID3
161 int equalOne = smallerOne;
162 equalOne++;
163 EXPECT_EQ(int(biggerOne), equalOne);
164 }
165
166 EXPECT_GT(int(aFullSecID2), int(aFullSecID3));
167
168
169 FullSecID aFullSecID4 = aFullSecID;
170
171 EXPECT_EQ(aFullSecID4, aFullSecID); // testing assignment operator;
172 }
173
174
176 TEST_F(FullSecIDTest, bufferOverflowTest)
177 {
178 B2WARNING("TODO: FullSecIDTest:bufferOverflowTest should catch cases of bad user input");
179 // WARNING TODO should catch cases of bad user input
180 }
182} // namespace
Testing everything from FullSecID.
Definition: fullSecID.h:21
Class to identify a sector inside of the VXD.
Definition: FullSecID.h:33
std::string getFullSecString() const
returns the FullSecID coded as string compatible to secIDs stored in the xml-sectormaps
Definition: FullSecID.cc:116
VxdID getVxdID() const
returns VxdID of sensor.
Definition: FullSecID.h:138
unsigned int getFullSecID() const
returns the FullSecID coded as integer for further use (can be reconverted to FullSecID by using Full...
Definition: FullSecID.h:150
unsigned short int getUniID() const
returns uniID of sensor (basically the same as VxdID (can simply converted to vxdID(uniID)) but a tri...
Definition: FullSecID.h:142
short int getLayerID() const
returns LayerID compatible with basf2 standards.
Definition: FullSecID.h:118
bool getSubLayerID() const
returns SubLayerID which tells you whether it is useful to search for compatible sectors in the same ...
Definition: FullSecID.h:134
short int getSecID() const
returns SecID of current FullSecID (only unique for each sensor).
Definition: FullSecID.h:146
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
Abstract base class for different kinds of events.