]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTDDLDecoder.cxx
Refactoring of classes + cleanup + documentaion.
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTDDLDecoder.cxx
1 #include  "AliHLTDDLDecoder.h"
2 #include  "AliHLTAltroData.h"
3
4 /**************************************************************************
5  * This file is property of and copyright by the Experimental Nuclear     *
6  * Physics Group, Dep. of Physics                                         *
7  * University of Oslo, Norway, 2007                                       *
8  *                                                                        * 
9  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
10  * Contributors are mentioned in the code where appropriate.              *
11  * Please report bugs to perthi@fys.uio.no                                * 
12  *                                                                        *
13  * Permission to use, copy, modify and distribute this software and its   *
14  * documentation strictly for non-commercial purposes is hereby granted   *
15  * without fee, provided that the above copyright notice appears in all   *
16  * copies and that both the copyright notice and this permission notice   *
17  * appear in the supporting documentation. The authors make no claims     *
18  * about the suitability of this software for any purpose. It is          *
19  * provided "as is" without express or implied warranty.                  *
20  **************************************************************************/
21
22 AliHLTDDLDecoder::AliHLTDDLDecoder() : f32DtaPtr(0), f8DtaPtr(0),fN32HeaderWords(8), fN32RcuTrailerWords(1), fNDDLBlocks(0), 
23                                        fBufferPos(0), fN40AltroWords(0), fN40RcuAltroWords(0), fSize(0), fSegmentation(0), 
24                                        f32LastDDLBlockSize(5), f32PayloadSize(0),fBufferIndex(0), fN10bitWords(0)
25 {
26
27 }
28
29 AliHLTDDLDecoder::~AliHLTDDLDecoder()
30 {
31
32 }
33
34 bool
35 AliHLTDDLDecoder::CheckPayload()
36 {
37   if(fN40AltroWords != fN40RcuAltroWords)
38     {
39       return  false;
40     } 
41   else
42     {
43
44       return true;
45
46     }
47
48 }
49
50 bool
51 AliHLTDDLDecoder::Decode()
52 {
53    fComplete = 0;
54    fInComplete = 0;
55
56   if((CheckPayload() == true)  &&  (fSize > 32) )
57     {
58       fDDLBlockCnt = 0;
59       fBufferIndex = 0;
60       fN10bitWords = 0;
61       
62       for(fI=0; fI < fNDDLBlocks; fI++)
63         {
64           DecodeDDLBlock();
65         }
66
67       DecodeLastDDLBlock(); 
68       return true;
69     }
70
71   else
72     {
73
74       cout <<"ERROR: data integrity check failed, discarding data" << endl;
75       cout << "Size of datablock is  " << fSize   << endl;
76       cout << "fN40AltroWords = "      << fN40AltroWords   << endl;
77       cout << "fN40RcuAltroWords = "   << fN40RcuAltroWords  << endl;
78       return false;
79     }
80 }
81
82 bool
83 AliHLTDDLDecoder::NextChannel(AliHLTAltroData *altroDataPtr)
84 {
85
86   if(fBufferPos >  fN32HeaderWords)
87     {
88       if((fBuffer[fBufferPos] << 4 ) | ((fBuffer[fBufferPos-1] & 0x3c0) >> 6) == 0x2aaa)
89         {
90           altroDataPtr->fIsComplete = true;
91           fComplete ++;
92         }
93       else
94         {
95           altroDataPtr->fIsComplete = false;
96           fInComplete ++;
97         }
98
99       fBufferPos --;
100       fNAltro10bitWords = ( (fBuffer[fBufferPos] & 0x3f) << 4 )   |  ((fBuffer[fBufferPos -1]  & (0xF << 6)) >> 6) ;
101       fBufferPos --;
102       fHadd =  ((fBuffer[fBufferPos] & 0x3)) << 10 | ( fBuffer[fBufferPos-1] );   
103       fBufferPos --;
104
105       if(fNAltro10bitWords%4 == 0)
106         {
107           fBufferPos = fBufferPos  -  fNAltro10bitWords;
108         }
109       else
110         {
111           fBufferPos = fBufferPos - fNAltro10bitWords -(4 - fNAltro10bitWords%4);
112         }
113
114       altroDataPtr->fData  = &fBuffer[fBufferPos];
115       fBufferPos --;
116       altroDataPtr->fDataSize =  fNAltro10bitWords ;
117       altroDataPtr->fHadd = fHadd; 
118
119       
120       return true;
121     }
122   else
123     {
124       return false;
125     }
126 }
127
128
129 float
130 AliHLTDDLDecoder::GetFailureRate()
131 {
132   float tmp = 0;
133   cout << "Number of Complete channles = " << fComplete <<endl;
134   cout << "Number of InComplete channles = " << fInComplete <<endl;
135   tmp = (100*(float)fInComplete)/((float)fComplete + (float)fInComplete);
136   cout <<"There are "<<  tmp <<"% incomplete channels"<<endl;
137   return  tmp;
138 }
139
140
141 int
142 AliHLTDDLDecoder::GetMarker(UInt_t *buffer, int index)
143 {
144   int tmpMarker = 0;
145   int tmpMask = 0x3c0;
146   tmpMarker = (buffer[index] << 4 ) | ((buffer[index-1] & tmpMask) >> 6);  
147   return tmpMarker;
148 }
149
150 void
151 AliHLTDDLDecoder::PrintInfo(AliHLTAltroData &altrodata, int n, int nPerLine)
152 {
153   cout << "altrodata.fDataSize = " << altrodata.fDataSize <<  endl;
154   cout << "altrodata.fHadd = "     << altrodata.fHadd  <<endl;
155   for(int i= 0; i< n; i++)
156     {
157       if( (i%nPerLine == 0) && (i != 0) )
158         {
159           printf("\n");
160         }
161       printf("%d\t", altrodata.fData[i]);
162     }
163   printf("\n");
164 }
165
166
167 void                     
168 AliHLTDDLDecoder::SetMemory(UChar_t *dtaPtr, UInt_t size)
169 {
170   f8DtaPtr =dtaPtr;
171   fSize = size;
172   f32PayloadSize = fSize/4 -  (fN32HeaderWords + fN32RcuTrailerWords);
173   fN40AltroWords = (32*f32PayloadSize)/40; 
174   f32LastDDLBlockSize =  f32PayloadSize%DDL_32BLOCK_SIZE;
175   fNDDLBlocks =  f32PayloadSize/5;
176   f8DtaPtr =f8DtaPtr + fSize;
177   f32DtaPtr = (UInt_t *) f8DtaPtr;
178   f32DtaPtr =  f32DtaPtr - fN32RcuTrailerWords;
179   fN40RcuAltroWords =  *f32DtaPtr;
180   f32DtaPtr = (UInt_t *)dtaPtr + fN32HeaderWords;
181   fBufferPos =  fN40AltroWords*4  -  1;
182 }
183
184 void
185 AliHLTDDLDecoder::DecodeDDLBlock()
186 {
187   fBuffer[fBufferIndex] =  *f32DtaPtr & 0x3ff;  //s0 
188   fBufferIndex ++;
189   fBuffer[fBufferIndex] = (*f32DtaPtr & 0xffc00) >> 10; //s1
190   fBufferIndex ++; 
191   fBuffer[fBufferIndex] = (*f32DtaPtr & 0x3ff00000) >> 20; //s2
192   fBufferIndex ++; 
193   fBuffer[fBufferIndex] = (*f32DtaPtr & 0xc0000000) >> 30; //s3_1 
194   f32DtaPtr ++;
195   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0xff) << 2); //s3_2 
196   fBufferIndex ++;
197   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff00) >> 8; //s4
198   fBufferIndex ++;
199   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc0000) >> 18; //s5
200   fBufferIndex ++;
201   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xf0000000) >> 28; //s6_1
202   f32DtaPtr ++;
203   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0x3f) << 4); //s6_2 
204   fBufferIndex ++;
205   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc0) >> 6; //s7
206   fBufferIndex ++;
207   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff0000) >> 16; //s8
208   fBufferIndex ++;
209   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xFC000000) >> 26; //s9_1
210   f32DtaPtr ++;
211   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0xf) << 6); //s9_2
212   fBufferIndex ++;
213   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff0) >> 4; //s10
214   fBufferIndex ++;
215   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc000) >> 14; //s11
216   fBufferIndex ++;
217   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xff000000) >> 24; //s12_1
218   f32DtaPtr ++;
219   fBuffer[fBufferIndex] =  fBuffer[fBufferIndex] | ((*f32DtaPtr & 0x3) << 8); //s12_2
220   fBufferIndex ++;
221   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc) >> 2; //s13
222   fBufferIndex ++;
223   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0x3ff000) >> 12; //s14
224   fBufferIndex ++;
225   fBuffer[fBufferIndex] =  (*f32DtaPtr & 0xffc00000) >> 22; //s15
226   fN10bitWords =fN10bitWords + 16 ;
227   f32DtaPtr ++;
228   fBufferIndex ++;
229   fDDLBlockCnt ++;  
230 }
231
232 void
233 AliHLTDDLDecoder::DecodeLastDDLBlock()
234 {
235   for(unsigned fI=0; fI < f32LastDDLBlockSize; fI++)
236     {
237       fDDLBlockDummy[fI] = *f32DtaPtr;
238       f32DtaPtr ++;
239     }
240   
241   f32DtaPtr = fDDLBlockDummy; 
242   f32DtaPtr ++;
243   DecodeDDLBlock();
244 }
245
246 void 
247 AliHLTDDLDecoder::SetNTrailerWords(int n)
248 {
249   fN32RcuTrailerWords = n;
250 }
251
252