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