Belle II Software  release-08-01-10
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 
12 using namespace std;
13 using namespace Belle2;
14 
15 RawFTSWFormat_v1::RawFTSWFormat_v1()
16 {
17 }
18 
19 RawFTSWFormat_v1::~RawFTSWFormat_v1()
20 {
21 }
22 
23 
24 int RawFTSWFormat_v1::Get15bitTLUTag(int n)
25 {
26  return (int)((unsigned int)(m_buffer[ GetBufferPos(n) + POS_FTSW_4 ]) & 0x00007FFF);
27 }
28 
29 unsigned int RawFTSWFormat_v1::GetTTCtimeTRGType(int n)
30 {
31  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_CTIME_TRGTYPE ]);
32 }
33 
34 
35 
36 int RawFTSWFormat_v1::GetTTCtime(int n)
37 {
38  return (int)((GetTTCtimeTRGType(n) & TTCTIME_MASK) >> TTCTIME_SHIFT);
39 }
40 
41 int RawFTSWFormat_v1::GetTRGType(int n)
42 {
43  return (int)(GetTTCtimeTRGType(n) & TRGTYPE_MASK);
44 }
45 
46 unsigned int RawFTSWFormat_v1::GetTTUtime(int n)
47 {
48  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_TT_UTIME ]);
49 }
50 
51 void 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 
59 void 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 
67 unsigned 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 
72 int RawFTSWFormat_v1::GetNwordsHeader(int n)
73 {
74  return m_buffer[ GetBufferPos(n) + POS_HDR_NWORDS ];
75 }
76 
77 
78 unsigned int RawFTSWFormat_v1::GetFTSWNodeID(int n)
79 {
80  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_NODE_ID ]);
81 }
82 
83 unsigned int RawFTSWFormat_v1::GetEveNo(int n)
84 {
85  return m_buffer[ GetBufferPos(n) + POS_EVE_NO ];
86 }
87 
88 unsigned int RawFTSWFormat_v1::GetMagicTrailer(int n)
89 {
90  return m_buffer[ GetBufferPos(n) + POS_MAGIC_1 ];
91 }
92 
93 void RawFTSWFormat_v1::CheckData(int n,
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 }
Abstract base class for different kinds of events.