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