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