]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSPD.cxx
Mainly changes related to the added treatment of inactive detector parts in
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSPD.cxx
CommitLineData
2906f4c2 1/**************************************************************************
1fd93b67 2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
2906f4c2 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
c52bf554 16/* $Id$ */
2906f4c2 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"
d9edae7b 26#include "AliLog.h"
2906f4c2 27
28ClassImp(AliITSRawStreamSPD)
29
2906f4c2 30const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
63244738 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}
2906f4c2 51};
d9c68335 52//__________________________________________________________________________
2906f4c2 53AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) :
54 AliITSRawStream(rawReader),
d9c68335 55 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),
c42b9ed0 56 fData(0),fOffset(0),fHitCount(0),
57 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
d9c68335 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)
2906f4c2 63{
c42b9ed0 64 // create an object to read ITS SPD raw digits
30ec89b5 65 fRawReader->Reset();
362c9d61 66 fRawReader->Select("ITSSPD");
c42b9ed0 67 // reset calib header words
68 for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) {
69 fCalHeadWord[iword]=0xffffffff;
70 }
b696414b 71 for (UInt_t eq=0; eq<20; eq++) {
72 fActiveEq[eq]=kFALSE;
73 }
c42b9ed0 74 NewEvent();
2906f4c2 75}
d9c68335 76//__________________________________________________________________________
77AliITSRawStreamSPD::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)
72600597 87{
d9c68335 88 // copy constructor
89 AliError("Copy constructor should not be used.");
90}
91//__________________________________________________________________________
92AliITSRawStreamSPD& 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//__________________________________________________________________________
99Bool_t AliITSRawStreamSPD::ReadNextShort() {
c42b9ed0 100 // read next 16 bit word into fData
72600597 101 if (fFirstWord) {
72600597 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);
c52bf554 112 const UInt_t *intPtr = fRawReader->GetEventId();
113 if (intPtr!=0) {
114 if (*intPtr!=fPrevEventId) { // if new event...
115 NewEvent();
116 fPrevEventId=*intPtr;
117 }
c42b9ed0 118 }
119 fFirstWord=kFALSE;
72600597 120 }
121 else {
122 fFirstWord=kTRUE;
123 fData = fDataChar1+(fDataChar2<<8);
124 }
d9c68335 125 fEqPLBytesRead+=2;
126
72600597 127 return kTRUE;
128}
d9c68335 129//__________________________________________________________________________
130Bool_t AliITSRawStreamSPD::ReadNextInt() {
c42b9ed0 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}
d9c68335 145//__________________________________________________________________________
146void AliITSRawStreamSPD::NewEvent() {
c42b9ed0 147 // call this to reset flags for a new event
148 for (UInt_t eqId=0; eqId<20; eqId++) {
149 fCalHeadRead[eqId]=kFALSE;
150 }
d9c68335 151 fEventCounter = -1;
152 fDDLID = -1;
153 fLastDDLID = -1;
c42b9ed0 154}
d9c68335 155//__________________________________________________________________________
3f917533 156Int_t AliITSRawStreamSPD::ReadCalibHeader() {
b696414b 157 // needs to be called in the beginning of each equipment data
c42b9ed0 158 // read the extra calibration header
3f917533 159 // returns the length of the header if it is present, -1 otherwise
72600597 160
c42b9ed0 161 Int_t ddlID = fRawReader->GetDDLID();
162 if (ddlID==-1) { // we may need to read one word to get the blockAttr
3f917533 163 if (!ReadNextShort()) return -1;
c42b9ed0 164 ddlID = fRawReader->GetDDLID();
165 }
d9c68335 166 // reset flags and counters
167 fEqPLBytesRead = 2;
168 fEqPLChipHeadersRead = 0;
169 fEqPLChipTrailersRead = 0;
170 fHeaderOrTrailerReadLast = kFALSE;
171 fFillOutOfSynch = kFALSE;
172
b696414b 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;
d9c68335 176 fExpectedHeaderTrailerCount = 0;
177 for (UInt_t hs=0; hs<6; hs++) {
b696414b 178 if (!fRawReader->TestBlockAttribute(hs)) {
179 fActiveHS[ddlID][hs]=kTRUE;
180 fExpectedHeaderTrailerCount+=10;
181 }
182 else {
183 fActiveHS[ddlID][hs]=kFALSE;
184 }
d9c68335 185 }
186
c42b9ed0 187 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
d9c68335 188 if (fRawReader->TestBlockAttribute(6)) { // is the calib header present?
c42b9ed0 189 if (ReadNextInt()) {
72600597 190 // length of cal header:
191 UInt_t calLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
c42b9ed0 192 if (calLen>kCalHeadLenMax) {
d9c68335 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());
3f917533 197 return -1;
c42b9ed0 198 }
d9c68335 199 else {
c42b9ed0 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 {
d9c68335 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());
3f917533 209 return -1;
c42b9ed0 210 }
211 }
3f917533 212 return calLen;
72600597 213 }
214 }
215 }
c42b9ed0 216
3f917533 217 return -1;
72600597 218}
d9c68335 219//__________________________________________________________________________
220Bool_t AliITSRawStreamSPD::Next() {
2906f4c2 221// read the next raw digit
222// returns kFALSE if there is no digit left
223
224 fPrevModuleID = fModuleID;
c42b9ed0 225
72600597 226 while (ReadNextShort()) {
c42b9ed0 227
d9c68335 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;
b696414b 234 // The next line is commented, since we do not have the information how many chips to expect
235 // CheckHeaderAndTrailerCount(fLastDDLID);
d9c68335 236 }
b696414b 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)
c42b9ed0 238 }
239 }
240 else {
d9c68335 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;
c42b9ed0 246 }
247
72600597 248 if ((fData & 0xC000) == 0x4000) { // header
d9c68335 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++;
2906f4c2 257 fHitCount = 0;
d9c68335 258 UShort_t eventCounter = (fData >> 4) & 0x007F;
259 if (fEventCounter < 0) {
260 fEventCounter = eventCounter;
72600597 261 }
d9c68335 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());
2906f4c2 276 }
c42b9ed0 277 fChipAddr = fData & 0x000F;
278 if (fChipAddr>9) {
d9c68335 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;
2906f4c2 284 }
c42b9ed0 285 fHalfStaveNr = (fData & 0x3800)>>11;
286 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
d9c68335 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;
2906f4c2 292 }
c42b9ed0 293 // translate ("online") ddl, hs, chip nr to ("offline") module id :
d9c68335 294 fModuleID = GetOfflineModuleFromOnline(fDDLID,fHalfStaveNr,fChipAddr);
72600597 295 }
296 else if ((fData & 0xC000) == 0x0000) { // trailer
d9c68335 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++;
2906f4c2 313 UShort_t hitCount = fData & 0x1FFF;
d9edae7b 314 if (hitCount != fHitCount){
d9c68335 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());
d9edae7b 319 }
320 }
72600597 321 else if ((fData & 0xC000) == 0x8000) { // pixel hit
d9c68335 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 }
2906f4c2 329 fHitCount++;
c42b9ed0 330 fCol = (fData & 0x001F);
331 fRow = (fData >> 5) & 0x00FF;
332
d9c68335 333 fCoord1 = GetOfflineColFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fCol);
334 fCoord2 = GetOfflineRowFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fRow);
c42b9ed0 335
2906f4c2 336 return kTRUE;
72600597 337 }
338 else { // fill word
d9edae7b 339 if ((fData & 0xC000) != 0xC000) {
d9c68335 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;
d9edae7b 352 }
2906f4c2 353 }
354
355 }
d9c68335 356 if (fDDLID>=0 && fDDLID<20) {
b696414b 357 // The next line is commented, since we do not have the information how many chips to expect
358 // CheckHeaderAndTrailerCount(fDDLID);
d9c68335 359 }
2906f4c2 360 return kFALSE;
361}
d9c68335 362//__________________________________________________________________________
363void 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());
b696414b 377 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerCountErr,ddlID,-1,-1,errMess.Data());
d9c68335 378 }
379}
380//__________________________________________________________________________
381void 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//__________________________________________________________________________
393const 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";
b696414b 410 else if (errorCode==kAdvEventCounterErr) return "Event Counter Error (Adv)";
411 else if (errorCode==kAdvEventCounterOrderErr) return "Event Counter Jump Error (Adv)";
d9c68335 412 else return "";
413}
414//__________________________________________________________________________
c42b9ed0 415Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
416 // Reads the half stave present status from the block attributes
b696414b 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.
c42b9ed0 419 Int_t ddlID = fRawReader->GetDDLID();
420 if (ddlID==-1) {
d9edae7b 421 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
c42b9ed0 422 return kFALSE;
423 }
424 else {
425 if (hs>=6) {
d9edae7b 426 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
c42b9ed0 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}
d9c68335 438//__________________________________________________________________________
c42b9ed0 439Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
440 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
441 else return kFALSE;
442}
443Bool_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}
447UInt_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}
451UInt_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}
455UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
456 if (hs<6) return fCalHeadWord[hs+10];
457 else return 0;
458}
1fd93b67 459Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
460 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
461 else return kFALSE;
462}
d9c68335 463//__________________________________________________________________________
6727e2db 464Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
465 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
466 else return 240;
467}
d9c68335 468//__________________________________________________________________________
6727e2db 469Bool_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}
d9c68335 479//__________________________________________________________________________
6727e2db 480Bool_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}
d9c68335 488//__________________________________________________________________________
6727e2db 489UInt_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}
d9c68335 498//__________________________________________________________________________
6727e2db 499UInt_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}
d9c68335 508//__________________________________________________________________________
6727e2db 509UInt_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) {
49c66823 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 }
63244738 521 }
49c66823 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 }
63244738 529 }
6727e2db 530 }
531 }
532 }
533 return 10; // error
534}
d9c68335 535//__________________________________________________________________________
6727e2db 536UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
537 // offline->online (col)
63244738 538 if (module<80) { // inner layer
539 return colM%32;
540 }
541 else if (module<240) { // outer layer
49c66823 542 return colM%32;
63244738 543 }
544 return 32; // error
6727e2db 545}
d9c68335 546//__________________________________________________________________________
6727e2db 547UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
548 // offline->online (row)
63244738 549 if (module<80) { // inner layer
49c66823 550 return (255-rowM);
63244738 551 }
552 else if (module<240) { // outer layer
553 return (255-rowM);
554 }
555 return 256; // error
6727e2db 556}
d9c68335 557//__________________________________________________________________________
6727e2db 558UInt_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}
d9c68335 563//__________________________________________________________________________
6727e2db 564UInt_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);
63244738 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) {
49c66823 578 return (col + offset); // outer layer, side A
63244738 579 }
580 else {
49c66823 581 return 159 - (31-col + offset); // outer layer, side C
63244738 582 }
583 }
6727e2db 584}
d9c68335 585//__________________________________________________________________________
6727e2db 586UInt_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
49c66823 589 return 255-row;
6727e2db 590}
d9c68335 591
592
593
594