]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTDDLDecoder.cxx
Effective c++, committed on behalf of �ystein Djuvsland
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTDDLDecoder.cxx
1 #include  "AliHLTDDLDecoder.h"
2 #include  "AliHLTAltroData.h"
3
4
5
6
7
8
9 AliHLTDDLDecoder::AliHLTDDLDecoder() : f32DtaPtr(0), f8DtaPtr(0),fN32HeaderWords(8), fN32RcuTrailerWords(2), fNDDLBlocks(0), 
10                                        fBufferPos(0), fN40AltroWords(0), fN40RcuAltroWords(0), fSize(0), fSegmentation(0), 
11                                        f32LastDDLBlockSize(5), f32PayloadSize(0),fBufferIndex(0), fN10bitWords(0)
12 {
13
14 }
15
16 AliHLTDDLDecoder::~AliHLTDDLDecoder()
17 {
18
19 }
20
21 bool
22 AliHLTDDLDecoder::CheckPayload()
23 {
24   if(fN40AltroWords != fN40RcuAltroWords)
25     {
26       return  false;
27     } 
28   else
29     {
30
31       return true;
32
33     }
34
35 }
36
37 bool
38 AliHLTDDLDecoder::Decode()
39 {
40    fComplete = 0;
41    fInComplete = 0;
42
43   if((CheckPayload() == true)  &&  (fSize > 32) )
44     {
45       fDDLBlockCnt = 0;
46       fBufferIndex = 0;
47       fN10bitWords = 0;
48       
49       for(fI=0; fI < fNDDLBlocks; fI++)
50         {
51           DecodeDDLBlock();
52         }
53
54       DecodeLastDDLBlock(); 
55       return true;
56     }
57
58   else
59     {
60
61       cout <<"ERROR: data integrity check failed, discarding data" << endl;
62       cout << "Size of datablock is  " << fSize   << endl;
63       cout << "fN40AltroWords = "      << fN40AltroWords   << endl;
64       cout << "fN40RcuAltroWords = "   << fN40RcuAltroWords  << endl;
65       return false;
66     }
67 }
68
69 /*
70   int tmpMarker = 0;
71   int tmpMask = 0x3c0;
72   tmpMarker = (buffer[index] << 4 ) | ((buffer[index-1] & tmpMask) >> 6);  
73   return tmpMarker;
74 */
75
76 bool
77 AliHLTDDLDecoder::NextChannel(AliHLTAltroData *altroDataPtr)
78 {
79   int tmp = 0;
80
81   if(fBufferPos >  fN32HeaderWords)
82     {
83       //      tmp  =  GetMarker(fBuffer, fBufferPos);
84       
85       if((fBuffer[fBufferPos] << 4 ) | ((fBuffer[fBufferPos-1] & 0x3c0) >> 6) == 0x2aaa)
86         {
87           altroDataPtr->fIsComplete = true;
88           fComplete ++;
89         }
90       else
91         {
92           altroDataPtr->fIsComplete = false;
93           fInComplete ++;
94           printf("\nERROR!!!!     marker = 0x%x\n", tmp);
95         }
96
97       //   printf("\nmarker = 0x%x", GetMarker(fBuffer, fBufferPos));
98
99       /* 
100       if(tmp == 0x2aaa)
101         {
102           //      printf("\nmarker = 0x%x", tmp);
103           altroDataPtr->fIsComplete = true;
104           fComplete ++;
105         }
106       else
107         {
108           altroDataPtr->fIsComplete = false;
109           fInComplete ++;
110           //      printf("\nERROR!!!!     marker = 0x%x\n", tmp);
111         }
112       */
113
114       fBufferPos --;
115       fNAltro10bitWords = ( (fBuffer[fBufferPos] & 0x3f) << 4 )   |  ((fBuffer[fBufferPos -1]  & (0xF << 6)) >> 6) ;
116       fBufferPos --;
117       fHadd =  ((fBuffer[fBufferPos] & 0x3)) << 10 | ( fBuffer[fBufferPos-1] );   
118       fBufferPos --;
119
120       if(fNAltro10bitWords%4 == 0)
121         {
122           //      altroDataPtr->fBunchPos  = fBufferPos; 
123           fBufferPos = fBufferPos  -  fNAltro10bitWords;
124         }
125       else
126         {
127           //      altroDataPtr->fBunchPos  = fBufferPos -(4 - fNAltro10bitWords%4);
128           fBufferPos = fBufferPos - fNAltro10bitWords -(4 - fNAltro10bitWords%4);
129         }
130
131       altroDataPtr->fData  = &fBuffer[fBufferPos];
132       fBufferPos --;
133       altroDataPtr->fDataSize =  fNAltro10bitWords ;
134       altroDataPtr->fHadd = fHadd; 
135
136
137       return true;
138     }
139   else
140     {
141       return false;
142     }
143 }
144
145 /*
146 bool
147 AliHLTDDLDecoder::NextBunch()
148 {
149
150 }
151 */
152
153
154 float
155 AliHLTDDLDecoder::GetFailureRate()
156 {
157   float tmp = 0;
158   cout << "Number of Complete channles = " << fComplete <<endl;
159   cout << "Number of InComplete channles = " << fInComplete <<endl;
160   tmp = (100*(float)fInComplete)/((float)fComplete + (float)fInComplete);
161
162   cout <<"There are "<<  tmp <<"% incomplete channels"<<endl;
163
164   return  tmp;
165 }
166
167 int
168 AliHLTDDLDecoder::GetMarker(UInt_t *buffer, int index)
169 {
170   int tmpMarker = 0;
171   int tmpMask = 0x3c0;
172   tmpMarker = (buffer[index] << 4 ) | ((buffer[index-1] & tmpMask) >> 6);  
173   return tmpMarker;
174 }
175
176 void
177 AliHLTDDLDecoder::PrintInfo(AliHLTAltroData &altrodata, int n, int nPerLine)
178 {
179   cout << "altrodata.fDataSize = " << altrodata.fDataSize <<  endl;
180   cout << "altrodata.fHadd = "     << altrodata.fHadd  <<endl;
181   for(int i= 0; i< n; i++)
182     {
183       if( (i%nPerLine == 0) && (i != 0) )
184         {
185           printf("\n");
186         }
187       printf("%d\t", altrodata.fData[i]);
188     }
189   printf("\n");
190 }
191
192 void                     
193 AliHLTDDLDecoder::SetMemory(UChar_t *dtaPtr, UInt_t size)
194 {
195   f8DtaPtr =dtaPtr;
196   fSize = size;
197   f32PayloadSize = fSize/4 -  (fN32HeaderWords + fN32RcuTrailerWords);
198   fN40AltroWords = (32*f32PayloadSize)/40; 
199   f32LastDDLBlockSize =  f32PayloadSize%DDL_32BLOCK_SIZE;
200   fNDDLBlocks =  f32PayloadSize/5;
201   f8DtaPtr =f8DtaPtr + fSize;
202   f32DtaPtr = (UInt_t *) f8DtaPtr;
203   f32DtaPtr =  f32DtaPtr - fN32RcuTrailerWords;
204   fN40RcuAltroWords =  *f32DtaPtr;
205   f32DtaPtr = (UInt_t *)dtaPtr + fN32HeaderWords;
206   fBufferPos =  fN40AltroWords*4  -  1;
207 }
208
209 void
210 AliHLTDDLDecoder::DecodeDDLBlock()
211 {
212   fBuffer[fBufferIndex] =  *f32DtaPtr & 0x3ff;  //s0 
213   fBufferIndex ++;
214   fBuffer[fBufferIndex] = (*f32DtaPtr & 0xffc00) >> 10; //s1
215   fBufferIndex ++; 
216   fBuffer[fBufferIndex] = (*f32DtaPtr & 0x3ff00000) >> 20; //s2
217   fBufferIndex ++; 
218   fBuffer[fBufferIndex] = (*f32DtaPtr & 0xc0000000) >> 30; //s3_1 
219   f32DtaPtr ++;
220   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0xff) << 2); //s3_2 
221   fBufferIndex ++;
222   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff00) >> 8; //s4
223   fBufferIndex ++;
224   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc0000) >> 18; //s5
225   fBufferIndex ++;
226   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xf0000000) >> 28; //s6_1
227   f32DtaPtr ++;
228   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0x3f) << 4); //s6_2 
229   fBufferIndex ++;
230   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc0) >> 6; //s7
231   fBufferIndex ++;
232   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff0000) >> 16; //s8
233   fBufferIndex ++;
234   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xFC000000) >> 26; //s9_1
235   f32DtaPtr ++;
236   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0xf) << 6); //s9_2
237   fBufferIndex ++;
238   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff0) >> 4; //s10
239   fBufferIndex ++;
240   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc000) >> 14; //s11
241   fBufferIndex ++;
242   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xff000000) >> 24; //s12_1
243   f32DtaPtr ++;
244   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0x3) << 8); //s12_2
245   fBufferIndex ++;
246   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc) >> 2; //s13
247   fBufferIndex ++;
248   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff000) >> 12; //s14
249   fBufferIndex ++;
250   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc00000) >> 22; //s15
251   fN10bitWords =fN10bitWords + 16 ;
252   f32DtaPtr ++;
253   fBufferIndex ++;
254   fDDLBlockCnt ++;  
255 }
256
257 void
258 AliHLTDDLDecoder::DecodeLastDDLBlock()
259 {
260   for(unsigned fI=0; fI < f32LastDDLBlockSize; fI++)
261     {
262       fDDLBlockDummy[fI] = *f32DtaPtr;
263       f32DtaPtr ++;
264     }
265   
266   f32DtaPtr = fDDLBlockDummy; 
267   f32DtaPtr ++;
268   DecodeDDLBlock();
269 }
270
271 void 
272 AliHLTDDLDecoder::SetNTrailerWords(int n)
273 {
274   fN32RcuTrailerWords = n;
275 }
276
277