Belle II Software light-2503-ceres
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 containing 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 containing 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:245

◆ ~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 297 of file UnitConst.cc.

298{
299 std::string result = "<set: ";
300 const std::string detectorNames[] = {"invalidDetector", "PXD", "SVD", "CDC", "TOP", "ARICH", "ECL", "KLM", "IR", "TRG", "DAQ", "BEAST", "TEST"};
301 for (size_t index = 1; index <= Const::TEST; index++) {
302 if (contains(EDetector(index))) {
303 if (result.size() > 6) {
304 result += ",";
305 }
306 result += detectorNames[index];
307 }
308 }
309 result += ">";
310 return result;
311}
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 208 of file UnitConst.cc.

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

◆ 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 219 of file UnitConst.cc.

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

◆ 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 245 of file UnitConst.cc.

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

◆ 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 258 of file UnitConst.cc.

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

◆ 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 277 of file UnitConst.cc.

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

◆ 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 288 of file UnitConst.cc.

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

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: