Belle II Software  release-08-01-10
RawFTSWFormat_v2.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_v2.h>
10 
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 RawFTSWFormat_v2::RawFTSWFormat_v2()
16 {
17 }
18 
19 RawFTSWFormat_v2::~RawFTSWFormat_v2()
20 {
21 }
22 
23 
24 unsigned int RawFTSWFormat_v2::GetTTCtimeTRGType(int n)
25 {
26  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_CTIME_TRGTYPE ]);
27 }
28 
29 
30 
31 int RawFTSWFormat_v2::GetTTCtime(int n)
32 {
33  return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
34 }
35 
36 int RawFTSWFormat_v2::GetTRGType(int n)
37 {
38  return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
39 }
40 
41 unsigned int RawFTSWFormat_v2::GetTTUtime(int n)
42 {
43  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_UTIME ]);
44 }
45 
46 void RawFTSWFormat_v2::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 
54 void RawFTSWFormat_v2::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 
62 unsigned long long int RawFTSWFormat_v2::GetTTTimeNs(int n)
63 {
64  return (unsigned long long int)GetTTUtime(n) * 1e9 + (long)((double)GetTTCtime(n) / 0.127216);
65 }
66 
67 int RawFTSWFormat_v2::GetNwordsHeader(int n)
68 {
69  return m_buffer[ GetBufferPos(n) + POS_HDR_NWORDS ];
70 }
71 
72 
73 unsigned int RawFTSWFormat_v2::GetFTSWNodeID(int n)
74 {
75  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_NODE_ID ]);
76 }
77 
78 unsigned int RawFTSWFormat_v2::GetEveNo(int n)
79 {
80  return m_buffer[ GetBufferPos(n) + POS_EVE_NO_1 ];
81 }
82 
83 unsigned int RawFTSWFormat_v2::GetMagicTrailer(int n)
84 {
85  return m_buffer[ GetBufferPos(n) + POS_MAGIC_1 ];
86 }
87 
88 int RawFTSWFormat_v2::GetIsHER(int n)
89 {
90  int* buffer = GetBuffer(n);
91  int ret = (buffer[ POS_INJECTION_INFO ] & INJ_HER_LER_MASK) >> INJ_HER_LER_SHIFT;
92  return ret; // 1 -> HER, 0 -> LER
93 }
94 
95 
96 unsigned int RawFTSWFormat_v2::GetTimeSinceLastInjection(int n)
97 {
98  unsigned int* buffer = (unsigned int*) GetBuffer(n);
99  unsigned int ret = (buffer[ POS_INJECTION_INFO ] & INJ_TIME_MASK) >> INJ_TIME_SHIFT;
100  return ret;
101 }
102 
103 unsigned int RawFTSWFormat_v2::GetTimeSincePrevTrigger(int n)
104 {
105  unsigned int* buffer = (unsigned int*) GetBuffer(n);
106  unsigned int ret = buffer[ POS_TIME_SINCE_PREV_TRG ];
107  return ret;
108 }
109 
110 unsigned int RawFTSWFormat_v2::GetBunchNumber(int n)
111 {
112  unsigned int* buffer = (unsigned int*) GetBuffer(n);
113  unsigned int ret = (buffer[ POS_BUNCH_NUM ] & INJ_BUNCH_MASK) >> INJ_BUNCH_SHIFT;
114  return ret;
115 }
116 
117 unsigned int RawFTSWFormat_v2::GetFrameCount(int n)
118 {
119  unsigned int* buffer = (unsigned int*) GetBuffer(n);
120  unsigned int ret = buffer[ POS_FRAME_COUNT ];
121  return ret;
122 }
123 
124 
125 void RawFTSWFormat_v2::CheckData(int n,
126  unsigned int prev_evenum, unsigned int* cur_evenum,
127  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
128 {
129  int err_flag = 0;
130  char err_buf[500];
131  *cur_evenum = GetEveNo(n);
132  *cur_exprunsubrun_no = GetExpRunSubrun(n);
133 
134 
135 #ifndef NO_DATA_CHECK
136  if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
137  if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
138  sprintf(err_buf, "[FATAL] ERROR_EVENT : Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
139  n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
140  printf("%s", err_buf);
141  err_flag = 1;
142  }
143  }
144 #endif
145 
146  if (GetBlockNwords(n) != SIZE_FTSW_PACKET) {
147  sprintf(err_buf, "[FATAL] ERROR_EVENT : invalid FTSW packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
148  n, GetBlockNwords(n), SIZE_FTSW_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
149  printf("%s", err_buf);
150  err_flag = 1;
151  }
152 
153  if (GetMagicTrailer(n) != FTSW_MAGIC_TRAILER) {
154  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",
155  n, GetMagicTrailer(n), FTSW_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
156  printf("%s", err_buf);
157  err_flag = 1;
158  }
159 
160  if (err_flag == 1) {
161  printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
162  printf("[DEBUG] ");
163  for (int k = 0 ; k < GetBlockNwords(n); k++) {
164  printf("0x%.8x ", (GetBuffer(n))[k]);
165  if (k % 10 == 9) printf("\n[DEBUG] ");
166  }
167  fflush(stderr);
168  string err_str = err_buf; throw (err_str);
169 
170  }
171 
172  return;
173 }
Abstract base class for different kinds of events.