Belle II Software development
PostRawCOPPERFormat_v2 Class Reference

The Raw COPPER class ver.2 This class stores data received by COPPER via belle2link Data from all detectors except PXD are stored in this class. More...

#include <PostRawCOPPERFormat_v2.h>

Inheritance diagram for PostRawCOPPERFormat_v2:
RawCOPPERFormat_v2 RawCOPPERFormat RawDataBlockFormat

Public Types

enum  {
  SIZE_COPPER_DRIVER_HEADER = 0 ,
  SIZE_COPPER_DRIVER_TRAILER = 0
}
 Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS. More...
 
enum  { SIZE_COPPER_HEADER = 0 }
 
enum  { SIZE_COPPER_TRAILER = 0 }
 
enum  {
  POS_B2LHSLB_MAGIC = 0 ,
  SIZE_B2LHSLB_HEADER = 1
}
 
enum  {
  POS_B2L_CTIME = 0 ,
  SIZE_B2LFEE_HEADER = 1
}
 
enum  {
  POS_B2LFEE_ERRCNT_CRC16 = 0 ,
  SIZE_B2LFEE_TRAILER = 1
}
 
enum  { SIZE_B2LHSLB_TRAILER = 0 }
 
enum  { DATA_FORMAT_VERSION = 2 }
 Format version number. More...
 
enum  {
  POS_NWORDS = 0 ,
  POS_NODE_ID = 6
}
 
enum  {
  POS_FTSW_ID_OLD = 5 ,
  TEMP_POS_NWORDS_HEADER = 1 ,
  OLD_FTSW_NWORDS_HEADER = 6
}
 

Public Member Functions

 PostRawCOPPERFormat_v2 ()
 Default constructor.
 
virtual ~PostRawCOPPERFormat_v2 ()
 Constructor using existing pointer to raw data buffer.
 
int GetDetectorNwords (int n, int finesse_num) OVERRIDE_CPP17
 get Detector buffer length
 
int * Get1stDetectorBuffer (int n) OVERRIDE_CPP17
 get Detector buffer of slot A
 
int * Get2ndDetectorBuffer (int n) OVERRIDE_CPP17
 get Detector Buffer of slot B
 
int * Get3rdDetectorBuffer (int n) OVERRIDE_CPP17
 get Detector Buffer of slot C
 
int * Get4thDetectorBuffer (int n) OVERRIDE_CPP17
 get Detector Buffer of slot D
 
unsigned int GetCOPPERCounter (int n) OVERRIDE_CPP17
 get posistion of COPPER block in unit of word
 
int GetOffset1stFINESSE (int n) OVERRIDE_CPP17
 get # of offset words for FINESSE slot A buffer position
 
int GetFINESSENwords (int n, int finesse) OVERRIDE_CPP17
 get data size of FINESSE buffer
 
virtual int * GetExpRunSubrunBuf (int n) OVERRIDE_CPP17
 get b2l block from "FEE b2link header"
 
virtual unsigned int GetB2LFEE32bitEventNumber (int n) OVERRIDE_CPP17
 get b2l block from "FEE b2link header"
 
unsigned int GetMagicDriverHeader (int n) OVERRIDE_CPP17
 get magic word of COPPER driver header
 
unsigned int GetMagicFPGAHeader (int n) OVERRIDE_CPP17
 get magic word of COPPER FPGA header
 
unsigned int GetMagicFPGATrailer (int n) OVERRIDE_CPP17
 get magic word of COPPER FPGA trailer
 
unsigned int GetMagicDriverTrailer (int n) OVERRIDE_CPP17
 get magic word of COPPER driver trailer
 
unsigned int GetTrailerChksum (int n) OVERRIDE_CPP17
 Get checksum in RawTrailer.
 
int GetEventCRC16Value (int n, int finesse_num) OVERRIDE_CPP17
 Get CRC16 value for an event.
 
bool CheckCOPPERMagic (int n) OVERRIDE_CPP17
 Check if COPPER Magic words are correct.
 
unsigned int FillTopBlockRawHeader (unsigned int m_node_id, unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
 should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
 
unsigned int GetDriverChkSum (int n) OVERRIDE_CPP17
 read COPPER driver's checksum value
 
unsigned int CalcDriverChkSum (int n) OVERRIDE_CPP17
 calc COPPER driver's checksum value
 
void CheckData (int n, unsigned int prev_evenum, unsigned int *cur_evenum, unsigned int prev_copper_ctr, unsigned int *cur_copper_ctr, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
 check data contents
 
void CheckUtimeCtimeTRGType (int n) OVERRIDE_CPP17
 check data contents
 
int CheckB2LHSLBMagicWords (int *finesse_buf, int finesse_nwords)
 check magic words
 
int CheckCRC16 (int n, int finesse_num)
 check magic words
 
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)
 
int Get1stDetectorNwords (int n) OVERRIDE_CPP17
 get Detector buffer length of slot A
 
int Get2ndDetectorNwords (int n) OVERRIDE_CPP17
 get Detector buffer length of slot B
 
int Get3rdDetectorNwords (int n) OVERRIDE_CPP17
 get Detector buffer length of slot C
 
int Get4thDetectorNwords (int n) OVERRIDE_CPP17
 get Detector buffer length of slot D
 
int * GetRawTrlBufPtr (int n) OVERRIDE_CPP17
 get buffer pointer of rawcopper trailer
 
int GetExpNo (int n) OVERRIDE_CPP17
 get Experimental # from header
 
unsigned int GetExpRunSubrun (int n) OVERRIDE_CPP17
 get Experimental # from header
 
int GetRunNo (int n) OVERRIDE_CPP17
 Exp# (10bit) run# (14bit) restart # (8bit)
 
int GetSubRunNo (int n) OVERRIDE_CPP17
 get run # (14bit)
 
unsigned int GetEveNo (int n) OVERRIDE_CPP17
 get subrun #(8bit)
 
int GetDataType (int n) OVERRIDE_CPP17
 get contents of header
 
int GetTruncMask (int n) OVERRIDE_CPP17
 get contents of header
 
unsigned int GetErrorBitFlag (int n) OVERRIDE_CPP17
 get contents of header
 
void AddErrorBitFlag (int n, unsigned int error_bit_flag) OVERRIDE_CPP17
 Add Detected Error bitflag.
 
int GetPacketCRCError (int n) OVERRIDE_CPP17
 check CRC packet Error
 
int GetEventCRCError (int n) OVERRIDE_CPP17
 check CRC event Error
 
unsigned int GetNodeID (int n) OVERRIDE_CPP17
 get node-ID from data
 
virtual int GetNumFINESSEBlock (int n) OVERRIDE_CPP17
 get # of FINNESEs which contains data
 
int Get1stFINESSENwords (int n) OVERRIDE_CPP17
 get data size of FINESSE slot A buffer
 
int Get2ndFINESSENwords (int n) OVERRIDE_CPP17
 get data size of FINESSE slot B buffer
 
int Get3rdFINESSENwords (int n) OVERRIDE_CPP17
 get data size of FINESSE slot C buffer
 
int Get4thFINESSENwords (int n) OVERRIDE_CPP17
 get data size of FINESSE slot D buffer
 
unsigned int GetTTCtimeTRGType (int n) OVERRIDE_CPP17
 get b2l block from "FEE b2link header"
 
unsigned int GetTTUtime (int n) OVERRIDE_CPP17
 Check if COPPER Magic words are correct.
 
int GetTTCtime (int n) OVERRIDE_CPP17
 Get ctime.
 
int GetTRGType (int n) OVERRIDE_CPP17
 Get trgtype.
 
void GetTTTimeVal (int n, struct timeval *tv) OVERRIDE_CPP17
 Get timeval.
 
int GetMaxNumOfCh (int n) OVERRIDE_CPP17
 Get the max number of channels in a readout board.
 
virtual int * GetDetectorBuffer (int n, int finesse_num)
 get Detector buffer
 
virtual int * GetRawHdrBufPtr (int n)
 get buffer pointer of rawcopper header(Currently same as GetBufferPos)
 
virtual int * GetFINESSEBuffer (int n, int finesse_num)
 get FINESSE buffer pointer
 
virtual int * Get1stFINESSEBuffer (int n)
 get FINESSE buffer pointer for slot A
 
virtual int * Get2ndFINESSEBuffer (int n)
 get FINESSE buffer pointer for slot B
 
virtual int * Get3rdFINESSEBuffer (int n)
 get FINESSE buffer pointer for slot C
 
virtual int * Get4thFINESSEBuffer (int n)
 get FINESSE buffer pointer for slot D
 
virtual int GetOffsetFINESSE (int n, int finesse)
 get # of offset words
 
virtual int GetOffset2ndFINESSE (int n)
 get # of offset words for FINESSE slot B buffer position
 
virtual int GetOffset3rdFINESSE (int n)
 get # of offset words for FINESSE slot C buffer position
 
virtual int GetOffset4thFINESSE (int n)
 get # of offset words for FINESSE slot D buffer position
 
virtual unsigned int CalcXORChecksum (int *buf, int nwords)
 calc XOR checksum
 
virtual int * PackDetectorBuf (int *packed_buf_nwords, int *const(&detector_buf_ch)[MAX_PCIE40_CH], int const(&nwords_ch)[MAX_PCIE40_CH], RawCOPPERPackerInfo rawcpr_info)
 Pack data for PCIe40 data-format.
 
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 void GetNodeName (int n, char *node_name, int bufsize)
 Get hostname of a node from the RawCOPPER header.
 
virtual void GetNodeName (char *node_name, unsigned int node_id, int bufsize)
 Get hostname of a node from an argument.
 
virtual bool CheckOnlineRemovedDataBit (int n, int finesse_num)
 Check if COPPER Magic words are correct.
 
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 )
 
virtual int TotalBufNwords ()
 Get total length of m_buffer.
 
virtual int GetBufferPos (int n)
 get position of data block in word
 
virtual int * GetBuffer (int n)
 get nth buffer pointer
 
virtual int * GetWholeBuffer ()
 get pointer to buffer(m_buffer)
 
virtual int GetNumEntries ()
 get # of data blocks = (# of nodes)*(# of events)
 
virtual int GetNumNodes ()
 get # of data sources(e.g. # of COPPER boards) in m_buffer
 
virtual int GetNumEvents ()
 get # of events in m_buffer
 
virtual int GetPreAllocFlag ()
 get malloc_flag
 
virtual int GetBlockNwords (int n)
 get size of a data block
 
virtual int CheckFTSWID (int n)
 get FTSW ID to check whether this data block is FTSW data or not
 
virtual int CheckTLUID (int n)
 get FTSW ID to check whether this data block is FTSW data or not
 
virtual void CopyBlock (int n, int *buf_to)
 Copy one datablock to buffer.
 
virtual void PrintData (int *buf, int nwords)
 print data
 

Public Attributes

RawHeader_v2 tmp_header
 header ( not recorded )
 
RawTrailer_v2 tmp_trailer
 trailer ( not recorded )
 

Protected Attributes

int m_nwords
 number of words of buffer
 
int m_num_nodes
 number of nodes in this object
 
int m_num_events
 number of events in this object
 
int * m_buffer
 Buffer.
 
int m_use_prealloc_buf
 not recorded
 

Detailed Description

The Raw COPPER class ver.2 This class stores data received by COPPER via belle2link Data from all detectors except PXD are stored in this class.

Definition at line 37 of file PostRawCOPPERFormat_v2.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Copper data words = ( total_data_length in COPPER header ) + COPPER_HEADER_TRAILER_NWORDS.

Definition at line 183 of file PostRawCOPPERFormat_v2.h.

183 {
184 SIZE_COPPER_DRIVER_HEADER = 0,
185 SIZE_COPPER_DRIVER_TRAILER = 0
186 };

◆ anonymous enum

anonymous enum

Definition at line 189 of file PostRawCOPPERFormat_v2.h.

189 {
190 SIZE_COPPER_HEADER = 0
191 };

◆ anonymous enum

anonymous enum

Definition at line 194 of file PostRawCOPPERFormat_v2.h.

194 {
195 SIZE_COPPER_TRAILER = 0
196 };

◆ anonymous enum

anonymous enum

Definition at line 199 of file PostRawCOPPERFormat_v2.h.

199 {
200 POS_B2LHSLB_MAGIC = 0,
201 SIZE_B2LHSLB_HEADER = 1
202 };

◆ anonymous enum

anonymous enum

Definition at line 206 of file PostRawCOPPERFormat_v2.h.

206 {
207 POS_B2L_CTIME = 0,
208 SIZE_B2LFEE_HEADER = 1
209 };

◆ anonymous enum

anonymous enum

Definition at line 212 of file PostRawCOPPERFormat_v2.h.

212 {
213 POS_B2LFEE_ERRCNT_CRC16 = 0,
214 SIZE_B2LFEE_TRAILER = 1
215 };

◆ anonymous enum

anonymous enum

Definition at line 220 of file PostRawCOPPERFormat_v2.h.

220 {
221 SIZE_B2LHSLB_TRAILER = 0
222 };

◆ anonymous enum

anonymous enum
inherited

Format version number.

Definition at line 187 of file RawCOPPERFormat_v2.h.

187 {
188 DATA_FORMAT_VERSION = 2
189 };

◆ anonymous enum

anonymous enum
inherited

Definition at line 75 of file RawDataBlockFormat.h.

75 {
76 POS_NWORDS = 0,
77 POS_NODE_ID = 6
78 };

◆ anonymous enum

anonymous enum
inherited

Definition at line 80 of file RawDataBlockFormat.h.

80 {
81 // Tentatively needed to distinguish new and old FTSW format, which will be changed in Nov. 2013
82 POS_FTSW_ID_OLD = 5,
83 TEMP_POS_NWORDS_HEADER = 1,
84 OLD_FTSW_NWORDS_HEADER = 6
85 };

Constructor & Destructor Documentation

◆ PostRawCOPPERFormat_v2()

Default constructor.

Definition at line 19 of file PostRawCOPPERFormat_v2.cc.

20{
21}

◆ ~PostRawCOPPERFormat_v2()

~PostRawCOPPERFormat_v2 ( )
virtual

Constructor using existing pointer to raw data buffer.

Destructor

Definition at line 23 of file PostRawCOPPERFormat_v2.cc.

24{
25}

Member Function Documentation

◆ CalcDriverChkSum()

unsigned int CalcDriverChkSum ( int  n)
virtual

calc COPPER driver's checksum value

Implements RawCOPPERFormat.

Definition at line 39 of file PostRawCOPPERFormat_v2.cc.

40{
41 char err_buf[500];
42 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
43 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
44 printf("[DEBUG] %s\n", err_buf);
45 B2FATAL(err_buf);
46 return 0;
47}

◆ CalcXORChecksum()

unsigned int CalcXORChecksum ( int *  buf,
int  nwords 
)
virtualinherited

calc XOR checksum

Definition at line 24 of file RawCOPPERFormat.cc.

25{
26 unsigned int checksum = 0;
27 for (int i = 0; i < nwords; i++) {
28 checksum = checksum ^ buf[ i ];
29 }
30 return checksum;
31}

◆ CheckB2LHSLBMagicWords()

int CheckB2LHSLBMagicWords ( int *  finesse_buf,
int  finesse_nwords 
)

check magic words

Definition at line 218 of file PostRawCOPPERFormat_v2.cc.

219{
220 char err_buf[500];
221 sprintf(err_buf, "[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
222 __FILE__, __PRETTY_FUNCTION__, __LINE__);
223 printf("Print out variables to reduce unused-variables-warnings : %p %d\n", finesse_buf, finesse_nwords);
224 printf("[DEBUG] %s\n", err_buf);
225 B2FATAL(err_buf);
226}

◆ CheckCOPPERMagic()

bool CheckCOPPERMagic ( int  n)
virtual

Check if COPPER Magic words are correct.

Implements RawCOPPERFormat.

Definition at line 179 of file PostRawCOPPERFormat_v2.cc.

180{
181 char err_buf[500];
182 char hostname[128];
183 GetNodeName(n, hostname, sizeof(hostname));
184 sprintf(err_buf,
185 "[FATAL] %s ch=%d : ERROR_EVENT : No magic word # in COPPER header (block %d). Exiting...: eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
186 hostname, -1,
187 n,
188 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
189 __FILE__, __PRETTY_FUNCTION__, __LINE__);
190 printf("[DEBUG] %s\n", err_buf);
191 B2FATAL(err_buf);
192 return false;
193}
virtual void GetNodeName(int n, char *node_name, int bufsize)
Get hostname of a node from the RawCOPPER header.
unsigned int GetEveNo(int n) OVERRIDE_CPP17
get subrun #(8bit)
int GetExpNo(int n) OVERRIDE_CPP17
get Experimental # from header
int GetRunNo(int n) OVERRIDE_CPP17
Exp# (10bit) run# (14bit) restart # (8bit)
int GetSubRunNo(int n) OVERRIDE_CPP17
get run # (14bit)

◆ CheckCRC16()

int CheckCRC16 ( int  n,
int  finesse_num 
)

check magic words

Definition at line 228 of file PostRawCOPPERFormat_v2.cc.

229{
230
231 //
232 // Calculate CRC16
233 //
234 int finesse_nwords = GetFINESSENwords(n, finesse_num);
235 if (finesse_nwords <= 0) {
236 char err_buf[500];
237 char hostname[128];
238 GetNodeName(n, hostname, sizeof(hostname));
239 sprintf(err_buf,
240 "[FATAL] %s ch=%d : ERROR_EVENT : The specified finesse(%c) seems to be empty(nwords = %d). Cannot calculate CRC16. Exiting...: eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
241 hostname, finesse_num,
242 65 + finesse_num, finesse_nwords,
243 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
244 __FILE__, __PRETTY_FUNCTION__, __LINE__);
245 printf("%s", err_buf); fflush(stdout);
246 B2FATAL(err_buf);
247 }
248
249 int* copper_buf = GetBuffer(n);
250
251
252 unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, &(copper_buf[ tmp_header.POS_TTCTIME_TRGTYPE ]), 1);
253 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[ tmp_header.POS_EVE_NO ]), 1);
254 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[ tmp_header.POS_TTUTIME ]), 1);
255 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[ tmp_header.POS_EXP_RUN_NO ]), 1);
256 int* buf = GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + POS_B2L_CTIME;
257 int pos_nwords = finesse_nwords - (static_cast<int>(SIZE_B2LHSLB_HEADER) + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER +
258 SIZE_B2LHSLB_TRAILER);
259 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
260
261 //
262 // Compare CRC16 with B2LCRC16
263 //
264 buf = GetFINESSEBuffer(n, finesse_num) + GetFINESSENwords(n,
265 finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
266
267 if (GetEveNo(n) % 100000 == 0) {
268 printf("#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n", GetEveNo(n), n, finesse_num,
269 *buf, temp_crc16);
270 }
271
272 // if ( false ) {
273 if ((unsigned short)(*buf & 0xFFFF) != temp_crc16) {
274
275 // dump an event
276 int copper_nwords = copper_buf[ tmp_header.POS_NWORDS ];
277 PrintData(copper_buf, copper_nwords);
278 // Check whether packet-CRC error has occcured or not.
279 if (copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ] & tmp_header.B2LINK_PACKET_CRC_ERROR) {
280 //
281 // Do not stop data
282 //
283 char err_buf[600];
284 char hostname[128];
285 GetNodeName(n, hostname, sizeof(hostname));
286
287 if ((GetNodeID(n) & DETECTOR_MASK) == ARICH_ID) {
288 sprintf(err_buf,
289 "[WARNING] %s ch=%d : ARICH : POST B2link event CRC16 error with B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x : This error is ignored and the error event will be recorded in .sroot file acording to request from ARICH group: slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
290 hostname, finesse_num,
291 *buf, temp_crc16, GetFINESSENwords(n, finesse_num), copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ],
292 65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
293 __FILE__, __PRETTY_FUNCTION__, __LINE__);
294 printf("%s", err_buf); fflush(stdout);
295 PrintData(GetFINESSEBuffer(n, finesse_num), GetFINESSENwords(n, finesse_num));
296 } else {
297 sprintf(err_buf,
298 "[FATAL] %s ch=%d : ERROR_EVENT : POST B2link event CRC16 error with B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x : slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
299 hostname, finesse_num,
300 *buf, temp_crc16, GetFINESSENwords(n, finesse_num), copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ],
301 65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
302 __FILE__, __PRETTY_FUNCTION__, __LINE__);
303 printf("%s", err_buf); fflush(stdout);
304 PrintData(GetFINESSEBuffer(n, finesse_num), GetFINESSENwords(n, finesse_num));
305#ifndef NO_ERROR_STOP
306 B2FATAL(err_buf);
307#endif
308 }
309
310
311
312 } else {
313 //
314 // Stop taking data
315 //
316 char err_buf[500];
317 char hostname[128];
318 GetNodeName(n, hostname, sizeof(hostname));
319 sprintf(err_buf,
320 "[FATAL] %s ch=%d : ERROR_EVENT : POST B2link event CRC16 error without B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x: slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
321 hostname, finesse_num,
322 *buf, temp_crc16, GetFINESSENwords(n, finesse_num), copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ],
323 65 + finesse_num, GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
324 __FILE__, __PRETTY_FUNCTION__, __LINE__);
325 printf("%s", err_buf); fflush(stdout);
326 PrintData(GetFINESSEBuffer(n, finesse_num), GetFINESSENwords(n, finesse_num));
327#ifndef NO_ERROR_STOP
328 B2FATAL(err_buf);
329#endif
330 }
331 // Modify XOR checksum due to adding a bit flag
332 copper_buf[ copper_nwords - tmp_trailer.RAWTRAILER_NWORDS + tmp_trailer.POS_CHKSUM ]
333 ^= copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ];
334 copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ] |= tmp_header.B2LINK_EVENT_CRC_ERROR;
335 copper_buf[ copper_nwords - tmp_trailer.RAWTRAILER_NWORDS + tmp_trailer.POS_CHKSUM ]
336 ^= copper_buf[ tmp_header.POS_TRUNC_MASK_DATATYPE ];
337 }
338
339 return 1;
340
341
342}
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
RawTrailer_v2 tmp_trailer
trailer ( not recorded )
RawHeader_v2 tmp_header
header ( not recorded )
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
virtual int * GetBuffer(int n)
get nth buffer pointer
virtual void PrintData(int *buf, int nwords)
print data
unsigned int GetNodeID(int n) OVERRIDE_CPP17
get node-ID from data

◆ CheckData()

void CheckData ( int  n,
unsigned int  prev_evenum,
unsigned int *  cur_evenum,
unsigned int  prev_copper_ctr,
unsigned int *  cur_copper_ctr,
unsigned int  prev_exprunsubrun_no,
unsigned int *  cur_exprunsubrun_no 
)
virtual

check data contents

Implements RawCOPPERFormat.

Definition at line 125 of file PostRawCOPPERFormat_v2.cc.

129{
130 char err_buf[500];
131 int err_flag = 0;
132
133 //
134 // Check incrementation of event #
135 //
136 *cur_evenum_rawcprhdr = GetEveNo(n);
137 *cur_exprunsubrun_no = GetExpRunSubrun(n);
138
139 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
140 if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
141 sprintf(err_buf, "CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
142 n, prev_evenum, *cur_evenum_rawcprhdr,
143 __FILE__, __PRETTY_FUNCTION__, __LINE__);
144 err_flag = 1;
145 }
146 }
147
148
149 //
150 // Check checksum calculated by DeSerializerCOPPER()
151 //
153 unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
154 if (tmp_trailer.GetChksum() != xor_chksum) {
155 char hostname[128];
156 GetNodeName(n, hostname, sizeof(hostname));
157 sprintf(err_buf,
158 "[FATAL] %s ch=%d : ERROR_EVENT : checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
159 hostname, -1,
160 n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
161 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
162 __FILE__, __PRETTY_FUNCTION__, __LINE__);
163 err_flag = 1;
164 }
165
166
167 if (err_flag == 1) {
168 printf("[DEBUG] %s\n", err_buf);
169 printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
171 printf("Print out variables to reduce unused-variables-warnings : %u %u\n", prev_copper_ctr, *cur_copper_ctr);
172 B2FATAL(err_buf);
173 }
174
175 return;
176
177}
virtual unsigned int CalcXORChecksum(int *buf, int nwords)
calc XOR checksum
virtual int GetBlockNwords(int n)
get size of a data block
int GetTrlNwords()
Set magic word.
unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17
get Experimental # from header
unsigned int GetChksum()
Set # of trailer words.
void SetBuffer(int *bufin)
return buffer
Definition: RawTrailer_v2.h:96
int * GetRawTrlBufPtr(int n) OVERRIDE_CPP17
get buffer pointer of rawcopper trailer

◆ CheckFTSWID()

int CheckFTSWID ( int  n)
virtualinherited

get FTSW ID to check whether this data block is FTSW data or not

Definition at line 73 of file RawDataBlockFormat.cc.

74{
75 int pos = POS_NODE_ID;
76 if (m_buffer[ GetBufferPos(n) + TEMP_POS_NWORDS_HEADER ] == OLD_FTSW_NWORDS_HEADER) {
77 pos = POS_FTSW_ID_OLD;
78 }
79
80 if ((m_buffer[ GetBufferPos(n) + pos ] & 0xffffff00) == 0x54544400) { // "TTD" + format version ( 0x20=DESY, 0x31=2018/7/11)
81 return 1;
82 } else {
83 return 0;
84 }
85}
virtual int GetBufferPos(int n)
get position of data block in word

◆ CheckOnlineRemovedDataBit()

bool CheckOnlineRemovedDataBit ( int  n,
int  finesse_num 
)
virtualinherited

Check if COPPER Magic words are correct.

Reimplemented in PostRawCOPPERFormat_latest, and PreRawCOPPERFormat_latest.

Definition at line 217 of file RawCOPPERFormat.cc.

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}

◆ CheckTLUID()

int CheckTLUID ( int  n)
virtualinherited

get FTSW ID to check whether this data block is FTSW data or not

Definition at line 88 of file RawDataBlockFormat.cc.

89{
90 int pos = POS_NODE_ID;
91 if (m_buffer[ GetBufferPos(n) + TEMP_POS_NWORDS_HEADER ] == OLD_FTSW_NWORDS_HEADER) {
92 pos = POS_FTSW_ID_OLD;
93 }
94 if (m_buffer[ GetBufferPos(n) + pos ] == 0x544c5520) { // "TLU "
95 return 1;
96 } else {
97 return 0;
98 }
99}

◆ CheckUtimeCtimeTRGType()

void CheckUtimeCtimeTRGType ( int  n)
virtual

check data contents

Implements RawCOPPERFormat.

Definition at line 195 of file PostRawCOPPERFormat_v2.cc.

196{
197 char err_buf[500];
198 sprintf(err_buf, "[FATAL] This function is not supported (block %d). Exiting...\n%s %s %d\n",
199 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
200 printf("[DEBUG] %s\n", err_buf);
201 B2FATAL(err_buf);
202}

◆ CompareHeaderValue()

void CompareHeaderValue ( int  n,
const unsigned int(&)  input_val[MAX_PCIE40_CH],
std::vector< std::vector< unsigned int > > &  result 
)
virtualinherited

Compare value from different channels and make a statistics table.

Reimplemented in RawCOPPERFormat_latest.

Definition at line 170 of file RawCOPPERFormat.cc.

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}

◆ CopyBlock()

void CopyBlock ( int  n,
int *  buf_to 
)
virtualinherited

Copy one datablock to buffer.

Definition at line 173 of file RawDataBlockFormat.cc.

174{
175 memcpy(buf_to, GetBuffer(n), GetBlockNwords(n) * sizeof(int));
176 return;
177}

◆ FillTopBlockRawHeader()

unsigned int FillTopBlockRawHeader ( unsigned int  m_node_id,
unsigned int  prev_eve32,
unsigned int  prev_exprunsubrun_no,
unsigned int *  cur_exprunsubrun_no 
)
virtual

should be called by DeSerializerCOPPER.cc and fill contents in RawHeader

Implements RawCOPPERFormat.

Definition at line 204 of file PostRawCOPPERFormat_v2.cc.

207{
208 char err_buf[500];
209 sprintf(err_buf, "[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
210 __FILE__, __PRETTY_FUNCTION__, __LINE__);
211 printf("Print out variables to reduce unused-variables-warnings : %u %u %u %u\n",
212 m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no);
213 printf("[DEBUG] %s\n", err_buf);
214 B2FATAL(err_buf);
215}

◆ GetB2LFEE32bitEventNumber()

unsigned int GetB2LFEE32bitEventNumber ( int  n)
virtual

get b2l block from "FEE b2link header"

Implements RawCOPPERFormat.

Definition at line 107 of file PostRawCOPPERFormat_v2.cc.

108{
109 char err_buf[500];
110 char hostname[128];
111 GetNodeName(n, hostname, sizeof(hostname));
112 sprintf(err_buf,
113 "[FATAL] %s ch=%d : ERROR_EVENT : No event # in B2LFEE header. (block %d) Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
114 hostname, -1,
115 n,
116 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
117 __FILE__, __PRETTY_FUNCTION__, __LINE__);
118 printf("[DEBUG] %s\n", err_buf);
119 B2FATAL(err_buf);
120 return 0;
121}

◆ GetBlockNwords()

int GetBlockNwords ( int  n)
virtualinherited

get size of a data block

Definition at line 107 of file RawDataBlockFormat.cc.

108{
109 int size;
110 if (n == (m_num_events * m_num_nodes) - 1) {
111 size = m_nwords - GetBufferPos(n);
112 } else {
113 size = GetBufferPos(n + 1) - GetBufferPos(n);
114 }
115 return size;
116}
int m_num_events
number of events in this object
int m_num_nodes
number of nodes in this object
int m_nwords
number of words of buffer

◆ GetBuffer()

int * GetBuffer ( int  n)
virtualinherited

get nth buffer pointer

Definition at line 124 of file RawDataBlockFormat.cc.

125{
126 int pos_nwords = GetBufferPos(n);
127 return &(m_buffer[ pos_nwords ]);
128}

◆ GetBufferPos()

int GetBufferPos ( int  n)
virtualinherited

get position of data block in word

Definition at line 30 of file RawDataBlockFormat.cc.

31{
32 if (m_buffer == NULL || m_nwords <= 0) {
33 char err_buf[500];
34 sprintf(err_buf, "[FATAL] RawPacket buffer(%p) is not available or length(%d) is not set.\n %s %s %d\n",
35 m_buffer, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
36 printf("%s", err_buf); fflush(stdout);
37 B2FATAL(err_buf);
38 }
39
40 if (n >= (m_num_events * m_num_nodes)) {
41 char err_buf[500];
42 sprintf(err_buf, "[FATAL] Invalid COPPER block No. (%d : max %d ) is specified. Exiting... \n %s %s %d\n",
43 n, (m_num_events * m_num_nodes), __FILE__, __PRETTY_FUNCTION__, __LINE__);
44 printf("%s", err_buf); fflush(stdout);
45 B2FATAL(err_buf);
46 }
47
48 int pos_nwords = 0;
49 for (int i = 1; i <= n ; i++) {
50 if (m_buffer[ pos_nwords ] <= 0) {
51 char err_buf[500];
52 sprintf(err_buf,
53 "[FATAL] ERROR_EVENT : length of this data block is strange ( %d words ). Maybe data is corrupted or RawHeader info has not been filled yet. Exiting...",
54 m_buffer[ pos_nwords ]);
55 printf("%s", err_buf);
56 B2FATAL(err_buf);
57 } else {
58 pos_nwords += m_buffer[ pos_nwords ];
59 }
60 if (pos_nwords >= m_nwords) {
61 char err_buf[500];
62 sprintf(err_buf, "[FATAL] ERROR_EVENT : value of pos_nwords(%d) is larger than m_nwords(%d). Exiting...\n %s %s %d\n",
63 pos_nwords, m_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
64 printf("%s", err_buf); fflush(stdout);
65 B2FATAL(err_buf); // to reduce multiple error messages
66 }
67 }
68 return pos_nwords;
69
70}

◆ GetDetectorBuffer()

int * GetDetectorBuffer ( int  n,
int  finesse_num 
)
virtualinherited

get Detector buffer

Reimplemented in PostRawCOPPERFormat_latest, and PreRawCOPPERFormat_latest.

Definition at line 94 of file RawCOPPERFormat.cc.

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}
virtual int * Get4thDetectorBuffer(int n)=0
get Detector Buffer of slot D
virtual int * Get2ndDetectorBuffer(int n)=0
get Detector Buffer of slot B
virtual int * Get3rdDetectorBuffer(int n)=0
get Detector Buffer of slot C
virtual int * Get1stDetectorBuffer(int n)=0
get Detector buffer of slot A

◆ GetDetectorNwords()

int GetDetectorNwords ( int  n,
int  finesse_num 
)
virtual

get Detector buffer length

Implements RawCOPPERFormat.

Definition at line 28 of file PostRawCOPPERFormat_v2.cc.

29{
30 int nwords = 0;
31 if (GetFINESSENwords(n, finesse_num) > 0) {
32 nwords = GetFINESSENwords(n, finesse_num)
33 - (static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
34 }
35 return nwords;
36}

◆ GetFINESSEBuffer()

int * GetFINESSEBuffer ( int  n,
int  finesse_num 
)
virtualinherited

get FINESSE buffer pointer

Reimplemented in RawCOPPERFormat_latest.

Definition at line 65 of file RawCOPPERFormat.cc.

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}
virtual int * Get3rdFINESSEBuffer(int n)
get FINESSE buffer pointer for slot C
virtual int * Get2ndFINESSEBuffer(int n)
get FINESSE buffer pointer for slot B
virtual int * Get4thFINESSEBuffer(int n)
get FINESSE buffer pointer for slot D
virtual int * Get1stFINESSEBuffer(int n)
get FINESSE buffer pointer for slot A

◆ GetFINESSENwords()

int GetFINESSENwords ( int  n,
int  finesse 
)
virtual

get data size of FINESSE buffer

Implements RawCOPPERFormat.

Definition at line 50 of file PostRawCOPPERFormat_v2.cc.

51{
52 int pos_nwords_0, pos_nwords_1;
53 int nwords = 0;
54 switch (finesse_num) {
55 case 0 :
56 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_1ST_FINESSE;
57 pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
58 nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
59 break;
60 case 1 :
61 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
62 pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
63 nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
64 break;
65 case 2 :
66 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
67 pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
68 nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
69 break;
70 case 3 :
71 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
72 {
73 int nwords_1 = GetBlockNwords(n)
74 - SIZE_COPPER_DRIVER_TRAILER
76 nwords = nwords_1 - m_buffer[ pos_nwords_0 ];
77 }
78 break;
79 default :
80 char err_buf[500];
81 sprintf(err_buf, "[FATAL] Invalid finesse # : %s %s %d\n",
82 __FILE__, __PRETTY_FUNCTION__, __LINE__);
83 printf("[DEBUG] %s\n", err_buf);
84 B2FATAL(err_buf);
85 }
86
87 if (nwords < 0 || nwords > 1e6) {
88 char err_buf[500];
89 char hostname[128];
90 GetNodeName(n, hostname, sizeof(hostname));
91 sprintf(err_buf, "[FATAL] %s ch=%d : ERROR_EVENT : # of words is strange. %d : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
92 hostname, finesse_num,
93 nwords,
95 __FILE__, __PRETTY_FUNCTION__, __LINE__);
96 printf("[DEBUG] %s\n", err_buf);
97 B2FATAL(err_buf);
98 }
99
100 return nwords;
101
102}

◆ GetNodeName() [1/2]

void GetNodeName ( char *  node_name,
unsigned int  node_id,
int  bufsize 
)
virtualinherited

Get hostname of a node from an argument.

Definition at line 200 of file RawCOPPERFormat.cc.

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}

◆ GetNodeName() [2/2]

void GetNodeName ( int  n,
char *  node_name,
int  bufsize 
)
virtualinherited

Get hostname of a node from the RawCOPPER header.

Definition at line 182 of file RawCOPPERFormat.cc.

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}
virtual unsigned int GetNodeID(int n)=0
get node-ID from data

◆ GetNumEntries()

virtual int GetNumEntries ( )
inlinevirtualinherited

get # of data blocks = (# of nodes)*(# of events)

Definition at line 49 of file RawDataBlockFormat.h.

49{ return m_num_events * m_num_nodes; }

◆ GetNumEvents()

virtual int GetNumEvents ( )
inlinevirtualinherited

get # of events in m_buffer

Definition at line 55 of file RawDataBlockFormat.h.

55{ return m_num_events; }

◆ GetNumFINESSEBlock()

int GetNumFINESSEBlock ( int  n)
virtualinherited

get # of FINNESEs which contains data

Implements RawCOPPERFormat.

Definition at line 29 of file RawCOPPERFormat_v2.cc.

30{
31 int cnt = 0;
32 for (int i = 0; i < 4; i++) {
33 if (GetFINESSENwords(n, i) > 0) {
34 cnt++;
35 }
36 }
37 return cnt;
38}
virtual int GetFINESSENwords(int n, int finesse)=0
get data size of FINESSE buffer

◆ GetNumNodes()

virtual int GetNumNodes ( )
inlinevirtualinherited

get # of data sources(e.g. # of COPPER boards) in m_buffer

Definition at line 52 of file RawDataBlockFormat.h.

52{ return m_num_nodes; }

◆ GetOffsetFINESSE()

int GetOffsetFINESSE ( int  n,
int  finesse 
)
virtualinherited

get # of offset words

Definition at line 36 of file RawCOPPERFormat.cc.

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}
virtual int GetOffset1stFINESSE(int n)=0
get # of offset words for FINESSE slot A buffer position
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
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

◆ GetPreAllocFlag()

virtual int GetPreAllocFlag ( )
inlinevirtualinherited

get malloc_flag

Definition at line 58 of file RawDataBlockFormat.h.

58{ return m_use_prealloc_buf; }

◆ GetWholeBuffer()

int * GetWholeBuffer ( )
virtualinherited

get pointer to buffer(m_buffer)

Definition at line 119 of file RawDataBlockFormat.cc.

120{
121 return m_buffer;
122}

◆ PackDetectorBuf() [1/2]

int * PackDetectorBuf ( int *  packed_buf_nwords,
int *const(&)  detector_buf_ch[MAX_PCIE40_CH],
int const(&)  nwords_ch[MAX_PCIE40_CH],
RawCOPPERPackerInfo  rawcpr_info 
)
virtualinherited

Pack data for PCIe40 data-format.

Reimplemented in PostRawCOPPERFormat_latest, and PreRawCOPPERFormat_latest.

Definition at line 156 of file RawCOPPERFormat.cc.

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}

◆ PackDetectorBuf() [2/2]

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 
)
virtual

Pack data (format ver. = -1 -> Select the latest format version)

Implements RawCOPPERFormat.

Definition at line 345 of file PostRawCOPPERFormat_v2.cc.

351{
352 int* packed_buf = NULL;
353
354 int poswords_to = 0;
355 int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
356 const int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
357
358 // calculate the event length
359 int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
360
361 for (int i = 0; i < 4; i++) {
362 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue; // for an empty FINESSE slot
363 length_nwords += nwords[ i ];
364 length_nwords += static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER
365 + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
366 }
367
368 // allocate buffer
369 packed_buf = new int[ length_nwords ];
370 memset(packed_buf, 0, sizeof(int) * length_nwords);
371
372 //
373 // Fill RawHeader
374 //
375 tmp_header.SetBuffer(packed_buf);
376
377 packed_buf[ tmp_header.POS_NWORDS ] = length_nwords; // total length
378 packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] =
379 0x7f7f0000
380 | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
381 | tmp_header.RAWHEADER_NWORDS; // ver.#, header length
382 packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.exp_num << 22)
383 | (rawcpr_info.run_subrun_num & 0x003FFFFF); // exp. and run #
384 packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.eve_num; // eve #
385 packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4; // tt_ctime
386 packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.tt_utime; // tt_utime
387 packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.node_id; // node ID
388
389 // fill the positions of finesse buffers
390 packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ] = static_cast<int>(tmp_header.RAWHEADER_NWORDS) + SIZE_COPPER_HEADER;
391
392 packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ];
393 if (nwords[ 0 ] > 0) {
394 packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] +=
395 nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
396 }
397
398 packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ];
399 if (nwords[ 1 ] > 0) {
400 packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] +=
401 nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
402 }
403
404 packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ];
405 if (nwords[ 2 ] > 0) {
406 packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER +
407 SIZE_B2LHSLB_TRAILER;
408 }
409 poswords_to += tmp_header.GetHdrNwords();
410
411 // Fill COPPER header
412 poswords_to += SIZE_COPPER_HEADER;
413
414 // Fill FINESSE buffer
415 for (int i = 0; i < 4; i++) {
416
417 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0) continue; // for an empty FINESSE slot
418
419 // Fill b2link HSLB header
420 packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.eve_num);
421 poswords_to += SIZE_B2LHSLB_HEADER;
422
423 // Fill b2link FEE header
424 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.b2l_ctime & 0x7FFFFFF) << 4;
425 poswords_to += SIZE_B2LFEE_HEADER;
426
427 // copy the 1st Detector Buffer
428 memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*sizeof(int));
429 poswords_to += nwords[ i ];
430
431 // Fill b2link FEE trailer
432 unsigned int crc16 = 0;
433 packed_buf[ poswords_to + POS_B2LFEE_ERRCNT_CRC16 ] = crc16 &
434 0xffff; // Error count is stored in this buffer for ver.2 format but it is set to zero here.
435 poswords_to += SIZE_B2LFEE_TRAILER;
436
437 // Fill b2link HSLB trailer
438 poswords_to += SIZE_B2LHSLB_TRAILER;
439
440 }
441
442 // Fill COPPER trailer
443 poswords_to += SIZE_COPPER_TRAILER;
444
445 // Fill RawTrailer
446 packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
447 poswords_to += tmp_trailer.GetTrlNwords();
448
449 *packed_buf_nwords = poswords_to;
450
451 return packed_buf;
452}
void SetBuffer(int *bufin)
set buffer
Definition: RawHeader_v2.h:47
int GetHdrNwords()
get contents of header
Definition: RawHeader_v2.h:360

◆ PrintData()

void PrintData ( int *  buf,
int  nwords 
)
virtualinherited

print data

Definition at line 161 of file RawDataBlockFormat.cc.

162{
163 printf("[DEBUG] ");
164 for (int i = 0; i < nwords; i++) {
165 printf("%.8x ", buf[ i ]);
166 if (i % 10 == 9) printf("\n[DEBUG] ");
167 }
168 printf("\n[DEBUG] ");
169 printf("\n");
170 return;
171}

◆ SetBuffer()

void SetBuffer ( int *  bufin,
int  nwords,
int  delete_flag,
int  num_events,
int  num_nodes 
)
virtualinherited

set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )

Definition at line 131 of file RawDataBlockFormat.cc.

132{
133
134 if (bufin == NULL) {
135 char err_buf[500];
136 sprintf(err_buf, "[DEBUG] bufin is NULL. Exting...\n");
137 printf("%s", err_buf); fflush(stdout);
138 B2FATAL(err_buf);
139 }
140
141 if (!m_use_prealloc_buf && m_buffer != NULL) delete[] m_buffer;
142
143 if (delete_flag == 0) {
144 m_use_prealloc_buf = true;
145 } else {
146 m_use_prealloc_buf = false;
147 }
148
149 m_nwords = nwords;
150 m_buffer = bufin;
151
152 m_num_nodes = num_nodes;
153 m_num_events = num_events;
154
155 return;
156
157}

◆ TotalBufNwords()

int TotalBufNwords ( )
virtualinherited

Get total length of m_buffer.

Definition at line 101 of file RawDataBlockFormat.cc.

102{
103 return m_nwords;
104}

Member Data Documentation

◆ m_buffer

int* m_buffer
protectedinherited

Buffer.

Definition at line 98 of file RawDataBlockFormat.h.

◆ m_num_events

int m_num_events
protectedinherited

number of events in this object

Definition at line 95 of file RawDataBlockFormat.h.

◆ m_num_nodes

int m_num_nodes
protectedinherited

number of nodes in this object

Definition at line 92 of file RawDataBlockFormat.h.

◆ m_nwords

int m_nwords
protectedinherited

number of words of buffer

Definition at line 89 of file RawDataBlockFormat.h.

◆ m_use_prealloc_buf

int m_use_prealloc_buf
protectedinherited

not recorded

flag for deleting m_buffer in destructer( 0:delete, 1: not delete) When using pre-allocated buffer, the buffer should be reused and not deleted in the destructer

Definition at line 102 of file RawDataBlockFormat.h.

◆ tmp_header

RawHeader_v2 tmp_header
inherited

header ( not recorded )

Definition at line 192 of file RawCOPPERFormat_v2.h.

◆ tmp_trailer

RawTrailer_v2 tmp_trailer
inherited

trailer ( not recorded )

Definition at line 195 of file RawCOPPERFormat_v2.h.


The documentation for this class was generated from the following files: