9 #include <rawdata/dataobjects/RawCOPPER.h>
11 #include <framework/utilities/HTML.h>
22 RawCOPPER::RawCOPPER()
28 RawCOPPER::~RawCOPPER()
30 if (m_access != NULL)
delete m_access;
34 void RawCOPPER::SetVersion()
37 if (m_buffer == NULL) {
39 sprintf(err_buf,
"m_buffer is NULL. Exiting...");
40 printf(
"%s", err_buf); fflush(stdout);
44 if (m_access != NULL) {
48 m_version = ((m_buffer[ POS_FORMAT_VERSION ]) & FORMAT_MASK) >> 8;
51 case LATEST_POSTREDUCTION_FORMAT_VER :
55 case (0x80 + LATEST_POSTREDUCTION_FORMAT_VER) :
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);
88 m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
94 void RawCOPPER::SetVersion(
string class_name)
97 if (m_access != NULL) {
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;
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);
137 m_access->SetBuffer(m_buffer, m_nwords, 0, m_num_events, m_num_nodes);
141 void RawCOPPER::SetBuffer(
int* bufin,
int nwords,
int delete_flag,
int num_events,
int num_nodes)
145 sprintf(err_buf,
"[DEBUG] bufin is NULL. Exting...\n");
146 printf(
"%s", err_buf); fflush(stdout);
150 if (!m_use_prealloc_buf && m_buffer != NULL)
delete[] m_buffer;
152 if (delete_flag == 0) {
153 m_use_prealloc_buf =
true;
155 m_use_prealloc_buf =
false;
161 m_num_nodes = num_nodes;
162 m_num_events = num_events;
169 void RawCOPPER::ShowBuffer()
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);
183 void RawCOPPER::PackDetectorBuf(
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,
191 if (m_access != NULL) {
199 int* packed_buf = NULL;
201 detector_buf_1st, nwords_1st,
202 detector_buf_2nd, nwords_2nd,
203 detector_buf_3rd, nwords_3rd,
204 detector_buf_4th, nwords_4th,
208 SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
211 m_access->SetBuffer(m_buffer, m_nwords, delete_flag, m_num_events, m_num_nodes);
216 void RawCOPPER::PackDetectorBuf(
int*
const(&detector_buf_ch)[MAX_PCIE40_CH],
217 int const(&nwords_ch)[MAX_PCIE40_CH],
220 if (LATEST_POSTREDUCTION_FORMAT_VER < 4) {
222 sprintf(err_buf,
"This function must be used for PCIe40 data(ver.4 or later). Exiting...");
223 printf(
"%s", err_buf); fflush(stdout);
227 if (m_access != NULL) {
232 m_version = LATEST_POSTREDUCTION_FORMAT_VER;
236 int* packed_buf = NULL;
237 packed_buf = m_access->PackDetectorBuf(&m_nwords,
238 detector_buf_ch, nwords_ch,
242 SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
245 m_access->SetBuffer(m_buffer, m_nwords, delete_flag, m_num_events, m_num_nodes);
251 void RawCOPPER::PackDetectorBuf4DummyData(
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,
259 if (m_access != NULL) {
268 int* packed_buf = NULL;
270 detector_buf_1st, nwords_1st,
271 detector_buf_2nd, nwords_2nd,
272 detector_buf_3rd, nwords_3rd,
273 detector_buf_4th, nwords_4th,
277 SetBuffer(packed_buf, m_nwords, delete_flag, m_num_events, m_num_nodes);
280 m_access->SetBuffer(m_buffer, m_nwords, delete_flag, m_num_events, m_num_nodes);
285 std::string RawCOPPER::getInfoHTML()
const
293 s <<
"Entries: " << nEntries;
294 s <<
", Total size (32bit words): " << m_nwords <<
"<br>";
296 s <<
"COPPER format version: " << m_version;
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++) {
305 s <<
"<p>Finesse " << char(a + iFinesse) <<
" (Size: " << nWords <<
")</p>";
306 s << HTML::getHexDump(buf, nWords) <<
"<br>";
313 void RawCOPPER::CompareHeaderValue(
int n,
const unsigned int (&input_val)[MAX_PCIE40_CH], vector<vector< unsigned int>>& result)
315 CheckVersionSetBuffer();
316 m_access->CompareHeaderValue(n, input_val, result);
The Raw COPPER class ver.
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...
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) OVERRIDE_CPP17
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...
virtual int GetNumEntries()
get # of data blocks = (# of nodes)*(# of events)
void CheckVersionSetBuffer()
Check the version number of data format.
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
unsigned int GetNodeID(int n)
get node-ID from data
Abstract base class for different kinds of events.