Belle II Software development
RawFTSWFormat_latest.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_latest.h>
10
11
12using namespace std;
13using namespace Belle2;
14
16{
17}
18
20{
21}
22
23
25{
26 return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_CTIME_TRGTYPE ]);
27}
28
29
30
32{
33 return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
34}
35
37{
38 return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
39}
40
42{
43 return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_UTIME ]);
44}
45
46void RawFTSWFormat_latest::GetTTTimeVal(int n, struct timeval* tv)
47{
48 tv->tv_sec = GetTTUtime(n);
49 tv->tv_usec = (int)(((double)GetTTCtime(n)) / 127.216);
50
51 return ;
52}
53
54void RawFTSWFormat_latest::GetTTTimeSpec(int n, struct timespec* ts)
55{
56 ts->tv_sec = GetTTUtime(n);
57 ts->tv_nsec = (long)(((double)GetTTCtime(n)) / 0.127216);
58
59 return ;
60}
61
62void RawFTSWFormat_latest::GetPCTimeVal(int n, struct timeval* tv)
63{
64 tv->tv_sec = (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TVSEC_FROM_PC ]);
65 tv->tv_usec = (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TVUSEC_FROM_PC ]);
66 return ;
67}
68
69
70unsigned long long int RawFTSWFormat_latest::GetTTTimeNs(int n)
71{
72 return (unsigned long long int)GetTTUtime(n) * 1e9 + (long)((double)GetTTCtime(n) / 0.127216);
73}
74
76{
77 return m_buffer[ GetBufferPos(n) + POS_HDR_NWORDS ];
78}
79
80
82{
83 return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_NODE_ID ]);
84}
85
87{
88 return m_buffer[ GetBufferPos(n) + POS_EVE_NO_1 ];
89}
90
92{
93 return m_buffer[ GetBufferPos(n) + POS_MAGIC_1 ];
94}
95
97{
98 int* buffer = GetBuffer(n);
99 int ret = (buffer[ POS_INJECTION_INFO ] & INJ_HER_LER_MASK) >> INJ_HER_LER_SHIFT;
100 return ret; // 1 -> HER, 0 -> LER
101}
102
103
105{
106 unsigned int* buffer = (unsigned int*) GetBuffer(n);
107 unsigned int ret = (buffer[ POS_INJECTION_INFO ] & INJ_TIME_MASK) >> INJ_TIME_SHIFT;
108 return ret;
109}
110
112{
113 unsigned int* buffer = (unsigned int*) GetBuffer(n);
114 unsigned int ret = buffer[ POS_TIME_SINCE_PREV_TRG ];
115 return ret;
116}
117
119{
120 unsigned int* buffer = (unsigned int*) GetBuffer(n);
121 unsigned int ret = (buffer[ POS_BUNCH_NUM ] & INJ_BUNCH_MASK) >> INJ_BUNCH_SHIFT;
122 return ret;
123}
124
126{
127 unsigned int* buffer = (unsigned int*) GetBuffer(n);
128 unsigned int ret = buffer[ POS_FRAME_COUNT ];
129 return ret;
130}
131
132
134 unsigned int prev_evenum, unsigned int* cur_evenum,
135 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
136{
137 int err_flag = 0;
138 char err_buf[500];
139 *cur_evenum = GetEveNo(n);
140 *cur_exprunsubrun_no = GetExpRunSubrun(n);
141
142
143#ifndef NO_DATA_CHECK
144 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
145 if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
146 sprintf(err_buf, "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
147 n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
148 printf("%s", err_buf);
149 err_flag = 1;
150 }
151 }
152#endif
153
154 if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
155 sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
156 n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
157 printf("%s", err_buf);
158 err_flag = 1;
159 }
160
161 if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
162 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",
163 n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
164 printf("%s", err_buf); fflush(stdout);
165 err_flag = 1;
166 }
167
168 if (err_flag == 1) {
169 printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
170 printf("[DEBUG] ");
171 for (int k = 0 ; k < GetBlockNwords(n); k++) {
172 printf("0x%.8x ", (GetBuffer(n))[k]);
173 if (k % 10 == 9) printf("\n[DEBUG] ");
174 }
175 fflush(stderr);
176 B2FATAL(err_buf);
177 }
178
179 return;
180}
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.
int GetTRGType(int n) OVERRIDE_CPP17
Get trgtype.
unsigned int GetMagicTrailer(int n) OVERRIDE_CPP17
Get magic number for data corruption check.
void GetTTTimeVal(int n, struct timeval *tv) OVERRIDE_CPP17
Get timeval from ctime and utime.
unsigned int GetTimeSinceLastInjection(int n) OVERRIDE_CPP17
Get time since the last injection.
virtual ~RawFTSWFormat_latest()
Constructor using existing pointer to raw data buffer.
int GetNwordsHeader(int n) OVERRIDE_CPP17
Get # of words of header.
RawFTSWFormat_latest()
Default constructor.
unsigned int GetBunchNumber(int n) OVERRIDE_CPP17
Get a bunch number.
unsigned int GetTTUtime(int n) OVERRIDE_CPP17
get unixtime of the trigger
unsigned int GetTimeSincePrevTrigger(int n) OVERRIDE_CPP17
Get time since the previous trigger.
unsigned int GetFrameCount(int n) OVERRIDE_CPP17
Get a frame count.
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.
void GetPCTimeVal(int n, struct timeval *tv) OVERRIDE_CPP17
Get stored information of getimeofday in a PC.
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
int GetIsHER(int n) OVERRIDE_CPP17
HER injection = 1 or LER injection = 0.
unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17
Exp# (10bit) run# (14bit) restart # (8bit)
Abstract base class for different kinds of events.
STL namespace.