]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSDD.cxx
Restore backward compatibility for SDD map objects - Savannah bug 49895 (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 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     return 0x081 + ((value & 0x3f) << 1);
106   } else if ((value & 0x20) == 0) {
107     return 0x104 + ((value & 0x1f) << 3);
108   } else {
109     return 0x208 + ((value & 0x1f) << 4);
110   }
111   
112 }
113
114 //______________________________________________________________________
115 Bool_t AliITSRawStreamSDD::Next()
116 {
117 // read the next raw digit
118 // returns kFALSE if there is no digit left
119 // returns kTRUE and fCompletedModule=kFALSE and fCompletedDDL=kFALSE when a digit is found
120 // returns kTRUE and fCompletedModule=kTRUE  and fCompletedDDL=kFALSE when a module is completed (=3x3FFFFFFF footer words)
121 // returns kTRUE and fCompletedModule=kFALSE and fCompletedDDL=kTRUE  when a DDL is completed (=jitter word)
122
123   fPrevModuleID = fModuleID;
124   fCompletedModule=kFALSE;
125
126   while (kTRUE) {
127     if(fResetSkip){
128       Reset();
129       Bool_t kSkip = SkipHeaderWord();
130       if(!kSkip) return kSkip;  
131       fResetSkip=kFALSE;
132     }
133     if ((fChannel < 0) || (fCarlosId < 0) || (fChannel >= 2) || (fCarlosId >= kModulesPerDDL) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel]) ) {
134       if (!fRawReader->ReadNextInt(fData)) return kFALSE;  // read next word
135
136
137       if((fData >> 16) == 0x7F00){ // jitter word
138         fJitter = fData&0x000000ff;
139         fResetSkip=kTRUE;
140         fCompletedModule=kFALSE;
141         fCompletedDDL=kTRUE;
142         return kTRUE;
143        }
144
145       UInt_t nData28= fData >> 28;
146       UInt_t nData30= fData >> 30;
147
148
149       if (nData28== 0x02) {           // header
150         fEventId = (fData >> 3) & 0x07FF; 
151       } else if (nData28== 0x03) {    // Carlos and FIFO words or Footers
152         if(fData>=fICarlosWord[0]&&fData<=fICarlosWord[11]) { // Carlos Word
153           fCarlosId = fData-fICarlosWord[0];
154           Int_t iFifoIdx = fCarlosId/3;
155           fNfifo[iFifoIdx] = fCarlosId;
156         } else if (fData>=fIFifoWord[0]&&fData<=fIFifoWord[3]){ // FIFO word
157           fCarlosId = fNfifo[fData-fIFifoWord[0]];          
158         } else if(fData==0x3FFFFFFF){ // Carlos footer
159           fICountFoot[fCarlosId]++; // stop before the last word (last word=jitter)
160           if(fICountFoot[fCarlosId]==3){
161             fCompletedModule=kTRUE;
162             fCompletedDDL=kFALSE;
163             return kTRUE;
164           }
165         } else if(fData==0x3F1F1F1F){ // CarlosRX footer
166           // CARLOSRX footer -- do nothing
167         }else{
168           fRawReader->AddMajorErrorLog(kDataError,"Bad footer");
169           AliWarning(Form("Invalid data: bad footer %08X\n", fData));
170           return kFALSE;            
171         }
172       } else if (nData30 == 0x02 || nData30 == 0x03) {
173         fChannel = nData30-2;
174         fChannelData[fCarlosId][fChannel] += 
175           (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
176         fLastBit[fCarlosId][fChannel] += 30;
177       } else if (nData28== 0x04) {
178         // JTAG word -- do nothing
179       } else {                               // unknown data format
180         fRawReader->AddMajorErrorLog(kDataFormatErr,Form("Invalid data %8.8x",fData));
181         AliWarning(Form("Invalid data: %08X\n", fData));
182         return kFALSE;
183       }
184       
185       if(fCarlosId>=0 && fCarlosId <kModulesPerDDL){
186         Int_t nDDL=fRawReader->GetDDLID();
187         fModuleID = GetModuleNumber(nDDL,fCarlosId);
188       }
189     } else {  // decode data
190       if (fReadCode[fCarlosId][fChannel]) {// read the next code word
191         fChannelCode[fCarlosId][fChannel] = ReadBits();
192         fReadCode[fCarlosId][fChannel] = kFALSE;
193         fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
194       } else {                      // read the next data word
195         UInt_t data = ReadBits();
196         fReadCode[fCarlosId][fChannel] = kTRUE;
197         fReadBits[fCarlosId][fChannel] = 3;
198         if (fChannelCode[fCarlosId][fChannel] == 0) {         // set the time bin         
199           fTimeBin[fCarlosId][fChannel] = data;
200         } else if (fChannelCode[fCarlosId][fChannel] == 1) {  // next anode
201           fTimeBin[fCarlosId][fChannel] = 0;
202           fAnode[fCarlosId][fChannel]++;
203         } else {                                   // ADC signal data
204           fEightBitSignal=data + (1 << fChannelCode[fCarlosId][fChannel]);
205           if(fDecompressAmbra) fSignal = DecompAmbra(fEightBitSignal + fLowThresholdArray[fModuleID-kSPDModules][fChannel]);
206           fCoord1 = fAnode[fCarlosId][fChannel];
207           fCoord2 = fTimeBin[fCarlosId][fChannel];
208           fTimeBin[fCarlosId][fChannel]++;
209           fCompletedModule=kFALSE;
210           fCompletedDDL=kFALSE;
211           return kTRUE;
212         }
213       }
214     }
215   }
216   return kFALSE;
217 }
218
219 //______________________________________________________________________
220 void AliITSRawStreamSDD::Reset(){
221
222   //reset data member for a new ddl
223   for(Int_t i=0;i<2;i++){
224     for(Int_t ic=0;ic<kModulesPerDDL;ic++){
225       fChannelData[ic][i]=0;
226       fLastBit[ic][i]=0;
227       fChannelCode[ic][i]=0;
228       fReadCode[ic][i]=kTRUE;
229       fReadBits[ic][i]=3;
230       fTimeBin[ic][i]=0;
231       fAnode[ic][i]=0;     
232       fICountFoot[ic]=0;
233     }
234   }
235 }
236
237 //______________________________________________________________________
238 Bool_t AliITSRawStreamSDD::SkipHeaderWord(){
239   // skip the 1 DDL header word = 0xffffffff
240   while (kTRUE) {
241     if (!fRawReader->ReadNextInt(fData)) return kFALSE;    
242     if ((fData >> 30) == 0x01) continue;  // JTAG word
243     if(fData==0xFFFFFFFF) return kTRUE;
244   }
245 }
246