Belle II Software  release-08-01-10
RawCOPPERFormat.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/RawCOPPERFormat.h>
10 
11 
12 using namespace Belle2;
13 //ClassImp(RawCOPPERFormat);
14 
15 
16 RawCOPPERFormat::RawCOPPERFormat()
17 {
18 // m_nwords = 0;
19 // m_num_nodes = 0;
20 // m_num_events = 0;
21 // m_buffer = NULL;
22 }
23 
24 unsigned int RawCOPPERFormat::CalcXORChecksum(int* buf, int nwords)
25 {
26  unsigned int checksum = 0;
27  for (int i = 0; i < nwords; i++) {
28  checksum = checksum ^ buf[ i ];
29  }
30  return checksum;
31 }
32 
33 
34 
35 
36 int RawCOPPERFormat::GetOffsetFINESSE(int n, int finesse_num)
37 {
38  switch (finesse_num) {
39  case 0 :
40  return GetOffset1stFINESSE(n);
41  break;
42  case 1 :
43  return GetOffset2ndFINESSE(n);
44  break;
45  case 2 :
46  return GetOffset3rdFINESSE(n);
47  break;
48  case 3 :
49  return GetOffset4thFINESSE(n);
50  break;
51  default :
52  break;
53  }
54 
55  char err_buf[500];
56  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
57  __FILE__, __PRETTY_FUNCTION__, __LINE__);
58  printf("%s", err_buf); fflush(stdout);
59  B2FATAL(err_buf);
60 }
61 
62 
63 
64 
65 int* RawCOPPERFormat::GetFINESSEBuffer(int n, int finesse_num)
66 {
67  switch (finesse_num) {
68  case 0 :
69  return Get1stFINESSEBuffer(n);
70  break;
71  case 1 :
72  return Get2ndFINESSEBuffer(n);
73  break;
74  case 2 :
75  return Get3rdFINESSEBuffer(n);
76  break;
77  case 3 :
78  return Get4thFINESSEBuffer(n);
79  break;
80  default :
81  break;
82  }
83 
84  char err_buf[500];
85  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
86  __FILE__, __PRETTY_FUNCTION__, __LINE__);
87  printf("%s", err_buf); fflush(stdout);
88  B2FATAL(err_buf);
89 }
90 
91 
92 
93 
94 int* RawCOPPERFormat::GetDetectorBuffer(int n, int finesse_num)
95 {
96  switch (finesse_num) {
97  case 0 :
98  return Get1stDetectorBuffer(n);
99  break;
100  case 1 :
101  return Get2ndDetectorBuffer(n);
102  break;
103  case 2 :
104  return Get3rdDetectorBuffer(n);
105  break;
106  case 3 :
107  return Get4thDetectorBuffer(n);
108  break;
109  default :
110  break;
111  }
112 
113  char err_buf[500];
114  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
115  __FILE__, __PRETTY_FUNCTION__, __LINE__);
116  printf("%s", err_buf); fflush(stdout);
117  B2FATAL(err_buf);
118 }
119 
120 
121 // This function is available after RawCOPPER/Header ver.2
123 {
124  char err_buf[500];
125  sprintf(err_buf,
126  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d : %s %s %d: Exiting...\n",
127  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
128  printf("%s\n", err_buf); fflush(stdout);
129  B2FATAL(err_buf);
130  return -1;
131 }
132 
133 // This function is available after RawCOPPER/Header ver.2
135 {
136  char err_buf[500];
137  sprintf(err_buf,
138  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d : %s %s %d: Exiting...\n",
139  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
140  printf("%s\n", err_buf); fflush(stdout);
141  B2FATAL(err_buf);
142  return -1;
143 }
144 
145 int RawCOPPERFormat::GetEventCRC16Value(int n, int finesse_num)
146 {
147  char err_buf[500];
148  sprintf(err_buf,
149  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d fin=%d : %s %s %d: Exiting...\n",
150  n, finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
151  printf("%s\n", err_buf); fflush(stdout);
152  B2FATAL(err_buf);
153  return -1;
154 }
155 
156 int* RawCOPPERFormat::PackDetectorBuf(int* /*packed_buf_nwords*/,
157  int* const(& /*detector_buf_ch*/)[MAX_PCIE40_CH],
158  int const(& /*nwords_ch*/)[MAX_PCIE40_CH],
159  RawCOPPERPackerInfo /*rawcpr_info*/)
160 {
161  char err_buf[500];
162  sprintf(err_buf,
163  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. : %s %s %d: Exiting...\n", __FILE__,
164  __PRETTY_FUNCTION__, __LINE__);
165  printf("%s\n", err_buf); fflush(stdout);
166  B2FATAL(err_buf);
167  return NULL;
168 }
169 
170 void RawCOPPERFormat::CompareHeaderValue(int /*n*/, const unsigned int (& /*input_val*/)[MAX_PCIE40_CH],
171  std::vector<std::vector<unsigned int> >& /*result*/)
172 {
173  char err_buf[500];
174  sprintf(err_buf,
175  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. : %s %s %d: Exiting...\n", __FILE__,
176  __PRETTY_FUNCTION__, __LINE__);
177  printf("%s\n", err_buf); fflush(stdout);
178  B2FATAL(err_buf);
179  return;
180 }
181 
182 void RawCOPPERFormat::GetNodeName(int n, char* node_name, int bufsize)
183 {
184  unsigned int node_id = GetNodeID(n);
185  if (node_name == NULL || node_id == 0 || bufsize < 20) {
186  char err_buf[500];
187  sprintf(err_buf,
188  "[FATAL] Null pointer or strange node_id(%.8x)in an argument of this function. Exiting... : \n%s %s %d\n",
189  node_id,
190  __FILE__, __PRETTY_FUNCTION__, __LINE__);
191  printf("%s", err_buf); fflush(stdout);
192  B2FATAL(err_buf); // to reduce multiple error messages
193  } else {
194  sprintf(node_name, "cpr%u",
195  (10 * (node_id >> 28) + (node_id >> 24)) * 1000 +
196  (node_id & COPPERID_MASK));
197  }
198 }
199 
200 void RawCOPPERFormat::GetNodeName(char* node_name, unsigned int node_id, int bufsize)
201 {
202  if (node_name == NULL || node_id == 0 || bufsize < 20) {
203  char err_buf[500];
204  sprintf(err_buf,
205  "[FATAL] Null pointer or strange node_id(%.8x)in an argument of this function. Exiting... : \n%s %s %d\n",
206  node_id,
207  __FILE__, __PRETTY_FUNCTION__, __LINE__);
208  printf("%s", err_buf); fflush(stdout);
209  B2FATAL(err_buf); // to reduce multiple error messages
210  } else {
211  sprintf(node_name, "cpr%u",
212  (10 * (node_id >> 28) + (node_id >> 24)) * 1000 +
213  (node_id & COPPERID_MASK));
214  }
215 }
216 
217 bool RawCOPPERFormat::CheckOnlineRemovedDataBit(int n, int finesse_num)
218 {
219  char err_buf[500];
220  sprintf(err_buf,
221  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d fin=%d : %s %s %d: Exiting...\n",
222  n, finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
223  printf("%s\n", err_buf); fflush(stdout);
224  B2FATAL(err_buf);
225  return -1;
226 }
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 * Get1stDetectorBuffer(int n)=0
get Detector buffer of slot A
virtual int * Get2ndDetectorBuffer(int n)=0
get Detector Buffer of slot B
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)
virtual unsigned int GetNodeID(int n)=0
get node-ID from data
virtual int GetOffsetFINESSE(int n, int finesse)
get # of offset words
virtual unsigned int CalcXORChecksum(int *buf, int nwords)
calc XOR checksum
virtual bool CheckOnlineRemovedDataBit(int n, int finesse_num)
Check if COPPER Magic words are correct.
virtual int GetOffset1stFINESSE(int n)=0
get # of offset words for FINESSE slot A buffer position
virtual int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
virtual int GetEventCRC16Value(int n, int finesse_num)
Get Event CRC16 value.
virtual void GetNodeName(int n, char *node_name, int bufsize)
Get hostname of a node from the RawCOPPER header.
virtual int * Get3rdDetectorBuffer(int n)=0
get Detector Buffer of slot C
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
virtual int * Get4thDetectorBuffer(int n)=0
get Detector Buffer of slot D
virtual int GetEventCRCError(int n)
check CRC event Error
virtual int GetPacketCRCError(int n)
check CRC packet Error
struct to contain header information used by RawCOPPERFormat::Packer()
virtual int * Get3rdFINESSEBuffer(int n)
get FINESSE buffer pointer for slot C
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
virtual int * Get2ndFINESSEBuffer(int n)
get FINESSE buffer pointer for slot B
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
virtual int GetOffset3rdFINESSE(int n)
get # of offset words for FINESSE slot C buffer position
virtual int * Get4thFINESSEBuffer(int n)
get FINESSE buffer pointer for slot D
virtual int * Get1stFINESSEBuffer(int n)
get FINESSE buffer pointer for slot A
Abstract base class for different kinds of events.