Belle II Software development
ROIpayload Class Reference

ROIpayload TODO: Better explanation, Is there a reason to inherit from TObject and not Relationsobject here? This Object contains a binary blob which is send as whole from the HLT Roi Sender output node to the ONSEN system, containing the trigger decision and the Region od Interest (ROI) for data selection on the PXD modules See Data format definitions [BELLE2-NOTE-TE-2016-009] on https://docs.belle2.org/. More...

#include <ROIpayload.h>

Inheritance diagram for ROIpayload:

Public Types

using ubig32_t = boost::endian::big_uint32_t
 Shorthand for 32-bit integer stored in big-endian format.
 

Public Member Functions

 ROIpayload (int rois=0)
 Default constructor.
 
virtual ~ROIpayload ()
 destructor.
 
void setPayloadLength (int length)
 transient value
 
void setPayloadLength ()
 set payload length
 
void setHeader (bool Accepted, bool SendAll, bool SendROIs)
 set header
 
void setTriggerNumber (unsigned long int triggerNumber)
 set trigger number
 
void setRunSubrunExpNumber (int run, int subrun, int exp)
 set run/ subrun/exp number
 
void addROIraw (unsigned long int roiraw)
 add a ROIrawID
 
void setCRC ()
 set CRC
 
int getPacketLengthByte ()
 get packet length in bytes
 
int getLength ()
 get packet length
 
int * getRootdata ()
 get pointer to the data packet
 
void init (int length)
 initializer
 
int getNrROIs () const
 Get the nr of ROIs.
 
int getDHHID (int j) const
 Return DHH ID of ROI j.
 
int getMinVid (int j) const
 Return MinVid (Row 1) of ROI j.
 
int getMaxVid (int j) const
 Return MaxVid (Row 2) of ROI j.
 
int getMinUid (int j) const
 Return MinUid (Col 1) of ROI j.
 
int getMaxUid (int j) const
 Return MaxUid (Col 2) of ROI j.
 
int getType (int j) const
 Return Type (Datcon or HLT) of ROI j.
 

Public Attributes

int m_packetLengthByte = 0
 packet length in byte
 
int m_length
 packet length
 
int * m_rootdata
 pointer to data packet of m_length words
 
int m_index
 transient index
 
uint32_t * m_data32
 transient value
 
ROIrawID::baseTypem_data64
 transient value
 

Private Types

enum  {
  OFFSET_MAGIC = 0 ,
  OFFSET_LENGTH = 1 ,
  OFFSET_HEADER = 2 ,
  OFFSET_TRIGNR = 3 ,
  OFFSET_RUNNR = 4 ,
  OFFSET_ROIS = 5
}
 
enum  {
  HEADER_SIZE_WO_LENGTH = 3 ,
  HEADER_SIZE_WITH_LENGTH = 5 ,
  HEADER_SIZE_WITH_LENGTH_AND_CRC = 6
}
 

Detailed Description

ROIpayload TODO: Better explanation, Is there a reason to inherit from TObject and not Relationsobject here? This Object contains a binary blob which is send as whole from the HLT Roi Sender output node to the ONSEN system, containing the trigger decision and the Region od Interest (ROI) for data selection on the PXD modules See Data format definitions [BELLE2-NOTE-TE-2016-009] on https://docs.belle2.org/.

Warning: The class does not allow to be updated in data store! (BII-3191) -> a module might corrupt entries in the data store if a previous ROIpayload is already in the DataStore A complete rewrite of gthe class might be needed for that. For now, you have to check that there is no object in data store before, and raise a FATAL if so.

Definition at line 35 of file ROIpayload.h.

Member Typedef Documentation

◆ ubig32_t

using ubig32_t = boost::endian::big_uint32_t

Shorthand for 32-bit integer stored in big-endian format.

Definition at line 41 of file ROIpayload.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Definition at line 36 of file ROIpayload.h.

36{ OFFSET_MAGIC = 0, OFFSET_LENGTH = 1, OFFSET_HEADER = 2, OFFSET_TRIGNR = 3, OFFSET_RUNNR = 4, OFFSET_ROIS = 5};

◆ anonymous enum

anonymous enum
private

Definition at line 37 of file ROIpayload.h.

37{ HEADER_SIZE_WO_LENGTH = 3, HEADER_SIZE_WITH_LENGTH = 5, HEADER_SIZE_WITH_LENGTH_AND_CRC = 6};

Constructor & Destructor Documentation

◆ ROIpayload()

ROIpayload ( int  rois = 0)
explicit

Default constructor.

Definition at line 20 of file ROIpayload.cc.

21{
22 init(HEADER_SIZE_WITH_LENGTH + 2 * rois + 1); // HEADER + 2*ROIS + CHECKSUM
23};
void init(int length)
initializer
Definition: ROIpayload.cc:25

◆ ~ROIpayload()

virtual ~ROIpayload ( )
inlinevirtual

destructor.

Definition at line 50 of file ROIpayload.h.

50{ delete[] m_rootdata; };
int * m_rootdata
pointer to data packet of m_length words
Definition: ROIpayload.h:55

Member Function Documentation

◆ addROIraw()

void addROIraw ( unsigned long int  roiraw)

add a ROIrawID

Definition at line 82 of file ROIpayload.cc.

83{
84 if ((int*)(m_data64 + m_index) >= m_rootdata + m_length) {
85 B2ERROR("Adding too many ROIs to the ROIpayload." << std::endl <<
86 "Something really fishy is going on");
87 return;
88 }
89 m_data64[m_index++] = roiraw;
90}
int m_length
packet length
Definition: ROIpayload.h:53
int m_index
transient index
Definition: ROIpayload.h:58
ROIrawID::baseType * m_data64
transient value
Definition: ROIpayload.h:62

◆ getDHHID()

int getDHHID ( int  j) const
inline

Return DHH ID of ROI j.

Parameters
jIndex of ROI
Returns
DHH ID

Definition at line 95 of file ROIpayload.h.

96 {
97 if (j < 0 || j >= getNrROIs()) return -1;
98 return (((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH + 2 * j] & 0x3F0) >> 4; // & 0x3F0
99 }
int getNrROIs() const
Get the nr of ROIs.
Definition: ROIpayload.h:86

◆ getLength()

int getLength ( )
inline

get packet length

Definition at line 77 of file ROIpayload.h.

◆ getMaxUid()

int getMaxUid ( int  j) const
inline

Return MaxUid (Col 2) of ROI j.

Parameters
jIndex of ROI
Returns
MaxUid

Definition at line 136 of file ROIpayload.h.

137 {
138 if (j < 0 || j >= getNrROIs()) return -1;
139 return (((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH + 2 * j + 1]) & 0xFF;
140 }

◆ getMaxVid()

int getMaxVid ( int  j) const
inline

Return MaxVid (Row 2) of ROI j.

Parameters
jIndex of ROI
Returns
MaxVid

Definition at line 116 of file ROIpayload.h.

117 {
118 if (j < 0 || j >= getNrROIs()) return -1;
119 return (((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH + 2 * j + 1] & 0x3FF00) >> 8;
120 }

◆ getMinUid()

int getMinUid ( int  j) const
inline

Return MinUid (Col 1) of ROI j.

Parameters
jIndex of ROI
Returns
MinUid

Definition at line 126 of file ROIpayload.h.

127 {
128 if (j < 0 || j >= getNrROIs()) return -1;
129 return (((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH + 2 * j + 1] & 0x03FC0000) >> 18;
130 }

◆ getMinVid()

int getMinVid ( int  j) const
inline

Return MinVid (Row 1) of ROI j.

Parameters
jIndex of ROI
Returns
MinVid

Definition at line 105 of file ROIpayload.h.

106 {
107 if (j < 0 || j >= getNrROIs()) return -1;
108 return ((((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH + 2 * j] & 0xF) << 6) | ((((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH +
109 2 * j + 1] & 0xFC000000) >> 26) ;
110 }

◆ getNrROIs()

int getNrROIs ( ) const
inline

Get the nr of ROIs.

Returns
Nr of ROIs.

Definition at line 86 of file ROIpayload.h.

87 {
88 return (m_length - HEADER_SIZE_WITH_LENGTH_AND_CRC) / 2; // only minus checksum
89 }

◆ getPacketLengthByte()

int getPacketLengthByte ( )
inline

get packet length in bytes

Definition at line 76 of file ROIpayload.h.

◆ getRootdata()

int * getRootdata ( )
inline

get pointer to the data packet

Definition at line 79 of file ROIpayload.h.

79{return m_rootdata;} //[m_length]

◆ getType()

int getType ( int  j) const
inline

Return Type (Datcon or HLT) of ROI j.

Parameters
jIndex of ROI
Returns
Type of Roi

Definition at line 146 of file ROIpayload.h.

147 {
148 if (j < 0 || j >= getNrROIs()) return -1;
149 return (((ubig32_t*)m_rootdata)[HEADER_SIZE_WITH_LENGTH + 2 * j] & 0x400) >> 10;
150 }

◆ init()

void init ( int  length)

initializer

Definition at line 25 of file ROIpayload.cc.

26{
27 m_index = 0;
28 m_length = length;
29 if (length == 0)
30 m_rootdata = nullptr;
31 else
32 m_rootdata = new int[length];
33 m_data32 = (uint32_t*)m_rootdata;
34 m_data64 = (ROIrawID::baseType*)(m_data32 + HEADER_SIZE_WITH_LENGTH);
35}
uint32_t * m_data32
transient value
Definition: ROIpayload.h:60
uint64_t baseType
base type
Definition: ROIrawID.h:28

◆ setCRC()

void setCRC ( )

set CRC

Definition at line 92 of file ROIpayload.cc.

93{
94
95 // assert((int*)(m_data64 + m_index) == m_rootdata + m_length - 1);
96
97 // TODO Pointer comparison is bad
98 if ((int*)(m_data32 + m_index * 2 + HEADER_SIZE_WITH_LENGTH) >= m_rootdata + m_length) {
99 B2ERROR("No space left on the ROI payload to write the CRC." << std::endl);
100 return;
101 }
102
103 crc_optimal<32, 0x04C11DB7, 0, 0, false, false> dhh_crc_32;
104
105 dhh_crc_32.process_bytes((void*)(m_rootdata + OFFSET_HEADER),
106 HEADER_SIZE_WO_LENGTH * sizeof(uint32_t) + m_index * sizeof(uint64_t));
107
108 m_data32[OFFSET_ROIS + m_index * 2] = htonl(dhh_crc_32.checksum()) ;
109}

◆ setHeader()

void setHeader ( bool  Accepted,
bool  SendAll,
bool  SendROIs 
)

set header

For Testbeam/Debugging purpose, we do not do any selection -> move to a downscaler on ONSEN Merger / SlowControl

for debugging purpose, we want to see the ROIs which were send in (esp from DATCON) -> move to a downscaler on ONSEN Merger / SlowControl

Definition at line 58 of file ROIpayload.cc.

59{
60 unsigned int h = 0xCAFE0000; // Magic
61 if (Accepted) h |= 0x8000;
62 if (SendAll) h |=
63 0x4000;
64 if (SendROIs) h |=
65 0x2000;
66 m_data32[OFFSET_HEADER] = htonl(h);
67};

◆ setPayloadLength() [1/2]

void setPayloadLength ( )

set payload length

Definition at line 44 of file ROIpayload.cc.

45{
46 unsigned int lengthInBytes =
47 sizeof(uint32_t) + // The header
48 sizeof(uint32_t) + // The trigger number
49 sizeof(uint32_t) + // Run Subrun Experiment Number
50 m_index * sizeof(uint64_t) + // The rois
51 sizeof(uint32_t); // The CRC
52
53 m_data32[OFFSET_MAGIC] = htonl(MAGIC_WORD);
54 m_data32[OFFSET_LENGTH] = htonl(lengthInBytes);
55 m_packetLengthByte = lengthInBytes + 2 * sizeof(uint32_t); // The space for the magic word and payload length
56}
int m_packetLengthByte
packet length in byte
Definition: ROIpayload.h:52

◆ setPayloadLength() [2/2]

void setPayloadLength ( int  length)

transient value

set payload length

Definition at line 37 of file ROIpayload.cc.

38{
39 m_data32[OFFSET_MAGIC] = htonl(MAGIC_WORD);
40 m_data32[OFFSET_LENGTH] = htonl(length);
41 m_packetLengthByte = length + 2 * sizeof(uint32_t);
42}

◆ setRunSubrunExpNumber()

void setRunSubrunExpNumber ( int  run,
int  subrun,
int  exp 
)

set run/ subrun/exp number

set run, subrun and experiment number

Definition at line 74 of file ROIpayload.cc.

75{
76 int rseNumber;
77 rseNumber = (exp & 0x3FF) << 22 | (run & 0x3FFF) << 8 | (subrun & 0xFF) ;
78 m_data32[OFFSET_RUNNR] = htonl(rseNumber);
79};

◆ setTriggerNumber()

void setTriggerNumber ( unsigned long int  triggerNumber)

set trigger number

Definition at line 69 of file ROIpayload.cc.

70{
71 m_data32[OFFSET_TRIGNR] = htonl(triggerNumber);
72};

Member Data Documentation

◆ m_data32

uint32_t* m_data32

transient value

pointer to transient 32-bit value

Definition at line 60 of file ROIpayload.h.

◆ m_data64

ROIrawID::baseType* m_data64

transient value

pointer to transient 64-bit value

Definition at line 62 of file ROIpayload.h.

◆ m_index

int m_index

transient index

Definition at line 58 of file ROIpayload.h.

◆ m_length

int m_length

packet length

Definition at line 53 of file ROIpayload.h.

◆ m_packetLengthByte

int m_packetLengthByte = 0

packet length in byte

Definition at line 52 of file ROIpayload.h.

◆ m_rootdata

int* m_rootdata

pointer to data packet of m_length words

Definition at line 55 of file ROIpayload.h.


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