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