Belle II Software development
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:
Const::RestrictedDetectorSet< ASetType >

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:243

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

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

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

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

218{
219 return Const::DetectorSet::Iterator(0, m_bits, invalidDetector);
220}

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

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

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

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

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

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

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

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

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: