Belle II Software development
DataArray Class Reference

Helper class for getting data words from a finesse buffer Keeps checksum counter for each extracted data word and calculates tcp checksum on request. More...

#include <TOPUnpackerModule.h>

Public Member Functions

 DataArray (const int *data, int size, bool swap=false)
 Constructor.
 
int getWord ()
 Returns consecutive data word Updates internal checksum counter for each extracted word.
 
int peekWord ()
 Returns next data word without incrementing the memory pointer and without modifying the checksum counter.
 
int getLastWord ()
 Returns last data word.
 
unsigned int getIndex () const
 Returns index of last returned data word.
 
int getRemainingWords () const
 Returns number of remaining words in the buffer.
 
void resetChecksum ()
 Resets internal checksum counter.
 
unsigned int foldChecksum ()
 Performs folding of carry bits into checksum until only 16 LSBs are populated.
 
bool validateChecksum ()
 Validates current checksum counter status.
 

Private Member Functions

int swap32 (int x)
 Swap bytes of a 32-bit integer.
 

Private Attributes

int m_size = 0
 buffer size
 
const int * m_data = 0
 buffer data
 
int m_i = 0
 index
 
bool m_swap = false
 if true, swap bytes
 
unsigned int m_checksumCounter
 check sum counter
 

Detailed Description

Helper class for getting data words from a finesse buffer Keeps checksum counter for each extracted data word and calculates tcp checksum on request.

Definition at line 38 of file TOPUnpackerModule.h.

Constructor & Destructor Documentation

◆ DataArray()

DataArray ( const int *  data,
int  size,
bool  swap = false 
)
inline

Constructor.

Parameters
datapointer to finesse buffer (pointer must be valid)
sizebuffer size
swapif set to true, swap bytes

Definition at line 48 of file TOPUnpackerModule.h.

49 {
50 m_data = data;
51 m_size = size;
52 m_i = -1;
53 m_swap = swap;
55 }
const int * m_data
buffer data
bool m_swap
if true, swap bytes
unsigned int m_checksumCounter
check sum counter

Member Function Documentation

◆ foldChecksum()

unsigned int foldChecksum ( )
inline

Performs folding of carry bits into checksum until only 16 LSBs are populated.

Returns
reduced checksum counter

Definition at line 122 of file TOPUnpackerModule.h.

123 {
124 unsigned int chk = m_checksumCounter;
125 while ((chk >> 16) > 0) {
126 chk = (chk & 0xFFFF) + (chk >> 16);
127 }
128 return chk;
129 };

◆ getIndex()

unsigned int getIndex ( ) const
inline

Returns index of last returned data word.

Returns
index

Definition at line 104 of file TOPUnpackerModule.h.

104{return m_i;}

◆ getLastWord()

int getLastWord ( )
inline

Returns last data word.

Returns
last data word

Definition at line 93 of file TOPUnpackerModule.h.

94 {
95 if (m_size <= 0) return 0;
96 if (m_swap) return swap32(m_data[m_size - 1]);
97 return m_data[m_size - 1];
98 }
int swap32(int x)
Swap bytes of a 32-bit integer.

◆ getRemainingWords()

int getRemainingWords ( ) const
inline

Returns number of remaining words in the buffer.

Returns
number of remaining words

Definition at line 110 of file TOPUnpackerModule.h.

110{return m_size - m_i - 1;}

◆ getWord()

int getWord ( )
inline

Returns consecutive data word Updates internal checksum counter for each extracted word.

Verify checksum using DataArray::validateChecksum()

Returns
data word

Definition at line 63 of file TOPUnpackerModule.h.

64 {
65 m_i++;
66 if (m_i < m_size) {
67 m_checksumCounter += (m_data[m_i] & 0xFFFF) + ((m_data[m_i] >> 16) & 0xFFFF);
68 if (m_swap) return swap32(m_data[m_i]);
69 return m_data[m_i];
70 }
71 B2ERROR("Bug in data format: DataArray - index out of range");
72 return 0;
73 }

◆ peekWord()

int peekWord ( )
inline

Returns next data word without incrementing the memory pointer and without modifying the checksum counter.

Returns
data word

Definition at line 79 of file TOPUnpackerModule.h.

80 {
81 if (m_i + 1 < m_size) {
82 if (m_swap) return swap32(m_data[m_i + 1]);
83 return m_data[m_i + 1];
84 }
85
86 return 0;
87 }

◆ resetChecksum()

void resetChecksum ( )
inline

Resets internal checksum counter.

Call at the beginning of each new block that is checksummed.

Definition at line 116 of file TOPUnpackerModule.h.

◆ swap32()

int swap32 ( int  x)
inlineprivate

Swap bytes of a 32-bit integer.

Definition at line 146 of file TOPUnpackerModule.h.

147 {
148 return (((x << 24) & 0xFF000000) |
149 ((x << 8) & 0x00FF0000) |
150 ((x >> 8) & 0x0000FF00) |
151 ((x >> 24) & 0x000000FF));
152 }

◆ validateChecksum()

bool validateChecksum ( )
inline

Validates current checksum counter status.

Call at the end of each block that is checksummed.

Returns
checksum status, true if checksum is correct.

Definition at line 136 of file TOPUnpackerModule.h.

137 {
138 return (foldChecksum() == 0xFFFF);
139 }
unsigned int foldChecksum()
Performs folding of carry bits into checksum until only 16 LSBs are populated.

Member Data Documentation

◆ m_checksumCounter

unsigned int m_checksumCounter
private

check sum counter

Definition at line 158 of file TOPUnpackerModule.h.

◆ m_data

const int* m_data = 0
private

buffer data

Definition at line 155 of file TOPUnpackerModule.h.

◆ m_i

int m_i = 0
private

index

Definition at line 156 of file TOPUnpackerModule.h.

◆ m_size

int m_size = 0
private

buffer size

Definition at line 154 of file TOPUnpackerModule.h.

◆ m_swap

bool m_swap = false
private

if true, swap bytes

Definition at line 157 of file TOPUnpackerModule.h.


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