Belle II Software development
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
21using namespace Belle2;
22
23
24const int FullSecID::LayerBits = 4;
25const int FullSecID::SubLayerBits = 1;
26const int FullSecID::VxdIDBits = 16;
27const int FullSecID::SectorBits = 11;
28const int FullSecID::Bits = LayerBits + SubLayerBits + VxdIDBits + SectorBits;
29const int FullSecID::MaxLayer = (1 << LayerBits) - 1;
30const int FullSecID::MaxSubLayer = (1 << SubLayerBits) - 1;
31const int FullSecID::MaxVxdID = (1 << VxdIDBits) - 1;
32const int FullSecID::MaxSector = (1 << SectorBits) - 1;
33const int FullSecID::MaxID = std::numeric_limits<unsigned int>::max();
34const int FullSecID::LayerBitShift = SubLayerBits + VxdIDBits + SectorBits;
35const int FullSecID::SubLayerBitShift = VxdIDBits + SectorBits;
36const int FullSecID::VxdIDBitShift = SectorBits;
37const int FullSecID::SubLayerMask = MaxSubLayer << SubLayerBitShift;
38const int FullSecID::VxdIDMask = MaxVxdID << VxdIDBitShift;
39const int FullSecID::SectorMask = MaxSector;
40
41
42
43FullSecID::FullSecID(std::string sid)
44{
45 std::vector<std::string> stringSegments;
46 boost::split(stringSegments, sid, boost::is_any_of("_"));
47
48 unsigned int LayerID = stringSegments[0][0] -
49 '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.
50 unsigned int SubLayerID = 0;
51 if (stringSegments[0].size() > 1) {
52 SubLayerID = stringSegments[0][1] - '0';
53 }
54// unsigned int SubLayerID = stringSegments[0][1] - '0';
55 unsigned int UniID = std::stoi(stringSegments[1]); // C++03: atoi(stringSegments[1].c_str());
56 unsigned int sectorNumber = std::stoi(stringSegments[2]); // atoi(stringSegments[2].c_str());
57 B2DEBUG(29, "FullSecID-constructor: Value before converting: " << sid << ", after converting: layerID " << LayerID <<
58 ", subLayerID " << SubLayerID << ", UniID " << UniID << ", secID " << sectorNumber);
59 assert(LayerID < MaxLayer + 1);
60 assert(SubLayerID < MaxSubLayer + 1);
61 assert(UniID < MaxVxdID + 1);
62 assert(sectorNumber < MaxSector + 1);
63
64 LayerID <<= LayerBitShift;
65 SubLayerID <<= SubLayerBitShift;
66 UniID <<= VxdIDBitShift;
67 m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber;
68}
69
70
71
72FullSecID::FullSecID(VxdID vxdID, bool subLayerID, unsigned int sectorNumber):
73 m_fullSecID(0) // setting to 0 to be sure that value is 0 when using it within the brackets
74{
75 unsigned int LayerID = vxdID.getLayerNumber();
76 unsigned int SubLayerID = subLayerID; // converting to int
77 unsigned int UniID = vxdID;
78
79 B2DEBUG(28, "FullSecID-constructor: LayerID " << LayerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << SubLayerID <<
80 ", MaxSubLayer " << MaxSubLayer << ", UniID " << UniID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber <<
81 ", MaxSector " << MaxSector);
82 assert(LayerID < MaxLayer + 1);
83 assert(SubLayerID < MaxSubLayer + 1);
84 assert(UniID < MaxVxdID + 1);
85 assert(sectorNumber < MaxSector + 1);
86
87 LayerID <<= LayerBitShift;
88 SubLayerID <<= SubLayerBitShift;
89 UniID <<= VxdIDBitShift;
90 m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber; // should be the same as below
91// m_fullSecID = LayerID + SubLayerID + UniID + sectorNumber; // should be the same as above
92}
93
94
95
96FullSecID::FullSecID(unsigned int layerID, bool subLayerID, unsigned int sensorID, unsigned int sectorNumber)
97{
98 unsigned int SubLayerID = subLayerID; // converting to int
99 B2DEBUG(28, "FullSecID-constructor: LayerID " << layerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << subLayerID <<
100 ", MaxSubLayer " << MaxSubLayer << ", UniID " << sensorID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber <<
101 ", MaxSector " << MaxSector);
102 assert(layerID < MaxLayer + 1);
103 assert(SubLayerID < MaxSubLayer + 1);
104 assert(sensorID < MaxVxdID + 1);
105 assert(sectorNumber < MaxSector + 1);
106
107 layerID <<= LayerBitShift;
108 SubLayerID <<= SubLayerBitShift;
109 sensorID <<= VxdIDBitShift;
110 m_fullSecID = layerID | SubLayerID | sensorID | sectorNumber;
111 B2DEBUG(28, " m_fullSecID/binary: " << m_fullSecID << "/" << std::bitset<32>(m_fullSecID) << "\n, secID/binary: " << sectorNumber
112 << "/" << std::bitset<32>(sectorNumber) << ", layerID-binary: " << std::bitset<32>(layerID) << "\n, SubLayerID-binary: " <<
113 std::bitset<32>(SubLayerID) << ", sensorID-binary: " << std::bitset<32>(sensorID));
114}
115
117{
118 if (getLayerID() == 0) {
119 return (boost::format("0%1%_000_%2%") % getLayerID() % getSecID()).str();
120 }
121 return (boost::format("%1%%2%_%3%_%4%") % getLayerID() % getSubLayerID() % getUniID() %
122 getSecID()).str(); // WARNING this bypasses the following code - intended?
123// if (getLayerID() == 0) {
124// return (boost::format("%1%%2%_0.0.0_%3%") % getLayerID() % getSubLayerID() % getSecID()).str();
125// }
126// return (boost::format("%1%%2%_%3%.%4%.%5%_%6%") % getLayerID() % getSubLayerID() % getVxdID().getLayerNumber() % getVxdID().getLadderNumber() % getVxdID().getSensorNumber() % getSecID()).str();
127}
128
129
130
131
132// FullSecID::FullSecID(std::string sid)
133// {
134// vector<string> stringSegments;
135// boost::split(stringSegments, sid, boost::is_any_of("_"));
136//
137// 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.
138// unsigned int SubLayerID = stringSegments[0][1] - '0';
139// unsigned int UniID = atoi(stringSegments[1].c_str()); // C++ 11: std::stoi( stringSegments[1] )
140// unsigned int sectorNumber = atoi(stringSegments[2].c_str());
141// B2DEBUG(29, "FullSecID-constructor: Value before converting: " << sid << ", after converting: layerID " << LayerID << ", subLayerID " << SubLayerID << ", UniID " << UniID << ", secID " << sectorNumber);
142// assert(LayerID < MaxLayer + 1);
143// assert(SubLayerID < MaxSubLayer + 1);
144// assert(UniID < MaxVxdID + 1);
145// assert(sectorNumber < MaxSector + 1);
146//
147// LayerID <<= LayerBitShift;
148// SubLayerID <<= SubLayerBitShift;
149// UniID <<= VxdIDBitShift;
150// m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber;
151// }
152//
153//
154// FullSecID::FullSecID(VxdID vxdID, bool subLayerID, unsigned int sectorNumber):
155// m_fullSecID(0) // setting to 0 to be sure that value is 0 when using it within the brackets
156// {
157// unsigned int LayerID = vxdID.getLayerNumber();
158// unsigned int SubLayerID = subLayerID; // converting to int
159// unsigned int UniID = vxdID;
160//
161// B2DEBUG(28, "FullSecID-constructor: LayerID " << LayerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << SubLayerID << ", MaxSubLayer " << MaxSubLayer << ", UniID " << UniID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber << ", MaxSector " << MaxSector);
162// assert(LayerID < MaxLayer + 1);
163// assert(SubLayerID < MaxSubLayer + 1);
164// assert(UniID < MaxVxdID + 1);
165// assert(sectorNumber < MaxSector + 1);
166//
167// LayerID <<= LayerBitShift;
168// SubLayerID <<= SubLayerBitShift;
169// UniID <<= VxdIDBitShift;
170// m_fullSecID = LayerID | SubLayerID | UniID | sectorNumber; // should be the same as below
171// // m_fullSecID = LayerID + SubLayerID + UniID + sectorNumber; // should be the same as above
172// }
173//
174// FullSecID::FullSecID(unsigned int layerID, bool subLayerID, unsigned int sensorID, unsigned int sectorNumber)
175// {
176// unsigned int SubLayerID = subLayerID; // converting to int
177// B2DEBUG(28, "FullSecID-constructor: LayerID " << layerID << ", MaxLayer " << MaxLayer << ", SubLayerID " << subLayerID << ", MaxSubLayer " << MaxSubLayer << ", UniID " << sensorID << ", MaxVxdID " << MaxVxdID << ", sectorNumber " << sectorNumber << ", MaxSector " << MaxSector);
178// assert(layerID < MaxLayer + 1);
179// assert(SubLayerID < MaxSubLayer + 1);
180// assert(sensorID < MaxVxdID + 1);
181// assert(sectorNumber < MaxSector + 1);
182//
183// layerID <<= LayerBitShift;
184// SubLayerID <<= SubLayerBitShift;
185// sensorID <<= VxdIDBitShift;
186// m_fullSecID = layerID | SubLayerID | sensorID | sectorNumber; // should be the same as below
187// B2DEBUG(28, " 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))
188// }
189//
190// std::string FullSecID::getFullSecString() const
191// {
192// return (boost::format("%1%%2%_%3%_%4%") % getLayerID() % getSubLayerID() % getUniID() % getSecID()).str(); // WARNING this bypasses the following code - intended?
193// if (getLayerID() == 0) {
194// return (boost::format("%1%%2%_0.0.0_%3%") % getLayerID() % getSubLayerID() % getSecID()).str();
195// }
196// return (boost::format("%1%%2%_%3%.%4%.%5%_%6%") % getLayerID() % getSubLayerID() % getVxdID().getLayerNumber() % getVxdID().getLadderNumber() % getVxdID().getSensorNumber() % getSecID()).str();
197// }
198
static const int VxdIDBits
Number of bits available to store a full vxdID.
Definition: FullSecID.h:166
static const int SectorBits
Number of bits available to represent a sector.
Definition: FullSecID.h:170
std::string getFullSecString() const
returns the FullSecID coded as string compatible to secIDs stored in the xml-sectormaps
Definition: FullSecID.cc:116
static const int Bits
Total bit size of the VxdID.
Definition: FullSecID.h:174
static const int MaxVxdID
Maximum valid Sensor ID.
Definition: FullSecID.h:186
static const int MaxSubLayer
Maximum valid Ladder ID.
Definition: FullSecID.h:182
static const int SubLayerMask
mask to get subLayerID from fullSecID
Definition: FullSecID.h:210
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 LayerBits
Number of bits available to represent a layer.
Definition: FullSecID.h:158
static const int SectorMask
mask to get SectorID from fullSecID
Definition: FullSecID.h:218
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
static const int MaxID
Maximum value for ID.
Definition: FullSecID.h:194
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 VxdIDMask
mask to get VxdID from fullSecID
Definition: FullSecID.h:214
static const int MaxLayer
Maximum valid Layer ID.
Definition: FullSecID.h:178
static const int SubLayerBits
Number of bits available to represent a subLayer (a sublayer is 1 if current sector on sensor is in a...
Definition: FullSecID.h:162
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.