Belle II Software  release-05-02-19
VxdID.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef VXDID_H
12 #define VXDID_H
13 
14 #include <string>
15 #include <ostream>
16 
17 namespace Belle2 {
35  class VxdID {
36  public:
38  typedef unsigned short baseType;
39  enum {
41  LayerBits = 3,
45  SensorBits = 3,
47  SegmentBits = 5,
50 
52  MaxLayer = (1 << LayerBits) - 1,
54  MaxLadder = (1 << LadderBits) - 1,
56  MaxSensor = (1 << SensorBits) - 1,
58  MaxSegment = (1 << SegmentBits) - 1,
60  MaxID = (1 << Bits) - 1
61  };
62 
64  // cppcheck-suppress noExplicitConstructor
65  VxdID(baseType id = 0)
66  {
67  m_id.id = id;
68  }
71  {
72  m_id.parts.layer = layer;
73  m_id.parts.ladder = ladder;
74  m_id.parts.sensor = sensor;
75  m_id.parts.segment = segment;
76  }
78  explicit VxdID(const std::string& sensor);
80  VxdID(const VxdID& b): m_id(b.m_id) {}
81 
83  VxdID& operator=(const VxdID& b) { m_id = b.m_id; return *this; }
85  VxdID& operator=(baseType id) { m_id.id = id; return *this; }
87  operator baseType() const { return getID(); }
89  operator std::string() const;
91  bool operator==(const VxdID& b) const { return getID() == b.getID(); }
93  bool operator<(const VxdID& b) const { return getID() < b.getID(); }
94 
96  baseType getID() const { return m_id.id; }
98  baseType getLayerNumber() const { return m_id.parts.layer; }
100  baseType getLadderNumber() const { return m_id.parts.ladder; }
102  baseType getSensorNumber() const { return m_id.parts.sensor; }
104  baseType getSegmentNumber() const { return m_id.parts.segment; }
105 
107  void setID(baseType id) { m_id.id = id; }
109  void setLayerNumber(baseType layer) { m_id.parts.layer = layer; }
111  void setLadderNumber(baseType ladder) { m_id.parts.ladder = ladder; }
113  void setSensorNumber(baseType sensor) { m_id.parts.sensor = sensor; }
115  void setSegmentNumber(baseType segment) { m_id.parts.segment = segment; }
116 
118  std::string __str__() const { return (std::string)(*this); }
119 
120  private:
121 
122  union {
124 baseType id: Bits;
125  struct {
134  } parts ;
135  } m_id;
136  };
137 
139  std::ostream& operator<<(std::ostream& out, const VxdID& id);
141 }
142 
143 #endif //VXDID_H
Belle2::VxdID::LadderBits
@ LadderBits
Number of bits available to represent a ladder.
Definition: VxdID.h:51
Belle2::VxdID::layer
baseType layer
Layer id.
Definition: VxdID.h:141
Belle2::VxdID::MaxSensor
@ MaxSensor
Maximum valid Sensor ID.
Definition: VxdID.h:64
Belle2::VxdID::operator==
bool operator==(const VxdID &b) const
Check for equality.
Definition: VxdID.h:99
Belle2::VxdID::MaxLadder
@ MaxLadder
Maximum valid Ladder ID.
Definition: VxdID.h:62
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VxdID::MaxSegment
@ MaxSegment
Maximum valid Segment ID.
Definition: VxdID.h:66
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
Belle2::VxdID::m_id
union Belle2::VxdID::@301 m_id
Union to store the ID and all components in one go.
Belle2::VxdID::MaxID
@ MaxID
Maximum value for ID.
Definition: VxdID.h:68
Belle2::VxdID::getLadderNumber
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:108
Belle2::VxdID::setLayerNumber
void setLayerNumber(baseType layer)
Set the layer id.
Definition: VxdID.h:117
Belle2::VxdID::getID
baseType getID() const
Get the unique id.
Definition: VxdID.h:104
Belle2::VxdID::VxdID
VxdID(baseType id=0)
Constructor using the unique id.
Definition: VxdID.h:73
Belle2::VxdID::segment
baseType segment
Segment id.
Definition: VxdID.h:135
Belle2::VxdID::operator=
VxdID & operator=(const VxdID &b)
Assignment operator.
Definition: VxdID.h:91
Belle2::VxdID::baseType
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:46
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VxdID::setSegmentNumber
void setSegmentNumber(baseType segment)
Set the sensor segment.
Definition: VxdID.h:123
Belle2::VxdID::setSensorNumber
void setSensorNumber(baseType sensor)
Set the sensor id.
Definition: VxdID.h:121
Belle2::VxdID::parts
struct Belle2::VxdID::@301::@302 parts
< Struct to contain all id components
Belle2::VxdID::LayerBits
@ LayerBits
Number of bits available to represent a layer.
Definition: VxdID.h:49
Belle2::VxdID::getSensorNumber
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:110
Belle2::VxdID::SensorBits
@ SensorBits
Number of bits available to represent a sensor.
Definition: VxdID.h:53
Belle2::VxdID::ladder
baseType ladder
Ladder id.
Definition: VxdID.h:139
Belle2::VxdID::MaxLayer
@ MaxLayer
Maximum valid Layer ID.
Definition: VxdID.h:60
Belle2::VxdID::id
baseType id
Unique id.
Definition: VxdID.h:132
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::VxdID::setLadderNumber
void setLadderNumber(baseType ladder)
Set the ladder id.
Definition: VxdID.h:119
Belle2::VxdID::VxdID
VxdID(baseType layer, baseType ladder, baseType sensor, baseType segment=0)
Constructor using layer, ladder and sensor ids.
Definition: VxdID.h:78
Belle2::VxdID::sensor
baseType sensor
Sensor id.
Definition: VxdID.h:137
Belle2::VxdID::setID
void setID(baseType id)
Set the unique id.
Definition: VxdID.h:115
Belle2::VxdID::operator<
bool operator<(const VxdID &b) const
Order by unique id.
Definition: VxdID.h:101
Belle2::VxdID::__str__
std::string __str__() const
make this type printable in python with print(vxd_id)
Definition: VxdID.h:126
Belle2::VxdID::SegmentBits
@ SegmentBits
Number of bits available to represent segmentation of the sensor.
Definition: VxdID.h:55
Belle2::VxdID::getSegmentNumber
baseType getSegmentNumber() const
Get the sensor segment.
Definition: VxdID.h:112
Belle2::VxdID::Bits
@ Bits
Total bit size of the VxdID.
Definition: VxdID.h:57