Belle II Software  release-06-02-00
FullSecID.cc
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 
9 #include "tracking/dataobjects/FullSecID.h"
10 #include <framework/logging/Logger.h>
11 #include <limits> // needed for numeric_limits<t>::max()
12 #include <assert.h> // testing purposes
13 #include <boost/format.hpp> // needed for xml-data-compatibility
14 // #include <sstream> // stringstream, needed for xml-data-compatibility
15 #include <vector> // needed for xml-data-compatibility
16 #include <boost/algorithm/string.hpp> // needed for xml-data-compatibility
17 #include <bitset>
18 
19 
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 
25 const int FullSecID::LayerBits = 4;
26 const int FullSecID::SubLayerBits = 1;
27 const int FullSecID::VxdIDBits = 16;
28 const int FullSecID::SectorBits = 11;
29 const int FullSecID::Bits = LayerBits + SubLayerBits + VxdIDBits + SectorBits;
30 const int FullSecID::MaxLayer = (1 << LayerBits) - 1;
31 const int FullSecID::MaxSubLayer = (1 << SubLayerBits) - 1;
32 const int FullSecID::MaxVxdID = (1 << VxdIDBits) - 1;
33 const int FullSecID::MaxSector = (1 << SectorBits) - 1;
34 const int FullSecID::MaxID = std::numeric_limits<unsigned int>::max();
35 const int FullSecID::LayerBitShift = SubLayerBits + VxdIDBits + SectorBits;
36 const int FullSecID::SubLayerBitShift = VxdIDBits + SectorBits;
37 const int FullSecID::VxdIDBitShift = SectorBits;
38 const int FullSecID::SubLayerMask = MaxSubLayer << SubLayerBitShift;
39 const int FullSecID::VxdIDMask = MaxVxdID << VxdIDBitShift;
40 const int FullSecID::SectorMask = MaxSector;
41 
42 
43 
44 FullSecID::FullSecID(std::string sid)
45 {
46  vector<string> stringSegments;
47  boost::split(stringSegments, sid, boost::is_any_of("_"));
48 
49  unsigned int LayerID = stringSegments[0][0] -
50  '0'; // since chars are (compared to strings) very problematic to convert to ints, this solution is very dirty but at least it's short and easy to read.
51  unsigned int SubLayerID = 0;
52  if (stringSegments[0].size() > 1) {
53  SubLayerID = stringSegments[0][1] - '0';
54  }
55 // unsigned int SubLayerID = stringSegments[0][1] - '0';
56  unsigned int UniID = std::stoi(stringSegments[1]); // C++03: atoi(stringSegments[1].c_str());
57  unsigned int sectorNumber = std::stoi(stringSegments[2]); // atoi(stringSegments[2].c_str());
58  B2DEBUG(1000, "FullSecID-constructor: Value before converting: " << sid << ", after converting: layerID " << LayerID <<
59  ", subLayerID " << SubLayerID << ", UniID " << UniID << ", secID " << sectorNumber);
60  assert(LayerID < MaxLayer + 1);
61  assert(SubLayerID < MaxSubLayer + 1);
62  assert(UniID < MaxVxdID + 1);
63  assert(sectorNumber < MaxSector + 1);
64 
65  LayerID <<= LayerBitShift;
66  SubLayerID <<= SubLayerBitShift;
67  UniID <<= VxdIDBitShift;
68  m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber;
69 }
70 
71 
72 
73 FullSecID::FullSecID(VxdID vxdID, bool subLayerID, unsigned int sectorNumber):
74  m_fullSecID(0) // setting to 0 to be sure that value is 0 when using it within the brackets
75 {
76  unsigned int LayerID = vxdID.getLayerNumber();
77  unsigned int SubLayerID = subLayerID; // converting to int
78  unsigned int UniID = vxdID;
79 
80  B2DEBUG(175, "FullSecID-constructor: LayerID " << LayerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << SubLayerID <<
81  ", MaxSubLayer " << MaxSubLayer << ", UniID " << UniID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber <<
82  ", MaxSector " << MaxSector);
83  assert(LayerID < MaxLayer + 1);
84  assert(SubLayerID < MaxSubLayer + 1);
85  assert(UniID < MaxVxdID + 1);
86  assert(sectorNumber < MaxSector + 1);
87 
88  LayerID <<= LayerBitShift;
89  SubLayerID <<= SubLayerBitShift;
90  UniID <<= VxdIDBitShift;
91  m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber; // should be the same as below
92 // m_fullSecID = LayerID + SubLayerID + UniID + sectorNumber; // should be the same as above
93 }
94 
95 
96 
97 FullSecID::FullSecID(unsigned int layerID, bool subLayerID, unsigned int sensorID, unsigned int sectorNumber)
98 {
99  unsigned int SubLayerID = subLayerID; // converting to int
100  B2DEBUG(175, "FullSecID-constructor: LayerID " << layerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << subLayerID <<
101  ", MaxSubLayer " << MaxSubLayer << ", UniID " << sensorID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber <<
102  ", MaxSector " << MaxSector);
103  assert(layerID < MaxLayer + 1);
104  assert(SubLayerID < MaxSubLayer + 1);
105  assert(sensorID < MaxVxdID + 1);
106  assert(sectorNumber < MaxSector + 1);
107 
108  layerID <<= LayerBitShift;
109  SubLayerID <<= SubLayerBitShift;
110  sensorID <<= VxdIDBitShift;
111  m_fullSecID = layerID | SubLayerID | sensorID | sectorNumber;
112  B2DEBUG(175, " m_fullSecID/binary: " << m_fullSecID << "/" << std::bitset<32>(m_fullSecID) << "\n, secID/binary: " << sectorNumber
113  << "/" << std::bitset<32>(sectorNumber) << ", layerID-binary: " << std::bitset<32>(layerID) << "\n, SubLayerID-binary: " <<
114  std::bitset<32>(SubLayerID) << ", sensorID-binary: " << std::bitset<32>(sensorID));
115 }
116 
117 std::string FullSecID::getFullSecString() const
118 {
119  if (getLayerID() == 0) {
120  return (boost::format("0%1%_000_%2%") % getLayerID() % getSecID()).str();
121  }
122  return (boost::format("%1%%2%_%3%_%4%") % getLayerID() % getSubLayerID() % getUniID() %
123  getSecID()).str(); // WARNING this bypasses the following code - intended?
124 // if (getLayerID() == 0) {
125 // return (boost::format("%1%%2%_0.0.0_%3%") % getLayerID() % getSubLayerID() % getSecID()).str();
126 // }
127 // return (boost::format("%1%%2%_%3%.%4%.%5%_%6%") % getLayerID() % getSubLayerID() % getVxdID().getLayerNumber() % getVxdID().getLadderNumber() % getVxdID().getSensorNumber() % getSecID()).str();
128 }
129 
130 
131 
132 
133 // FullSecID::FullSecID(std::string sid)
134 // {
135 // vector<string> stringSegments;
136 // boost::split(stringSegments, sid, boost::is_any_of("_"));
137 //
138 // unsigned int LayerID = stringSegments[0][0] - '0'; // since chars are (compared to strings) very problematic to convert to ints, this solution is very dirty but at least it's short and easy to read.
139 // unsigned int SubLayerID = stringSegments[0][1] - '0';
140 // unsigned int UniID = atoi(stringSegments[1].c_str()); // C++ 11: std::stoi( stringSegments[1] )
141 // unsigned int sectorNumber = atoi(stringSegments[2].c_str());
142 // B2DEBUG(1000, "FullSecID-constructor: Value before converting: " << sid << ", after converting: layerID " << LayerID << ", subLayerID " << SubLayerID << ", UniID " << UniID << ", secID " << sectorNumber);
143 // assert(LayerID < MaxLayer + 1);
144 // assert(SubLayerID < MaxSubLayer + 1);
145 // assert(UniID < MaxVxdID + 1);
146 // assert(sectorNumber < MaxSector + 1);
147 //
148 // LayerID <<= LayerBitShift;
149 // SubLayerID <<= SubLayerBitShift;
150 // UniID <<= VxdIDBitShift;
151 // m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber;
152 // }
153 //
154 //
155 // FullSecID::FullSecID(VxdID vxdID, bool subLayerID, unsigned int sectorNumber):
156 // m_fullSecID(0) // setting to 0 to be shure that value is 0 when using it within the brackets
157 // {
158 // unsigned int LayerID = vxdID.getLayerNumber();
159 // unsigned int SubLayerID = subLayerID; // converting to int
160 // unsigned int UniID = vxdID;
161 //
162 // B2DEBUG(175, "FullSecID-constructor: LayerID " << LayerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << SubLayerID << ", MaxSubLayer " << MaxSubLayer << ", UniID " << UniID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber << ", MaxSector " << MaxSector);
163 // assert(LayerID < MaxLayer + 1);
164 // assert(SubLayerID < MaxSubLayer + 1);
165 // assert(UniID < MaxVxdID + 1);
166 // assert(sectorNumber < MaxSector + 1);
167 //
168 // LayerID <<= LayerBitShift;
169 // SubLayerID <<= SubLayerBitShift;
170 // UniID <<= VxdIDBitShift;
171 // m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber; // should be the same as below
172 // // m_fullSecID = LayerID + SubLayerID + UniID + sectorNumber; // should be the same as above
173 // }
174 //
175 // FullSecID::FullSecID(unsigned int layerID, bool subLayerID, unsigned int sensorID, unsigned int sectorNumber)
176 // {
177 // unsigned int SubLayerID = subLayerID; // converting to int
178 // B2DEBUG(175, "FullSecID-constructor: LayerID " << layerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << subLayerID << ", MaxSubLayer " << MaxSubLayer << ", UniID " << sensorID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber << ", MaxSector " << MaxSector);
179 // assert(layerID < MaxLayer + 1);
180 // assert(SubLayerID < MaxSubLayer + 1);
181 // assert(sensorID < MaxVxdID + 1);
182 // assert(sectorNumber < MaxSector + 1);
183 //
184 // layerID <<= LayerBitShift;
185 // SubLayerID <<= SubLayerBitShift;
186 // sensorID <<= VxdIDBitShift;
187 // m_fullSecID = layerID | SubLayerID | sensorID | sectorNumber; // should be the same as below
188 // B2DEBUG(175, " m_fullSecID/binary: " << m_fullSecID << "/" << std::bitset<32>(m_fullSecID) << "\n, secID/binary: " << sectorNumber << "/" << std::bitset<32>(sectorNumber) << ", layerID-binary: " << std::bitset<32>(layerID) << "\n, SubLayerID-binary: " << std::bitset<32>(SubLayerID) << ", sensorID-binary: " << std::bitset<32>(sensorID))
189 // }
190 //
191 // std::string FullSecID::getFullSecString() const
192 // {
193 // return (boost::format("%1%%2%_%3%_%4%") % getLayerID() % getSubLayerID() % getUniID() % getSecID()).str(); // WARNING this bypasses the following code - intended?
194 // if (getLayerID() == 0) {
195 // return (boost::format("%1%%2%_0.0.0_%3%") % getLayerID() % getSubLayerID() % getSecID()).str();
196 // }
197 // return (boost::format("%1%%2%_%3%.%4%.%5%_%6%") % getLayerID() % getSubLayerID() % getVxdID().getLayerNumber() % getVxdID().getLadderNumber() % getVxdID().getSensorNumber() % getSecID()).str();
198 // }
199 
std::string getFullSecString() const
returns the FullSecID coded as string compatible to secIDs stored in the xml-sectormaps
Definition: FullSecID.cc:117
static const int MaxVxdID
Maximum valid Sensor ID.
Definition: FullSecID.h:186
static const int MaxSubLayer
Maximum valid Ladder ID.
Definition: FullSecID.h:182
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
static const int MaxSector
Maximum valid Segment ID.
Definition: FullSecID.h:190
static const int LayerBitShift
Number of bits to shift for storing a LayerID.
Definition: FullSecID.h:198
static const int SubLayerBitShift
Number of bits to shift for storing a SubLayerID.
Definition: FullSecID.h:202
short int getLayerID() const
returns LayerID compatible with basf2 standards.
Definition: FullSecID.h:118
BaseType m_fullSecID
contains full info of current SecID.
Definition: FullSecID.h:221
bool getSubLayerID() const
returns SubLayerID which tells you whether it is useful to search for compatible sectors in the same ...
Definition: FullSecID.h:134
static const int MaxLayer
Maximum valid Layer ID.
Definition: FullSecID.h:178
FullSecID(const FullSecID &secID)
Copy constructor.
Definition: FullSecID.h:73
static const int VxdIDBitShift
Number of bits shift for storing a full vxdID.
Definition: FullSecID.h:206
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.