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