DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dd4hep::DDSegmentation::BitFieldCoder Class Reference

Helper class for decoding and encoding a bit field of 64bits for convenient declaration. More...

#include <BitFieldCoder.h>

Public Types

typedef std::map< std::string, unsigned int > IndexMap
 

Public Member Functions

 BitFieldCoder ()=default
 Default constructor. More...
 
 BitFieldCoder (const BitFieldCoder &)=default
 Copy constructor. More...
 
 BitFieldCoder (BitFieldCoder &&)=default
 Move constructor. More...
 
 ~BitFieldCoder ()=default
 Default destructor. More...
 
BitFieldCoderoperator= (const BitFieldCoder &)=default
 Assignment operator. More...
 
 BitFieldCoder (const std::string &initString)
 
FieldID get (CellID bitfield, size_t idx) const
 
FieldID get (CellID bitfield, const std::string &name) const
 
void set (CellID &bitfield, size_t idx, FieldID value) const
 
void set (CellID &bitfield, const std::string &name, FieldID value) const
 
unsigned highestBit () const
 
size_t size () const
 
size_t index (const std::string &name) const
 
const BitFieldElementoperator[] (const std::string &name) const
 
const BitFieldElementoperator[] (unsigned idx) const
 
std::string fieldDescription () const
 
std::string valueString (CellID bitfield) const
 
const std::vector< BitFieldElement > & fields () const
 
CellID mask () const
 

Static Public Member Functions

static CellID toLong (unsigned low_Word, unsigned high_Word)
 
static unsigned lowWord (CellID bitfield)
 
static unsigned highWord (CellID bitfield)
 

Protected Member Functions

void addField (const std::string &name, unsigned offset, int width)
 
void init (const std::string &initString)
 

Protected Attributes

std::vector< BitFieldElement_fields {}
 
IndexMap _map {}
 
CellID _joined {}
 

Detailed Description

Helper class for decoding and encoding a bit field of 64bits for convenient declaration.

and manipulation of sub fields of various widths.
This is a thread safe re-implementation of the functionality in the deprected BitField64.

Example:
BitFieldCoder bc("layer:7,system:-3,barrel:3,theta:32:11,phi:11" ) ;
bc.set( field, "layer" , 123 );
bc.set( field, "system" , -4 );
bc.set( field, "barrel" , 7 );
bc.set( field, "theta" , 180 );
bc.set( field, "phi" , 270 );
...
int theta = bc.get( field, "theta" ) ;
...
unsigned phiIndex = bc.index("phi") ;
int phi = bc.get( field, phiIndex ) ;

Author
F.Gaede, DESY
Date
2017-09

Definition at line 114 of file BitFieldCoder.h.

Member Typedef Documentation

◆ IndexMap

typedef std::map<std::string, unsigned int> dd4hep::DDSegmentation::BitFieldCoder::IndexMap

Definition at line 116 of file BitFieldCoder.h.

Constructor & Destructor Documentation

◆ BitFieldCoder() [1/4]

dd4hep::DDSegmentation::BitFieldCoder::BitFieldCoder ( )
default

Default constructor.

◆ BitFieldCoder() [2/4]

dd4hep::DDSegmentation::BitFieldCoder::BitFieldCoder ( const BitFieldCoder )
default

Copy constructor.

◆ BitFieldCoder() [3/4]

dd4hep::DDSegmentation::BitFieldCoder::BitFieldCoder ( BitFieldCoder &&  )
default

Move constructor.

◆ ~BitFieldCoder()

dd4hep::DDSegmentation::BitFieldCoder::~BitFieldCoder ( )
default

Default destructor.

◆ BitFieldCoder() [4/4]

dd4hep::DDSegmentation::BitFieldCoder::BitFieldCoder ( const std::string &  initString)
inline

The c'tor takes an initialization string of the form:
<fieldDesc>[,<fieldDesc>...]
fieldDesc = name:[start]:[-]length
where:
name: The name of the field
start: The start bit of the field. If omitted assumed to start immediately following previous field, or at the least significant bit if the first field.
length: The number of bits in the field. If preceeded by '-' the field is signed, otherwise unsigned.
Bit numbering is from the least significant bit (bit 0) to the most significant (bit 63).
Example: "layer:7,system:-3,barrel:3,theta:32:11,phi:11"

Definition at line 145 of file BitFieldCoder.h.

Member Function Documentation

◆ addField()

void dd4hep::DDSegmentation::BitFieldCoder::addField ( const std::string &  name,
unsigned  offset,
int  width 
)
protected

Add an additional field to the list

Definition at line 144 of file BitFieldCoder.cpp.

◆ fieldDescription()

std::string dd4hep::DDSegmentation::BitFieldCoder::fieldDescription ( ) const

Return a valid description string of all fields

Definition at line 123 of file BitFieldCoder.cpp.

◆ fields()

const std::vector<BitFieldElement>& dd4hep::DDSegmentation::BitFieldCoder::fields ( ) const
inline

Definition at line 218 of file BitFieldCoder.h.

◆ get() [1/2]

FieldID dd4hep::DDSegmentation::BitFieldCoder::get ( CellID  bitfield,
const std::string &  name 
) const
inline

Access to field through name .

Definition at line 171 of file BitFieldCoder.h.

◆ get() [2/2]

FieldID dd4hep::DDSegmentation::BitFieldCoder::get ( CellID  bitfield,
size_t  idx 
) const
inline

get value of sub-field specified by index

Definition at line 165 of file BitFieldCoder.h.

◆ highestBit()

unsigned dd4hep::DDSegmentation::BitFieldCoder::highestBit ( ) const

Highest bit used in fields [0-63]

Definition at line 96 of file BitFieldCoder.cpp.

◆ highWord()

static unsigned dd4hep::DDSegmentation::BitFieldCoder::highWord ( CellID  bitfield)
inlinestatic

The high word, bits 32-63

Definition at line 161 of file BitFieldCoder.h.

◆ index()

size_t dd4hep::DDSegmentation::BitFieldCoder::index ( const std::string &  name) const

Index for field named 'name'

Definition at line 84 of file BitFieldCoder.cpp.

◆ init()

void dd4hep::DDSegmentation::BitFieldCoder::init ( const std::string &  initString)
protected

Decode the initialization string as described in the constructor.

See also
BitFieldCoder( const std::string& initString )

Definition at line 166 of file BitFieldCoder.cpp.

◆ lowWord()

static unsigned dd4hep::DDSegmentation::BitFieldCoder::lowWord ( CellID  bitfield)
inlinestatic

The low word, bits 0-31

Definition at line 157 of file BitFieldCoder.h.

◆ mask()

CellID dd4hep::DDSegmentation::BitFieldCoder::mask ( ) const
inline

the mask of all the bits used in the description

Definition at line 223 of file BitFieldCoder.h.

◆ operator=()

BitFieldCoder& dd4hep::DDSegmentation::BitFieldCoder::operator= ( const BitFieldCoder )
default

Assignment operator.

◆ operator[]() [1/2]

const BitFieldElement& dd4hep::DDSegmentation::BitFieldCoder::operator[] ( const std::string &  name) const
inline

Const Access to field through name .

Definition at line 200 of file BitFieldCoder.h.

◆ operator[]() [2/2]

const BitFieldElement& dd4hep::DDSegmentation::BitFieldCoder::operator[] ( unsigned  idx) const
inline

Const Access to field through index .

Definition at line 206 of file BitFieldCoder.h.

◆ set() [1/2]

void dd4hep::DDSegmentation::BitFieldCoder::set ( CellID bitfield,
const std::string &  name,
FieldID  value 
) const
inline

Access to field through name .

Definition at line 183 of file BitFieldCoder.h.

◆ set() [2/2]

void dd4hep::DDSegmentation::BitFieldCoder::set ( CellID bitfield,
size_t  idx,
FieldID  value 
) const
inline

set value of sub-field specified by index

Definition at line 177 of file BitFieldCoder.h.

◆ size()

size_t dd4hep::DDSegmentation::BitFieldCoder::size ( ) const
inline

Number of values

Definition at line 192 of file BitFieldCoder.h.

◆ toLong()

static CellID dd4hep::DDSegmentation::BitFieldCoder::toLong ( unsigned  low_Word,
unsigned  high_Word 
)
inlinestatic

return a new 64bit value given as high and low 32bit words.

Definition at line 151 of file BitFieldCoder.h.

◆ valueString()

std::string dd4hep::DDSegmentation::BitFieldCoder::valueString ( CellID  bitfield) const

Return a string with a comma separated list of the current sub field values

Definition at line 109 of file BitFieldCoder.cpp.

Member Data Documentation

◆ _fields

std::vector<BitFieldElement> dd4hep::DDSegmentation::BitFieldCoder::_fields {}
protected

Definition at line 238 of file BitFieldCoder.h.

◆ _joined

CellID dd4hep::DDSegmentation::BitFieldCoder::_joined {}
protected

Definition at line 240 of file BitFieldCoder.h.

◆ _map

IndexMap dd4hep::DDSegmentation::BitFieldCoder::_map {}
protected

Definition at line 239 of file BitFieldCoder.h.


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