LDMX Software
IDField.cxx
1#include "DetDescr/IDField.h"
2
3namespace ldmx {
4
5IDField::IDField(std::string fieldName, unsigned index, unsigned startBit,
6 unsigned endBit)
7 : field_name_(fieldName),
8 index_(index),
9 start_bit_(startBit),
10 end_bit_(endBit) {
11 // Create bit mask for the field.
12 bit_mask_ = IDField::createBitMask(startBit, endBit);
13}
14
15const std::string& IDField::getFieldName() { return field_name_; }
16
17unsigned IDField::getIndex() { return index_; }
18
19unsigned IDField::getStartBit() { return start_bit_; }
20
21unsigned IDField::getEndBit() { return end_bit_; }
22
23unsigned IDField::getBitMask() { return bit_mask_; }
24
25unsigned IDField::createBitMask(unsigned startBit, unsigned endBit) {
26 unsigned mask = 0;
27 for (int i = startBit; i <= endBit; i++) {
28 mask |= 1 << i;
29 }
30 return mask;
31}
32
33unsigned IDField::countOnes(unsigned mask) {
34 unsigned rv = 0;
35 for (int i = 0; i < 32; i++)
36 if (mask & (1 << i)) rv++;
37 return rv;
38}
39
40} // namespace ldmx
unsigned getStartBit()
Get the start bit of the field.
Definition IDField.cxx:19
static unsigned countOnes(unsigned mask)
Utility for counting number of 1 in a mask.
Definition IDField.cxx:33
unsigned bit_mask_
The bit mask of the field.
Definition IDField.h:104
unsigned getIndex()
Get the index of the field.
Definition IDField.cxx:17
IDField(std::string name, unsigned index, unsigned startBit, unsigned endBit)
Class constructor.
Definition IDField.cxx:5
unsigned start_bit_
The start bit of the field.
Definition IDField.h:94
static unsigned createBitMask(unsigned startBit, unsigned endBit)
Utility for creating a bit mask from a start to end bit.
Definition IDField.cxx:25
unsigned end_bit_
The end bit of the field.
Definition IDField.h:99
unsigned index_
The index of the field.
Definition IDField.h:89
unsigned getBitMask()
Get a bit mask for this field.
Definition IDField.cxx:23
const std::string & getFieldName()
Get the name of the field.
Definition IDField.cxx:15
std::string field_name_
The name of the field.
Definition IDField.h:84
unsigned getEndBit()
Get the end bit of the field.
Definition IDField.cxx:21