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 : fieldName_(fieldName),
8 index_(index),
9 startBit_(startBit),
10 endBit_(endBit) {
11 // Create bit mask for the field.
12 bitMask_ = IDField::createBitMask(startBit, endBit);
13}
14
15const std::string& IDField::getFieldName() { return fieldName_; }
16
17unsigned IDField::getIndex() { return index_; }
18
19unsigned IDField::getStartBit() { return startBit_; }
20
21unsigned IDField::getEndBit() { return endBit_; }
22
23unsigned IDField::getBitMask() { return bitMask_; }
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 endBit_
The end bit of the field.
Definition IDField.h:99
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 startBit_
The start bit of the field.
Definition IDField.h:94
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
static unsigned createBitMask(unsigned startBit, unsigned endBit)
Utility for creating a bit mask from a start to end bit.
Definition IDField.cxx:25
unsigned bitMask_
The bit mask of the field.
Definition IDField.h:104
std::string fieldName_
The name of the field.
Definition IDField.h:84
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
unsigned getEndBit()
Get the end bit of the field.
Definition IDField.cxx:21