1 |
#include "Digitizer.h" |
2 |
|
3 |
void Digitizer::DigitizeRunHeader(){ |
4 |
const Int_t lenRH = fRunHeaderbuffer; // 37 not 54 |
5 |
UChar_t buffRH[lenRH]; |
6 |
UShort_t buffPSCU[8]; |
7 |
UChar_t *p; |
8 |
p=buffRH; |
9 |
|
10 |
// header: 16 bytes |
11 |
// DigitizePSCU(fRunHeaderbuffer*2,0x20,buffPSCU); |
12 |
DigitizePSCU(0x25,0x20,buffPSCU); |
13 |
memcpy(p,buffPSCU,16*sizeof(UChar_t)); |
14 |
p+=16; |
15 |
|
16 |
// time stamp (uint32): 0x82569c97 |
17 |
*(p++) = 0x82; |
18 |
*(p++) = 0x56; |
19 |
*(p++) = 0x9C; |
20 |
*(p++) = 0x97; |
21 |
|
22 |
// acq_setting_mode (uint8) |
23 |
*(p++) = 2; |
24 |
|
25 |
// obt (uint32) |
26 |
ULong64_t obt = fOBT + 30LL; |
27 |
while ( obt > 4294967295LL ) |
28 |
obt -= 4294967295LL; |
29 |
fOBT = (UInt_t)obt; |
30 |
// |
31 |
*(p++) = (UChar_t)(fOBT >> 24); |
32 |
*(p++) = (UChar_t)(fOBT >> 16); |
33 |
*(p++) = (UChar_t)(fOBT >> 8); |
34 |
*(p++) = (UChar_t)fOBT; |
35 |
|
36 |
// last time_sync_info (uint32) (from file 000_001_00110) |
37 |
*(p++) = 0x00; |
38 |
*(p++) = 0x08; |
39 |
*(p++) = 0x68; |
40 |
*(p++) = 0xEF; |
41 |
|
42 |
// fav. working schedule (uint8) |
43 |
*(p++) = 0; |
44 |
|
45 |
// eff. working schedule (uint8) |
46 |
*(p++) = 0; |
47 |
|
48 |
// trigger_mode_A (uint32) |
49 |
*(p++) = 0; |
50 |
*(p++) = 0; |
51 |
*(p++) = 0; |
52 |
*(p++) = 0x01; |
53 |
|
54 |
// trigger_mode_B (uint32) |
55 |
*(p++) = 0; |
56 |
*(p++) = 0; |
57 |
*(p++) = 0; |
58 |
*(p++) = 0x03; |
59 |
|
60 |
// acq_after_calib (0,1) (uint8) |
61 |
*(p++) = 0; |
62 |
|
63 |
// trk_calib_used (uint32) |
64 |
*(p++) = 0; |
65 |
*(p++) = 0; |
66 |
*(p++) = 0; |
67 |
*(p++) = 0x68; |
68 |
|
69 |
// acq_build_info (4 zero bits + 28 1's) (uint32) |
70 |
*(p++) = 0x3F; |
71 |
*(p++) = 0xFF; |
72 |
*(p++) = 0xFF; |
73 |
*(p++) = 0xFF; |
74 |
|
75 |
// acq_var_info (11 bits) (uint16) |
76 |
*(p++) = 0x23; |
77 |
*(p++) = 0x7F; |
78 |
|
79 |
// cal_dsp_mask (uint8) |
80 |
*(p++) = 0; |
81 |
|
82 |
// crc (uint16) |
83 |
UShort_t crcRH = (UShort_t)CM_Compute_CRC16((UINT16)0, (BYTE*)&buffRH, (UINT32)(fRunHeaderbuffer-1)); |
84 |
*(p++) = (UChar_t)(crcRH << 8); |
85 |
*p = (UChar_t)crcRH; |
86 |
|
87 |
memcpy(fDataRunHeader,buffRH,fRunHeaderbuffer*sizeof(UChar_t)); |
88 |
}; |
89 |
|
90 |
void Digitizer::DigitizeRunTrailer(){ |
91 |
UChar_t buffRT[fRunTrailerbuffer]; |
92 |
UShort_t buffPSCU[8]; |
93 |
UChar_t *p; |
94 |
p=buffRT; |
95 |
|
96 |
// header: 16 bytes |
97 |
// DigitizePSCU(fRunHeaderbuffer*2,0x21,buffPSCU); |
98 |
DigitizePSCU(0x19,0x21,buffPSCU); |
99 |
memcpy(p,buffPSCU,16*sizeof(UChar_t)); |
100 |
p+=16; |
101 |
|
102 |
// pkt_counter (uint32) |
103 |
fCounterPhys++; |
104 |
fCounter++; |
105 |
while ( fCounterPhys > 16777215 ) |
106 |
fCounterPhys -= 16777215; |
107 |
// |
108 |
*(p++) = (UChar_t)(fCounterPhys >> 24); |
109 |
*(p++) = (UChar_t)(fCounterPhys >> 16); |
110 |
*(p++) = (UChar_t)(fCounterPhys >> 8); |
111 |
*(p++) = (UChar_t)fCounterPhys; |
112 |
|
113 |
// pkt_readyCounter: valid packets in the run (uint32) |
114 |
*(p++) = 0; |
115 |
*(p++) = 0; |
116 |
*(p++) = 0; |
117 |
*(p++) = 0; |
118 |
|
119 |
// obt (uint32) |
120 |
ULong64_t obt = fOBT + 30LL; |
121 |
while ( obt > 4294967295LL ) |
122 |
obt -= 4294967295LL; |
123 |
fOBT = (UInt_t)obt; |
124 |
// |
125 |
*(p++) = (UChar_t)(fOBT >> 24); |
126 |
*(p++) = (UChar_t)(fOBT >> 16); |
127 |
*(p++) = (UChar_t)(fOBT >> 8); |
128 |
*(p++) = (UChar_t)fOBT; |
129 |
|
130 |
// last time_sync_info (uint32) |
131 |
*(p++) = 0; |
132 |
*(p++) = 0; |
133 |
*(p++) = 0; |
134 |
*(p++) = 0; |
135 |
|
136 |
// crc (uint16) |
137 |
UShort_t crcRT = (UShort_t)CM_Compute_CRC16((UINT16)0, (BYTE*)(buffRT), (UINT32)(fRunTrailerbuffer-1)); |
138 |
*(p++) = (UChar_t)(crcRT << 8); |
139 |
*p = (UChar_t)crcRT; |
140 |
|
141 |
memcpy(fDataRunTrailer,buffRT,fRunTrailerbuffer*sizeof(UChar_t)); |
142 |
}; |
143 |
|
144 |
void Digitizer::AddPadding(){ |
145 |
// |
146 |
Float_t pd0 = (fLen+16)/64.; |
147 |
Float_t pd1 = pd0 - (Float_t)int(pd0); |
148 |
Float_t padfrac = 64. - pd1 * 64.; |
149 |
// |
150 |
UInt_t padbytes = (UInt_t)padfrac; |
151 |
if ( padbytes > 0 && padbytes < 64 ){ |
152 |
// |
153 |
// here the padding length |
154 |
// |
155 |
fPadding = padbytes+64; |
156 |
// |
157 |
// random padding bytes |
158 |
// |
159 |
for (Int_t ur=0; ur<32; ur++){ |
160 |
fDataPadding[ur] = (UShort_t)rand(); |
161 |
}; |
162 |
}; |
163 |
}; |
164 |
|
165 |
|
166 |
void Digitizer::DigitizePSCU(UInt_t length, UChar_t type, UShort_t *pPSCU) { |
167 |
// |
168 |
UChar_t buff[16]; |
169 |
// |
170 |
// CPU signature |
171 |
// |
172 |
buff[0] = 0xFA; |
173 |
buff[1] = 0xFE; |
174 |
buff[2] = 0xDE; |
175 |
// |
176 |
// packet type (twice) |
177 |
// |
178 |
buff[3] = type; |
179 |
buff[4] = type; |
180 |
// |
181 |
// counter |
182 |
// |
183 |
fCounter++; |
184 |
while ( fCounter > 16777215 ){ |
185 |
fCounter -= 16777215; |
186 |
}; |
187 |
// |
188 |
buff[5] = (UChar_t)(fCounter >> 16); |
189 |
buff[6] = (UChar_t)(fCounter >> 8); |
190 |
buff[7] = (UChar_t)fCounter; |
191 |
// |
192 |
// on board time |
193 |
// |
194 |
ULong64_t obt = fOBT + 30LL; |
195 |
// |
196 |
while ( obt > 4294967295LL ){ |
197 |
obt -= 4294967295LL; |
198 |
}; |
199 |
fOBT = (UInt_t)obt; |
200 |
// |
201 |
buff[8] = (UChar_t)(fOBT >> 24); |
202 |
buff[9] = (UChar_t)(fOBT >> 16); |
203 |
buff[10] = (UChar_t)(fOBT >> 8); |
204 |
buff[11] = (UChar_t)fOBT; |
205 |
// |
206 |
// Packet length |
207 |
// |
208 |
fLen = length; |
209 |
// |
210 |
buff[12] = (UChar_t)(fLen >> 16); |
211 |
buff[13] = (UChar_t)(fLen >> 8); |
212 |
buff[14] = (UChar_t)fLen; |
213 |
// |
214 |
// CPU header CRC |
215 |
// |
216 |
buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15); |
217 |
// |
218 |
//memcpy(fDataPSCU,buff,16*sizeof(UChar_t)); |
219 |
memcpy(pPSCU,buff,16*sizeof(UChar_t)); |
220 |
// |
221 |
}; |