]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSPD_NEWGEO.cxx
moved component registration to agent; added component configuration/initialization...
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSPD_NEWGEO.cxx
CommitLineData
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
28ClassImp(AliITSRawStreamSPD)
29
6727e2db 30const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
31 { 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93},
32 {12,13, 8, 9, 96, 97,100,101,104,105,108,109},
33 {20,21,16,17,112,113,116,117,120,121,124,125},
34 {28,29,24,25,128,129,132,133,136,137,140,141},
35 {36,37,32,33,144,145,148,149,152,153,156,157},
36 {44,45,40,41,160,161,164,165,168,169,172,173},
37 {52,53,48,49,176,177,180,181,184,185,188,189},
38 {60,61,56,57,192,193,196,197,200,201,204,205},
39 {68,69,64,65,208,209,212,213,216,217,220,221},
40 {76,77,72,73,224,225,228,229,232,233,236,237},
41 { 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94},
42 {15,14,11,10, 99, 98,103,102,107,106,111,110},
43 {23,22,19,18,115,114,119,118,123,122,127,126},
44 {31,30,27,26,131,130,135,134,139,138,143,142},
45 {39,38,35,34,147,146,151,150,155,154,159,158},
46 {47,46,43,42,163,162,167,166,171,170,175,174},
47 {55,54,51,50,179,178,183,182,187,186,191,190},
48 {63,62,59,58,195,194,199,198,203,202,207,206},
49 {71,70,67,66,211,210,215,214,219,218,223,222},
50 {79,78,75,74,227,226,231,230,235,234,239,238}
51};
10bb1a34 52//__________________________________________________________________________
6727e2db 53AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) :
54 AliITSRawStream(rawReader),
10bb1a34 55 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),
6727e2db 56 fData(0),fOffset(0),fHitCount(0),
57 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
10bb1a34 58 fFirstWord(kTRUE),fPrevEventId(0xffffffff),
59 fEqPLBytesRead(0),fEqPLChipHeadersRead(0),fEqPLChipTrailersRead(0),
60 fHeaderOrTrailerReadLast(kFALSE),fExpectedHeaderTrailerCount(0),
61 fFillOutOfSynch(kFALSE),fDDLID(-1),fLastDDLID(-1),fAdvancedErrorLog(kFALSE),
62 fAdvLogger(NULL)
6727e2db 63{
64 // create an object to read ITS SPD raw digits
65 fRawReader->Select("ITSSPD");
66 // reset calib header words
67 for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) {
68 fCalHeadWord[iword]=0xffffffff;
69 }
70 NewEvent();
71}
10bb1a34 72//__________________________________________________________________________
73AliITSRawStreamSPD::AliITSRawStreamSPD(const AliITSRawStreamSPD& rstream) :
74 AliITSRawStream(rstream.fRawReader),
75 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),
76 fData(0),fOffset(0),fHitCount(0),
77 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
78 fFirstWord(kTRUE),fPrevEventId(0xffffffff),
79 fEqPLBytesRead(0),fEqPLChipHeadersRead(0),fEqPLChipTrailersRead(0),
80 fHeaderOrTrailerReadLast(kFALSE),fExpectedHeaderTrailerCount(0),
81 fFillOutOfSynch(kFALSE),fDDLID(-1),fLastDDLID(-1),fAdvancedErrorLog(kFALSE),
82 fAdvLogger(NULL)
6727e2db 83{
10bb1a34 84 // copy constructor
85 AliError("Copy constructor should not be used.");
86}
87//__________________________________________________________________________
88AliITSRawStreamSPD& AliITSRawStreamSPD::operator=(const AliITSRawStreamSPD& rstream) {
89 // assignment operator
90 if (this!=&rstream) {}
91 AliError("Assignment opertator should not be used.");
92 return *this;
93}
94//__________________________________________________________________________
95Bool_t AliITSRawStreamSPD::ReadNextShort() {
6727e2db 96 // read next 16 bit word into fData
97 if (fFirstWord) {
98 Bool_t b1 = fRawReader->ReadNextChar(fDataChar1);
99 if (!b1) return kFALSE;
100 Bool_t b2, b3, b4;
101 b2 = fRawReader->ReadNextChar(fDataChar2);
102 b3 = fRawReader->ReadNextChar(fDataChar3);
103 b4 = fRawReader->ReadNextChar(fDataChar4);
104 if (!(b2 && b3 && b4)) {
105 return kFALSE;
106 }
107 fData = fDataChar3+(fDataChar4<<8);
108 if ((*fRawReader->GetEventId())!=fPrevEventId) { // if new event...
109 NewEvent();
110 fPrevEventId=(*fRawReader->GetEventId());
111 }
112 fFirstWord=kFALSE;
113 }
114 else {
115 fFirstWord=kTRUE;
116 fData = fDataChar1+(fDataChar2<<8);
117 }
10bb1a34 118 fEqPLBytesRead+=2;
119
6727e2db 120 return kTRUE;
121}
10bb1a34 122//__________________________________________________________________________
123Bool_t AliITSRawStreamSPD::ReadNextInt() {
6727e2db 124 // reads next 32 bit into fDataChar1..4
125 // (if first 16 bits read already, just completes the present word)
126 if (fFirstWord) {
127 if (ReadNextShort() && ReadNextShort()) {
128 return kTRUE;
129 }
130 }
131 else {
132 if (ReadNextShort()) {
133 return kTRUE;
134 }
135 }
136 return kFALSE;
137}
10bb1a34 138//__________________________________________________________________________
139void AliITSRawStreamSPD::NewEvent() {
6727e2db 140 // call this to reset flags for a new event
141 for (UInt_t eqId=0; eqId<20; eqId++) {
142 fCalHeadRead[eqId]=kFALSE;
143 }
10bb1a34 144 fEventCounter = -1;
145 fDDLID = -1;
146 fLastDDLID = -1;
6727e2db 147}
10bb1a34 148//__________________________________________________________________________
3f917533 149Int_t AliITSRawStreamSPD::ReadCalibHeader() {
6727e2db 150 // read the extra calibration header
3f917533 151 // returns the length of the header if it is present, -1 otherwise
6727e2db 152
153 Int_t ddlID = fRawReader->GetDDLID();
154 if (ddlID==-1) { // we may need to read one word to get the blockAttr
3f917533 155 if (!ReadNextShort()) return -1;
6727e2db 156 ddlID = fRawReader->GetDDLID();
157 }
10bb1a34 158 // reset flags and counters
159 fEqPLBytesRead = 2;
160 fEqPLChipHeadersRead = 0;
161 fEqPLChipTrailersRead = 0;
162 fHeaderOrTrailerReadLast = kFALSE;
163 fFillOutOfSynch = kFALSE;
164
165 // check what number of chip headers/trailers to expect
166 fExpectedHeaderTrailerCount = 0;
167 for (UInt_t hs=0; hs<6; hs++) {
168 if (!fRawReader->TestBlockAttribute(hs)) fExpectedHeaderTrailerCount+=10;
169 }
170
6727e2db 171 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
10bb1a34 172 if (fRawReader->TestBlockAttribute(6)) { // is the calib header present?
6727e2db 173 if (ReadNextInt()) {
174 // length of cal header:
175 UInt_t calLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
176 if (calLen>kCalHeadLenMax) {
10bb1a34 177 TString errMess = Form("Header length %d > max = %d",calLen,kCalHeadLenMax);
178 AliError(errMess.Data());
179 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
180 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
3f917533 181 return -1;
6727e2db 182 }
10bb1a34 183 else {
6727e2db 184 for (UInt_t iword=0; iword<calLen; iword++) {
185 if (ReadNextInt()) {
186 fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
187 }
188 else {
10bb1a34 189 TString errMess = "Header length problem";
190 AliError(errMess.Data());
191 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
192 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
3f917533 193 return -1;
6727e2db 194 }
195 }
3f917533 196 return calLen;
6727e2db 197 }
198 }
199 }
200
3f917533 201 return -1;
6727e2db 202}
10bb1a34 203//__________________________________________________________________________
204Bool_t AliITSRawStreamSPD::Next() {
6727e2db 205// read the next raw digit
206// returns kFALSE if there is no digit left
207
6727e2db 208 fPrevModuleID = fModuleID;
209
210 while (ReadNextShort()) {
211
10bb1a34 212 fLastDDLID = fDDLID;
213 fDDLID = fRawReader->GetDDLID();
214 if (fDDLID>=0 && fDDLID<20) {
215 if (!fCalHeadRead[fDDLID]) {
216 if (fLastDDLID!=-1) { // if not the first equipment for this event
217 fEqPLBytesRead -= 2;
218 CheckHeaderAndTrailerCount(fLastDDLID);
219 }
3f917533 220 if (ReadCalibHeader()>=0) continue;
6727e2db 221 }
222 }
223 else {
10bb1a34 224 TString errMess = Form("Error in DDL number (=%d) , setting it to 19",fDDLID);
225 AliError(errMess.Data());
226 fRawReader->AddMajorErrorLog(kDDLNumberErr,errMess.Data());
227 if (fAdvancedErrorLog) fAdvLogger->AddMessage(errMess.Data());
228 fDDLID=19;
6727e2db 229 }
230
231 if ((fData & 0xC000) == 0x4000) { // header
10bb1a34 232 if (fHeaderOrTrailerReadLast) {
233 TString errMess = "Chip trailer missing";
234 AliError(errMess.Data());
235 fRawReader->AddMajorErrorLog(kTrailerMissingErr,errMess.Data());
236 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerMissingErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
237 }
238 fHeaderOrTrailerReadLast = kTRUE;
239 fEqPLChipHeadersRead++;
6727e2db 240 fHitCount = 0;
10bb1a34 241 UShort_t eventCounter = (fData >> 4) & 0x007F;
242 if (fEventCounter < 0) {
243 fEventCounter = eventCounter;
6727e2db 244 }
10bb1a34 245 else if (eventCounter != fEventCounter) {
246 TString errMess;
247 if (fEqPLChipHeadersRead==1) {
248 errMess = Form("Mismatching event counters between this equipment and the previous: %d != %d",
249 eventCounter,fEventCounter);
250 }
251 else {
252 errMess = Form("Mismatching event counters between this chip header and the previous: %d != %d",
253 eventCounter,fEventCounter);
254 }
255 fEventCounter = eventCounter;
256 AliError(errMess.Data());
257 fRawReader->AddMajorErrorLog(kEventCounterErr,errMess.Data());
258 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kEventCounterErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
6727e2db 259 }
260 fChipAddr = fData & 0x000F;
261 if (fChipAddr>9) {
10bb1a34 262 TString errMess = Form("Overflow chip address %d - set to 0",fChipAddr);
263 AliError(errMess.Data());
264 fRawReader->AddMajorErrorLog(kChipAddrErr,errMess.Data());
265 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kChipAddrErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
266 fChipAddr=0;
6727e2db 267 }
268 fHalfStaveNr = (fData & 0x3800)>>11;
269 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
10bb1a34 270 TString errMess = Form("Half stave number error: %d - set to 0",fHalfStaveNr);
271 AliError(errMess.Data());
272 fRawReader->AddMajorErrorLog(kHSNumberErr,errMess.Data());
273 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHSNumberErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
274 fHalfStaveNr=0;
6727e2db 275 }
276 // translate ("online") ddl, hs, chip nr to ("offline") module id :
10bb1a34 277 fModuleID = GetOfflineModuleFromOnline(fDDLID,fHalfStaveNr,fChipAddr);
6727e2db 278 }
279 else if ((fData & 0xC000) == 0x0000) { // trailer
10bb1a34 280 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 0 ) {
281 TString errMess = "Fill word is missing";
282 AliError(errMess.Data());
283 fRawReader->AddMajorErrorLog(kFillMissingErr,errMess.Data());
284 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
285 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
286 else fFillOutOfSynch = kTRUE;
287 }
288 if (!fHeaderOrTrailerReadLast) {
289 TString errMess = "Trailer without previous header";
290 AliError(errMess.Data());
291 fRawReader->AddMajorErrorLog(kTrailerWithoutHeaderErr,errMess.Data());
292 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerWithoutHeaderErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
293 }
294 fHeaderOrTrailerReadLast = kFALSE;
295 fEqPLChipTrailersRead++;
6727e2db 296 UShort_t hitCount = fData & 0x1FFF;
297 if (hitCount != fHitCount){
10bb1a34 298 TString errMess = Form("Number of hits %d, while %d expected",fHitCount,hitCount);
299 AliError(errMess.Data());
300 fRawReader->AddMajorErrorLog(kNumberHitsErr,errMess.Data());
301 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kNumberHitsErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
6727e2db 302 }
303 }
304 else if ((fData & 0xC000) == 0x8000) { // pixel hit
10bb1a34 305 if (!fHeaderOrTrailerReadLast) {
306 TString errMess = "Chip header missing";
307 AliError(errMess.Data());
308 fRawReader->AddMajorErrorLog(kHeaderMissingErr,errMess.Data());
309 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
310 fHeaderOrTrailerReadLast = kTRUE;
311 }
6727e2db 312 fHitCount++;
313 fCol = (fData & 0x001F);
314 fRow = (fData >> 5) & 0x00FF;
315
10bb1a34 316 fCoord1 = GetOfflineColFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fCol);
317 fCoord2 = GetOfflineRowFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fRow);
6727e2db 318
319 return kTRUE;
320 }
321 else { // fill word
322 if ((fData & 0xC000) != 0xC000) {
10bb1a34 323 TString errMess = "Wrong fill word!";
324 AliError(errMess.Data());
325 fRawReader->AddMajorErrorLog(kWrongFillWordErr,errMess.Data());
326 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kWrongFillWordErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
327 }
328 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 2 ) {
329 TString errMess = "Fill word is unexpected";
330 AliError(errMess.Data());
331 fRawReader->AddMajorErrorLog(kFillUnexpectErr,errMess.Data());
332 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillUnexpectErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
333 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
334 else fFillOutOfSynch = kTRUE;
6727e2db 335 }
336 }
337
338 }
10bb1a34 339 if (fDDLID>=0 && fDDLID<20) {
340 CheckHeaderAndTrailerCount(fDDLID);
341 }
6727e2db 342 return kFALSE;
343}
10bb1a34 344//__________________________________________________________________________
345void AliITSRawStreamSPD::CheckHeaderAndTrailerCount(Int_t ddlID) {
346 // Checks that the number of header and trailers found for the ddl are as expected
347 if (fEqPLChipHeadersRead != fExpectedHeaderTrailerCount) {
348 TString errMess = Form("Chip header count inconsistent %d != %d (expected) for ddl %d",
349 fEqPLChipHeadersRead,fExpectedHeaderTrailerCount,ddlID);
350 AliError(errMess.Data());
351 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
352 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,-1,-1,errMess.Data());
353 }
354 if (fEqPLChipTrailersRead != fExpectedHeaderTrailerCount) {
355 TString errMess = Form("Chip trailer count inconsistent %d != %d (expected) for ddl %d",
356 fEqPLChipTrailersRead,fExpectedHeaderTrailerCount,ddlID);
357 AliError(errMess.Data());
358 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
359 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,-1,-1,errMess.Data());
360 }
361}
362//__________________________________________________________________________
363void AliITSRawStreamSPD::ActivateAdvancedErrorLog(Bool_t activate, AliITSRawStreamSPDErrorLog* advLogger) {
364 // Activate the advanced error logging.
365 // Logger object has to be created elsewhere and a pointer sent here.
366 fAdvancedErrorLog=activate;
367 if (activate && advLogger!=NULL) {
368 fAdvLogger = advLogger;
369 }
370 if (fAdvLogger==NULL) {
371 fAdvancedErrorLog=kFALSE;
372 }
373}
374//__________________________________________________________________________
375const Char_t* AliITSRawStreamSPD::GetErrorName(UInt_t errorCode) {
376 // Returns a string for each error code
377 if (errorCode==kTotal) return "All Errors";
378 else if (errorCode==kHeaderMissingErr) return "Header Missing";
379 else if (errorCode==kTrailerMissingErr) return "Trailer Missing";
380 else if (errorCode==kTrailerWithoutHeaderErr) return "Trailer Unexpected";
381 else if (errorCode==kHeaderCountErr) return "Header Count Wrong";
382 else if (errorCode==kTrailerCountErr) return "Trailer Count Wrong";
383 else if (errorCode==kFillUnexpectErr) return "Fill Unexpected";
384 else if (errorCode==kFillMissingErr) return "Fill Missing";
385 else if (errorCode==kWrongFillWordErr) return "Fill Word Wrong";
386 else if (errorCode==kNumberHitsErr) return "Hit Count Wrong";
387 else if (errorCode==kEventCounterErr) return "Event Counter Error";
388 else if (errorCode==kDDLNumberErr) return "DDL Number Error";
389 else if (errorCode==kHSNumberErr) return "HS Number Error";
390 else if (errorCode==kChipAddrErr) return "Chip Address Error";
391 else if (errorCode==kCalHeaderLengthErr) return "Calib Header Length Error";
392 else return "";
393}
394//__________________________________________________________________________
6727e2db 395Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
396 // Reads the half stave present status from the block attributes
397 Int_t ddlID = fRawReader->GetDDLID();
398 if (ddlID==-1) {
6727e2db 399 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
400 return kFALSE;
401 }
402 else {
403 if (hs>=6) {
6727e2db 404 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
405 return kFALSE;
406 }
407 UChar_t attr = fRawReader->GetBlockAttributes();
408 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
409 return kFALSE;
410 }
411 else {
412 return kTRUE;
413 }
414 }
415}
10bb1a34 416//__________________________________________________________________________
6727e2db 417Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
418 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
419 else return kFALSE;
420}
421Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
422 if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
423 else return kFALSE;
424}
425UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
426 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
427 else return 0;
428}
429UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
430 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
431 else return 0;
432}
433UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
434 if (hs<6) return fCalHeadWord[hs+10];
435 else return 0;
436}
437Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
438 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
439 else return kFALSE;
440}
10bb1a34 441//__________________________________________________________________________
6727e2db 442Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
443 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
444 else return 240;
445}
10bb1a34 446//__________________________________________________________________________
6727e2db 447Bool_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) {
448 // converts offline coordinates to online
449 eq = GetOnlineEqIdFromOffline(module);
450 hs = GetOnlineHSFromOffline(module);
451 chip = GetOnlineChipFromOffline(module,colM);
452 col = GetOnlineColFromOffline(module,colM);
453 row = GetOnlineRowFromOffline(module,rowM);
454 if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
455 else return kTRUE;
456}
10bb1a34 457//__________________________________________________________________________
6727e2db 458Bool_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) {
459 // converts online coordinates to offline
460 module = GetOfflineModuleFromOnline(eq,hs,chip);
461 colM = GetOfflineColFromOnline(eq,hs,chip,col);
462 rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
463 if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
464 else return kTRUE;
465}
10bb1a34 466//__________________________________________________________________________
6727e2db 467UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
468 // offline->online (eq)
469 for (UInt_t eqId=0; eqId<20; eqId++) {
470 for (UInt_t iModule=0; iModule<12; iModule++) {
471 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
472 }
473 }
474 return 20; // error
475}
10bb1a34 476//__________________________________________________________________________
6727e2db 477UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
478 // offline->online (hs)
479 for (UInt_t eqId=0; eqId<20; eqId++) {
480 for (UInt_t iModule=0; iModule<12; iModule++) {
481 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
482 }
483 }
484 return 6; // error
485}
10bb1a34 486//__________________________________________________________________________
6727e2db 487UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
488 // offline->online (chip)
489 for (UInt_t eq=0; eq<20; eq++) {
490 for (UInt_t iModule=0; iModule<12; iModule++) {
491 if (GetModuleNumber(eq,iModule)==(Int_t)module) {
492 if (eq<10) { // side A
493 return (159-colM)/32 + 5*(iModule%2);
494 }
495 else { // side C
496 return colM/32 + 5*(iModule%2);
497 }
498 }
499 }
500 }
501 return 10; // error
502}
10bb1a34 503//__________________________________________________________________________
6727e2db 504UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
505 // offline->online (col)
506 if (module<80) { // inner layer
507 return colM%32;
508 }
509 else if (module<240) { // outer layer
510 return (159-colM)%32;
511 }
512 return 32; // error
513}
10bb1a34 514//__________________________________________________________________________
6727e2db 515UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
516 // offline->online (row)
517 if (module<80) { // inner layer
518 return rowM;
519 }
520 else if (module<240) { // outer layer
521 return (255-rowM);
522 }
523 return 256; // error
524}
10bb1a34 525//__________________________________________________________________________
6727e2db 526UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
527 // online->offline (module)
528 if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
529 else return 240;
530}
10bb1a34 531//__________________________________________________________________________
6727e2db 532UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
533 // online->offline (col)
534 if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
535 UInt_t offset = 32 * (chip % 5);
536 if (hs<2) {
537 if (eqId<10) {
538 return 159 - (31-col + offset); // inner layer, side A
539 }
540 else {
541 return col + offset; // inner layer, side C
542 }
543 }
544 else {
545 if (eqId<10) {
546 return 159 - (col + offset); // outer layer, side A
547 }
548 else {
549 return 31-col + offset; // outer layer, side C
550 }
551 }
552}
10bb1a34 553//__________________________________________________________________________
6727e2db 554UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
555 // online->offline (row)
556 if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error
557 if (hs<2) {
558 return row;
559 }
560 else {
561 return 255-row;
562 }
563}
10bb1a34 564
565
566
567