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