Belle II Software development
RawFTSW.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <rawdata/dataobjects/RawFTSW.h>
10using namespace std;
11using namespace Belle2;
12
14{
15 m_access = NULL;
16 m_version = -1;
17}
18
20{
21 if (m_access != NULL) delete m_access;
22 m_access = NULL;
23}
24
26{
27 if (m_buffer == NULL) {
28 char err_buf[500];
29 sprintf(err_buf, "m_buffer is NULL. Exiting...");
30 printf("%s", err_buf); fflush(stdout);
31 B2FATAL(err_buf);
32 }
33
34 if (m_access != NULL) {
35 delete m_access;
36 m_access = nullptr;
37 }
38
39 //
40 // Assign unpacker
41 //
42 // Special treatment is required because Nakao-san did not set verision number in ver.0,1, and 2 header.
43 // I'm using the size of header which is stored the 1st word (0,1,..)
44 //
45 int temp_version = m_version;
46 if (m_buffer[ POS_HEADER_SIZE ] == VER_0_HEADER_SIZE) {
47 char err_buf[500];
48 sprintf(err_buf,
49 "[FATAL] Ver.0 of RawFTSW( so-called early DESYtest format ) is detected but not supported. (header size = 0x%.8x ) Exiting...\n %s %s %d\n",
50 m_buffer[ POS_HEADER_SIZE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
51 printf("%s", err_buf); fflush(stdout);
52 B2FATAL(err_buf);
53 } else if (m_buffer[ POS_NODE_FORMAT_ID ] == FORMAT_ID_VER_0TO2) {
54 if (m_buffer[ POS_HEADER_SIZE ] == VER_2_HEADER_SIZE) {
56 m_version = 2; // as of 2019.3.2, the latest version is 2.
57 } else if (m_buffer[ POS_HEADER_SIZE ] == VER_1_HEADER_SIZE) {
59 m_version = 1;
60 } else {
61 char err_buf[500];
62 sprintf(err_buf, "[FATAL] ERROR_EVENT : Invalid RawFTSW header size of FTSW data format(= 0x%.8x words). Exiting...\n %s %s %d\n",
63 m_buffer[ POS_HEADER_SIZE ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
64 printf("%s", err_buf); fflush(stdout);
65 B2FATAL(err_buf);
66 }
67 } else if (m_buffer[ POS_NODE_FORMAT_ID ] == FORMAT_ID_VER_0TO3 ||
68 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544432 ||
69 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544433 ||
70 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544434 ||
71 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544435 ||
72 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544436 ||
73 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544437 ||
74 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544438 ||
75 m_buffer[ POS_NODE_FORMAT_ID ] == 0x54544439) {
76 // Request from Nakao-san in Oct. 15, 2019
77 // - FORMAT_ID_VER_0TO3 should be changed to x"54544431" from x"5454421"
78 // - RawFTSWFormat_latest should accept newer format versions(= larger version number), so that this unpacker
79 // will not stop due to version error, when Nakao-san updated version number in RawFTSW data.
80 // -- Since the latest format is basically the addition of some variables in RawFTSW data, probably it won't cause the problem.
82 m_version = 3; // as of 2019.3.20 the latest version is 3.
83 } else {
84 char err_buf[500];
85 sprintf(err_buf,
86 "[FATAL] ERROR_EVENT : Invalid RawFTSW header size(= 0x%.8x words) or version number.(=0x%.8x) Exiting...\n %s %s %d\n",
87 m_buffer[ POS_HEADER_SIZE ], m_buffer[ POS_NODE_FORMAT_ID ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
88 printf("%s", err_buf); fflush(stdout);
89 B2FATAL(err_buf);
90 }
91
92
93 if (temp_version >= 0 && temp_version != m_version) {
94 char err_buf[500];
95 sprintf(err_buf,
96 "[FATAL] Already assigned RawFTSW format version (= %.8x) is different from the one (= 0x%.8x) from the current event. Exiting...\n %s %s %d\n",
97 temp_version, m_version, __FILE__, __PRETTY_FUNCTION__, __LINE__);
98 printf("%s", err_buf); fflush(stdout);
99 B2FATAL(err_buf);
100 }
101
103}
104
105
106// I copied this from RawCOPPER.cc, since SetVersion() is necessary for RawFTSW after ver.2 is included.
107void RawFTSW::SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes)
108{
109
110 if (bufin == NULL) {
111 char err_buf[500];
112 sprintf(err_buf, "[FATAL] bufin is NULL. Exting...\n");
113 printf("%s", err_buf); fflush(stdout);
114 B2FATAL(err_buf);
115 }
116 if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
117
118 if (delete_flag == 0) {
119 m_use_prealloc_buf = true;
120 } else {
121 m_use_prealloc_buf = false;
122 }
123
124 m_nwords = nwords;
125 m_buffer = bufin;
126
127 m_num_nodes = num_nodes;
128 m_num_events = num_events;
129
130 SetVersion();
131
132}
virtual void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes)
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
int m_num_events
number of events in this object
Definition: RawDataBlock.h:151
int m_num_nodes
number of nodes in this object
Definition: RawDataBlock.h:148
int m_use_prealloc_buf
flag for deleting m_buffer in destructer( 0:delete, 1: not delete) When using pre-allocated buffer,...
Definition: RawDataBlock.h:158
int * m_buffer
Buffer.
Definition: RawDataBlock.h:154
int m_nwords
do not record
Definition: RawDataBlock.h:145
The Raw FTSW class 3 ( 2019.8.20 )
The Raw FTSW class ver.1 .
The Raw FTSW class ver.2 .
void SetVersion()
read data, detect and set the version number of the data format
Definition: RawFTSW.cc:25
RawFTSW()
Default constructor.
Definition: RawFTSW.cc:13
virtual ~RawFTSW()
Constructor using existing pointer to raw data buffer.
Definition: RawFTSW.cc:19
@ POS_NODE_FORMAT_ID
Added to distinguish different version.
Definition: RawFTSW.h:217
@ VER_1_HEADER_SIZE
Unpacker for ver.0(early DESY version) is not available.
Definition: RawFTSW.h:226
@ VER_0_HEADER_SIZE
The same number of this information must appear in RawFTSWFormat*.h. Information should be placed in ...
Definition: RawFTSW.h:225
RawFTSWFormat * m_access
class to access
Definition: RawFTSW.h:232
int m_version
do not record
Definition: RawFTSW.h:235
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawFTSW.cc:107
Abstract base class for different kinds of events.
STL namespace.