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