Belle II Software development
RawCOPPER.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/RawCOPPER.h>
10
11#include <framework/utilities/HTML.h>
12#include <sstream>
13
14
15using namespace std;
16using namespace Belle2;
17
18//#define DESY
19//#define NO_DATA_CHECK
20//#define WO_FIRST_EVENUM_CHECK
21
23{
24 m_access = NULL;
25 m_version = -1;
26}
27
29{
30 if (m_access != NULL) delete m_access;
31 m_access = NULL;
32}
33
35{
36
37 if (m_buffer == NULL) {
38 char err_buf[500];
39 sprintf(err_buf, "m_buffer is NULL. Exiting...");
40 printf("%s", err_buf); fflush(stdout);
41 B2FATAL(err_buf);
42 }
43
44 if (m_access != NULL) {
45 delete m_access;
46 }
47
48 m_version = ((m_buffer[ POS_FORMAT_VERSION ]) & FORMAT_MASK) >> 8;
49
50 switch (m_version) {
51 case LATEST_POSTREDUCTION_FORMAT_VER :
53 // printf("Calling PostRawCOPPERFormat_latest\n");
54 break;
55 case (0x80 + LATEST_POSTREDUCTION_FORMAT_VER) :
57 // printf("Calling PreRawCOPPERFormat_latest\n");
58 break;
59 case 0x2 :
61 // printf("Calling PostRawCOPPERFormat_latest\n");
62 break;
63 case (0x80 + 0x2) :
65 // printf("Calling PreRawCOPPERFormat_latest\n");
66 break;
67 case 0x1 :
69 // printf("Calling RawCOPPERFormat_v1\n");
70 break;
71 case (0x80 + 0x1) :
73 // printf("Calling PreRawCOPPERFormat_latest\n");
74 break;
75 case 0 :
77 // printf("Calling RawCOPPERFormat_v0\n");
78 break;
79 default : {
80 char err_buf[500];
81 sprintf(err_buf, "[FATAL] ERROR_EVENT : Invalid version of a data format(0x%.8x = 0x7f7f**..). Exiting...\n %s %s %d\n",
82 m_buffer[ POS_FORMAT_VERSION ], __FILE__, __PRETTY_FUNCTION__, __LINE__);
83 printf("%s", err_buf); fflush(stdout);
84 B2FATAL(err_buf); // to reduce multiple error messages
85 }
86 }
87
89
90
91
92}
93
94void RawCOPPER::SetVersion(string class_name)
95{
96
97 if (m_access != NULL) {
98 delete m_access;
99 }
100
101 if (class_name == "PostRawCOPPERFormat_latest") {
103 m_version = (0 << 7) | LATEST_POSTREDUCTION_FORMAT_VER;
104 } else if (class_name == "PreRawCOPPERFormat_latest") {
106 m_version = (1 << 7) | LATEST_POSTREDUCTION_FORMAT_VER;
107 } else if (class_name == "PostRawCOPPERFormat_v1") {
109 m_version = (0 << 7) | 1;
110 } else if (class_name == "PreRawCOPPERFormat_v1") {
112 m_version = (1 << 7) | 1;
113 } else if (class_name == "RawCOPPERFormat_v0") {
115 m_version = (0 << 7) | 0;
116 } else {
117 char err_buf[500];
118 sprintf(err_buf, "Invalid name of a data format class (%s). Exiting...\n %s %s %d\n",
119 class_name.c_str(), __FILE__, __PRETTY_FUNCTION__, __LINE__);
120 printf("%s", err_buf); fflush(stdout);
121 B2FATAL(err_buf);
122 }
123
124// if( class_name == "RawCOPPERFormat_v0" ){
125// m_access = new RawCOPPERFormat_v0;
126// m_version = ( 0 << 7 ) | 0;
127// }else if( class_name == "PreRawCOPPERFormat_v0" ){
128// m_access = new PreRawCOPPERFormat_v0;
129// m_version = ( 1 << 7 ) | 0;
130// }else if( class_name == "RawCOPPERFormat_v2" ){
131// m_access = new RawCOPPERFormat_v2;
132// m_version = ( 0 << 7 ) | 2;
133// }else if( class_name == "PreRawCOPPERFormat_v2" ){
134// m_access = new PreRawCOPPERFormat_v2;
135// m_version = ( 1 << 7 ) | 2;
136// }
138
139}
140
141void RawCOPPER::SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes)
142{
143 if (bufin == NULL) {
144 char err_buf[500];
145 sprintf(err_buf, "[DEBUG] bufin is NULL. Exting...\n");
146 printf("%s", err_buf); fflush(stdout);
147 B2FATAL(err_buf);
148 }
149
150 if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
151
152 if (delete_flag == 0) {
153 m_use_prealloc_buf = true;
154 } else {
155 m_use_prealloc_buf = false;
156 }
157
158 m_nwords = nwords;
159 m_buffer = bufin;
160
161 m_num_nodes = num_nodes;
162 m_num_events = num_events;
163
164 SetVersion();
165
166}
167
168
170{
171
172 printf("\n");
173 printf("POINTER %p\n", m_buffer);
174 for (int k = 0; k < 100; k++) {
175 printf("%.8x ", m_buffer[ k ]);
176 if ((k + 1) % 10 == 0) printf("\n%.8x : ", k);
177 }
178 printf("\n");
179
180}
181
182
184 int* detector_buf_1st, int nwords_1st,
185 int* detector_buf_2nd, int nwords_2nd,
186 int* detector_buf_3rd, int nwords_3rd,
187 int* detector_buf_4th, int nwords_4th,
188 RawCOPPERPackerInfo rawcprpacker_info)
189{
190 // This function should be used for packing COPPER-format data.
191 if (m_access != NULL) {
192 delete m_access;
193 }
194 m_access = new PostRawCOPPERFormat_v2; // The latest version for COPPER-format
195 m_version = 2; // The latest version for COPPER-format
196 m_num_events = 1;
197 m_num_nodes = 1;
198
199 int* packed_buf = NULL;
200 packed_buf = m_access->PackDetectorBuf(&m_nwords,
201 detector_buf_1st, nwords_1st,
202 detector_buf_2nd, nwords_2nd,
203 detector_buf_3rd, nwords_3rd,
204 detector_buf_4th, nwords_4th,
205 rawcprpacker_info);
206
207 int delete_flag = 1; // Not use preallocated buffer. Delete m_buffer when destructer is called.
208 SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
209
210 delete_flag = 0; // For m_access, need not to delete m_buffer
212
213 return;
214}
215
216void RawCOPPER::PackDetectorBuf(int* const(&detector_buf_ch)[MAX_PCIE40_CH],
217 int const(&nwords_ch)[MAX_PCIE40_CH],
218 RawCOPPERPackerInfo rawcprpacker_info)
219{
220 if (LATEST_POSTREDUCTION_FORMAT_VER < 4) {
221 char err_buf[500];
222 sprintf(err_buf, "This function must be used for PCIe40 data(ver.4 or later). Exiting...");
223 printf("%s", err_buf); fflush(stdout);
224 B2FATAL(err_buf);
225 }
226
227 if (m_access != NULL) {
228 delete m_access;
229 }
230
232 m_version = LATEST_POSTREDUCTION_FORMAT_VER;
233 m_num_events = 1;
234 m_num_nodes = 1;
235
236 int* packed_buf = NULL;
237 packed_buf = m_access->PackDetectorBuf(&m_nwords,
238 detector_buf_ch, nwords_ch,
239 rawcprpacker_info);
240
241 int delete_flag = 1; // Not use preallocated buffer. Delete m_buffer when destructer is called.
242 SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
243
244 delete_flag = 0; // For m_access, need not to delete m_buffer
246
247 return;
248}
249
250
252 int* detector_buf_1st, int nwords_1st,
253 int* detector_buf_2nd, int nwords_2nd,
254 int* detector_buf_3rd, int nwords_3rd,
255 int* detector_buf_4th, int nwords_4th,
256 RawCOPPERPackerInfo rawcprpacker_info)
257{
258 // This function should be used for packing COPPER-format data.
259 if (m_access != NULL) {
260 delete m_access;
261 }
262 m_access = new PostRawCOPPERFormat_v2; // The latest version for COPPER-format
263 m_version = 2; // The latest version for COPPER-format
264
265 m_num_events = 1;
266 m_num_nodes = 1;
267
268 int* packed_buf = NULL;
269 packed_buf = m_access->PackDetectorBuf(&m_nwords,
270 detector_buf_1st, nwords_1st,
271 detector_buf_2nd, nwords_2nd,
272 detector_buf_3rd, nwords_3rd,
273 detector_buf_4th, nwords_4th,
274 rawcprpacker_info);
275
276 int delete_flag = 1; // Not use preallocated buffer. Delete m_buffer when destructer is called.
277 SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
278
279 delete_flag = 0; // For m_access, need not to delete m_buffer
281
282 return;
283}
284
285std::string RawCOPPER::getInfoHTML() const
286{
287 std::stringstream s;
288 //TODO: All these methods should be const instead.
289 RawCOPPER* nonconst_this = const_cast<RawCOPPER*>(this);
290 nonconst_this->CheckVersionSetBuffer();
291
292 const int nEntries = nonconst_this->GetNumEntries();
293 s << "Entries: " << nEntries;
294 s << ", Total size (32bit words): " << m_nwords << "<br>";
295
296 s << "COPPER format version: " << m_version;
297
298 const char a = 'A'; //finesses are counted from A to D
299 for (int iEntry = 0; iEntry < nEntries; ++iEntry) {
300 s << "<h4>Entry " << iEntry << "</h4>";
301 s << "Node ID: 0x" << std::hex << nonconst_this->GetNodeID(iEntry) << std::dec;
302 for (int iFinesse = 0; iFinesse < 4; iFinesse++) {
303 const int nWords = nonconst_this->GetDetectorNwords(iEntry, iFinesse);
304 const int* buf = nonconst_this->GetDetectorBuffer(iEntry, iFinesse);
305 s << "<p>Finesse " << char(a + iFinesse) << " (Size: " << nWords << ")</p>";
306 s << HTML::getHexDump(buf, nWords) << "<br>";
307 }
308 }
309
310 return s.str();
311}
312
313void RawCOPPER::CompareHeaderValue(int n, const unsigned int (&input_val)[MAX_PCIE40_CH], vector<vector< unsigned int>>& result)
314{
316 m_access->CompareHeaderValue(n, input_val, result);
317 return;
318}
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
The Raw COPPER class ver.2 This class stores data received by COPPER via belle2link Data from all det...
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
The Raw COPPER class ver.0 ( from August, 2013 to April, 2014 ) This class stores data received by CO...
virtual void CompareHeaderValue(int n, const unsigned int(&input_val)[MAX_PCIE40_CH], std::vector< std::vector< unsigned int > > &result)
Compare value from different channels and make a statistics table.
virtual int * PackDetectorBuf(int *packed_buf_nwords, int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)=0
Pack data (format ver. = -1 -> Select the latest format version)
struct to contain header information used by RawCOPPERFormat::Packer()
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
void SetVersion()
read data, detect and set the version number of the data format
Definition: RawCOPPER.cc:34
RawCOPPERFormat * m_access
class to access
Definition: RawCOPPER.h:333
void CompareHeaderValue(int n, const unsigned int(&input_val)[MAX_PCIE40_CH], std::vector< std::vector< unsigned int > > &result)
Compare value from different channels and make a statistics table.
Definition: RawCOPPER.cc:313
void ShowBuffer()
show m_buffer
Definition: RawCOPPER.cc:169
void PackDetectorBuf(int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)
Packer for RawCOPPER class Pack data (format ver.
Definition: RawCOPPER.cc:183
virtual ~RawCOPPER()
Constructor using existing pointer to raw data buffer.
Definition: RawCOPPER.cc:28
void PackDetectorBuf4DummyData(int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)
Pack dummy data (format ver. = -1 -> Select the latest format version)
Definition: RawCOPPER.cc:251
int m_version
do not record
Definition: RawCOPPER.h:336
RawCOPPER()
Default constructor.
Definition: RawCOPPER.cc:22
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
Definition: RawCOPPER.cc:285
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: RawCOPPER.cc:141
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
virtual int GetNumEntries()
get # of data blocks = (# of nodes)*(# of events)
Definition: RawDataBlock.h:67
int m_nwords
do not record
Definition: RawDataBlock.h:145
void CheckVersionSetBuffer()
Check the version number of data format.
Definition: RawCOPPER.h:741
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
Definition: RawCOPPER.h:657
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Definition: RawCOPPER.h:681
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
std::string getHexDump(const int *buf, int length)
Create hexdump of given buffer.
Definition: HTML.cc:121
Abstract base class for different kinds of events.
STL namespace.