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