LDMX Software
PackedIndex.h
Go to the documentation of this file.
1
7#ifndef DETDESCR_PACKEDINDEX_H_
8#define DETDESCR_PACKEDINDEX_H_
9
10#include <stdint.h>
11
12namespace ldmx {
13
31template <unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
33 public:
48 PackedIndex(unsigned int v0, unsigned int v1, unsigned int v2 = 0,
49 unsigned int v3 = 0) {
50 index_ = v0 + v1 * m0 + v2 * m0 * m1 + v3 * m0 * m1 * m2;
51 }
52
54 PackedIndex(uint32_t value) : index_{value} {}
55
57 unsigned int field0() const { return index_ % m0; }
59 unsigned int field1() const { return (index_ / m0) % m1; }
61 unsigned int field2() const { return (index_ / (m0 * m1)) % m2; }
63 unsigned int field3() const { return (index_ / (m0 * m1 * m2)); }
64
66 uint32_t value() const { return index_; }
67
68 private:
70 uint32_t index_;
71
72}; // PackedIndex
73} // namespace ldmx
74
75#endif // DETDESCR_PACKEDINDEX_H_
A maximally-packed index of up to four different fields.
Definition PackedIndex.h:32
PackedIndex(unsigned int v0, unsigned int v1, unsigned int v2=0, unsigned int v3=0)
Constructor from field values Put our values into a single 32-bit integer.
Definition PackedIndex.h:48
unsigned int field3() const
Get the value of field 3.
Definition PackedIndex.h:63
unsigned int field2() const
Get the value of field 2.
Definition PackedIndex.h:61
unsigned int field0() const
Get the value of field 0.
Definition PackedIndex.h:57
unsigned int field1() const
Get the value of field 1.
Definition PackedIndex.h:59
uint32_t index_
The 32-bit integer that is storing our fields.
Definition PackedIndex.h:70
uint32_t value() const
Get the fully packed index.
Definition PackedIndex.h:66
PackedIndex(uint32_t value)
Constructor from index value.
Definition PackedIndex.h:54