Belle II Software light-2406-ragdoll
Const::RestrictedDetectorSet< ASetType > Class Template Reference

A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs. More...

#include <Const.h>

Inheritance diagram for Const::RestrictedDetectorSet< ASetType >:
Collaboration diagram for Const::RestrictedDetectorSet< ASetType >:

Public Member Functions

 RestrictedDetectorSet ()
 Exception that is thrown if there is the attempt to add an invalid detector ID to a restricted set.
 
 RestrictedDetectorSet (const DetectorSet &set)
 (Copy) constructor.
 
 RestrictedDetectorSet (EDetector det)
 Constructor for a set containg one detector ID.
 
RestrictedDetectorSetoperator+= (const DetectorSet &set)
 Addition of another set to this one.
 
Iterator begin () const
 Beginning iterator.
 
Iterator end () const
 Ending iterator.
 
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.
 

Static Public Member Functions

static DetectorSet set ()
 Accessor for the set of valid detector IDs.
 

Private Member Functions

void checkSet () const
 Check of set validity.
 
 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

template<class ASetType>
class Belle2::Const::RestrictedDetectorSet< ASetType >

A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.

Definition at line 296 of file Const.h.

Constructor & Destructor Documentation

◆ RestrictedDetectorSet() [1/3]

Exception that is thrown if there is the attempt to add an invalid detector ID to a restricted set.

Default constructor.

Definition at line 307 of file Const.h.

307: DetectorSet() {}
DetectorSet()
Default constructor.
Definition: Const.h:179

◆ RestrictedDetectorSet() [2/3]

RestrictedDetectorSet ( const DetectorSet set)
inline

(Copy) constructor.

Parameters
setThe copied set of detector IDs.

Definition at line 314 of file Const.h.

static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:333
void checkSet() const
Check of set validity.
Definition: Const.h:340

◆ RestrictedDetectorSet() [3/3]

Constructor for a set containg one detector ID.

Parameters
detThe detector ID.

Definition at line 321 of file Const.h.

321: DetectorSet(det) {checkSet();}

Member Function Documentation

◆ __str__()

std::string __str__ ( ) const
inherited

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()

Const::DetectorSet::Iterator begin ( ) const
inherited

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}
uint16_t m_bits
The internal representation of the set as bit pattern.
Definition: Const.h:286

◆ checkSet()

void checkSet ( ) const
inlineprivate

Check of set validity.

If an invalid detector ID is found an exception is thrown.

Definition at line 340 of file Const.h.

340{if (!ASetType::set().contains(*this)) throw InvalidDetectorTypeError();}

◆ contains() [1/2]

bool contains ( const DetectorSet set) const
inlineinherited

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
inlineinherited

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()

Const::DetectorSet::Iterator end ( ) const
inherited

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)
staticprivateinherited

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)
staticprivateinherited

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
inherited

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}
static uint16_t getBit(EDetector det)
Conversion of detector ID to bit pattern.
Definition: UnitConst.cc:246

◆ operator!=()

bool operator!= ( const DetectorSet set) const
inlineinherited

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+=()

RestrictedDetectorSet & operator+= ( const DetectorSet set)
inline

Addition of another set to this one.

Parameters
setThe other set of detector IDs.

Definition at line 327 of file Const.h.

327{DetectorSet::operator +=(set); checkSet(); return *this;}
DetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:211

◆ operator-=()

DetectorSet & operator-= ( const DetectorSet set)
inlineinherited

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
inlineinherited

Equality operator.

Parameters
setThe other set of detector IDs.

Definition at line 223 of file Const.h.

223{return m_bits == set.m_bits;}

◆ set()

static DetectorSet set ( )
inlinestatic

Accessor for the set of valid detector IDs.

Returns
The set of valid detector IDs.

Definition at line 333 of file Const.h.

333{return ASetType::set();}

◆ size()

size_t size ( ) const
inherited

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
privateinherited

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