]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSDD.cxx
Fix bug affecting the data decoding in the DAs (F. Prino)
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSDD.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 UInt_t AliITSRawStreamSDD::fgkCodeLength[8] =  {8, 18, 2, 3, 4, 5, 6, 7};
31
32 //______________________________________________________________________
33 AliITSRawStreamSDD::AliITSRawStreamSDD(AliRawReader* rawReader) :
34   AliITSRawStream(rawReader),
35 fDDLModuleMap(0),
36 fData(0),
37 fEventId(0),
38 fCarlosId(-1),
39 fChannel(0),
40 fJitter(0),
41 fEightBitSignal(0),
42 fDecompressAmbra(kTRUE)
43 {
44 // create an object to read ITS SDD raw digits
45   Reset();
46   for(Int_t im=0;im<kSDDModules;im++){
47     fLowThresholdArray[im][0]=0;
48     fLowThresholdArray[im][1]=0;
49   }
50   for(Int_t i=0;i<kFifoWords;i++) fNfifo[i]=0;
51   for(Int_t i=0;i<kDDLsNumber;i++) fSkip[i]=0;
52   fRawReader->Reset();
53   fRawReader->Select("ITSSDD");
54
55   for(Short_t i=0; i<kCarlosWords; i++) fICarlosWord[i]=0x30000000 + i; // 805306368+i;
56   for(Short_t i=0; i<kFifoWords; i++) fIFifoWord[i]=0x30000010 + i;  // 805306384+i;
57 }
58
59 //______________________________________________________________________
60 AliITSRawStreamSDD::AliITSRawStreamSDD(const AliITSRawStreamSDD& rs) :
61 AliITSRawStream(rs.fRawReader),
62 fDDLModuleMap(rs.fDDLModuleMap),
63 fData(0),
64 fEventId(0),
65 fCarlosId(-1),
66 fChannel(0),
67 fJitter(0),
68 fEightBitSignal(0),
69 fDecompressAmbra(kTRUE)
70 {
71   // copy constructor
72   AliError("Copy constructor should not be used.");
73 }
74 //__________________________________________________________________________
75 AliITSRawStreamSDD& AliITSRawStreamSDD::operator=(const AliITSRawStreamSDD& rs) {
76   // assignment operator
77   if (this!=&rs) {}
78   AliError("Assignment opertator should not be used.");
79   return *this;
80 }
81
82 //______________________________________________________________________
83 AliITSRawStreamSDD::~AliITSRawStreamSDD(){
84   if(fDDLModuleMap) delete fDDLModuleMap;
85 }
86 //______________________________________________________________________
87 UInt_t AliITSRawStreamSDD::ReadBits()
88 {
89 // read bits from the given channel
90   UInt_t result = (fChannelData[fCarlosId][fChannel] & ((1<<fReadBits[fCarlosId][fChannel]) - 1));
91   fChannelData[fCarlosId][fChannel] >>= fReadBits[fCarlosId][fChannel]; 
92   fLastBit[fCarlosId][fChannel] -= fReadBits[fCarlosId][fChannel];
93   return result;
94 }
95
96 //______________________________________________________________________
97 Int_t AliITSRawStreamSDD::DecompAmbra(Int_t value) const
98 {
99   // AMBRA decompression (from 8 to 10 bit)
100   
101   if ((value & 0x80) == 0) {
102     return value & 0x7f;
103   } else if ((value & 0x40) == 0) {
104     return 0x081 + ((value & 0x3f) << 1);
105   } else if ((value & 0x20) == 0) {
106     return 0x104 + ((value & 0x1f) << 3);
107   } else {
108     return 0x208 + ((value & 0x1f) << 4);
109   }
110   
111 }
112
113 //______________________________________________________________________
114 Bool_t AliITSRawStreamSDD::Next()
115 {
116 // read the next raw digit
117 // returns kFALSE if there is no digit left
118 // returns kTRUE and fCompletedModule=kFALSE when a digit is found
119 // returns kTRUE and fCompletedModule=kTRUE  when a module is completed (=3x3FFFFFFF footer words)
120
121   fPrevModuleID = fModuleID;
122   fCompletedModule=kFALSE;
123
124   while (kTRUE) {
125   
126     if ((fChannel < 0) || (fCarlosId < 0) || (fChannel >= 2) || (fCarlosId >= kModulesPerDDL) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel]) ) {
127       if (!fRawReader->ReadNextInt(fData)) return kFALSE;  // read next word
128
129
130       if((fData >> 16) == 0x7F00){ // jitter word
131         Reset();
132         Bool_t kSkip = SkipHeaderWord();
133         if(!kSkip) return kSkip;        
134         continue;
135       }
136
137       UInt_t nData28= fData >> 28;
138       UInt_t nData30= fData >> 30;
139
140
141       if (nData28== 0x02) {           // header
142         fEventId = (fData >> 3) & 0x07FF; 
143       } else if (nData28== 0x03) {    // Carlos and FIFO words or Footers
144         if(fData>=fICarlosWord[0]&&fData<=fICarlosWord[11]) { // Carlos Word
145           fCarlosId = fData-fICarlosWord[0];
146           Int_t iFifoIdx = fCarlosId/3;
147           fNfifo[iFifoIdx] = fCarlosId;
148         } else if (fData>=fIFifoWord[0]&&fData<=fIFifoWord[3]){ // FIFO word
149           fCarlosId = fNfifo[fData-fIFifoWord[0]];          
150         } else if(fData==0x3FFFFFFF){ // Carlos footer
151           fICountFoot[fCarlosId]++; // stop before the last word (last word=jitter)
152           if(fICountFoot[fCarlosId]==3){
153             fCompletedModule=kTRUE;
154             return kTRUE;
155           }
156         } else if(fData==0x3F1F1F1F){ // CarlosRX footer
157           // CARLOSRX footer -- do nothing
158         }else{
159           fRawReader->AddMajorErrorLog(kDataError,"Bad footer");
160           AliWarning(Form("Invalid data: bad footer %08X\n", fData));
161           return kFALSE;            
162         }
163       } else if (nData30 == 0x02 || nData30 == 0x03) {
164         fChannel = nData30-2;
165         fChannelData[fCarlosId][fChannel] += 
166           (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
167         fLastBit[fCarlosId][fChannel] += 30;
168       } else if (nData28== 0x04) {
169         // JTAG word -- do nothing
170       } else {                               // unknown data format
171         fRawReader->AddMajorErrorLog(kDataFormatErr,Form("Invalid data %8.8x",fData));
172         AliWarning(Form("Invalid data: %08X\n", fData));
173         return kFALSE;
174       }
175       
176       if(fCarlosId>=0 && fCarlosId <kModulesPerDDL){
177         Int_t nDDL=fRawReader->GetDDLID();
178         fModuleID = GetModuleNumber(nDDL,fCarlosId);
179       }
180     } else {  // decode data
181       if (fReadCode[fCarlosId][fChannel]) {// read the next code word
182         fChannelCode[fCarlosId][fChannel] = ReadBits();
183         fReadCode[fCarlosId][fChannel] = kFALSE;
184         fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
185       } else {                      // read the next data word
186         UInt_t data = ReadBits();
187         fReadCode[fCarlosId][fChannel] = kTRUE;
188         fReadBits[fCarlosId][fChannel] = 3;
189         if (fChannelCode[fCarlosId][fChannel] == 0) {         // set the time bin         
190           fTimeBin[fCarlosId][fChannel] = data;
191         } else if (fChannelCode[fCarlosId][fChannel] == 1) {  // next anode
192           fTimeBin[fCarlosId][fChannel] = 0;
193           fAnode[fCarlosId][fChannel]++;
194         } else {                                   // ADC signal data
195           fEightBitSignal=data + (1 << fChannelCode[fCarlosId][fChannel]);
196           if(fDecompressAmbra) fSignal = DecompAmbra(fEightBitSignal + fLowThresholdArray[fModuleID-kSPDModules][fChannel]);
197           fCoord1 = fAnode[fCarlosId][fChannel];
198           fCoord2 = fTimeBin[fCarlosId][fChannel];
199           fTimeBin[fCarlosId][fChannel]++;
200           return kTRUE;
201         }
202       }
203     }
204   }
205   return kFALSE;
206 }
207
208 //______________________________________________________________________
209 void AliITSRawStreamSDD::Reset(){
210
211   //reset data member for a new ddl
212   for(Int_t i=0;i<2;i++){
213     for(Int_t ic=0;ic<kModulesPerDDL;ic++){
214       fChannelData[ic][i]=0;
215       fLastBit[ic][i]=0;
216       fChannelCode[ic][i]=0;
217       fReadCode[ic][i]=kTRUE;
218       fReadBits[ic][i]=3;
219       fTimeBin[ic][i]=0;
220       fAnode[ic][i]=0;     
221       fICountFoot[ic]=0;
222     }
223   }
224 }
225
226 //______________________________________________________________________
227 Bool_t AliITSRawStreamSDD::SkipHeaderWord(){
228   // skip the 1 DDL header word = 0xffffffff
229   while (kTRUE) {
230     if (!fRawReader->ReadNextInt(fData)) return kFALSE;    
231     if ((fData >> 30) == 0x01) continue;  // JTAG word
232     if(fData==0xFFFFFFFF) return kTRUE;
233   }
234 }
235