SDD raw data treatment: same format for real and simulated data
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSDD.cxx
CommitLineData
2906f4c2 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
27ClassImp(AliITSRawStreamSDD)
28
2906f4c2 29const Int_t AliITSRawStreamSDD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
a97b3678 30
31 {240,241,242,246,247,248,252,253,254,258,259,260},
32 {264,265,266,270,271,272,276,277,278,282,283,284},
33 {288,289,290,294,295,296,300,301,302,306,307,308},
34 {312,313,314,318,319,320,-1,-1,-1,-1,-1,-1},
35 {243,244,245,249,250,251,255,256,257,261,262,263},
36 {267,268,269,273,274,275,279,280,281,285,286,287},
37 {291,292,293,297,298,299,303,304,305,309,310,311},
38 {315,316,317,321,322,323,-1,-1,-1,-1,-1,-1},
39 {324,325,326,327,332,333,334,335,340,341,342,343},
40 {348,349,350,351,356,357,358,359,364,365,366,367},
41 {372,373,374,375,380,381,382,383,388,389,390,391},
42 {396,397,398,399,404,405,406,407,412,413,414,415},
43 {420,421,422,423,428,429,430,431,436,437,438,439},
44 {444,445,446,447,452,453,454,455,460,461,462,463},
45 {468,469,470,471,476,477,478,479,484,485,486,487},
46 {492,493,494,495,-1,-1,-1,-1,-1,-1,-1,-1},
47 {328,329,330,331,336,337,338,339,344,345,346,347},
48 {352,353,354,355,360,361,362,363,368,369,370,371},
49 {376,377,378,379,384,385,386,387,392,393,394,395},
50 {400,401,402,403,408,409,410,411,416,417,418,419},
51 {424,425,426,427,432,433,434,435,440,441,442,443},
52 {448,449,450,451,456,457,458,459,464,465,466,467},
53 {472,473,474,475,480,481,482,483,488,489,490,491},
54 {496,497,498,499,-1,-1,-1,-1,-1,-1,-1,-1}};
1ba0280f 55
56const UInt_t AliITSRawStreamSDD::fgkCodeLength[8] = {8, 18, 2, 3, 4, 5, 6, 7};
2906f4c2 57
58AliITSRawStreamSDD::AliITSRawStreamSDD(AliRawReader* rawReader) :
e56160b8 59 AliITSRawStream(rawReader),
60fData(0),
e56160b8 61fCarlosId(0),
a97b3678 62fEventId(0),
e56160b8 63fChannel(0),
a97b3678 64fJitter(0),
65fNCarlos(kModulesPerDDL),
66fNfifo0(0),
67fNfifo1(0),
68fNfifo2(0),
69fNfifo3(0),
70fDDL(0){
2906f4c2 71// create an object to read ITS SDD raw digits
1ba0280f 72
1ba0280f 73 for(Int_t i=0;i<2;i++){
a97b3678 74 for(Int_t ic=0;ic<kModulesPerDDL;ic++){
75 fChannelData[ic][i]=0;
76 fLastBit[ic][i]=0;
77 fChannelCode[ic][i]=0;
78 fReadCode[ic][i]=kFALSE;
79 fReadBits[ic][i]=0;
80 fTimeBin[ic][i]=0;
81 fAnode[ic][i]=0;
82 }
1ba0280f 83 fLowThreshold[i]=0;
84 }
a97b3678 85 for(Int_t i=0;i<kDDLsNumber;i++) fSkip[i]=0;
86 fRawReader->Reset();
362c9d61 87 fRawReader->Select("ITSSDD");
1ba0280f 88
a97b3678 89 //fRawReader->SelectEquipment(17, 101, 101);//select this for test data
90 //fNCarlos = 8; //select this for test data
1ba0280f 91}
92
93UInt_t AliITSRawStreamSDD::ReadBits()
94{
95// read bits from the given channel
96
a97b3678 97 UInt_t result = (fChannelData[fCarlosId][fChannel] & ((1<<fReadBits[fCarlosId][fChannel]) - 1));
98 fChannelData[fCarlosId][fChannel] >>= fReadBits[fCarlosId][fChannel];
99 fLastBit[fCarlosId][fChannel] -= fReadBits[fCarlosId][fChannel];
1ba0280f 100 return result;
2906f4c2 101}
102
1ba0280f 103Int_t AliITSRawStreamSDD::DecompAmbra(Int_t value) const
104{
a97b3678 105 // AMBRA decompression (from 8 to 10 bit)
106
1ba0280f 107 if ((value & 0x80) == 0) {
108 return value & 0x7f;
109 } else if ((value & 0x40) == 0) {
110 return 0x081 + ((value & 0x3f) << 1);
111 } else if ((value & 0x20) == 0) {
112 return 0x104 + ((value & 0x1f) << 3);
113 } else {
114 return 0x208 + ((value & 0x1f) << 4);
115 }
a97b3678 116
1ba0280f 117}
2906f4c2 118
119Bool_t AliITSRawStreamSDD::Next()
120{
121// read the next raw digit
122// returns kFALSE if there is no digit left
123
124 fPrevModuleID = fModuleID;
a97b3678 125 fDDL=fRawReader->GetDDLID();
126 Int_t ddln = fRawReader->GetDDLID();
127 if(ddln <0) ddln=0;
128 while (fSkip[ddln] < 9) {
129 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
130 if ((fData >> 30) == 0x01) continue; // JTAG word
131 fSkip[ddln]++;
132 }
133
134
135 Int_t countFoot[kModulesPerDDL];
136 for(Int_t i=0;i<kModulesPerDDL;i++) countFoot[i]=0;
137 while (kTRUE) {
138 if ((fChannel < 0) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel])) {
139
140 if (!fRawReader->ReadNextInt(fData)) return kFALSE; // read next word
141 ddln = fRawReader->GetDDLID();
142 if(ddln!=fDDL){
143 Reset();
144 for(Int_t icr=0;icr<kModulesPerDDL;icr++) countFoot[icr]=0;
145 }
146 if(ddln < 0 || ddln > (kDDLsNumber-1)) ddln = 0;
147 while (fSkip[ddln] < 9) {
148 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
149 if ((fData >> 30) == 0x01) continue; // JTAG word
150 fSkip[ddln]++;
151 }
152
153 fChannel = -1;
154
155
156 if( ((fData << 4) >> 4) == 0){
157 fCarlosId = 0;fNfifo0 = fCarlosId;
158 }
159 else if (((fData << 4) >> 4) == 1){
160 fCarlosId = 1;fNfifo0 = fCarlosId;
161 }
162 else if (((fData << 4) >> 4) == 2){
163 fCarlosId = 2;
164 if(fNCarlos == 8) fNfifo1 = fCarlosId;
165 else fNfifo0 = fCarlosId;
166 }
167 else if (((fData << 4) >> 4) == 3){
168 fCarlosId = 3;fNfifo1 = fCarlosId;
169 }
170 else if (((fData << 4) >> 4) == 4){
171 fCarlosId = 4;
172 if(fNCarlos == 8) fNfifo2 = fCarlosId;
173 else fNfifo1 = fCarlosId;
174 }
175 else if (((fData << 4) >> 4) == 5){
176 fCarlosId = 5;
177 if(fNCarlos == 8) fNfifo2 = fCarlosId;
178 else fNfifo1 = fCarlosId;
179 }
180 else if (((fData << 4) >> 4) == 6){
181 fCarlosId = 6;
182 if(fNCarlos == 8) fNfifo3 = fCarlosId;
183 else fNfifo2 = fCarlosId;
184 }
185 else if (((fData << 4) >> 4) == 7){
186 fCarlosId = 7;
187 if(fNCarlos == 8) fNfifo3 = fCarlosId;
188 else fNfifo2 = fCarlosId;
189 }
190 else if (((fData << 4) >> 4) == 8){
191 fCarlosId = 8;fNfifo2 = fCarlosId;
192 }
193 else if (((fData << 4) >> 4) == 9){
194 fCarlosId = 9;fNfifo3 = fCarlosId;
195 }
196 else if (((fData << 4) >> 4) == 10){
197 fCarlosId = 10;fNfifo3 = fCarlosId;
198 }
199 else if (((fData << 4) >> 4) == 11){
200 fCarlosId = 11;fNfifo3 = fCarlosId;
201 }
202 else if (((fData << 4) >> 4) == 16){
203 fCarlosId = fNfifo0;
204 }
205 else if (((fData << 4) >> 4) == 17){
206 fCarlosId = fNfifo1;
207 }
208 else if (((fData << 4) >> 4) == 18){
209 fCarlosId = fNfifo2;
210 }
211 else if (((fData << 4) >> 4) == 19){
212 fCarlosId = fNfifo3;
213 }
214 if(fData==1059004191) continue;
215 if (fNCarlos == 8 && (fCarlosId == 8 || fCarlosId == 9 ||
216 fCarlosId ==10 || fCarlosId == 11))continue;
217
218 fModuleID = fgkDDLModuleMap[fRawReader->GetDDLID()][fCarlosId];
219
220 if ((fData >> 28) == 0x02) { // header
221 fEventId = (fData >> 3) & 0x07FF;
222 } else if ((fData >> 28) == 0x03) { // footer
223 countFoot[fCarlosId]++; // stop before the last word (last word=jitter)
224 if(countFoot[fCarlosId]==3){
225 return kFALSE;
226 }
227 } else if ((fData >> 29) == 0x00) { // error
2906f4c2 228
a97b3678 229 if ((fData & 0x00000163) != 0) {
230
231 Error("Next", "error codes = %8.8x",fData);
232 return kFALSE;
233
234 }
235 } else if ((fData >> 30) == 0x01) { // JTAG word
236 // ignored
237 } else if ((fData >> 30) == 0x02) { // channel 0 data
238
239 fChannel = 0;
240 } else if ((fData >> 30) == 0x03) { // channel 1 data
241 fChannel = 1;
242 } else { // unknown data format
243 Error("Next", "invalid data: %8.8x\n", fData);
244 return kFALSE;
245 }
246
247 if (fChannel >= 0) { // add read word to the data
248 fChannelData[fCarlosId][fChannel] +=
249 (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
250 fLastBit[fCarlosId][fChannel] += 30;
251 }
252
253 } else { // decode data
254
255 if (fReadCode[fCarlosId][fChannel]) {// read the next code word
256 fChannelCode[fCarlosId][fChannel] = ReadBits();
257 fReadCode[fCarlosId][fChannel] = kFALSE;
258 fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
259
260 } else { // read the next data word
261 UInt_t data = ReadBits();
262 fReadCode[fCarlosId][fChannel] = kTRUE;
263 fReadBits[fCarlosId][fChannel] = 3;
264 if (fChannelCode[fCarlosId][fChannel] == 0) { // set the time bin
265 fTimeBin[fCarlosId][fChannel] = data;
266 } else if (fChannelCode[fCarlosId][fChannel] == 1) { // next anode
267 fTimeBin[fCarlosId][fChannel] = 0;
268 fAnode[fCarlosId][fChannel]++;
269
270 }else { // ADC signal data
271 fSignal = DecompAmbra(data + (1 << fChannelCode[fCarlosId][fChannel]) + fLowThreshold[fChannel]);
272 fCoord1 = fAnode[fCarlosId][fChannel];
273 fCoord2 = fTimeBin[fCarlosId][fChannel];
274 fTimeBin[fCarlosId][fChannel]++;
275 return kTRUE;
276 }
277 }
278 }
279 }
280 return kFALSE;
2906f4c2 281
2906f4c2 282}
1ba0280f 283
a97b3678 284void AliITSRawStreamSDD::Reset(){
285 //reset data member for a new ddl
286
287 for(Int_t i=0;i<2;i++){
288 for(Int_t ic=0;ic<kModulesPerDDL;ic++){
289 fChannelData[ic][i]=0;
290 fLastBit[ic][i]=0;
291 fChannelCode[ic][i]=0;
292 fReadCode[ic][i]=kFALSE;
293 fReadBits[ic][i]=0;
294 fTimeBin[ic][i]=0;
295 fAnode[ic][i]=0;
296 }
297 fLowThreshold[i]=0;
298 }
299 fChannel=-1;
300 fDDL=fRawReader->GetDDLID();
301}