Belle II Software development
PreRawCOPPERFormat_latest Class Reference

The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by COPPER via belle2linkt Data from all detectors except PXD are stored in this class. More...

#include <PreRawCOPPERFormat_latest.h>

Inheritance diagram for PreRawCOPPERFormat_latest:
RawCOPPERFormat_latest RawCOPPERFormat RawDataBlockFormat

Public Types

enum  {
  POS_MAGIC_B2LHSLB = 0 ,
  SIZE_B2LHSLB_HEADER = 1
}
 
enum  {
  POS_TT_CTIME_TYPE = 0 ,
  POS_TT_TAG = 1 ,
  POS_TT_UTIME = 2 ,
  POS_EXP_RUN = 3 ,
  POS_B2L_CTIME = 4 ,
  SIZE_B2LFEE_HEADER = 5
}
 
enum  {
  POS_TT_CTIME_B2LFEE = 0 ,
  POS_CHKSUM_B2LFEE = 1 ,
  SIZE_B2LFEE_TRAILER = 2
}
 
enum  {
  POS_CHKSUM_B2LHSLB = 0 ,
  SIZE_B2LHSLB_TRAILER = 1
}
 
enum  {
  B2LHSLB_HEADER_MAGIC = 0xFFAA0000 ,
  B2LHSLB_TRAILER_MAGIC = 0xFF550000
}
 
enum  { DATA_FORMAT_VERSION = 4 }
 Format version number. More...
 
enum  {
  SIZE_COPPER_DRIVER_HEADER = 0 ,
  SIZE_COPPER_DRIVER_TRAILER = 0
}
 
enum  { SIZE_COPPER_HEADER = 0 }
 
enum  { SIZE_COPPER_TRAILER = 0 }
 
enum  { ONLINE_REMOVED_DATA = 15 }
 
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

 PreRawCOPPERFormat_latest ()
 Default constructor.
 
virtual ~PreRawCOPPERFormat_latest ()
 Constructor using existing pointer to raw data buffer.
 
int GetDetectorNwords (int n, int finesse_num) OVERRIDE_CPP17
 get Detector buffer length
 
unsigned int GetCOPPERCounter (int n) OVERRIDE_CPP17
 get posistion of COPPER block in unit of word
 
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 a checksum on trailer
 
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 of B2link HSLB header/trailer
 
int CalcReducedDataSize (int *bufin, int nwords, int num_events, int num_nodes)
 reduce and merge header/trailer
 
void CopyReducedData (int *bufin, int nwords, int num_events, int num_nodes, int *buf_to, int *nwords_to)
 reduce and merge header/trailer
 
int CalcReducedNwords (int n)
 calculate reduced data size
 
int CopyReducedBuffer (int n, int *buf_to)
 copy data to reduced buffer
 
int CheckCRC16 (int n, int finesse_num)
 check CRC16 in B2LFEE trailer
 
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 * PackDetectorBuf (int *packed_buf_nwords, int *const(&detector_buf_ch)[MAX_PCIE40_CH], int const(&nwords_ch)[MAX_PCIE40_CH], RawCOPPERPackerInfo rawcpr_info) OVERRIDE_CPP17
 Pack data (format ver. = -1 -> Select the latest format version)
 
int * GetDetectorBuffer (int n, int finesse_num) OVERRIDE_CPP17
 Get a pointer to detector buffer.
 
bool CheckOnlineRemovedDataBit (int n, int finesse_num) OVERRIDE_CPP17
 check if this channel's data has been removed on a readout PC for CDC online "masking" True : data contents was removed on a readout PC
 
int Get1stDetectorNwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector buffer length of slot A
 
int Get2ndDetectorNwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector buffer length of slot B
 
int Get3rdDetectorNwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector buffer length of slot C
 
int Get4thDetectorNwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector buffer length of slot D
 
int * Get1stDetectorBuffer (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector buffer of slot A
 
int * Get2ndDetectorBuffer (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector Buffer of slot B
 
int * Get3rdDetectorBuffer (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector Buffer of slot C
 
int * Get4thDetectorBuffer (int n) OVERRIDE_CPP17 FINAL_CPP17
 get Detector Buffer 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 FINAL_CPP17
 get data size of FINESSE slot A buffer
 
int Get2ndFINESSENwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get data size of FINESSE slot B buffer
 
int Get3rdFINESSENwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get data size of FINESSE slot C buffer
 
int Get4thFINESSENwords (int n) OVERRIDE_CPP17 FINAL_CPP17
 get data size of FINESSE slot D buffer
 
int GetOffset1stFINESSE (int n) OVERRIDE_CPP17 FINAL_CPP17
 get # of offset words for FINESSE slot A buffer position
 
int GetOffset2ndFINESSE (int n) OVERRIDE_CPP17 FINAL_CPP17
 get # of offset words for FINESSE slot B buffer position
 
int GetOffset3rdFINESSE (int n) OVERRIDE_CPP17 FINAL_CPP17
 get # of offset words for FINESSE slot C buffer position
 
int GetOffset4thFINESSE (int n) OVERRIDE_CPP17 FINAL_CPP17
 get # of offset words for FINESSE slot D buffer position
 
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.
 
int * GetFINESSEBuffer (int n, int finesse_num) OVERRIDE_CPP17
 Get a pointer to a FINESSE buffer.
 
int GetFINESSENwords (int n, int finesse_num) OVERRIDE_CPP17
 Get the size of a finesse buffer.
 
void CompareHeaderValue (int n, const unsigned int(&input_val)[MAX_PCIE40_CH], std::vector< std::vector< unsigned int > > &summary_table) OVERRIDE_CPP17
 Check header value of all channels.
 
virtual int * GetRawHdrBufPtr (int n)
 get buffer pointer of rawcopper header(Currently same as GetBufferPos)
 
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 GetEventCRC16Value (int n, int finesse_num)
 Get Event CRC16 value.
 
virtual int GetOffsetFINESSE (int n, int finesse)
 get # of offset words
 
virtual unsigned int CalcXORChecksum (int *buf, int nwords)
 calc XOR checksum
 
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 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

PostRawCOPPERFormat_latest m_reduced_rawcpr
 data fromat after size reduction
 
RawHeader_latest tmp_header
 header ( not recorded )
 
RawTrailer_latest 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.1 ( the latest version since May, 2014 ) This class stores data received by COPPER via belle2linkt Data from all detectors except PXD are stored in this class.

Definition at line 30 of file PreRawCOPPERFormat_latest.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Definition at line 178 of file PreRawCOPPERFormat_latest.h.

178 {
179 POS_MAGIC_B2LHSLB = 0,
180 // POS_EVE_CNT_B2LHSLB = 1,
181 SIZE_B2LHSLB_HEADER = 1
182 };

◆ anonymous enum

anonymous enum

Definition at line 186 of file PreRawCOPPERFormat_latest.h.

186 {
187 POS_TT_CTIME_TYPE = 0,
188 POS_TT_TAG = 1,
189 POS_TT_UTIME = 2,
190 POS_EXP_RUN = 3,
191 POS_B2L_CTIME = 4,
192 SIZE_B2LFEE_HEADER = 5
193 };

◆ anonymous enum

anonymous enum

Definition at line 199 of file PreRawCOPPERFormat_latest.h.

199 {
200 POS_TT_CTIME_B2LFEE = 0,
201 POS_CHKSUM_B2LFEE = 1,
202 SIZE_B2LFEE_TRAILER = 2
203 };

◆ anonymous enum

anonymous enum

Definition at line 209 of file PreRawCOPPERFormat_latest.h.

209 {
210 POS_CHKSUM_B2LHSLB = 0,
211 SIZE_B2LHSLB_TRAILER = 1
212 };

◆ anonymous enum

anonymous enum

Definition at line 217 of file PreRawCOPPERFormat_latest.h.

217 {
218 B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
219 B2LHSLB_TRAILER_MAGIC = 0xFF550000
220 };

◆ anonymous enum

anonymous enum
inherited

Format version number.

Definition at line 230 of file RawCOPPERFormat_latest.h.

230 {
231 DATA_FORMAT_VERSION = 4
232 };

◆ anonymous enum

anonymous enum
inherited

Definition at line 237 of file RawCOPPERFormat_latest.h.

237 {
238 SIZE_COPPER_DRIVER_HEADER = 0,
239 SIZE_COPPER_DRIVER_TRAILER = 0
240 };

◆ anonymous enum

anonymous enum
inherited

Definition at line 243 of file RawCOPPERFormat_latest.h.

243 {
244 SIZE_COPPER_HEADER = 0
245 };

◆ anonymous enum

anonymous enum
inherited

Definition at line 248 of file RawCOPPERFormat_latest.h.

248 {
249 SIZE_COPPER_TRAILER = 0
250 };

◆ anonymous enum

anonymous enum
inherited

Definition at line 255 of file RawCOPPERFormat_latest.h.

255 {
256 ONLINE_REMOVED_DATA = 15
257 };

◆ 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

◆ PreRawCOPPERFormat_latest()

Default constructor.

Definition at line 20 of file PreRawCOPPERFormat_latest.cc.

21{
22}

◆ ~PreRawCOPPERFormat_latest()

Constructor using existing pointer to raw data buffer.

Destructor

Definition at line 24 of file PreRawCOPPERFormat_latest.cc.

25{
26}

Member Function Documentation

◆ CalcDriverChkSum()

unsigned int CalcDriverChkSum ( int  n)
virtual

calc COPPER driver's checksum value

Implements RawCOPPERFormat.

Definition at line 28 of file PreRawCOPPERFormat_latest.cc.

29{
30 int min = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS;
31 int max = GetBufferPos(n) + GetBlockNwords(n)
32 - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
33 unsigned int chksum = 0;
34 for (int i = min; i < max; i++) {
35 chksum ^= m_buffer[ i ];
36 }
37 return chksum;
38}
RawTrailer_latest tmp_trailer
trailer ( not recorded )
RawHeader_latest tmp_header
header ( not recorded )
virtual int GetBlockNwords(int n)
get size of a data block
virtual int GetBufferPos(int n)
get position of data block in word

◆ CalcReducedDataSize()

int CalcReducedDataSize ( int *  bufin,
int  nwords,
int  num_events,
int  num_nodes 
)

reduce and merge header/trailer

Definition at line 465 of file PreRawCOPPERFormat_latest.cc.

466{
467 //
468 // Calculate reduced length for a total RawDataBlock (containing multiple data blocks)
469 //
470 RawDataBlockFormat radblk_fmt;
471 int delete_flag = 0;
472 radblk_fmt.SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
473
474 int reduced_nwords = 0;
475 for (int k = 0; k < radblk_fmt.GetNumEvents(); k++) {
476 int num_nodes_in_sendblock = radblk_fmt.GetNumNodes();
477 for (int l = 0; l < num_nodes_in_sendblock; l++) {
478 int entry_id = l + k * num_nodes_in_sendblock;
479
480 if (radblk_fmt.CheckFTSWID(entry_id) || radblk_fmt.CheckTLUID(entry_id)) {
481 reduced_nwords += radblk_fmt.GetBlockNwords(entry_id);
482 } else {
483 PreRawCOPPERFormat_latest temp_prerawcpr;
484 int temp_delete_flag = 0, temp_num_eve = 1, temp_num_nodes = 1;
485
486 // Call CalcReducedNwords
487 temp_prerawcpr.SetBuffer(radblk_fmt.GetBuffer(entry_id),
488 radblk_fmt.GetBlockNwords(entry_id),
489 temp_delete_flag, temp_num_eve,
490 temp_num_nodes);
491 reduced_nwords += temp_prerawcpr.CalcReducedNwords(0);
492 }
493 }
494 }
495 return reduced_nwords;
496
497}
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
int CalcReducedNwords(int n)
calculate reduced data size
The RawDataBlockFormat class Format information for rawdata handling.
virtual int CheckFTSWID(int n)
get FTSW ID to check whether this data block is FTSW data or not
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 GetNumNodes()
get # of data sources(e.g. # of COPPER boards) in m_buffer
virtual int * GetBuffer(int n)
get nth buffer pointer
virtual int GetNumEvents()
get # of events in m_buffer
virtual int CheckTLUID(int n)
get FTSW ID to check whether this data block is FTSW data or not

◆ CalcReducedNwords()

int CalcReducedNwords ( int  n)

calculate reduced data size

Definition at line 536 of file PreRawCOPPERFormat_latest.cc.

537{
538 char err_buf[500];
539 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
540 __FILE__, __PRETTY_FUNCTION__, __LINE__);
541 printf("[DEBUG] %s\n", err_buf);
542 B2FATAL(err_buf);
543 return -1;
544}

◆ 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 of B2link HSLB header/trailer

Definition at line 558 of file PreRawCOPPERFormat_latest.cc.

559{
560
561 if ((finesse_buf[ POS_MAGIC_B2LHSLB ] & 0xFFFF0000) == B2LHSLB_HEADER_MAGIC &&
562 ((finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ] & 0xFFFF0000)
563 == B2LHSLB_TRAILER_MAGIC)) {
564 return 1;
565 } else {
567 char err_buf[500];
568 sprintf(err_buf,
569 "Invalid B2LHSLB magic words : header 0x%x (= should be ffaa**** ) or trailer 0x%x (= should be ff55**** ). Exiting... :%s %s %d\n",
570 finesse_buf[ POS_MAGIC_B2LHSLB ],
571 finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ],
572 __FILE__, __PRETTY_FUNCTION__, __LINE__);
573#ifndef NO_ERROR_STOP
574 printf("%s", err_buf); fflush(stdout);
575 B2FATAL(err_buf);
576#endif
577 }
578}
int m_nwords
number of words of buffer
virtual void PrintData(int *buf, int nwords)
print data

◆ CheckCOPPERMagic()

bool CheckCOPPERMagic ( int  n)
virtual

Check if COPPER Magic words are correct.

Implements RawCOPPERFormat.

Definition at line 282 of file PreRawCOPPERFormat_latest.cc.

283{
284 char err_buf[500];
285 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
286 __FILE__, __PRETTY_FUNCTION__, __LINE__);
287 printf("[DEBUG] %s\n", err_buf);
288 B2FATAL(err_buf);
289 return false;
290}

◆ CheckCRC16()

int CheckCRC16 ( int  n,
int  finesse_num 
)

check CRC16 in B2LFEE trailer

Definition at line 582 of file PreRawCOPPERFormat_latest.cc.

583{
584 //
585 // Calculate CRC16
586 //
587 int* buf = GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER;
588 int nwords = GetFINESSENwords(n, finesse_num) - (static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_TRAILER +
589 SIZE_B2LHSLB_TRAILER);
590 unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, buf, nwords);
591
592 //
593 // Compare CRC16 with B2LCRC16
594 //
595 buf = GetFINESSEBuffer(n, finesse_num) + GetFINESSENwords(n, finesse_num)
596 - ((SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) + SIZE_B2LHSLB_TRAILER) ;
597
598 if ((unsigned short)(*buf & 0xFFFF) != temp_crc16) {
599 char err_buf[500];
600 char hostname[128];
601 GetNodeName(n, hostname, sizeof(hostname));
602 PrintData(GetBuffer(n), *(GetBuffer(n) + tmp_header.POS_NWORDS));
603 printf("[FATAL] %s ch=%d : ERROR_EVENT : PRE CRC16 error : slot %c : B2LCRC16 %x Calculated CRC16 %x : Nwords of FINESSE buf %d\n",
604 hostname, finesse_num,
605 65 + finesse_num, *buf, temp_crc16, GetFINESSENwords(n, finesse_num));
606 int* temp_buf = GetFINESSEBuffer(n, finesse_num);
607 for (int k = 0; k < GetFINESSENwords(n, finesse_num); k++) {
608 printf("%.8x ", temp_buf[ k ]);
609 if ((k + 1) % 10 == 0) {
610 printf("\n");
611 }
612 }
613 printf("\n");
614 fflush(stdout);
615 sprintf(err_buf,
616 "[FATAL] %s ch=%d : ERROR_EVENT : slot %c : B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PreRawCOPPERfromat class. Exiting...\n %s %s %d\n",
617 hostname, finesse_num,
618 65 + finesse_num, (unsigned short)(*buf & 0xFFFF), temp_crc16,
619 __FILE__, __PRETTY_FUNCTION__, __LINE__);
620 printf("%s", err_buf); fflush(stdout);
621 B2FATAL(err_buf); // to reduce multiple error messages
622 }
623 return 1;
624
625}
virtual void GetNodeName(int n, char *node_name, int bufsize)
Get hostname of a node from the RawCOPPER header.
int * GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to a FINESSE buffer.
int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17
Get the size of a finesse buffer.

◆ 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 124 of file PreRawCOPPERFormat_latest.cc.

128{
129
130 char err_buf[3000];
131 int err_flag = 0;
132
133 //
134 // Event # check
135 //
136 *cur_evenum_rawcprhdr = GetEveNo(n);
137 unsigned int evenum_feehdr = GetB2LFEE32bitEventNumber(n);
138 if (*cur_evenum_rawcprhdr != evenum_feehdr) {
139 char hostname[128];
140 GetNodeName(n, hostname, sizeof(hostname));
141 sprintf(err_buf,
142 "[FATAL] %s ch=%d : ERROR_EVENT : Event # in PreRawCOPPERFormat_latest header and FEE header is different : cprhdr 0x%x feehdr 0x%x : Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
143 hostname, -1,
144 *cur_evenum_rawcprhdr, evenum_feehdr,
145 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
146 __FILE__, __PRETTY_FUNCTION__, __LINE__);
147 err_flag = 1;
148 }
149
150 //
151 // Check incrementation of event #
152 //
153 *cur_exprunsubrun_no = GetExpRunSubrun(n);
154 *cur_copper_ctr = GetCOPPERCounter(n);
155 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
156 if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
157 char hostname[128];
158 GetNodeName(n, hostname, sizeof(hostname));
159 sprintf(err_buf,
160 "[FATAL] %s ch=%d : ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : prevrun %.8x currun %.8x: Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
161 hostname, -1,
162 n, prev_evenum, *cur_evenum_rawcprhdr, prev_exprunsubrun_no, *cur_exprunsubrun_no,
163 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
164 __FILE__, __PRETTY_FUNCTION__, __LINE__);
165 err_flag = 1;
166 }
167 if ((unsigned int)(prev_copper_ctr + 1) != *cur_copper_ctr) {
168 char hostname[128];
169 GetNodeName(n, hostname, sizeof(hostname));
170 sprintf(err_buf,
171 "[FATAL] %s ch=%d : ERROR_EVENT : COPPER counter jump : i %d prev 0x%x cur 0x%x : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
172 hostname, -1,
173 n, prev_copper_ctr, *cur_copper_ctr,
174 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
175 __FILE__, __PRETTY_FUNCTION__, __LINE__);
176 err_flag = 1;
177 }
178 } else {
179 printf("[DEBUG] New run started. cur run %.8x prev. run %.8x cur eve %.8x prev eve %8.x : eve 0x%x exp %d run %d sub %d\n",
180 *cur_exprunsubrun_no, prev_exprunsubrun_no, *cur_evenum_rawcprhdr, prev_evenum,
181 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n));
182
183 // Check if the first event of a run is zero.
184 if ((unsigned int)GetRunNo(n) != (prev_exprunsubrun_no & RawHeader_latest::RUNNO_MASK) >> RawHeader_latest::RUNNO_SHIFT) {
185 if (*cur_evenum_rawcprhdr != 0) {
186
187 unsigned int eve[MAX_PCIE40_CH];
188 for (int i = 0; i < MAX_PCIE40_CH ; ++i) {
189 eve[ i ] = 0xbaadf00d;
190 if (GetFINESSENwords(n, i) > 0) {
191 int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
192 eve[ i ] = m_buffer[ pos_nwords ];
193 }
194 }
195
196 vector<vector<unsigned int>> summary_table;
197 CompareHeaderValue(n, eve, summary_table);
198 char hostname[128];
199 GetNodeName(n, hostname, sizeof(hostname));
200 sprintf(err_buf,
201 "[FATAL] %s ch=%d : ERROR_EVENT : Invalid Event # at the beginning of the run (It should be zero.): preveve 0x%x cureve 0x%x : prev(exp %u run %u sub %u ) cur(exp %u run %u sub %u ) (",
202 hostname, -1,
203 prev_evenum, *cur_evenum_rawcprhdr,
204 prev_exprunsubrun_no >> 22, (prev_exprunsubrun_no >> 8) & 0x3FFF, prev_exprunsubrun_no & 0xFF,
205 *cur_exprunsubrun_no >> 22, (*cur_exprunsubrun_no >> 8) & 0x3FFF, *cur_exprunsubrun_no & 0xFF);
206
207 char err_buf_temp[2500];
208 for (unsigned i = 0; i < summary_table.size(); ++i) {
209 memcpy(err_buf_temp, err_buf, sizeof(err_buf_temp));
210 sprintf(err_buf, "%s [ch= %u ,val= %u (# of chs= %u )] ",
211 err_buf_temp,
212 summary_table.at(i).at(0), summary_table.at(i).at(2), summary_table.at(i).at(1));
213 }
214 memcpy(err_buf_temp, err_buf, sizeof(err_buf_temp));
215 sprintf(err_buf, "%s Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
216 err_buf_temp,
217 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
218 __FILE__, __PRETTY_FUNCTION__, __LINE__);
219 err_flag = 1;
220 }
221 }
222 }
223
224
225
226 //
227 // Check is utime and ctime_trgtype same over different FINESSE data
228 //
230
231 //
232 // Check checksum calculated by COPPER driver
233 //
234 if (GetDriverChkSum(n) != CalcDriverChkSum(n)) {
235 char hostname[128];
236 GetNodeName(n, hostname, sizeof(hostname));
237 sprintf(err_buf,
238 "[FATAL] %s ch=%d : ERROR_EVENT : COPPER driver 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",
239 hostname, -1,
240 n, GetBlockNwords(n), *cur_evenum_rawcprhdr, GetDriverChkSum(n), CalcDriverChkSum(n),
241 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
242 __FILE__, __PRETTY_FUNCTION__, __LINE__);
243 err_flag = 1;
244 }
245
246 //
247 // Check checksum calculated by DeSerializerCOPPER()
248 //
250 unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
251 if (tmp_trailer.GetChksum() != xor_chksum) {
252 char hostname[128];
253 GetNodeName(n, hostname, sizeof(hostname));
254 sprintf(err_buf,
255 "[FATAL] %s ch=%d : ERROR_EVENT : PreRawCOPPERFormat_latest 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",
256 hostname, -1,
257 n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
258 GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
259 __FILE__, __PRETTY_FUNCTION__, __LINE__);
260 err_flag = 1;
261 }
262
263 if (err_flag == 1) {
264 printf("%s", err_buf); fflush(stdout);
265 printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
267 for (int i = 0; i < MAX_PCIE40_CH; i++) {
268 printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
269 if (GetFINESSENwords(n, i) > 0) {
270 CheckCRC16(n, i);
271 }
272 }
273 printf("[DEBUG] ========== No CRC error : block %d =========\n", n);
274 // string err_str = err_buf; throw (err_str);
275 B2FATAL(err_buf); // to reduce multiple error messages
276 }
277
278 return;
279
280}
int CheckCRC16(int n, int finesse_num)
check CRC16 in B2LFEE trailer
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
void CompareHeaderValue(int n, const unsigned int(&input_val)[MAX_PCIE40_CH], std::vector< std::vector< unsigned int > > &summary_table) OVERRIDE_CPP17
Check header value of all channels.
virtual int GetOffsetFINESSE(int n, int finesse)
get # of offset words
virtual unsigned int CalcXORChecksum(int *buf, int nwords)
calc XOR checksum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
unsigned int GetEveNo(int n) OVERRIDE_CPP17
get subrun #(8bit)
int GetTrlNwords()
Set magic word.
unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17
get Experimental # from header
int GetExpNo(int n) OVERRIDE_CPP17
get Experimental # from header
unsigned int GetChksum()
Set # of trailer words.
void SetBuffer(int *bufin)
return buffer
int GetRunNo(int n) OVERRIDE_CPP17
Exp# (10bit) run# (14bit) restart # (8bit)
int * GetRawTrlBufPtr(int n) OVERRIDE_CPP17
get buffer pointer of rawcopper trailer
int GetSubRunNo(int n) OVERRIDE_CPP17
get run # (14bit)

◆ 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}

◆ 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 292 of file PreRawCOPPERFormat_latest.cc.

293{
294
295#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
296 CheckB2LFEEHeaderVersion(n);
297#endif
298 int err_flag = 0;
299 int flag = 0;
300 unsigned int temp_utime = 0, temp_ctime_trgtype = 0, temp_eve = 0, temp_exprun = 0;
301 unsigned int temp_ctime_trgtype_footer, temp_eve_footer;
302 unsigned int utime[MAX_PCIE40_CH], ctime_trgtype[MAX_PCIE40_CH], eve[MAX_PCIE40_CH], exprun[MAX_PCIE40_CH];
303 char err_buf[4000];
304
305 memset(utime, 0, sizeof(utime));
306 memset(ctime_trgtype, 0, sizeof(ctime_trgtype));
307 memset(eve, 0, sizeof(eve));
308 memset(exprun, 0, sizeof(exprun));
309
310 int first_ch = 0;
311 for (int i = 0; i < MAX_PCIE40_CH; i++) {
312 int finesse_nwords = GetFINESSENwords(n, i);
313 if (finesse_nwords > 0) {
314 int offset_finesse = GetOffsetFINESSE(n, i);
315 ctime_trgtype[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
316 utime[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
317 eve[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_TT_TAG ];
318 exprun[ i ] = m_buffer[ offset_finesse + SIZE_B2LHSLB_HEADER + POS_EXP_RUN ];
319 temp_ctime_trgtype_footer =
320 m_buffer[ offset_finesse + finesse_nwords - (static_cast<int>(SIZE_B2LFEE_TRAILER) + SIZE_B2LHSLB_TRAILER) + POS_TT_CTIME_B2LFEE ];
321 temp_eve_footer =
322 m_buffer[ offset_finesse + finesse_nwords - (static_cast<int>(SIZE_B2LFEE_TRAILER) + SIZE_B2LHSLB_TRAILER) + POS_CHKSUM_B2LFEE ];
323
324 if (flag == 0) {
325 temp_ctime_trgtype = ctime_trgtype[ i ];
326 temp_utime = utime[ i ];
327 temp_eve = eve[ i ];
328 temp_exprun = exprun[ i ];
329 flag = 1;
330 first_ch = i;
331 } else {
332 if (temp_ctime_trgtype != ctime_trgtype[ i ] || temp_utime != utime[ i ] ||
333 temp_eve != eve[ i ] || temp_exprun != exprun[ i ]) {
334 char hostname[128];
335 GetNodeName(n, hostname, sizeof(hostname));
336 if (err_flag == 0) {
337 for (int j = 0; j < MAX_PCIE40_CH; j++) {
338 if (GetFINESSENwords(n, j) > 0) {
339 printf("[DEBUG] %s ch=%d : FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x eve 0x%.8x exprun 0x%.8x\n",
340 hostname, -1,
341 j, GetFINESSENwords(n, j), ctime_trgtype[ j ], utime[ j ], eve[ j ], exprun[ j ]);
342 }
343 }
344 }
345
346 char err_buf_1[2500], err_buf_2[3000], err_buf_3[3500];
347 sprintf(err_buf_1,
348 "[FATAL] %s ch=%d : ERROR_EVENT : mismatch header value over FINESSEs. Exiting...",
349 hostname, -1);
350 sprintf(err_buf_2,
351 "%s FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x eve 0x%.8x exprun 0x%.8x",
352 err_buf_1,
353 first_ch, GetFINESSENwords(n, first_ch), ctime_trgtype[ first_ch ], utime[ first_ch ], eve[ first_ch ], exprun[ first_ch ]);
354 sprintf(err_buf_3,
355 "%s FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x eve 0x%.8x exprun 0x%.8x",
356 err_buf_2,
357 i, GetFINESSENwords(n, i), ctime_trgtype[ i ], utime[ i ], eve[ i ], exprun[ i ]);
358 sprintf(err_buf, "%s\n %s %s %d\n",
359 err_buf_3,
360 __FILE__, __PRETTY_FUNCTION__, __LINE__);
361 printf("%s", err_buf); fflush(stdout);
362
363 err_flag = 1;
364 break;
365 } else if (temp_ctime_trgtype != temp_ctime_trgtype_footer ||
366 (temp_eve & 0xffff) != ((temp_eve_footer >> 16) & 0xffff)) {
367 char hostname[128];
368 GetNodeName(n, hostname, sizeof(hostname));
369 sprintf(err_buf,
370 "[FATAL] %s ch=%d : ERROR_EVENT : mismatch(finesse %d) between header(ctime %.8x eve %.8x) and footer(ctime %.8x eve_crc16 %.8x). Exiting...\n %s %s %d\n",
371 hostname, i,
372 i, temp_ctime_trgtype, temp_eve, temp_ctime_trgtype_footer, temp_eve_footer,
373 __FILE__, __PRETTY_FUNCTION__, __LINE__);
374 printf("%s", err_buf); fflush(stdout);
375 err_flag = 1;
376 }
377 }
378 }
379 }
380
381 if (err_flag != 0) {
382 for (int i = 0; i < MAX_PCIE40_CH; i++) {
383 if (GetFINESSENwords(n, i) > 0) {
384 printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
385 CheckCRC16(n, i);
386 printf("[DEBUG] ========== CRC check is done. : block %d =========\n", n);
387 }
388 }
389#ifndef NO_ERROR_STOP
390 // string err_str = err_buf; throw (err_str);
391 B2FATAL(err_buf); // to reduce multiple error messages
392#endif
393 }
394 return;
395}

◆ CompareHeaderValue()

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

Check header value of all channels.

Reimplemented from RawCOPPERFormat.

Definition at line 256 of file RawCOPPERFormat_latest.cc.

258{
259
260 //
261 // Format of summary_table
262 // <The 1st channel of a value> <# of channels of the value> <the value>
263 //
264 std::vector<std::vector<unsigned int>> temp;
265 for (int i = 0; i < MAX_PCIE40_CH; i++) {
266 if (GetFINESSENwords(n, i) > 0) {
267
268 int same_flag = 0;
269 for (unsigned j = 0; j < summary_table.size(); ++j) {
270 if (input_val[i] == summary_table.at(j).at(2)) {
271 summary_table.at(j).at(1)++;
272 same_flag = 1;
273 break;
274 }
275 }
276 if (same_flag == 0) {
277 summary_table.push_back({ static_cast<unsigned int>(i), 1, input_val[i] });
278 }
279 }
280 }
281 sort(summary_table.begin(), summary_table.end(), [](const std::vector<unsigned int>& alpha,
282 const std::vector<unsigned int>& beta) {return alpha.at(1) < beta.at(1);});
283 return;
284}

◆ 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}

◆ CopyReducedBuffer()

int CopyReducedBuffer ( int  n,
int *  buf_to 
)

copy data to reduced buffer

Definition at line 547 of file PreRawCOPPERFormat_latest.cc.

548{
549 char err_buf[500];
550 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
551 __FILE__, __PRETTY_FUNCTION__, __LINE__);
552 printf("[DEBUG] %s\n", err_buf);
553 B2FATAL(err_buf);
554 return -1;
555}

◆ CopyReducedData()

void CopyReducedData ( int *  bufin,
int  nwords,
int  num_events,
int  num_nodes,
int *  buf_to,
int *  nwords_to 
)

reduce and merge header/trailer

Definition at line 500 of file PreRawCOPPERFormat_latest.cc.

501{
502 //
503 // Make a reduced buffer a total RawDataBlock (containing multiple data blocks)
504 //
505 RawDataBlockFormat radblk_fmt;
506 int delete_flag = 0;
507 radblk_fmt.SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
508
509 int pos_nwords_to = 0;
510 for (int k = 0; k < radblk_fmt.GetNumEvents(); k++) {
511 int num_nodes_in_sendblock = radblk_fmt.GetNumNodes();
512 for (int l = 0; l < num_nodes_in_sendblock; l++) {
513 int entry_id = l + k * num_nodes_in_sendblock;
514 if (radblk_fmt.CheckFTSWID(entry_id) ||
515 radblk_fmt.CheckTLUID(entry_id)) {
516 radblk_fmt.CopyBlock(entry_id, buf_to + pos_nwords_to);
517 pos_nwords_to += radblk_fmt.GetBlockNwords(entry_id);
518
519 } else {
520 SetBuffer(radblk_fmt.GetBuffer(entry_id),
521 radblk_fmt.GetBlockNwords(entry_id), 0, 1, 1);
522
523 pos_nwords_to += CopyReducedBuffer(0, buf_to + pos_nwords_to);
524
525
526 }
527 }
528 }
529
530 *nwords_to = pos_nwords_to;
531
532 return ;
533}
int CopyReducedBuffer(int n, int *buf_to)
copy data to reduced buffer
virtual void CopyBlock(int n, int *buf_to)
Copy one datablock to buffer.

◆ 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 397 of file PreRawCOPPERFormat_latest.cc.

399{
400 char err_buf[500];
401 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
402 __FILE__, __PRETTY_FUNCTION__, __LINE__);
403 printf("[DEBUG] %s\n", err_buf);
404 B2FATAL(err_buf);
405 return 0;
406}

◆ Get1stDetectorBuffer()

int * Get1stDetectorBuffer ( int  n)
virtualinherited

get Detector buffer of slot A

Implements RawCOPPERFormat.

Definition at line 174 of file RawCOPPERFormat_latest.cc.

175{
176 char err_buf[500];
177 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
178 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
179 printf("[DEBUG] %s\n", err_buf);
180 B2FATAL(err_buf);
181 return NULL;
182}

◆ Get1stDetectorNwords()

int Get1stDetectorNwords ( int  n)
virtualinherited

get Detector buffer length of slot A

Implements RawCOPPERFormat.

Definition at line 92 of file RawCOPPERFormat_latest.cc.

93{
94 char err_buf[500];
95 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
96 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
97 printf("[DEBUG] %s\n", err_buf);
98 B2FATAL(err_buf);
99 return 0;
100}

◆ Get1stFINESSENwords()

int Get1stFINESSENwords ( int  n)
virtualinherited

get data size of FINESSE slot A buffer

Implements RawCOPPERFormat.

Definition at line 133 of file RawCOPPERFormat_latest.cc.

134{
135 char err_buf[500];
136 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
137 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
138 printf("[DEBUG] %s\n", err_buf);
139 B2FATAL(err_buf);
140 return 0;
141}

◆ Get2ndDetectorBuffer()

int * Get2ndDetectorBuffer ( int  n)
virtualinherited

get Detector Buffer of slot B

Implements RawCOPPERFormat.

Definition at line 184 of file RawCOPPERFormat_latest.cc.

185{
186 char err_buf[500];
187 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
188 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
189 printf("[DEBUG] %s\n", err_buf);
190 B2FATAL(err_buf);
191 return NULL;
192}

◆ Get2ndDetectorNwords()

int Get2ndDetectorNwords ( int  n)
virtualinherited

get Detector buffer length of slot B

Implements RawCOPPERFormat.

Definition at line 102 of file RawCOPPERFormat_latest.cc.

103{
104 char err_buf[500];
105 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
106 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
107 printf("[DEBUG] %s\n", err_buf);
108 B2FATAL(err_buf);
109 return 0;
110}

◆ Get2ndFINESSENwords()

int Get2ndFINESSENwords ( int  n)
virtualinherited

get data size of FINESSE slot B buffer

Implements RawCOPPERFormat.

Definition at line 143 of file RawCOPPERFormat_latest.cc.

144{
145 char err_buf[500];
146 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
147 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
148 printf("[DEBUG] %s\n", err_buf);
149 B2FATAL(err_buf);
150 return 0;
151}

◆ Get3rdDetectorBuffer()

int * Get3rdDetectorBuffer ( int  n)
virtualinherited

get Detector Buffer of slot C

Implements RawCOPPERFormat.

Definition at line 194 of file RawCOPPERFormat_latest.cc.

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

◆ Get3rdDetectorNwords()

int Get3rdDetectorNwords ( int  n)
virtualinherited

get Detector buffer length of slot C

Implements RawCOPPERFormat.

Definition at line 112 of file RawCOPPERFormat_latest.cc.

113{
114 char err_buf[500];
115 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
116 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
117 printf("[DEBUG] %s\n", err_buf);
118 B2FATAL(err_buf);
119 return 0;
120}

◆ Get3rdFINESSENwords()

int Get3rdFINESSENwords ( int  n)
virtualinherited

get data size of FINESSE slot C buffer

Implements RawCOPPERFormat.

Definition at line 153 of file RawCOPPERFormat_latest.cc.

154{
155 char err_buf[500];
156 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
157 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
158 printf("[DEBUG] %s\n", err_buf);
159 B2FATAL(err_buf);
160 return 0;
161}

◆ Get4thDetectorBuffer()

int * Get4thDetectorBuffer ( int  n)
virtualinherited

get Detector Buffer of slot D

Implements RawCOPPERFormat.

Definition at line 204 of file RawCOPPERFormat_latest.cc.

205{
206 char err_buf[500];
207 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
208 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
209 printf("[DEBUG] %s\n", err_buf);
210 B2FATAL(err_buf);
211 return NULL;
212}

◆ Get4thDetectorNwords()

int Get4thDetectorNwords ( int  n)
virtualinherited

get Detector buffer length of slot D

Implements RawCOPPERFormat.

Definition at line 122 of file RawCOPPERFormat_latest.cc.

123{
124 char err_buf[500];
125 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
126 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
127 printf("[DEBUG] %s\n", err_buf);
128 B2FATAL(err_buf);
129 return 0;
130}

◆ Get4thFINESSENwords()

int Get4thFINESSENwords ( int  n)
virtualinherited

get data size of FINESSE slot D buffer

Implements RawCOPPERFormat.

Definition at line 163 of file RawCOPPERFormat_latest.cc.

164{
165 char err_buf[500];
166 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
167 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
168 printf("[DEBUG] %s\n", err_buf);
169 B2FATAL(err_buf);
170 return 0;
171}

◆ GetB2LFEE32bitEventNumber()

unsigned int GetB2LFEE32bitEventNumber ( int  n)
virtual

get b2l block from "FEE b2link header"

Implements RawCOPPERFormat.

Definition at line 40 of file PreRawCOPPERFormat_latest.cc.

41{
42
43#ifndef READ_OLD_B2LFEE_FORMAT_FILE
44
45 int err_flag = 0;
46 unsigned int eve_num = 0;
47 int flag = 0;
48 unsigned int eve[MAX_PCIE40_CH];
49 for (int i = 0; i < MAX_PCIE40_CH; i++) {
50 eve[ i ] = 0xbaadf00d;
51 if (GetFINESSENwords(n, i) > 0) {
52 int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
53 eve[ i ] = m_buffer[ pos_nwords ];
54 if (flag != 1) eve_num = eve[ i ];
55 if (eve_num != eve[ i ]) err_flag = 1;
56 flag = 1;
57 }
58 }
59
60 if (flag == 0) {
62 char err_buf[500];
63 char hostname[128];
64 GetNodeName(n, hostname, sizeof(hostname));
65 sprintf(err_buf,
66 "[FATAL] %s ch=%d : ERROR_EVENT : No HSLB data in COPPER data. Exiting... : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
67 hostname, -1,
69 __FILE__, __PRETTY_FUNCTION__, __LINE__);
70 printf("%s", err_buf); fflush(stdout);
71 // string err_str = err_buf; throw (err_str);
72 B2FATAL(err_buf); // to reduce multiple error messages
73 }
74
75 if (err_flag == 1) {
76 vector<vector<unsigned int>> summary_table;
77 CompareHeaderValue(n, eve, summary_table);
78
79 char err_buf[3000];
80 char err_buf_temp[2500];
81 char hostname[128];
82 GetNodeName(n, hostname, sizeof(hostname));
83 sprintf(err_buf, "[FATAL] %s ch=%d : ERROR_EVENT : CORRUPTED DATA: Different event number over HSLBs :", hostname, -1);
84 for (unsigned i = 0; i < summary_table.size(); ++i) {
85 memcpy(err_buf_temp, err_buf, sizeof(err_buf_temp));
86 sprintf(err_buf, "%s [ch= %u ,val= %u (# of chs= %u )] ",
87 err_buf_temp,
88 summary_table.at(i).at(0), summary_table.at(i).at(2), summary_table.at(i).at(1));
89 }
90 memcpy(err_buf_temp, err_buf, sizeof(err_buf_temp));
91 sprintf(err_buf, "%s : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
92 err_buf_temp,
94 __FILE__, __PRETTY_FUNCTION__, __LINE__);
95
96 printf("[DEBUG] %s\n", err_buf);
98 for (int i = 0; i < MAX_PCIE40_CH; ++i) {
99 printf("[DEBUG] ========== CRC check : block # %d finesse %d ==========\n", n, i);
100 if (GetFINESSENwords(n, i) > 0) {
101 CheckCRC16(n, i);
102 }
103 }
104 printf("[DEBUG] ========== No CRC error. : block %d =========\n", n);
105#ifndef NO_ERROR_STOP
106 // string err_str = err_buf; throw (err_str);
107 B2FATAL(err_buf); // to reduce multiple error messages
108#endif //NO_ERROR_STOP
109 }
110 return eve_num;
111
112#else // READ_OLD_B2LFEE_FORMAT_FILE
113
114 char err_buf[500];
115 sprintf(err_buf, "[FATAL] You need comment out READ_OLD_B2LFEE_FORMAT_FILE if you are handling a new data format\n%s %s %d\n",
116 __FILE__, __PRETTY_FUNCTION__, __LINE__);
117 printf("%s", err_buf); fflush(stdout);
118 B2FATAL(err_buf); // to reduce multiple error messages
119#endif // READ_OLD_B2LFEE_FORMAT_FILE
120
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

◆ 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}

◆ GetEventCRC16Value()

int GetEventCRC16Value ( int  n,
int  finesse_num 
)
virtualinherited

Get Event CRC16 value.

Reimplemented in PostRawCOPPERFormat_latest, and PostRawCOPPERFormat_v2.

Definition at line 145 of file RawCOPPERFormat.cc.

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}

◆ 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 30 of file RawCOPPERFormat_latest.cc.

31{
32 int cnt = 0;
33 for (int i = 0; i < 4; i++) {
34 if (GetFINESSENwords(n, i) > 0) {
35 cnt++;
36 }
37 }
38 return cnt;
39}

◆ 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; }

◆ GetOffset1stFINESSE()

int GetOffset1stFINESSE ( int  n)
virtualinherited

get # of offset words for FINESSE slot A buffer position

Implements RawCOPPERFormat.

Definition at line 214 of file RawCOPPERFormat_latest.cc.

215{
216 char err_buf[500];
217 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
218 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
219 printf("[DEBUG] %s\n", err_buf);
220 B2FATAL(err_buf);
221 return 0;
222}

◆ GetOffset2ndFINESSE()

int GetOffset2ndFINESSE ( int  n)
virtualinherited

get # of offset words for FINESSE slot B buffer position

Reimplemented from RawCOPPERFormat.

Definition at line 225 of file RawCOPPERFormat_latest.cc.

226{
227 char err_buf[500];
228 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
229 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
230 printf("[DEBUG] %s\n", err_buf);
231 B2FATAL(err_buf);
232 return 0;
233}

◆ GetOffset3rdFINESSE()

int GetOffset3rdFINESSE ( int  n)
virtualinherited

get # of offset words for FINESSE slot C buffer position

Reimplemented from RawCOPPERFormat.

Definition at line 236 of file RawCOPPERFormat_latest.cc.

237{
238 char err_buf[500];
239 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
240 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
241 printf("[DEBUG] %s\n", err_buf);
242 B2FATAL(err_buf);
243 return 0;
244}

◆ GetOffset4thFINESSE()

int GetOffset4thFINESSE ( int  n)
virtualinherited

get # of offset words for FINESSE slot D buffer position

Reimplemented from RawCOPPERFormat.

Definition at line 246 of file RawCOPPERFormat_latest.cc.

247{
248 char err_buf[500];
249 sprintf(err_buf, "[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
250 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
251 printf("[DEBUG] %s\n", err_buf);
252 B2FATAL(err_buf);
253 return 0;
254}

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

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

Reimplemented from RawCOPPERFormat.

Definition at line 643 of file PreRawCOPPERFormat_latest.cc.

647{
648 int* packed_buf = NULL;
649 int poswords_to = 0;
650
651 // calculate the event length
652 int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
653
654 for (int i = 0; i < MAX_PCIE40_CH; i++) {
655 if (detector_buf_ch[ i ] == NULL || nwords_ch[ i ] <= 0) continue; // for an empty FINESSE slot
656 length_nwords += nwords_ch[ i ];
657 length_nwords += static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
658 }
659
660 // allocate buffer
661 packed_buf = new int[ length_nwords ];
662 memset(packed_buf, 0, sizeof(int) * length_nwords);
663
664 //
665 // Fill RawHeader
666 //
667 tmp_header.SetBuffer(packed_buf);
668
669 packed_buf[ tmp_header.POS_NWORDS ] = length_nwords; // total length
670 packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] = 0x7f7f8000
671 | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
672 | tmp_header.RAWHEADER_NWORDS; // ver.#, header length
673 packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.exp_num << tmp_header.EXP_SHIFT)
674 | (rawcpr_info.run_subrun_num & 0x003FFFFF); // exp. and run #
675 packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.eve_num; // eve #
676 packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4; // tt_ctime
677 packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.tt_utime; // tt_utime
678 packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.node_id; // node ID
679
680 // fill the positions of finesse buffers
681 int ch = 0;
682 packed_buf[ tmp_header.POS_CH_POS_TABLE + ch ] = tmp_header.RAWHEADER_NWORDS;
683 for (int i = 1; i < MAX_PCIE40_CH; i++) {
684 ch = i;
685 if (nwords_ch[ ch - 1 ] == 0) {
686 packed_buf[ tmp_header.POS_CH_POS_TABLE + ch ] = packed_buf[ tmp_header.POS_CH_POS_TABLE + (ch - 1) ];
687 } else {
688 packed_buf[ tmp_header.POS_CH_POS_TABLE + ch ] = packed_buf[ tmp_header.POS_CH_POS_TABLE + (ch - 1) ] +
689 nwords_ch[ ch - 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
690 }
691 }
692 poswords_to += tmp_header.GetHdrNwords();
693
694 // Fill FINESSE buffer
695 for (int i = 0; i < MAX_PCIE40_CH; i++) {
696 if (detector_buf_ch[ i ] == NULL || nwords_ch[ i ] <= 0) continue; // for an empty FINESSE slot
697
698 // Fill b2link HSLB header
699 packed_buf[ poswords_to + POS_MAGIC_B2LHSLB ] = 0xffaa0000 | (0xffff & rawcpr_info.eve_num);
700 poswords_to += SIZE_B2LHSLB_HEADER;
701 int* crc16_start = &(packed_buf[ poswords_to ]);
702
703 // Fill b2link FEE header
704 packed_buf[ poswords_to + POS_TT_CTIME_TYPE ] = (rawcpr_info.tt_ctime & 0x7FFFFFF) << 4;
705 unsigned int temp_ctime_type = packed_buf[ poswords_to + POS_TT_CTIME_TYPE ];
706 packed_buf[ poswords_to + POS_TT_TAG ] = rawcpr_info.eve_num;
707 packed_buf[ poswords_to + POS_TT_UTIME ] = rawcpr_info.tt_utime;
708 packed_buf[ poswords_to + POS_EXP_RUN ] = (rawcpr_info.exp_num << tmp_header.EXP_SHIFT) | (rawcpr_info.run_subrun_num &
709 0x003FFFFF); // exp. and run #
710 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.b2l_ctime & 0x7FFFFFF) << 4;
711 poswords_to += SIZE_B2LFEE_HEADER;
712
713 // copy the 1st Detector Buffer
714 memcpy(packed_buf + poswords_to, detector_buf_ch[ i ], nwords_ch[ i ]*sizeof(int));
715 poswords_to += nwords_ch[ i ];
716
717 // Fill b2link b2tt-tag trailer
718 packed_buf[ poswords_to + POS_TT_CTIME_B2LFEE ] = temp_ctime_type;
719
720 // Fill b2link FEE trailer
721 unsigned short crc16 = CalcCRC16LittleEndian(0xffff, crc16_start, nwords_ch[ i ] + SIZE_B2LFEE_HEADER);
722 packed_buf[ poswords_to + POS_CHKSUM_B2LFEE ] = ((0xffff & rawcpr_info.eve_num) << 16) | (crc16 & 0xffff);
723 poswords_to += SIZE_B2LFEE_TRAILER;
724
725 // Fill b2link HSLB trailer
726 packed_buf[ poswords_to + POS_CHKSUM_B2LHSLB ] = 0xff550000;
727 poswords_to += SIZE_B2LHSLB_TRAILER;
728 }
729
730 // Calculate RawCOPPER checksum and fill RawTrailer
731 unsigned int chksum = 0;
732 for (int i = 0; i < poswords_to; i++) {
733 chksum ^= packed_buf[ i ];
734 }
735 packed_buf[ poswords_to + tmp_trailer.POS_CHKSUM ] = chksum;
736
737 packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
738 poswords_to += tmp_trailer.GetTrlNwords();
739
740 *packed_buf_nwords = poswords_to;
741 return packed_buf;
742}
unsigned int b2l_ctime
32bit unitx time at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user ...
unsigned int eve_num
Run # and subrun # ( 22bit )
unsigned int tt_ctime
Node ID (32bit)
unsigned int tt_utime
27bit clock ticks at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user...
unsigned int node_id
Event Number (32bit)
unsigned int run_subrun_num
Experiment number (10bit)
unsigned int exp_num
Experiment number (10bit)
void SetBuffer(int *bufin)
set buffer
int GetHdrNwords()
get contents of header

◆ 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 627 of file PreRawCOPPERFormat_latest.cc.

633{
634 char err_buf[500];
635 sprintf(err_buf, "[FATAL] This function is not supported. (%u) Exiting...: \n%s %s %d\n",
636 rawcpr_info.eve_num,
637 __FILE__, __PRETTY_FUNCTION__, __LINE__);
638 printf("[DEBUG] %s\n", err_buf);
639 B2FATAL(err_buf);
640 return NULL;
641}

◆ 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_reduced_rawcpr

PostRawCOPPERFormat_latest m_reduced_rawcpr

data fromat after size reduction

Definition at line 223 of file PreRawCOPPERFormat_latest.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_latest tmp_header
inherited

header ( not recorded )

Definition at line 260 of file RawCOPPERFormat_latest.h.

◆ tmp_trailer

RawTrailer_latest tmp_trailer
inherited

trailer ( not recorded )

Definition at line 263 of file RawCOPPERFormat_latest.h.


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