8 #include <rawdata/dataobjects/RawFTSWFormat_v1.h>
14 RawFTSWFormat_v1::RawFTSWFormat_v1()
18 RawFTSWFormat_v1::~RawFTSWFormat_v1()
23 int RawFTSWFormat_v1::Get15bitTLUTag(
int n)
25 return (
int)((
unsigned int)(m_buffer[ GetBufferPos(n) + POS_FTSW_4 ]) & 0x00007FFF);
28 unsigned int RawFTSWFormat_v1::GetTTCtimeTRGType(
int n)
30 return (
unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_CTIME_TRGTYPE ]);
35 int RawFTSWFormat_v1::GetTTCtime(
int n)
37 return (
int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
40 int RawFTSWFormat_v1::GetTRGType(
int n)
42 return (
int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
45 unsigned int RawFTSWFormat_v1::GetTTUtime(
int n)
47 return (
unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_UTIME ]);
50 void RawFTSWFormat_v1::GetTTTimeVal(
int n,
struct timeval* tv)
52 tv->tv_sec = GetTTUtime(n);
53 tv->tv_usec = (int)(((
double)GetTTCtime(n)) / 127.216);
58 void RawFTSWFormat_v1::GetTTTimeSpec(
int n,
struct timespec* ts)
60 ts->tv_sec = GetTTUtime(n);
61 ts->tv_nsec = (long)(((
double)GetTTCtime(n)) / 0.127216);
66 unsigned long long int RawFTSWFormat_v1::GetTTTimeNs(
int n)
68 return (
unsigned long long int)GetTTUtime(n) * 1e9 + (long)((
double)GetTTCtime(n) / 0.127216);
71 int RawFTSWFormat_v1::GetNwordsHeader(
int n)
73 return m_buffer[ GetBufferPos(n) + POS_HDR_NWORDS ];
77 unsigned int RawFTSWFormat_v1::GetFTSWNodeID(
int n)
79 return (
unsigned int)(m_buffer[ GetBufferPos(n) + POS_NODE_ID ]);
82 unsigned int RawFTSWFormat_v1::GetEveNo(
int n)
84 return m_buffer[ GetBufferPos(n) + POS_EVE_NO ];
87 unsigned int RawFTSWFormat_v1::GetMagicTrailer(
int n)
89 return m_buffer[ GetBufferPos(n) + POS_MAGIC_1 ];
92 void RawFTSWFormat_v1::CheckData(
int n,
93 unsigned int prev_evenum,
unsigned int* cur_evenum,
94 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
98 *cur_evenum = GetEveNo(n);
99 *cur_exprunsubrun_no = GetExpRunSubrun(n);
102 #ifndef NO_DATA_CHECK
103 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
104 if ((
unsigned int)(prev_evenum + 1) != *cur_evenum) {
105 sprintf(err_buf,
"[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
106 n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
107 printf(
"%s", err_buf);
113 if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
114 sprintf(err_buf,
"[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
115 n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
116 printf(
"%s", err_buf);
120 if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
121 sprintf(err_buf,
"[FATAL] ERROR_EVENT : invalid magic word : block %d magic word 0x%x must be 0x%x : Exiting...\n %s %s %d\n",
122 n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
123 printf(
"%s", err_buf);
128 printf(
"[DEBUG] ========== dump a data block : block # %d==========\n", n);
130 for (
int k = 0 ; k < GetBlockNwords(n); k++) {
131 printf(
"0x%.8x ", (GetBuffer(n))[k]);
132 if (k % 10 == 9) printf(
"\n[DEBUG] ");