Belle II Software  release-08-01-10
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>
10 using namespace std;
11 using namespace Belle2;
12 
13 RawFTSW::RawFTSW()
14 {
15  m_access = NULL;
16  m_version = -1;
17 }
18 
19 RawFTSW::~RawFTSW()
20 {
21  if (m_access != NULL) delete m_access;
22  m_access = NULL;
23 }
24 
25 void RawFTSW::SetVersion()
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) {
55  m_access = new RawFTSWFormat_v2;
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) {
58  m_access = new RawFTSWFormat_v1;
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.
81  m_access = new RawFTSWFormat_latest;
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 
102  m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
103 }
104 
105 
106 // I copied this from RawCOPPER.cc, since SetVersion() is necessary for RawFTSW after ver.2 is included.
107 void 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 }
The Raw FTSW class 3 ( 2019.8.20 )
The Raw FTSW class ver.1 .
The Raw FTSW class ver.2 .
Abstract base class for different kinds of events.