LDMX Software
Public Member Functions | Private Attributes | List of all members
ldmx::PackedIndex< m0, m1, m2 > Class Template Reference

A maximally-packed index of up to four different fields. More...

#include <PackedIndex.h>

Public Member Functions

 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.
 
 PackedIndex (uint32_t value)
 Constructor from index value.
 
unsigned int field0 () const
 Get the value of field 0.
 
unsigned int field1 () const
 Get the value of field 1.
 
unsigned int field2 () const
 Get the value of field 2.
 
unsigned int field3 () const
 Get the value of field 3.
 
uint32_t value () const
 Get the fully packed index.
 

Private Attributes

uint32_t index_
 The 32-bit integer that is storing our fields.
 

Detailed Description

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
class ldmx::PackedIndex< m0, m1, m2 >

A maximally-packed index of up to four different fields.

We can pack an index with different fields by knowing each field's modulus or the number of different values the field can have.

For example, if a field has values 0, 1, 2, 3 then its modulus is four.

The maths underlying this packing also assumes that values start with 0 and count up.

Template Parameters

in] m0 modulus of field 0

Template Parameters

in] m1 modulus of field 1, optional

Template Parameters

in] m2 modulus of field 2, optional

Definition at line 32 of file PackedIndex.h.

Constructor & Destructor Documentation

◆ PackedIndex() [1/2]

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
ldmx::PackedIndex< m0, m1, m2 >::PackedIndex ( unsigned int  v0,
unsigned int  v1,
unsigned int  v2 = 0,
unsigned int  v3 = 0 
)
inline

Constructor from field values Put our values into a single 32-bit integer.

We are provided two to four values to pack.

Note
We do not check if the values are below the maxima defined by the template parameters.
Parameters
[in]v0value of field 0
[in]v1value of field 1
[in]v2value of field 2
[in]v3value of field 3

Definition at line 48 of file PackedIndex.h.

49 {
50 index_ = v0 + v1 * m0 + v2 * m0 * m1 + v3 * m0 * m1 * m2;
51 }
uint32_t index_
The 32-bit integer that is storing our fields.
Definition PackedIndex.h:70

References ldmx::PackedIndex< m0, m1, m2 >::index_.

◆ PackedIndex() [2/2]

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
ldmx::PackedIndex< m0, m1, m2 >::PackedIndex ( uint32_t  value)
inline

Constructor from index value.

Definition at line 54 of file PackedIndex.h.

54: index_{value} {}
uint32_t value() const
Get the fully packed index.
Definition PackedIndex.h:66

Member Function Documentation

◆ field0()

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
unsigned int ldmx::PackedIndex< m0, m1, m2 >::field0 ( ) const
inline

Get the value of field 0.

Definition at line 57 of file PackedIndex.h.

57{ return index_ % m0; }

References ldmx::PackedIndex< m0, m1, m2 >::index_.

◆ field1()

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
unsigned int ldmx::PackedIndex< m0, m1, m2 >::field1 ( ) const
inline

Get the value of field 1.

Definition at line 59 of file PackedIndex.h.

59{ return (index_ / m0) % m1; }

References ldmx::PackedIndex< m0, m1, m2 >::index_.

◆ field2()

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
unsigned int ldmx::PackedIndex< m0, m1, m2 >::field2 ( ) const
inline

Get the value of field 2.

Definition at line 61 of file PackedIndex.h.

61{ return (index_ / (m0 * m1)) % m2; }

References ldmx::PackedIndex< m0, m1, m2 >::index_.

◆ field3()

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
unsigned int ldmx::PackedIndex< m0, m1, m2 >::field3 ( ) const
inline

Get the value of field 3.

Definition at line 63 of file PackedIndex.h.

63{ return (index_ / (m0 * m1 * m2)); }

References ldmx::PackedIndex< m0, m1, m2 >::index_.

◆ value()

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
uint32_t ldmx::PackedIndex< m0, m1, m2 >::value ( ) const
inline

Get the fully packed index.

Definition at line 66 of file PackedIndex.h.

66{ return index_; }

References ldmx::PackedIndex< m0, m1, m2 >::index_.

Member Data Documentation

◆ index_

template<unsigned int m0, unsigned int m1 = 0, unsigned int m2 = 0>
uint32_t ldmx::PackedIndex< m0, m1, m2 >::index_
private

The documentation for this class was generated from the following file: