]>
Commit | Line | Data |
---|---|---|
6727e2db | 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 SPD digits in raw data. | |
21 | /// | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | #include "AliITSRawStreamSPD.h" | |
25 | #include "AliRawReader.h" | |
26 | #include "AliLog.h" | |
27 | ||
28 | ClassImp(AliITSRawStreamSPD) | |
29 | ||
30 | ||
31 | const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = { | |
32 | { 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93}, | |
33 | {12,13, 8, 9, 96, 97,100,101,104,105,108,109}, | |
34 | {20,21,16,17,112,113,116,117,120,121,124,125}, | |
35 | {28,29,24,25,128,129,132,133,136,137,140,141}, | |
36 | {36,37,32,33,144,145,148,149,152,153,156,157}, | |
37 | {44,45,40,41,160,161,164,165,168,169,172,173}, | |
38 | {52,53,48,49,176,177,180,181,184,185,188,189}, | |
39 | {60,61,56,57,192,193,196,197,200,201,204,205}, | |
40 | {68,69,64,65,208,209,212,213,216,217,220,221}, | |
41 | {76,77,72,73,224,225,228,229,232,233,236,237}, | |
42 | { 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94}, | |
43 | {15,14,11,10, 99, 98,103,102,107,106,111,110}, | |
44 | {23,22,19,18,115,114,119,118,123,122,127,126}, | |
45 | {31,30,27,26,131,130,135,134,139,138,143,142}, | |
46 | {39,38,35,34,147,146,151,150,155,154,159,158}, | |
47 | {47,46,43,42,163,162,167,166,171,170,175,174}, | |
48 | {55,54,51,50,179,178,183,182,187,186,191,190}, | |
49 | {63,62,59,58,195,194,199,198,203,202,207,206}, | |
50 | {71,70,67,66,211,210,215,214,219,218,223,222}, | |
51 | {79,78,75,74,227,226,231,230,235,234,239,238} | |
52 | }; | |
53 | ||
54 | ||
55 | AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) : | |
56 | AliITSRawStream(rawReader), | |
57 | fEventNumber(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0), | |
58 | fData(0),fOffset(0),fHitCount(0), | |
59 | fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0), | |
60 | fFirstWord(kTRUE),fPrevEventId(0xffffffff) | |
61 | { | |
62 | // create an object to read ITS SPD raw digits | |
63 | fRawReader->Select("ITSSPD"); | |
64 | // reset calib header words | |
65 | for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) { | |
66 | fCalHeadWord[iword]=0xffffffff; | |
67 | } | |
68 | NewEvent(); | |
69 | } | |
70 | ||
71 | Bool_t AliITSRawStreamSPD::ReadNextShort() | |
72 | { | |
73 | // read next 16 bit word into fData | |
74 | if (fFirstWord) { | |
75 | Bool_t b1 = fRawReader->ReadNextChar(fDataChar1); | |
76 | if (!b1) return kFALSE; | |
77 | Bool_t b2, b3, b4; | |
78 | b2 = fRawReader->ReadNextChar(fDataChar2); | |
79 | b3 = fRawReader->ReadNextChar(fDataChar3); | |
80 | b4 = fRawReader->ReadNextChar(fDataChar4); | |
81 | if (!(b2 && b3 && b4)) { | |
82 | return kFALSE; | |
83 | } | |
84 | fData = fDataChar3+(fDataChar4<<8); | |
85 | if ((*fRawReader->GetEventId())!=fPrevEventId) { // if new event... | |
86 | NewEvent(); | |
87 | fPrevEventId=(*fRawReader->GetEventId()); | |
88 | } | |
89 | fFirstWord=kFALSE; | |
90 | } | |
91 | else { | |
92 | fFirstWord=kTRUE; | |
93 | fData = fDataChar1+(fDataChar2<<8); | |
94 | } | |
95 | ||
96 | return kTRUE; | |
97 | } | |
98 | ||
99 | Bool_t AliITSRawStreamSPD::ReadNextInt() | |
100 | { | |
101 | // reads next 32 bit into fDataChar1..4 | |
102 | // (if first 16 bits read already, just completes the present word) | |
103 | if (fFirstWord) { | |
104 | if (ReadNextShort() && ReadNextShort()) { | |
105 | return kTRUE; | |
106 | } | |
107 | } | |
108 | else { | |
109 | if (ReadNextShort()) { | |
110 | return kTRUE; | |
111 | } | |
112 | } | |
113 | return kFALSE; | |
114 | } | |
115 | ||
116 | void AliITSRawStreamSPD::NewEvent() | |
117 | { | |
118 | // call this to reset flags for a new event | |
119 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
120 | fCalHeadRead[eqId]=kFALSE; | |
121 | } | |
122 | fEventNumber=-1; | |
123 | } | |
124 | ||
125 | Bool_t AliITSRawStreamSPD::ReadCalibHeader() | |
126 | { | |
127 | // read the extra calibration header | |
128 | // returns kTRUE if the header is present and has length > 0 | |
129 | ||
130 | Int_t ddlID = fRawReader->GetDDLID(); | |
131 | if (ddlID==-1) { // we may need to read one word to get the blockAttr | |
132 | if (!ReadNextShort()) return kFALSE; | |
133 | ddlID = fRawReader->GetDDLID(); | |
134 | } | |
135 | UChar_t attr = fRawReader->GetBlockAttributes(); | |
136 | if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE; | |
137 | if ((attr & 0x40) == 0x40) { // is the header present? | |
138 | if (ReadNextInt()) { | |
139 | // length of cal header: | |
140 | UInt_t calLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24); | |
141 | if (calLen>kCalHeadLenMax) { | |
142 | fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,Form("Header length %d > max = %d",calLen,kCalHeadLenMax)); | |
143 | AliWarning(Form("Header length problem. %d > %d (max)",calLen,kCalHeadLenMax)); | |
144 | return kFALSE; | |
145 | } | |
146 | else if (calLen>0) { | |
147 | for (UInt_t iword=0; iword<calLen; iword++) { | |
148 | if (ReadNextInt()) { | |
149 | fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24); | |
150 | } | |
151 | else { | |
152 | fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,"header length problem"); | |
153 | AliWarning("header length problem"); | |
154 | return kFALSE; | |
155 | } | |
156 | } | |
157 | return kTRUE; | |
158 | } | |
159 | } | |
160 | } | |
161 | ||
162 | return kFALSE; | |
163 | } | |
164 | ||
165 | Bool_t AliITSRawStreamSPD::Next() | |
166 | { | |
167 | // read the next raw digit | |
168 | // returns kFALSE if there is no digit left | |
169 | ||
170 | Int_t ddlID=-1; | |
171 | fPrevModuleID = fModuleID; | |
172 | ||
173 | while (ReadNextShort()) { | |
174 | ||
175 | ddlID = fRawReader->GetDDLID(); | |
176 | if (ddlID>=0 && ddlID<20) { | |
177 | if (!fCalHeadRead[ddlID]) { | |
178 | ReadCalibHeader(); | |
179 | } | |
180 | } | |
181 | else { | |
182 | fRawReader->AddMajorErrorLog(kDDLNumberErr,Form("Wrong DDL number %d",ddlID)); | |
183 | AliWarning(Form("DDL number error (= %d) , setting it to 19", ddlID)); | |
184 | ddlID=19; | |
185 | } | |
186 | ||
187 | if ((fData & 0xC000) == 0x4000) { // header | |
188 | fHitCount = 0; | |
189 | UShort_t eventNumber = (fData >> 4) & 0x007F; | |
190 | if (fEventNumber < 0) { | |
191 | fEventNumber = eventNumber; | |
192 | } | |
193 | else if (eventNumber != fEventNumber) { | |
194 | fRawReader->AddMajorErrorLog(kEventNumberErr,Form("Reading event number %d instead of %d",eventNumber,fEventNumber)); | |
195 | AliWarning(Form("mismatching event numbers: %d != %d",eventNumber, fEventNumber)); | |
196 | } | |
197 | fChipAddr = fData & 0x000F; | |
198 | if (fChipAddr>9) { | |
199 | fRawReader->AddMajorErrorLog(kChipAddrErr,Form("Overflow chip address %d - set to 9",fChipAddr)); | |
200 | AliWarning(Form("overflow chip addr (= %d) , setting it to 9", fChipAddr)); | |
201 | fChipAddr=9; | |
202 | } | |
203 | fHalfStaveNr = (fData & 0x3800)>>11; | |
204 | if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) { | |
205 | fRawReader->AddMajorErrorLog(kStaveNumberErr,Form("Half stave number error %d - set to 5",fHalfStaveNr)); | |
206 | AliWarning(Form("half stave number error(=%d) , setting it to 5", fHalfStaveNr)); | |
207 | fHalfStaveNr=5; | |
208 | } | |
209 | // translate ("online") ddl, hs, chip nr to ("offline") module id : | |
210 | fModuleID = GetOfflineModuleFromOnline(ddlID,fHalfStaveNr,fChipAddr); | |
211 | // fOffset = 32 * (fChipAddr % 5); | |
212 | } | |
213 | else if ((fData & 0xC000) == 0x0000) { // trailer | |
214 | UShort_t hitCount = fData & 0x1FFF; | |
215 | if (hitCount != fHitCount){ | |
216 | fRawReader->AddMajorErrorLog(kNumbHitsErr,Form("Number of hits %d instead of %d",hitCount,fHitCount)); | |
217 | AliWarning(Form("wrong number of hits: %d != %d", fHitCount, hitCount)); | |
218 | } | |
219 | } | |
220 | else if ((fData & 0xC000) == 0x8000) { // pixel hit | |
221 | fHitCount++; | |
222 | fCol = (fData & 0x001F); | |
223 | fRow = (fData >> 5) & 0x00FF; | |
224 | ||
225 | fCoord1 = GetOfflineColFromOnline(ddlID,fHalfStaveNr,fChipAddr,fCol); | |
226 | fCoord2 = GetOfflineRowFromOnline(ddlID,fHalfStaveNr,fChipAddr,fRow); | |
227 | ||
228 | // translate ("online") chipcol, chiprow to ("offline") col (coord1), row (coord2): | |
229 | // This will change, waiting for new geometry!!! | |
230 | // fCoord1 = fCol; | |
231 | // if (fModuleID < 80 && ddlID < 10) fCoord1=31-fCoord1; | |
232 | // else if (fModuleID >=80 && ddlID >=10) fCoord1=31-fCoord1; | |
233 | // fCoord1 += fOffset; | |
234 | // if (ddlID>=10) fCoord1=159-fCoord1; | |
235 | // fCoord2 = fRow; | |
236 | // if (fModuleID<80) fCoord2=255-fCoord2; | |
237 | ||
238 | return kTRUE; | |
239 | } | |
240 | else { // fill word | |
241 | if ((fData & 0xC000) != 0xC000) { | |
242 | fRawReader->AddMajorErrorLog(kWrongWordErr,"Wrong fill word"); | |
243 | AliWarning("wrong fill word!"); | |
244 | } | |
245 | } | |
246 | ||
247 | } | |
248 | ||
249 | return kFALSE; | |
250 | } | |
251 | Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) { | |
252 | // Reads the half stave present status from the block attributes | |
253 | Int_t ddlID = fRawReader->GetDDLID(); | |
254 | if (ddlID==-1) { | |
255 | fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,"DDL ID = -1. Cannot read block attributes."); | |
256 | AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE."); | |
257 | return kFALSE; | |
258 | } | |
259 | else { | |
260 | if (hs>=6) { | |
261 | fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,Form( "HS >= 6 requested (%d). Return kFALSE.",hs)); | |
262 | AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs)); | |
263 | return kFALSE; | |
264 | } | |
265 | UChar_t attr = fRawReader->GetBlockAttributes(); | |
266 | if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present | |
267 | return kFALSE; | |
268 | } | |
269 | else { | |
270 | return kTRUE; | |
271 | } | |
272 | } | |
273 | } | |
274 | ||
275 | Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const { | |
276 | if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001)); | |
277 | else return kFALSE; | |
278 | } | |
279 | Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const { | |
280 | if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1); | |
281 | else return kFALSE; | |
282 | } | |
283 | UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const { | |
284 | if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff); | |
285 | else return 0; | |
286 | } | |
287 | UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const { | |
288 | if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff); | |
289 | else return 0; | |
290 | } | |
291 | UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const { | |
292 | if (hs<6) return fCalHeadWord[hs+10]; | |
293 | else return 0; | |
294 | } | |
295 | Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const { | |
296 | if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1); | |
297 | else return kFALSE; | |
298 | } | |
299 | ||
300 | ||
301 | ||
302 | ||
303 | Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) { | |
304 | if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule]; | |
305 | else return 240; | |
306 | } | |
307 | ||
308 | ||
309 | ||
310 | ||
311 | Bool_t AliITSRawStreamSPD::OfflineToOnline(UInt_t module, UInt_t colM, UInt_t rowM, UInt_t& eq, UInt_t& hs, UInt_t& chip, UInt_t& col, UInt_t& row) { | |
312 | // converts offline coordinates to online | |
313 | eq = GetOnlineEqIdFromOffline(module); | |
314 | hs = GetOnlineHSFromOffline(module); | |
315 | chip = GetOnlineChipFromOffline(module,colM); | |
316 | col = GetOnlineColFromOffline(module,colM); | |
317 | row = GetOnlineRowFromOffline(module,rowM); | |
318 | if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE; | |
319 | else return kTRUE; | |
320 | } | |
321 | ||
322 | ||
323 | Bool_t AliITSRawStreamSPD::OnlineToOffline(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row, UInt_t& module, UInt_t& colM, UInt_t& rowM) { | |
324 | // converts online coordinates to offline | |
325 | module = GetOfflineModuleFromOnline(eq,hs,chip); | |
326 | colM = GetOfflineColFromOnline(eq,hs,chip,col); | |
327 | rowM = GetOfflineRowFromOnline(eq,hs,chip,row); | |
328 | if (module>=240 || colM>=160 || rowM>=256) return kFALSE; | |
329 | else return kTRUE; | |
330 | } | |
331 | ||
332 | ||
333 | UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) { | |
334 | // offline->online (eq) | |
335 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
336 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
337 | if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId; | |
338 | } | |
339 | } | |
340 | return 20; // error | |
341 | } | |
342 | ||
343 | UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) { | |
344 | // offline->online (hs) | |
345 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
346 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
347 | if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2; | |
348 | } | |
349 | } | |
350 | return 6; // error | |
351 | } | |
352 | ||
353 | UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) { | |
354 | // offline->online (chip) | |
355 | for (UInt_t eq=0; eq<20; eq++) { | |
356 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
357 | if (GetModuleNumber(eq,iModule)==(Int_t)module) { | |
358 | if (eq<10) { // side A | |
359 | return (159-colM)/32 + 5*(iModule%2); | |
360 | } | |
361 | else { // side C | |
362 | return colM/32 + 5*(iModule%2); | |
363 | } | |
364 | } | |
365 | } | |
366 | } | |
367 | return 10; // error | |
368 | } | |
369 | ||
370 | UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) { | |
371 | // offline->online (col) | |
372 | if (module<80) { // inner layer | |
373 | return colM%32; | |
374 | } | |
375 | else if (module<240) { // outer layer | |
376 | return (159-colM)%32; | |
377 | } | |
378 | return 32; // error | |
379 | } | |
380 | ||
381 | UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) { | |
382 | // offline->online (row) | |
383 | if (module<80) { // inner layer | |
384 | return rowM; | |
385 | } | |
386 | else if (module<240) { // outer layer | |
387 | return (255-rowM); | |
388 | } | |
389 | return 256; // error | |
390 | } | |
391 | ||
392 | ||
393 | ||
394 | ||
395 | ||
396 | UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) { | |
397 | // online->offline (module) | |
398 | if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5]; | |
399 | else return 240; | |
400 | } | |
401 | ||
402 | UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) { | |
403 | // online->offline (col) | |
404 | if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error | |
405 | UInt_t offset = 32 * (chip % 5); | |
406 | if (hs<2) { | |
407 | if (eqId<10) { | |
408 | return 159 - (31-col + offset); // inner layer, side A | |
409 | } | |
410 | else { | |
411 | return col + offset; // inner layer, side C | |
412 | } | |
413 | } | |
414 | else { | |
415 | if (eqId<10) { | |
416 | return 159 - (col + offset); // outer layer, side A | |
417 | } | |
418 | else { | |
419 | return 31-col + offset; // outer layer, side C | |
420 | } | |
421 | } | |
422 | } | |
423 | ||
424 | UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) { | |
425 | // online->offline (row) | |
426 | if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error | |
427 | if (hs<2) { | |
428 | return row; | |
429 | } | |
430 | else { | |
431 | return 255-row; | |
432 | } | |
433 | } |