9 #include <rawdata/dataobjects/RawDataBlockFormat.h>
14 RawDataBlockFormat::RawDataBlockFormat()
17 m_use_prealloc_buf = 0;
23 RawDataBlockFormat::~RawDataBlockFormat()
25 if (!m_use_prealloc_buf && m_buffer != NULL) {
30 int RawDataBlockFormat::GetBufferPos(
int n)
32 if (m_buffer == NULL || m_nwords <= 0) {
34 sprintf(err_buf,
"[FATAL] RawPacket buffer(%p) is not available or length(%d) is not set.\n %s %s %d\n",
35 m_buffer, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
36 printf(
"%s", err_buf); fflush(stdout);
40 if (n >= (m_num_events * m_num_nodes)) {
42 sprintf(err_buf,
"[FATAL] Invalid COPPER block No. (%d : max %d ) is specified. Exiting... \n %s %s %d\n",
43 n, (m_num_events * m_num_nodes), __FILE__, __PRETTY_FUNCTION__, __LINE__);
44 printf(
"%s", err_buf); fflush(stdout);
49 for (
int i = 1; i <= n ; i++) {
50 if (m_buffer[ pos_nwords ] <= 0) {
53 "[FATAL] ERROR_EVENT : length of this data block is strange ( %d words ). Maybe data is corrupted or RawHeader info has not been filled yet. Exiting...",
54 m_buffer[ pos_nwords ]);
55 printf(
"%s", err_buf);
58 pos_nwords += m_buffer[ pos_nwords ];
60 if (pos_nwords >= m_nwords) {
62 sprintf(err_buf,
"[FATAL] ERROR_EVENT : value of pos_nwords(%d) is larger than m_nwords(%d). Exiting...\n %s %s %d\n",
63 pos_nwords, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
64 printf(
"%s", err_buf); fflush(stdout);
73 int RawDataBlockFormat::CheckFTSWID(
int n)
75 int pos = POS_NODE_ID;
76 if (m_buffer[ GetBufferPos(n) + TEMP_POS_NWORDS_HEADER ] == OLD_FTSW_NWORDS_HEADER) {
77 pos = POS_FTSW_ID_OLD;
80 if ((m_buffer[ GetBufferPos(n) + pos ] & 0xffffff00) == 0x54544400) {
88 int RawDataBlockFormat::CheckTLUID(
int n)
90 int pos = POS_NODE_ID;
91 if (m_buffer[ GetBufferPos(n) + TEMP_POS_NWORDS_HEADER ] == OLD_FTSW_NWORDS_HEADER) {
92 pos = POS_FTSW_ID_OLD;
94 if (m_buffer[ GetBufferPos(n) + pos ] == 0x544c5520) {
101 int RawDataBlockFormat::TotalBufNwords()
107 int RawDataBlockFormat::GetBlockNwords(
int n)
110 if (n == (m_num_events * m_num_nodes) - 1) {
111 size = m_nwords - GetBufferPos(n);
113 size = GetBufferPos(n + 1) - GetBufferPos(n);
119 int* RawDataBlockFormat::GetWholeBuffer()
124 int* RawDataBlockFormat::GetBuffer(
int n)
126 int pos_nwords = GetBufferPos(n);
127 return &(m_buffer[ pos_nwords ]);
131 void RawDataBlockFormat::SetBuffer(
int* bufin,
int nwords,
int delete_flag,
int num_events,
int num_nodes)
136 sprintf(err_buf,
"[DEBUG] bufin is NULL. Exting...\n");
137 printf(
"%s", err_buf); fflush(stdout);
141 if (!m_use_prealloc_buf && m_buffer != NULL)
delete[] m_buffer;
143 if (delete_flag == 0) {
144 m_use_prealloc_buf =
true;
146 m_use_prealloc_buf =
false;
152 m_num_nodes = num_nodes;
153 m_num_events = num_events;
161 void RawDataBlockFormat::PrintData(
int* buf,
int nwords)
164 for (
int i = 0; i < nwords; i++) {
165 printf(
"%.8x ", buf[ i ]);
166 if (i % 10 == 9) printf(
"\n[DEBUG] ");
168 printf(
"\n[DEBUG] ");
173 void RawDataBlockFormat::CopyBlock(
int n,
int* buf_to)
175 memcpy(buf_to, GetBuffer(n), GetBlockNwords(n) *
sizeof(
int));
Abstract base class for different kinds of events.