]>
Commit | Line | Data |
---|---|---|
31a920d3 | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: Per Thomas Hille <perthi@fys.uio.no> * | |
ebf7cafe | 6 | * Ã\98ystein Djuvsland <oystein.djuvsland@gmail.com> * |
31a920d3 | 7 | * * |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
17 | #include <Riostream.h> | |
18 | #include "AliAltroDecoder.h" | |
19 | #include "AliAltroData.h" | |
20 | ||
21 | ClassImp(AliAltroDecoder) | |
22 | ||
23 | AliAltroDecoder::AliAltroDecoder() : f32DtaPtr(0), | |
ebf7cafe | 24 | f8DtaPtr(0), |
25 | fN32HeaderWords(8), | |
26 | fN40AltroWords(0), | |
27 | fN40RcuAltroWords(0), | |
28 | fNDDLBlocks(0), | |
29 | f32LastDDLBlockSize(5), | |
30 | f32PayloadSize(0), | |
31 | fOutBufferIndex(0), | |
32 | fSize(0), | |
33 | fNAltro10bitWords(0), | |
34 | fComplete(0), | |
35 | fInComplete(0), | |
36 | fDecodeIfCorruptedTrailer(kTRUE), | |
37 | fIsDecoded(kFALSE), | |
38 | fIsFatalCorruptedTrailer(kTRUE) | |
31a920d3 | 39 | { |
40 | // see header file for class documentation | |
41 | } | |
42 | ||
43 | ||
44 | AliAltroDecoder::~AliAltroDecoder() | |
45 | { | |
46 | // see header file for class documentation | |
47 | } | |
48 | ||
49 | ||
50 | Bool_t AliAltroDecoder::CheckPayloadTrailer() | |
51 | { | |
52 | // see header file for documentation | |
53 | if(fN40AltroWords != fN40RcuAltroWords) | |
54 | { | |
55 | return kFALSE; | |
56 | } | |
57 | else | |
58 | { | |
59 | return kTRUE; | |
60 | } | |
61 | } | |
62 | ||
63 | ||
64 | Bool_t AliAltroDecoder::Decode() | |
ebf7cafe | 65 | { |
66 | if( fIsFatalCorruptedTrailer == kTRUE) | |
31a920d3 | 67 | { |
ebf7cafe | 68 | printf("\n AliAltroDecoder::Decode(), WARNING, attempt to decode badly corrupted data\n"); |
69 | printf("\n AliAltroDecoder::Decode(). Please check on the return value (-1 if fataly corrupted) of the SetMemory() function\n"); | |
70 | return kFALSE; | |
71 | } | |
72 | ||
73 | else | |
31a920d3 | 74 | { |
ebf7cafe | 75 | // see header file for class documentation |
76 | fComplete = 0; | |
77 | fInComplete = 0; | |
78 | ||
79 | Int_t tmpcnt = countAAApaddings(); | |
31a920d3 | 80 | |
ebf7cafe | 81 | if(tmpcnt == 3) |
82 | { | |
83 | fN40AltroWords = fN40AltroWords -1; | |
84 | } | |
85 | else if(tmpcnt == 5) | |
86 | { | |
87 | fN40AltroWords = fN40AltroWords -2; | |
88 | } | |
89 | else if(tmpcnt == 8) | |
90 | { | |
91 | fN40AltroWords = fN40AltroWords -3; | |
92 | } | |
31a920d3 | 93 | |
ebf7cafe | 94 | if( ((CheckPayloadTrailer() == kTRUE) || fDecodeIfCorruptedTrailer == kTRUE ) && (fSize > 32) ) |
31a920d3 | 95 | { |
ebf7cafe | 96 | // fDDLBlockCnt = 0; |
97 | fOutBufferIndex = 0; | |
98 | ||
99 | for(Int_t i = 0; i < fNDDLBlocks; i++) | |
100 | { | |
101 | DecodeDDLBlock(); | |
102 | } | |
31a920d3 | 103 | |
ebf7cafe | 104 | DecodeLastDDLBlock(); |
105 | fOutBufferIndex = fN40AltroWords*4 - 1; | |
31a920d3 | 106 | |
ebf7cafe | 107 | // DumpData(fOutBuffer, 400,4); |
31a920d3 | 108 | |
ebf7cafe | 109 | fIsDecoded = kTRUE; |
110 | return kTRUE; | |
111 | } | |
112 | ||
113 | else | |
114 | { | |
115 | cout <<" ERROR: data integrity check failed, discarding data" << endl; | |
116 | cout << "Size of datablock is " << fSize << endl; | |
117 | cout << "fN40AltroWords = " << fN40AltroWords << endl; | |
118 | cout << "fN40RcuAltroWords = " << fN40RcuAltroWords << endl; | |
119 | return kFALSE; | |
120 | } | |
31a920d3 | 121 | |
31a920d3 | 122 | } |
123 | } | |
124 | ||
125 | ||
126 | Bool_t AliAltroDecoder::NextChannel(AliAltroData *altroDataPtr) | |
127 | { | |
ebf7cafe | 128 | if(fIsFatalCorruptedTrailer == kTRUE) |
31a920d3 | 129 | { |
ebf7cafe | 130 | printf("\n AliAltroDecoder::NextChannel(), WARNING, attempt to decode badly corrupted data\n"); |
131 | printf("\n AliAltroDecoder::NextChannel(), Please check on the return value (-1 if fataly corrupted) of the SetMemory() function\n"); | |
132 | return kFALSE; | |
133 | } | |
134 | ||
135 | else | |
31a920d3 | 136 | { |
31a920d3 | 137 | |
ebf7cafe | 138 | if(fIsDecoded != kTRUE) |
139 | { | |
140 | cout <<"AliAltroDecoder::NextChanne, WARNING, buffer was not decoded, decoding now.. "<< endl; | |
141 | Decode(); | |
142 | } | |
31a920d3 | 143 | |
ebf7cafe | 144 | if(fOutBufferIndex > fN32HeaderWords) |
31a920d3 | 145 | { |
ebf7cafe | 146 | if((fOutBuffer[fOutBufferIndex] << 4 ) | ((fOutBuffer[fOutBufferIndex-1] & 0x3c0) >> 6) == 0x2aaa) |
147 | { | |
148 | altroDataPtr->SetIsComplete(kTRUE); | |
149 | fComplete ++; | |
150 | } | |
151 | else | |
152 | { | |
153 | altroDataPtr->SetIsComplete(kFALSE); | |
154 | fInComplete ++; | |
155 | } | |
156 | ||
157 | fOutBufferIndex --; | |
158 | fNAltro10bitWords = ( (fOutBuffer[fOutBufferIndex] & 0x3f) << 4 ) | ((fOutBuffer[fOutBufferIndex -1] & (0xF << 6)) >> 6) ; | |
159 | fOutBufferIndex --; | |
160 | altroDataPtr->SetHadd( ((fOutBuffer[fOutBufferIndex] & 0x3)) << 10 | ( fOutBuffer[fOutBufferIndex-1] ) ); | |
161 | ||
162 | fOutBufferIndex --; | |
163 | ||
164 | if(fNAltro10bitWords%4 == 0) | |
165 | { | |
166 | fOutBufferIndex = fOutBufferIndex - fNAltro10bitWords; | |
167 | } | |
168 | else | |
169 | { | |
170 | fOutBufferIndex = fOutBufferIndex - fNAltro10bitWords -(4 - fNAltro10bitWords%4); | |
171 | } | |
172 | ||
173 | ||
174 | altroDataPtr->SetData( &fOutBuffer[fOutBufferIndex] ); | |
175 | fOutBufferIndex --; | |
176 | altroDataPtr->SetDataSize( fNAltro10bitWords ); | |
177 | return kTRUE; | |
178 | ||
31a920d3 | 179 | } |
180 | else | |
181 | { | |
ebf7cafe | 182 | return kFALSE; |
31a920d3 | 183 | } |
184 | ||
31a920d3 | 185 | } |
186 | } | |
187 | ||
188 | ||
189 | ||
190 | Int_t AliAltroDecoder::countAAApaddings() | |
191 | { | |
192 | UShort_t *tailPtr= (UShort_t *)(f32DtaPtr +f32PayloadSize); | |
193 | Int_t cnt = 0; | |
194 | ||
195 | tailPtr --; | |
196 | ||
197 | while(*tailPtr == 0xaaaa) | |
198 | { | |
199 | cnt ++; | |
200 | tailPtr --; | |
201 | } | |
202 | ||
203 | tailPtr = tailPtr + cnt +1; | |
204 | ||
205 | return cnt; | |
206 | } | |
207 | ||
208 | ||
209 | Float_t AliAltroDecoder::GetFailureRate() | |
210 | { | |
211 | // see header file for documentation | |
212 | Float_t tmp = 0; | |
213 | cout << "Number of Complete channles = " << fComplete <<endl; | |
214 | cout << "Number of InComplete channles = " << fInComplete <<endl; | |
215 | tmp = (100*(Float_t)fInComplete)/((Float_t)fComplete + (Float_t)fInComplete); | |
216 | cout <<"There are "<< tmp <<"% incomplete channels"<<endl; | |
217 | return tmp; | |
218 | } | |
219 | ||
220 | ||
221 | void AliAltroDecoder::PrintInfo(AliAltroData &altrodata, Int_t n, Int_t nPerLine) | |
222 | { | |
223 | // see header file for documentation | |
224 | cout << "altrodata.fDataSize = " << altrodata.GetDataSize() << endl; | |
225 | cout << "altrodata.fHadd = " << altrodata.GetHadd() <<endl; | |
226 | const UInt_t* data = altrodata.GetData(); | |
227 | for(Int_t i= 0; i< n; i++) | |
228 | { | |
229 | if( (i%nPerLine == 0) && (i != 0) ) | |
230 | { | |
231 | printf("\n"); | |
232 | } | |
233 | printf("%d\t", data[i]); | |
234 | } | |
235 | printf("\n"); | |
236 | } | |
237 | ||
238 | ||
ebf7cafe | 239 | int AliAltroDecoder::SetMemory(UChar_t *dtaPtr, UInt_t size) |
31a920d3 | 240 | { |
ebf7cafe | 241 | int iRet = 0; |
31a920d3 | 242 | Int_t tmpTrailerSize; |
243 | fIsDecoded = kFALSE; | |
244 | f8DtaPtr =dtaPtr; | |
245 | fSize = size; | |
246 | f8DtaPtr =f8DtaPtr + fSize; | |
247 | f32DtaPtr = (UInt_t *)f8DtaPtr; | |
248 | tmpTrailerSize = *(f32DtaPtr - 1); | |
249 | ||
250 | if(tmpTrailerSize <= MAX_TRAILER_WORDS) | |
251 | { | |
252 | tmpTrailerSize = tmpTrailerSize; //assume that the last word of the buffer gives the number of trailer words | |
253 | } | |
254 | else | |
255 | { | |
256 | tmpTrailerSize = 1; //assume that last word is ONE, and that the this word gives the number of 40 bit altro words | |
257 | } | |
258 | ||
259 | f32PayloadSize = fSize/4 - (fN32HeaderWords + tmpTrailerSize); | |
260 | fN40AltroWords = (32*f32PayloadSize)/40; | |
261 | fNDDLBlocks = f32PayloadSize/5; | |
262 | f32LastDDLBlockSize = f32PayloadSize%DDL_32BLOCK_SIZE; | |
ebf7cafe | 263 | |
264 | if(tmpTrailerSize > 0 && tmpTrailerSize < 5) | |
265 | { | |
266 | f32DtaPtr = f32DtaPtr - tmpTrailerSize; | |
267 | fN40RcuAltroWords = *f32DtaPtr; | |
268 | f32DtaPtr = (UInt_t *)dtaPtr + fN32HeaderWords; | |
269 | fIsFatalCorruptedTrailer = kFALSE; | |
270 | } | |
271 | else | |
272 | { | |
273 | printf("\n AliAltroDecoder::SetMemory, ERROR\n, trailer is corrupted"); | |
274 | fIsFatalCorruptedTrailer = kTRUE; | |
275 | iRet = -1; | |
276 | } | |
277 | ||
278 | ||
279 | return iRet; | |
280 | ||
31a920d3 | 281 | } |
282 | ||
283 | ||
284 | void AliAltroDecoder::DecodeDDLBlock() | |
285 | { | |
286 | // see header file for documentation | |
287 | fOutBuffer[fOutBufferIndex] = *f32DtaPtr & 0x3ff; //s0 | |
288 | fOutBufferIndex ++; | |
289 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xffc00) >> 10; //s1 | |
290 | fOutBufferIndex ++; | |
291 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0x3ff00000) >> 20; //s2 | |
292 | fOutBufferIndex ++; | |
293 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xc0000000) >> 30; //s3_1 | |
294 | f32DtaPtr ++; | |
295 | fOutBuffer[fOutBufferIndex] = fOutBuffer[fOutBufferIndex] | ((*f32DtaPtr & 0xff) << 2); //s3_2 | |
296 | fOutBufferIndex ++; | |
297 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0x3ff00) >> 8; //s4 | |
298 | fOutBufferIndex ++; | |
299 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xffc0000) >> 18; //s5 | |
300 | fOutBufferIndex ++; | |
301 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xf0000000) >> 28; //s6_1 | |
302 | f32DtaPtr ++; | |
303 | fOutBuffer[fOutBufferIndex] = fOutBuffer[fOutBufferIndex] | ((*f32DtaPtr & 0x3f) << 4); //s6_2 | |
304 | fOutBufferIndex ++; | |
305 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xffc0) >> 6; //s7 | |
306 | fOutBufferIndex ++; | |
307 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0x3ff0000) >> 16; //s8 | |
308 | fOutBufferIndex ++; | |
309 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xFC000000) >> 26; //s9_1 | |
310 | f32DtaPtr ++; | |
311 | fOutBuffer[fOutBufferIndex] = fOutBuffer[fOutBufferIndex] | ((*f32DtaPtr & 0xf) << 6); //s9_2 | |
312 | fOutBufferIndex ++; | |
313 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0x3ff0) >> 4; //s10 | |
314 | fOutBufferIndex ++; | |
315 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xffc000) >> 14; //s11 | |
316 | fOutBufferIndex ++; | |
317 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xff000000) >> 24; //s12_1 | |
318 | f32DtaPtr ++; | |
319 | fOutBuffer[fOutBufferIndex] = fOutBuffer[fOutBufferIndex] | ((*f32DtaPtr & 0x3) << 8); //s12_2 | |
320 | fOutBufferIndex ++; | |
321 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xffc) >> 2; //s13 | |
322 | fOutBufferIndex ++; | |
323 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0x3ff000) >> 12; //s14 | |
324 | fOutBufferIndex ++; | |
325 | fOutBuffer[fOutBufferIndex] = (*f32DtaPtr & 0xffc00000) >> 22; //s15 | |
326 | f32DtaPtr ++; | |
327 | fOutBufferIndex ++; | |
328 | } | |
329 | ||
330 | ||
331 | void AliAltroDecoder::DecodeLastDDLBlock() | |
332 | { | |
333 | // see header file for documentation | |
334 | for(Int_t i=0; i < f32LastDDLBlockSize; i++) | |
335 | { | |
336 | fDDLBlockDummy[i] = *f32DtaPtr; | |
337 | f32DtaPtr ++; | |
338 | } | |
339 | ||
340 | f32DtaPtr = fDDLBlockDummy; | |
341 | f32DtaPtr ++; | |
342 | DecodeDDLBlock(); | |
343 | } |