]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSDD.cxx
Adding comments (Laurent)
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSDD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$*/
17
18 ///////////////////////////////////////////////////////////////////////////////
19 ///
20 /// This class provides access to ITS SDD digits in raw data.
21 ///
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliITSRawStreamSDD.h"
25 #include "AliRawReader.h"
26 #include "AliLog.h"
27
28 ClassImp(AliITSRawStreamSDD)
29
30 const Int_t AliITSRawStreamSDD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
31  
32   {240,241,242,246,247,248,252,253,254,258,259,260},
33   {264,265,266,270,271,272,276,277,278,282,283,284},
34   {288,289,290,294,295,296,300,301,302,306,307,308},
35   {312,313,314,318,319,320,-1,-1,-1,-1,-1,-1},
36   {243,244,245,249,250,251,255,256,257,261,262,263},
37   {267,268,269,273,274,275,279,280,281,285,286,287},
38   {291,292,293,297,298,299,303,304,305,309,310,311},
39   {315,316,317,321,322,323,-1,-1,-1,-1,-1,-1},
40   {324,325,326,327,332,333,334,335,340,341,342,343},
41   {348,349,350,351,356,357,358,359,364,365,366,367},
42   {372,373,374,375,380,381,382,383,388,389,390,391},
43   {396,397,398,399,404,405,406,407,412,413,414,415},
44   {420,421,422,423,428,429,430,431,436,437,438,439},
45   {444,445,446,447,452,453,454,455,460,461,462,463},
46   {468,469,470,471,476,477,478,479,484,485,486,487},
47   {492,493,494,495,-1,-1,-1,-1,-1,-1,-1,-1},
48   {328,329,330,331,336,337,338,339,344,345,346,347},
49   {352,353,354,355,360,361,362,363,368,369,370,371},
50   {376,377,378,379,384,385,386,387,392,393,394,395},
51   {400,401,402,403,408,409,410,411,416,417,418,419},
52   {424,425,426,427,432,433,434,435,440,441,442,443},
53   {448,449,450,451,456,457,458,459,464,465,466,467},
54   {472,473,474,475,480,481,482,483,488,489,490,491},
55   {496,497,498,499,-1,-1,-1,-1,-1,-1,-1,-1}};
56   
57 const UInt_t AliITSRawStreamSDD::fgkCodeLength[8] =  {8, 18, 2, 3, 4, 5, 6, 7};
58
59 AliITSRawStreamSDD::AliITSRawStreamSDD(AliRawReader* rawReader) :
60   AliITSRawStream(rawReader),
61 fData(0),
62 fCarlosId(0),
63 fEventId(0),
64 fChannel(0),
65 fJitter(0),
66 fNCarlos(kModulesPerDDL),
67 fNfifo0(0),
68 fNfifo1(0),
69 fNfifo2(0),
70 fNfifo3(0),
71 fDDL(0){
72 // create an object to read ITS SDD raw digits
73   
74   for(Int_t i=0;i<2;i++){
75     for(Int_t ic=0;ic<kModulesPerDDL;ic++){
76       fChannelData[ic][i]=0;
77       fLastBit[ic][i]=0;
78       fChannelCode[ic][i]=0;
79       fReadCode[ic][i]=kFALSE;
80       fReadBits[ic][i]=0;
81       fTimeBin[ic][i]=0;
82       fAnode[ic][i]=0;     
83     }
84     fLowThreshold[i]=0;
85   }
86   for(Int_t i=0;i<kDDLsNumber;i++) fSkip[i]=0;
87   fRawReader->Reset();
88   fRawReader->Select("ITSSDD");
89
90   //  fRawReader->SelectEquipment(17, 101, 101);//select this for test data
91   //  fNCarlos = 8; //select this for test data
92 }
93
94 UInt_t AliITSRawStreamSDD::ReadBits()
95 {
96 // read bits from the given channel
97   UInt_t result = (fChannelData[fCarlosId][fChannel] & ((1<<fReadBits[fCarlosId][fChannel]) - 1));
98   fChannelData[fCarlosId][fChannel] >>= fReadBits[fCarlosId][fChannel]; 
99   fLastBit[fCarlosId][fChannel] -= fReadBits[fCarlosId][fChannel];
100   return result;
101 }
102
103 Int_t AliITSRawStreamSDD::DecompAmbra(Int_t value) const
104 {
105   // AMBRA decompression (from 8 to 10 bit)
106   
107   if ((value & 0x80) == 0) {
108     return value & 0x7f;
109   } else if ((value & 0x40) == 0) {
110     return 0x081 + ((value & 0x3f) << 1);
111   } else if ((value & 0x20) == 0) {
112     return 0x104 + ((value & 0x1f) << 3);
113   } else {
114     return 0x208 + ((value & 0x1f) << 4);
115   }
116   
117 }
118
119 Bool_t AliITSRawStreamSDD::Next()
120 {
121 // read the next raw digit
122 // returns kFALSE if there is no digit left
123
124   fPrevModuleID = fModuleID;
125   fDDL=fRawReader->GetDDLID();
126   Int_t ddln = fRawReader->GetDDLID();
127   if(ddln <0) ddln=0;
128   while (fSkip[ddln] < 9) {
129     if (!fRawReader->ReadNextInt(fData))return kFALSE;
130     if ((fData >> 30) == 0x01) continue;  // JTAG word
131     fSkip[ddln]++;
132   }
133   
134
135   Int_t countFoot[kModulesPerDDL];
136   for(Int_t i=0;i<kModulesPerDDL;i++) countFoot[i]=0;
137   UInt_t iCarlos0Word=805306368;
138   UInt_t iCarlos1Word=805306369;
139   UInt_t iCarlos2Word=805306370;
140   UInt_t iCarlos3Word=805306371;
141   UInt_t iCarlos4Word=805306372;
142   UInt_t iCarlos5Word=805306373;
143   UInt_t iCarlos6Word=805306374;
144   UInt_t iCarlos7Word=805306375;
145   UInt_t iCarlos8Word=805306376;
146   UInt_t iCarlos9Word=805306377;
147   UInt_t iCarlos10Word=805306378;
148   UInt_t iCarlos11Word=805306379;
149   UInt_t iFifo0Word=805306384;
150   UInt_t iFifo1Word=805306385;
151   UInt_t iFifo2Word=805306386;
152   UInt_t iFifo3Word=805306387;
153   while (kTRUE) {
154     if ((fChannel < 0) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel])) {
155
156       if (!fRawReader->ReadNextInt(fData)){ 
157         return kFALSE;  // read next word 
158       }
159       ddln = fRawReader->GetDDLID();
160       if(ddln!=fDDL){
161         Reset();
162         for(Int_t icr=0;icr<kModulesPerDDL;icr++) countFoot[icr]=0;
163       }
164       if(ddln < 0 || ddln > (kDDLsNumber-1)) ddln  = 0;
165       while (fSkip[ddln] < 9) {
166         if (!fRawReader->ReadNextInt(fData)){ 
167           return kFALSE;
168         }
169         if ((fData >> 30) == 0x01) continue;  // JTAG word
170         fSkip[ddln]++;
171       }
172
173       fChannel = -1;
174       if((fData>=iCarlos0Word&&fData<=iCarlos11Word)||(fData>=iFifo0Word&&fData<=iFifo3Word)){
175         if(fData==iCarlos0Word){
176           fCarlosId = 0;
177           fNfifo0 = fCarlosId;
178         }
179         else if (fData==iCarlos1Word){
180           fCarlosId = 1;
181           fNfifo0 = fCarlosId;
182         }
183         else if (fData==iCarlos2Word){
184           fCarlosId = 2;
185           if(fNCarlos == 8) fNfifo1 = fCarlosId;
186           else fNfifo0 = fCarlosId;
187         }
188         else if (fData==iCarlos3Word){
189           fCarlosId = 3;
190           fNfifo1 = fCarlosId;
191         }
192         else if (fData==iCarlos4Word){
193           fCarlosId = 4;
194           if(fNCarlos == 8) fNfifo2 = fCarlosId;
195           else fNfifo1 = fCarlosId;
196         }
197         else if (fData==iCarlos5Word){
198           fCarlosId = 5;
199           if(fNCarlos == 8) fNfifo2 = fCarlosId;
200           else fNfifo1 = fCarlosId;
201         }
202         else if (fData==iCarlos6Word){
203           fCarlosId = 6;
204           if(fNCarlos == 8) fNfifo3 = fCarlosId;
205           else fNfifo2 = fCarlosId;
206         }
207         else if (fData==iCarlos7Word){
208           fCarlosId = 7;
209           if(fNCarlos == 8) fNfifo3 = fCarlosId;
210           else fNfifo2 = fCarlosId;
211         }
212         else if (fData==iCarlos8Word){
213           fCarlosId = 8;
214           fNfifo2 = fCarlosId;
215         }
216         else if (fData==iCarlos9Word){
217           fCarlosId = 9;
218           fNfifo3 = fCarlosId;
219         }
220         else if (fData==iCarlos10Word){
221           fCarlosId = 10;
222           fNfifo3 = fCarlosId;
223         }
224         else if (fData==iCarlos11Word){
225           fCarlosId = 11;
226           fNfifo3 = fCarlosId;
227         }
228         else if (fData==iFifo0Word){
229           fCarlosId = fNfifo0;
230         }
231         else if (fData==iFifo1Word){
232           fCarlosId = fNfifo1;
233         }
234         else if (fData==iFifo2Word){
235           fCarlosId = fNfifo2;
236         }
237         else if (fData==iFifo3Word){
238           fCarlosId = fNfifo3;
239         }
240       }
241       if(fData==1059004191) continue;
242       if (fNCarlos == 8 && (fCarlosId == 8 || fCarlosId == 9 || 
243                             fCarlosId ==10 || fCarlosId == 11))continue;
244       
245       fModuleID = fgkDDLModuleMap[fRawReader->GetDDLID()][fCarlosId];
246       
247       if ((fData >> 28) == 0x02) {           // header
248         fEventId = (fData >> 3) & 0x07FF;
249       } else if ((fData >> 28) == 0x03) {    // footer
250         countFoot[fCarlosId]++; // stop before the last word (last word=jitter)
251         Bool_t exit=kTRUE;
252         for(Int_t ic=0;ic<fNCarlos;ic++){
253           if(countFoot[ic]<3) exit=kFALSE;
254         }
255         if(exit){
256           return kFALSE;
257         }        
258       } else if ((fData >> 29) == 0x00) {    // error
259
260         if ((fData & 0x00000163) != 0) {         
261           fRawReader->AddMajorErrorLog(kDataError,Form("Error code = %8.8x",fData));     
262           AliWarning(Form("error codes = %8.8x",fData));
263           return kFALSE;          
264         }
265       } else if ((fData >> 30) == 0x01) {    // JTAG word
266         // ignored
267       } else if ((fData >> 30) == 0x02) {    // channel 0 data
268         
269         fChannel = 0;
270       } else if ((fData >> 30) == 0x03) {    // channel 1 data
271         fChannel = 1;
272       } else {                               // unknown data format
273         fRawReader->AddMajorErrorLog(kDataFormatErr,Form("Invalid data %8.8x",fData));
274         AliWarning(Form("invalid data: %8.8x\n", fData));
275         return kFALSE;
276       }
277       
278       if (fChannel >= 0) {   // add read word to the data
279         fChannelData[fCarlosId][fChannel] += 
280           (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
281         fLastBit[fCarlosId][fChannel] += 30;
282       }
283
284     } else {  // decode data
285
286       if (fReadCode[fCarlosId][fChannel]) {// read the next code word
287         fChannelCode[fCarlosId][fChannel] = ReadBits();
288         fReadCode[fCarlosId][fChannel] = kFALSE;
289         fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
290
291       } else {                      // read the next data word
292         UInt_t data = ReadBits();
293         fReadCode[fCarlosId][fChannel] = kTRUE;
294         fReadBits[fCarlosId][fChannel] = 3;
295         if (fChannelCode[fCarlosId][fChannel] == 0) {         // set the time bin         
296           fTimeBin[fCarlosId][fChannel] = data;
297         } else if (fChannelCode[fCarlosId][fChannel] == 1) {  // next anode
298           fTimeBin[fCarlosId][fChannel] = 0;
299           fAnode[fCarlosId][fChannel]++;
300
301         }else {                                   // ADC signal data
302           fSignal = DecompAmbra(data + (1 << fChannelCode[fCarlosId][fChannel]) + fLowThreshold[fChannel]);
303           fCoord1 = fAnode[fCarlosId][fChannel];
304           fCoord2 = fTimeBin[fCarlosId][fChannel];
305           fTimeBin[fCarlosId][fChannel]++;
306           return kTRUE;
307         }
308       }
309     }
310   }
311   return kFALSE;  
312
313 }
314
315 void AliITSRawStreamSDD::Reset(){
316   //reset data member for a new ddl
317   
318   for(Int_t i=0;i<2;i++){
319     for(Int_t ic=0;ic<kModulesPerDDL;ic++){
320       fChannelData[ic][i]=0;
321       fLastBit[ic][i]=0;
322       fChannelCode[ic][i]=0;
323       fReadCode[ic][i]=kFALSE;
324       fReadBits[ic][i]=0;
325       fTimeBin[ic][i]=0;
326       fAnode[ic][i]=0;     
327     }
328     fLowThreshold[i]=0;
329   }
330   fChannel=-1;
331   fDDL=fRawReader->GetDDLID();
332 }