Belle II Software development
RawPXD Class Reference

The Raw PXD class. More...

#include <RawPXD.h>

Inheritance diagram for RawPXD:

Public Member Functions

 RawPXD ()
 Default constructor.
 
 RawPXD (int *, int)
 Constructor using existing pointer to raw data buffer which needs to be copied
 
 RawPXD (const std::vector< unsigned int > &header, const std::vector< std::vector< unsigned char > > &payload)
 Constructor using existing data which needs to be copied to a new raw data buffer, only used by PXDPacker.
 
virtual ~RawPXD ()
 Destructor.
 
virtual int size () const
 get size of buffer in 32 Bit words
 
virtual int * data (void)
 get pointer to data
 
std::string getInfoHTML () const
 Return a short summary of this object's contents in HTML format.
 

Static Private Member Functions

static unsigned int endian_swap (unsigned int x)
 Endian swap a int32.
 

Private Attributes

int m_nwords
 Number of (32bit) Words stored in the buffer.
 
int * m_buffer
 Raw dump of ONSEN data. buffer of size m_nwords (32bit int)
 

Detailed Description

The Raw PXD class.

This class stores the RAW data received from the ONSEN system. This data is then decoded by the pxdUnpacker module. For system simulation, pxdPacker writes out in this objects.

Definition at line 27 of file RawPXD.h.

Constructor & Destructor Documentation

◆ RawPXD() [1/3]

RawPXD ( )

Default constructor.

Definition at line 16 of file RawPXD.cc.

16 : m_nwords(0), m_buffer(NULL)
17{
18}
int * m_buffer
Raw dump of ONSEN data. buffer of size m_nwords (32bit int)
Definition: RawPXD.h:60
int m_nwords
Number of (32bit) Words stored in the buffer.
Definition: RawPXD.h:58

◆ RawPXD() [2/3]

RawPXD ( int *  buffer,
int  length_in_Bytes 
)

Constructor using existing pointer to raw data buffer which needs to be copied

Definition at line 20 of file RawPXD.cc.

21 : m_nwords(0), m_buffer(NULL)
22{
23 m_nwords = (length_in_Bytes + 3) / 4;
24 m_buffer = new int[m_nwords];
25 memcpy(m_buffer, buffer, m_nwords * sizeof(int));
26}

◆ RawPXD() [3/3]

RawPXD ( const std::vector< unsigned int > &  header,
const std::vector< std::vector< unsigned char > > &  payload 
)

Constructor using existing data which needs to be copied to a new raw data buffer, only used by PXDPacker.

Definition at line 37 of file RawPXD.cc.

38 : m_nwords(0), m_buffer(NULL)
39{
40 // This function is only used by the PXDPacker in simulations. Does not make sense for other cases
41 // Now create header from payload , this can be done with less loops, but speed is not the issue here
42 int nr_frames = header.size();
43 int payload_size = 0; // in 32 bit words
44 for (auto& it : header) {
45 payload_size += (it + 3) / 4; // in 32 bit word, rounded up
46 }
47
48 m_nwords = 2 + nr_frames + payload_size; // 321 bit words
49
50 m_buffer = new int[m_nwords];
51
52 B2DEBUG(20, "RawPXD Frames " << header.size() << " Data " << payload_size << " (32 bitword)");
53
54 // now we know the actual payload length
55 int offset = 0;
56 m_buffer[offset++] = 0xBEBAFECA ; // 0xCAFEBABEu;
57 m_buffer[offset++] = endian_swap(nr_frames);
58 // and now append the frame length table
59 for (auto& it : payload) {
60 m_buffer[offset++] = endian_swap(it.size()); // in chars, rounded up to 32 bit boundary
61 }
62 // and now append the actual paylaod data
63 unsigned char* data = (unsigned char*) &m_buffer[offset];
64 for (auto& it : payload) {
65 memcpy(data, it.data(), it.size());
66 data += (it.size() + 3) & 0xFFFFFFFC; // in chars, rounded up to 32 bit boundary
67 }
68 // done
69}
static unsigned int endian_swap(unsigned int x)
Endian swap a int32.
Definition: RawPXD.cc:28
virtual int * data(void)
get pointer to data
Definition: RawPXD.cc:81

◆ ~RawPXD()

~RawPXD ( )
virtual

Destructor.

Definition at line 71 of file RawPXD.cc.

72{
73 if (m_buffer != NULL) delete[] m_buffer;
74}

Member Function Documentation

◆ data()

int * data ( void  )
virtual

get pointer to data

Definition at line 81 of file RawPXD.cc.

82{
83 int* ptr = &m_buffer[0];
84 return ptr;
85}

◆ endian_swap()

unsigned int endian_swap ( unsigned int  x)
staticprivate

Endian swap a int32.

Definition at line 28 of file RawPXD.cc.

29{
30 x = (x >> 24) |
31 ((x << 8) & 0x00FF0000) |
32 ((x >> 8) & 0x0000FF00) |
33 (x << 24);
34 return x;
35}

◆ getInfoHTML()

std::string getInfoHTML ( ) const

Return a short summary of this object's contents in HTML format.

Definition at line 87 of file RawPXD.cc.

88{
89 std::string s;
90 if (m_nwords >= 2)
91 s += "Frames: " + std::to_string(endian_swap(m_buffer[1])) + ", ";
92
93 s += "Size (32bit words): " + std::to_string(m_nwords) + "<br /><br />";
95 return s;
96}
std::string getHexDump(const int *buf, int length)
Create hexdump of given buffer.
Definition: HTML.cc:121

◆ size()

int size ( ) const
virtual

get size of buffer in 32 Bit words

Definition at line 76 of file RawPXD.cc.

77{
78 return m_nwords;
79}

Member Data Documentation

◆ m_buffer

int* m_buffer
private

Raw dump of ONSEN data. buffer of size m_nwords (32bit int)

Definition at line 60 of file RawPXD.h.

◆ m_nwords

int m_nwords
private

Number of (32bit) Words stored in the buffer.

There might be unsused bytes in the last word.

Definition at line 58 of file RawPXD.h.


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