Belle II Software light-2406-ragdoll
Const::DetectorSet Class Reference

The DetectorSet class for sets of detector IDs in the form of EDetector values. More...

#include <Const.h>

Inheritance diagram for Const::DetectorSet:

Classes

class  Iterator
 Iterator. More...
 

Public Member Functions

 DetectorSet ()
 Default constructor.
 
 DetectorSet (const DetectorSet &)=default
 Copy constructor.
 
DetectorSetoperator= (const DetectorSet &)=default
 Assignment operator.
 
 DetectorSet (EDetector det)
 Constructor for a set containig one detector ID.
 
virtual ~DetectorSet ()
 Destructor.
 
Iterator begin () const
 Beginning iterator.
 
Iterator end () const
 Ending iterator.
 
DetectorSetoperator+= (const DetectorSet &set)
 Addition of another set to this one.
 
DetectorSetoperator-= (const DetectorSet &set)
 Subtraction of another set from this one.
 
bool operator== (const DetectorSet &set) const
 Equality operator.
 
bool operator!= (const DetectorSet &set) const
 Inequality operator.
 
bool contains (const DetectorSet &set) const
 Check whether this set contains another set.
 
bool contains (const Iterator &it) const
 Check whether this set contains detector specified by iterator.
 
int getIndex (EDetector det) const
 Getter for the index of a given detector in this set.
 
size_t size () const
 Getter for number of detector IDs in this set.
 
std::string __str__ () const
 String for printing in python.
 

Private Member Functions

 DetectorSet (uint16_t bits)
 Constructor.
 
 ClassDef (DetectorSet, 1)
 Class version.
 

Static Private Member Functions

static uint16_t getBit (EDetector det)
 Conversion of detector ID to bit pattern.
 
static EDetector getDetector (uint16_t bit)
 Conversion of bit pattern to detector ID.
 

Private Attributes

uint16_t m_bits
 The internal representation of the set as bit pattern.
 

Detailed Description

The DetectorSet class for sets of detector IDs in the form of EDetector values.

Only detectors may be included, not subdetectors.

Definition at line 80 of file Const.h.

Constructor & Destructor Documentation

◆ DetectorSet() [1/3]

DetectorSet ( )
inline

Default constructor.

Definition at line 179 of file Const.h.

179: m_bits(0) {}
uint16_t m_bits
The internal representation of the set as bit pattern.
Definition: Const.h:286

◆ DetectorSet() [2/3]

DetectorSet ( EDetector  det)
inline

Constructor for a set containig one detector ID.

Parameters
detThe ID of the detector.

Definition at line 190 of file Const.h.

190: m_bits(getBit(det)) {}
static uint16_t getBit(EDetector det)
Conversion of detector ID to bit pattern.
Definition: UnitConst.cc:246

◆ ~DetectorSet()

virtual ~DetectorSet ( )
inlinevirtual

Destructor.

Definition at line 195 of file Const.h.

195{};

◆ DetectorSet() [3/3]

DetectorSet ( uint16_t  bits)
inlineexplicitprivate

Constructor.

Parameters
bitsThe internal representation of the set as bit pattern.

Definition at line 269 of file Const.h.

269: m_bits(bits) {};

Member Function Documentation

◆ __str__()

std::string __str__ ( ) const

String for printing in python.

Definition at line 298 of file UnitConst.cc.

299{
300 std::string result = "<set: ";
301 const std::string detectorNames[] = {"invalidDetector", "PXD", "SVD", "CDC", "TOP", "ARICH", "ECL", "KLM", "IR", "TRG", "DAQ", "BEAST", "TEST"};
302 for (size_t index = 1; index <= Const::TEST; index++) {
303 if (contains(EDetector(index))) {
304 if (result.size() > 6) {
305 result += ",";
306 }
307 result += detectorNames[index];
308 }
309 }
310 result += ">";
311 return result;
312}
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:235
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42

◆ begin()

Beginning iterator.

Definition at line 209 of file UnitConst.cc.

210{
211 uint16_t setBit = 1;
212 while ((m_bits & setBit) == 0) {
213 setBit = setBit << 1;
214 if (setBit >= 0x1000)
215 return Const::DetectorSet::Iterator(0, m_bits, invalidDetector);
216 }
217 return Const::DetectorSet::Iterator(0, m_bits, setBit);
218}

◆ contains() [1/2]

bool contains ( const DetectorSet set) const
inline

Check whether this set contains another set.

Parameters
setThe other set of detector IDs.

Definition at line 235 of file Const.h.

235{return (m_bits & set.m_bits) == set.m_bits;}

◆ contains() [2/2]

bool contains ( const Iterator it) const
inline

Check whether this set contains detector specified by iterator.

Parameters
[in]itIterator.

Definition at line 241 of file Const.h.

242 {
243 return (m_bits & it.getSetBit()) != 0;
244 }

◆ end()

Ending iterator.

Definition at line 220 of file UnitConst.cc.

221{
222 return Const::DetectorSet::Iterator(0, m_bits, invalidDetector);
223}

◆ getBit()

unsigned short getBit ( Const::EDetector  det)
staticprivate

Conversion of detector ID to bit pattern.

Parameters
detThe detector ID.
Returns
The bit pattern representing the given detector ID.

Definition at line 246 of file UnitConst.cc.

247{
248 if (det == 0 || det > 0x100) {
249 B2ERROR("Const::DetectorSet::getBit() called for an invalid detector "
250 "identifier (possibly a subdetector):" << det);
251 return 0;
252 }
253 if (det > TEST) {
254 B2ERROR("Const::DetectorSet::getBit(): Invalid detector ID");
255 }
256 return (1 << (det - 1));
257}

◆ getDetector()

Const::EDetector getDetector ( uint16_t  bit)
staticprivate

Conversion of bit pattern to detector ID.

Parameters
bitThe bit pattern.
Returns
The detector ID corresponding to the given bit pattern.

Definition at line 259 of file UnitConst.cc.

260{
261 switch (bit) {
262 case 0x0001: return PXD;
263 case 0x0002: return SVD;
264 case 0x0004: return CDC;
265 case 0x0008: return TOP;
266 case 0x0010: return ARICH;
267 case 0x0020: return ECL;
268 case 0x0040: return KLM;
269 case 0x0080: return IR;
270 case 0x0100: return TRG;
271 case 0x0200: return DAQ;
272 case 0x0400: return BEAST;
273 case 0x0800: return TEST;
274 default: return invalidDetector;
275 }
276}

◆ getIndex()

int getIndex ( EDetector  det) const

Getter for the index of a given detector in this set.

Parameters
detThe detector ID.
Returns
Index of the detector ID in this set, or -1 if the detector ID is not in this set.

Definition at line 278 of file UnitConst.cc.

279{
280 unsigned short bit = getBit(det);
281 if ((m_bits & bit) == 0) return -1;
282 int index = 0;
283 for (unsigned short setBit = 1; setBit < bit; setBit *= 2) {
284 if ((m_bits & setBit) != 0) ++index;
285 }
286 return index;
287}

◆ operator!=()

bool operator!= ( const DetectorSet set) const
inline

Inequality operator.

Parameters
setThe other set of detector IDs.

Definition at line 229 of file Const.h.

229{return m_bits != set.m_bits;}

◆ operator+=()

DetectorSet & operator+= ( const DetectorSet set)
inline

Addition of another set to this one.

Parameters
setThe other set of detector IDs.

Definition at line 211 of file Const.h.

211{m_bits |= set.m_bits; return *this;}

◆ operator-=()

DetectorSet & operator-= ( const DetectorSet set)
inline

Subtraction of another set from this one.

Parameters
setThe other set of detector IDs.

Definition at line 217 of file Const.h.

217{m_bits &= ~set.m_bits; return *this;}

◆ operator==()

bool operator== ( const DetectorSet set) const
inline

Equality operator.

Parameters
setThe other set of detector IDs.

Definition at line 223 of file Const.h.

223{return m_bits == set.m_bits;}

◆ size()

size_t size ( ) const

Getter for number of detector IDs in this set.

Definition at line 289 of file UnitConst.cc.

290{
291 int size = 0;
292 for (unsigned short setBit = 1; setBit < 0x1000; setBit *= 2) {
293 if ((m_bits & setBit) != 0) ++size;
294 }
295 return size;
296}
size_t size() const
Getter for number of detector IDs in this set.
Definition: UnitConst.cc:289

Member Data Documentation

◆ m_bits

uint16_t m_bits
private

The internal representation of the set as bit pattern.

Definition at line 286 of file Const.h.


The documentation for this class was generated from the following files: