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