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