Belle II Software development
RawFTSWFormat_v1.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <rawdata/dataobjects/RawFTSWFormat_v1.h>
10
11
12using namespace std;
13using namespace Belle2;
14
16{
17}
18
20{
21}
22
23
25{
26 return (int)((unsigned int)(m_buffer[ GetBufferPos(n) + POS_FTSW_4 ]) & 0x00007FFF);
27}
28
30{
31 return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_CTIME_TRGTYPE ]);
32}
33
34
35
37{
38 return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
39}
40
42{
43 return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
44}
45
47{
48 return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_UTIME ]);
49}
50
51void RawFTSWFormat_v1::GetTTTimeVal(int n, struct timeval* tv)
52{
53 tv->tv_sec = GetTTUtime(n);
54 tv->tv_usec = (int)(((double)GetTTCtime(n)) / 127.216);
55
56 return ;
57}
58
59void RawFTSWFormat_v1::GetTTTimeSpec(int n, struct timespec* ts)
60{
61 ts->tv_sec = GetTTUtime(n);
62 ts->tv_nsec = (long)(((double)GetTTCtime(n)) / 0.127216);
63
64 return ;
65}
66
67unsigned long long int RawFTSWFormat_v1::GetTTTimeNs(int n)
68{
69 return (unsigned long long int)GetTTUtime(n) * 1e9 + (long)((double)GetTTCtime(n) / 0.127216);
70}
71
73{
74 return m_buffer[ GetBufferPos(n) + POS_HDR_NWORDS ];
75}
76
77
79{
80 return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_NODE_ID ]);
81}
82
83unsigned int RawFTSWFormat_v1::GetEveNo(int n)
84{
85 return m_buffer[ GetBufferPos(n) + POS_EVE_NO ];
86}
87
89{
90 return m_buffer[ GetBufferPos(n) + POS_MAGIC_1 ];
91}
92
94 unsigned int prev_evenum, unsigned int* cur_evenum,
95 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
96{
97 int err_flag = 0;
98 char err_buf[500];
99 *cur_evenum = GetEveNo(n);
100 *cur_exprunsubrun_no = GetExpRunSubrun(n);
101
102
103#ifndef NO_DATA_CHECK
104 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
105 if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
106 sprintf(err_buf, "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
107 n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
108 printf("%s", err_buf);
109 err_flag = 1;
110 }
111 }
112#endif
113
114 if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
115 sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
116 n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
117 printf("%s", err_buf);
118 err_flag = 1;
119 }
120
121 if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
122 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",
123 n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
124 printf("%s", err_buf);
125 err_flag = 1;
126 }
127
128 if (err_flag == 1) {
129 printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
130 printf("[DEBUG] ");
131 for (int k = 0 ; k < GetBlockNwords(n); k++) {
132 printf("0x%.8x ", (GetBuffer(n))[k]);
133 if (k % 10 == 9) printf("\n[DEBUG] ");
134 }
135 fflush(stderr);
136 B2FATAL(err_buf);
137 }
138
139 return;
140}
virtual int GetBlockNwords(int n)
get size of a data block
virtual int GetBufferPos(int n)
get position of data block in word
virtual int * GetBuffer(int n)
get nth buffer pointer
int GetTTCtime(int n) OVERRIDE_CPP17
Get ctime of the trigger.
unsigned int GetEveNo(int n) OVERRIDE_CPP17
Get event #.
void GetTTTimeSpec(int n, struct timespec *ts) OVERRIDE_CPP17
Get timespec from ctime and utime.
RawFTSWFormat_v1()
Default constructor.
int GetTRGType(int n) OVERRIDE_CPP17
Get trgtype.
unsigned int GetMagicTrailer(int n) OVERRIDE_CPP17
Get magic number for data corruption check.
int Get15bitTLUTag(int n) OVERRIDE_CPP17
DESY test only.
void GetTTTimeVal(int n, struct timeval *tv) OVERRIDE_CPP17
Get timeval from ctime and utime.
int GetNwordsHeader(int n) OVERRIDE_CPP17
Get # of words of header.
virtual ~RawFTSWFormat_v1()
Constructor using existing pointer to raw data buffer.
unsigned int GetTTUtime(int n) OVERRIDE_CPP17
get unixtime of the trigger
unsigned int GetFTSWNodeID(int n) OVERRIDE_CPP17
Get Node # ( should be "TTD " )
unsigned long long int GetTTTimeNs(int n) OVERRIDE_CPP17
Get time in ns since epoch from ctime and utime.
unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17
Get a word containing ctime and trigger type info.
void CheckData(int n, unsigned int prev_evenum, unsigned int *cur_evenum, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
check the data contents
unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17
Exp# (10bit) run# (14bit) restart # (8bit)
Abstract base class for different kinds of events.
STL namespace.