]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSPD.cxx
### files: AliTPCTempMap.h (.cxx)
[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;
478d804c 73 for (UInt_t hs=0; hs<6; hs++) {
74 fActiveHS[eq][hs]=kFALSE;
75 for (UInt_t chip=0; chip<10; chip++) {
76 fActiveChip[eq][hs][chip]=kFALSE;
77 fEventCounterFull[eq][hs][chip] = -1;
78 }
79 }
b696414b 80 }
c42b9ed0 81 NewEvent();
2906f4c2 82}
d9c68335 83//__________________________________________________________________________
84AliITSRawStreamSPD::AliITSRawStreamSPD(const AliITSRawStreamSPD& rstream) :
85 AliITSRawStream(rstream.fRawReader),
86 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),
87 fData(0),fOffset(0),fHitCount(0),
88 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
89 fFirstWord(kTRUE),fPrevEventId(0xffffffff),
90 fEqPLBytesRead(0),fEqPLChipHeadersRead(0),fEqPLChipTrailersRead(0),
91 fHeaderOrTrailerReadLast(kFALSE),fExpectedHeaderTrailerCount(0),
92 fFillOutOfSynch(kFALSE),fDDLID(-1),fLastDDLID(-1),fAdvancedErrorLog(kFALSE),
93 fAdvLogger(NULL)
72600597 94{
d9c68335 95 // copy constructor
96 AliError("Copy constructor should not be used.");
97}
98//__________________________________________________________________________
99AliITSRawStreamSPD& AliITSRawStreamSPD::operator=(const AliITSRawStreamSPD& rstream) {
100 // assignment operator
101 if (this!=&rstream) {}
102 AliError("Assignment opertator should not be used.");
103 return *this;
104}
105//__________________________________________________________________________
106Bool_t AliITSRawStreamSPD::ReadNextShort() {
c42b9ed0 107 // read next 16 bit word into fData
72600597 108 if (fFirstWord) {
72600597 109 Bool_t b1 = fRawReader->ReadNextChar(fDataChar1);
110 if (!b1) return kFALSE;
111 Bool_t b2, b3, b4;
112 b2 = fRawReader->ReadNextChar(fDataChar2);
113 b3 = fRawReader->ReadNextChar(fDataChar3);
114 b4 = fRawReader->ReadNextChar(fDataChar4);
115 if (!(b2 && b3 && b4)) {
116 return kFALSE;
117 }
118 fData = fDataChar3+(fDataChar4<<8);
c52bf554 119 const UInt_t *intPtr = fRawReader->GetEventId();
120 if (intPtr!=0) {
121 if (*intPtr!=fPrevEventId) { // if new event...
122 NewEvent();
123 fPrevEventId=*intPtr;
124 }
c42b9ed0 125 }
126 fFirstWord=kFALSE;
72600597 127 }
128 else {
129 fFirstWord=kTRUE;
130 fData = fDataChar1+(fDataChar2<<8);
131 }
d9c68335 132 fEqPLBytesRead+=2;
133
72600597 134 return kTRUE;
135}
d9c68335 136//__________________________________________________________________________
137Bool_t AliITSRawStreamSPD::ReadNextInt() {
c42b9ed0 138 // reads next 32 bit into fDataChar1..4
139 // (if first 16 bits read already, just completes the present word)
140 if (fFirstWord) {
141 if (ReadNextShort() && ReadNextShort()) {
142 return kTRUE;
143 }
144 }
145 else {
146 if (ReadNextShort()) {
147 return kTRUE;
148 }
149 }
150 return kFALSE;
151}
d9c68335 152//__________________________________________________________________________
153void AliITSRawStreamSPD::NewEvent() {
c42b9ed0 154 // call this to reset flags for a new event
155 for (UInt_t eqId=0; eqId<20; eqId++) {
156 fCalHeadRead[eqId]=kFALSE;
157 }
d9c68335 158 fEventCounter = -1;
159 fDDLID = -1;
160 fLastDDLID = -1;
4f98b62b 161 for (UInt_t eq=0; eq<20; eq++) {
162 for (UInt_t hs=0; hs<6; hs++) {
163 for (UInt_t chip=0; chip<10; chip++) {
164 fFastOrSignal[eq][hs][chip] = kFALSE;
165 }
166 }
167 }
c42b9ed0 168}
d9c68335 169//__________________________________________________________________________
3f917533 170Int_t AliITSRawStreamSPD::ReadCalibHeader() {
b696414b 171 // needs to be called in the beginning of each equipment data
c42b9ed0 172 // read the extra calibration header
3f917533 173 // returns the length of the header if it is present, -1 otherwise
72600597 174
c42b9ed0 175 Int_t ddlID = fRawReader->GetDDLID();
176 if (ddlID==-1) { // we may need to read one word to get the blockAttr
3f917533 177 if (!ReadNextShort()) return -1;
c42b9ed0 178 ddlID = fRawReader->GetDDLID();
179 }
d9c68335 180 // reset flags and counters
181 fEqPLBytesRead = 2;
182 fEqPLChipHeadersRead = 0;
183 fEqPLChipTrailersRead = 0;
184 fHeaderOrTrailerReadLast = kFALSE;
185 fFillOutOfSynch = kFALSE;
186
b696414b 187 // set eq active and the participating half-staves (for access from outside this class),
478d804c 188 // set what number of chip headers/trailers to expect (for the moment not used)
b696414b 189 fActiveEq[ddlID]=kTRUE;
d9c68335 190 fExpectedHeaderTrailerCount = 0;
191 for (UInt_t hs=0; hs<6; hs++) {
b696414b 192 if (!fRawReader->TestBlockAttribute(hs)) {
193 fActiveHS[ddlID][hs]=kTRUE;
194 fExpectedHeaderTrailerCount+=10;
195 }
196 else {
197 fActiveHS[ddlID][hs]=kFALSE;
198 }
d9c68335 199 }
200
c42b9ed0 201 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
d9c68335 202 if (fRawReader->TestBlockAttribute(6)) { // is the calib header present?
c42b9ed0 203 if (ReadNextInt()) {
72600597 204 // length of cal header:
205 UInt_t calLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
c42b9ed0 206 if (calLen>kCalHeadLenMax) {
d9c68335 207 TString errMess = Form("Header length %d > max = %d",calLen,kCalHeadLenMax);
208 AliError(errMess.Data());
209 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
210 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
3f917533 211 return -1;
c42b9ed0 212 }
d9c68335 213 else {
c42b9ed0 214 for (UInt_t iword=0; iword<calLen; iword++) {
215 if (ReadNextInt()) {
216 fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
217 }
218 else {
d9c68335 219 TString errMess = "Header length problem";
220 AliError(errMess.Data());
221 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
222 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
3f917533 223 return -1;
c42b9ed0 224 }
225 }
3f917533 226 return calLen;
72600597 227 }
228 }
229 }
c42b9ed0 230
3f917533 231 return -1;
72600597 232}
d9c68335 233//__________________________________________________________________________
234Bool_t AliITSRawStreamSPD::Next() {
2906f4c2 235// read the next raw digit
236// returns kFALSE if there is no digit left
237
238 fPrevModuleID = fModuleID;
c42b9ed0 239
72600597 240 while (ReadNextShort()) {
c42b9ed0 241
d9c68335 242 fLastDDLID = fDDLID;
243 fDDLID = fRawReader->GetDDLID();
244 if (fDDLID>=0 && fDDLID<20) {
245 if (!fCalHeadRead[fDDLID]) {
246 if (fLastDDLID!=-1) { // if not the first equipment for this event
247 fEqPLBytesRead -= 2;
b696414b 248 // The next line is commented, since we do not have the information how many chips to expect
249 // CheckHeaderAndTrailerCount(fLastDDLID);
d9c68335 250 }
b696414b 251 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 252 }
253 }
254 else {
d9c68335 255 TString errMess = Form("Error in DDL number (=%d) , setting it to 19",fDDLID);
256 AliError(errMess.Data());
257 fRawReader->AddMajorErrorLog(kDDLNumberErr,errMess.Data());
258 if (fAdvancedErrorLog) fAdvLogger->AddMessage(errMess.Data());
259 fDDLID=19;
c42b9ed0 260 }
261
72600597 262 if ((fData & 0xC000) == 0x4000) { // header
d9c68335 263 if (fHeaderOrTrailerReadLast) {
264 TString errMess = "Chip trailer missing";
265 AliError(errMess.Data());
266 fRawReader->AddMajorErrorLog(kTrailerMissingErr,errMess.Data());
267 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerMissingErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
268 }
269 fHeaderOrTrailerReadLast = kTRUE;
270 fEqPLChipHeadersRead++;
2906f4c2 271 fHitCount = 0;
d9c68335 272 UShort_t eventCounter = (fData >> 4) & 0x007F;
273 if (fEventCounter < 0) {
274 fEventCounter = eventCounter;
72600597 275 }
d9c68335 276 else if (eventCounter != fEventCounter) {
277 TString errMess;
278 if (fEqPLChipHeadersRead==1) {
279 errMess = Form("Mismatching event counters between this equipment and the previous: %d != %d",
280 eventCounter,fEventCounter);
281 }
282 else {
283 errMess = Form("Mismatching event counters between this chip header and the previous: %d != %d",
284 eventCounter,fEventCounter);
285 }
286 fEventCounter = eventCounter;
287 AliError(errMess.Data());
288 fRawReader->AddMajorErrorLog(kEventCounterErr,errMess.Data());
289 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kEventCounterErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
2906f4c2 290 }
c42b9ed0 291 fChipAddr = fData & 0x000F;
292 if (fChipAddr>9) {
d9c68335 293 TString errMess = Form("Overflow chip address %d - set to 0",fChipAddr);
294 AliError(errMess.Data());
295 fRawReader->AddMajorErrorLog(kChipAddrErr,errMess.Data());
296 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kChipAddrErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
297 fChipAddr=0;
2906f4c2 298 }
c42b9ed0 299 fHalfStaveNr = (fData & 0x3800)>>11;
300 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
d9c68335 301 TString errMess = Form("Half stave number error: %d - set to 0",fHalfStaveNr);
302 AliError(errMess.Data());
303 fRawReader->AddMajorErrorLog(kHSNumberErr,errMess.Data());
304 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHSNumberErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
305 fHalfStaveNr=0;
2906f4c2 306 }
478d804c 307 fActiveChip[fDDLID][fHalfStaveNr][fChipAddr]=kTRUE;
308 fEventCounterFull[fDDLID][fHalfStaveNr][fChipAddr] = eventCounter;
c42b9ed0 309 // translate ("online") ddl, hs, chip nr to ("offline") module id :
d9c68335 310 fModuleID = GetOfflineModuleFromOnline(fDDLID,fHalfStaveNr,fChipAddr);
4f98b62b 311 }
312
72600597 313 else if ((fData & 0xC000) == 0x0000) { // trailer
d9c68335 314 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 0 ) {
315 TString errMess = "Fill word is missing";
316 AliError(errMess.Data());
317 fRawReader->AddMajorErrorLog(kFillMissingErr,errMess.Data());
318 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
319 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
320 else fFillOutOfSynch = kTRUE;
321 }
322 if (!fHeaderOrTrailerReadLast) {
323 TString errMess = "Trailer without previous header";
324 AliError(errMess.Data());
325 fRawReader->AddMajorErrorLog(kTrailerWithoutHeaderErr,errMess.Data());
326 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerWithoutHeaderErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
327 }
328 fHeaderOrTrailerReadLast = kFALSE;
329 fEqPLChipTrailersRead++;
4f98b62b 330 UShort_t hitCount = fData & 0x0FFF;
d9edae7b 331 if (hitCount != fHitCount){
d9c68335 332 TString errMess = Form("Number of hits %d, while %d expected",fHitCount,hitCount);
333 AliError(errMess.Data());
334 fRawReader->AddMajorErrorLog(kNumberHitsErr,errMess.Data());
335 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kNumberHitsErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
d9edae7b 336 }
4f98b62b 337 Bool_t errorBit = fData & 0x1000;
338 if (errorBit) {
339 TString errMess = Form("Trailer error bit set for chip %d,%d,%d",fDDLID,fHalfStaveNr,fChipAddr);
340 AliError(errMess.Data());
341 fRawReader->AddMajorErrorLog(kTrailerErrorBitErr,errMess.Data());
342 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerErrorBitErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
343 }
344 Bool_t fastorBit = fData & 0x2000;
345 fFastOrSignal[fDDLID][fHalfStaveNr][fChipAddr] = fastorBit;
d9edae7b 346 }
4f98b62b 347
72600597 348 else if ((fData & 0xC000) == 0x8000) { // pixel hit
d9c68335 349 if (!fHeaderOrTrailerReadLast) {
350 TString errMess = "Chip header missing";
351 AliError(errMess.Data());
352 fRawReader->AddMajorErrorLog(kHeaderMissingErr,errMess.Data());
353 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
354 fHeaderOrTrailerReadLast = kTRUE;
355 }
2906f4c2 356 fHitCount++;
c42b9ed0 357 fCol = (fData & 0x001F);
358 fRow = (fData >> 5) & 0x00FF;
359
d9c68335 360 fCoord1 = GetOfflineColFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fCol);
361 fCoord2 = GetOfflineRowFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fRow);
c42b9ed0 362
2906f4c2 363 return kTRUE;
4f98b62b 364 }
365
72600597 366 else { // fill word
d9edae7b 367 if ((fData & 0xC000) != 0xC000) {
d9c68335 368 TString errMess = "Wrong fill word!";
369 AliError(errMess.Data());
370 fRawReader->AddMajorErrorLog(kWrongFillWordErr,errMess.Data());
371 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kWrongFillWordErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
372 }
373 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 2 ) {
374 TString errMess = "Fill word is unexpected";
375 AliError(errMess.Data());
376 fRawReader->AddMajorErrorLog(kFillUnexpectErr,errMess.Data());
377 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillUnexpectErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
378 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
379 else fFillOutOfSynch = kTRUE;
d9edae7b 380 }
2906f4c2 381 }
382
383 }
d9c68335 384 if (fDDLID>=0 && fDDLID<20) {
b696414b 385 // The next line is commented, since we do not have the information how many chips to expect
386 // CheckHeaderAndTrailerCount(fDDLID);
d9c68335 387 }
2906f4c2 388 return kFALSE;
389}
d9c68335 390//__________________________________________________________________________
391void AliITSRawStreamSPD::CheckHeaderAndTrailerCount(Int_t ddlID) {
392 // Checks that the number of header and trailers found for the ddl are as expected
393 if (fEqPLChipHeadersRead != fExpectedHeaderTrailerCount) {
394 TString errMess = Form("Chip header count inconsistent %d != %d (expected) for ddl %d",
395 fEqPLChipHeadersRead,fExpectedHeaderTrailerCount,ddlID);
396 AliError(errMess.Data());
397 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
478d804c 398 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
d9c68335 399 }
400 if (fEqPLChipTrailersRead != fExpectedHeaderTrailerCount) {
401 TString errMess = Form("Chip trailer count inconsistent %d != %d (expected) for ddl %d",
402 fEqPLChipTrailersRead,fExpectedHeaderTrailerCount,ddlID);
403 AliError(errMess.Data());
404 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
478d804c 405 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
d9c68335 406 }
407}
408//__________________________________________________________________________
409void AliITSRawStreamSPD::ActivateAdvancedErrorLog(Bool_t activate, AliITSRawStreamSPDErrorLog* advLogger) {
410 // Activate the advanced error logging.
411 // Logger object has to be created elsewhere and a pointer sent here.
412 fAdvancedErrorLog=activate;
413 if (activate && advLogger!=NULL) {
414 fAdvLogger = advLogger;
415 }
416 if (fAdvLogger==NULL) {
417 fAdvancedErrorLog=kFALSE;
418 }
419}
420//__________________________________________________________________________
421const Char_t* AliITSRawStreamSPD::GetErrorName(UInt_t errorCode) {
422 // Returns a string for each error code
423 if (errorCode==kTotal) return "All Errors";
424 else if (errorCode==kHeaderMissingErr) return "Header Missing";
425 else if (errorCode==kTrailerMissingErr) return "Trailer Missing";
426 else if (errorCode==kTrailerWithoutHeaderErr) return "Trailer Unexpected";
427 else if (errorCode==kHeaderCountErr) return "Header Count Wrong";
428 else if (errorCode==kTrailerCountErr) return "Trailer Count Wrong";
429 else if (errorCode==kFillUnexpectErr) return "Fill Unexpected";
430 else if (errorCode==kFillMissingErr) return "Fill Missing";
431 else if (errorCode==kWrongFillWordErr) return "Fill Word Wrong";
432 else if (errorCode==kNumberHitsErr) return "Hit Count Wrong";
433 else if (errorCode==kEventCounterErr) return "Event Counter Error";
434 else if (errorCode==kDDLNumberErr) return "DDL Number Error";
435 else if (errorCode==kHSNumberErr) return "HS Number Error";
436 else if (errorCode==kChipAddrErr) return "Chip Address Error";
437 else if (errorCode==kCalHeaderLengthErr) return "Calib Header Length Error";
b696414b 438 else if (errorCode==kAdvEventCounterErr) return "Event Counter Error (Adv)";
439 else if (errorCode==kAdvEventCounterOrderErr) return "Event Counter Jump Error (Adv)";
4f98b62b 440 else if (errorCode==kTrailerErrorBitErr) return "Trailer Error Bit Set";
d9c68335 441 else return "";
442}
443//__________________________________________________________________________
4f98b62b 444Bool_t AliITSRawStreamSPD::GetFastOrSignal(UInt_t eq, UInt_t hs, UInt_t chip) {
445 // returns if there was a fastor signal from this chip
446 if (eq>=20 || hs>=6 || chip>=10) {
447 TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
448 AliError(errMess.Data());
449 return kFALSE;
450 }
451 return fFastOrSignal[eq][hs][chip];
452}
453//__________________________________________________________________________
478d804c 454Bool_t AliITSRawStreamSPD::IsActiveEq(UInt_t eq) const {
455 // returns if the eq is active (seen in data)
456 if (eq>=20) {
457 TString errMess = Form("eq = %d out of bounds. Return kFALSE.",eq);
458 AliError(errMess.Data());
459 return kFALSE;
460 }
461 return fActiveEq[eq];
462}
463//__________________________________________________________________________
464Bool_t AliITSRawStreamSPD::IsActiveHS(UInt_t eq, UInt_t hs) const {
465 // returns if the hs is active (info from block attr)
466 if (eq>=20 || hs>=6) {
467 TString errMess = Form("eq,hs = %d,%d out of bounds. Return kFALSE.",eq,hs);
468 AliError(errMess.Data());
469 return kFALSE;
470 }
471 return fActiveHS[eq][hs];
472}
473//__________________________________________________________________________
474Bool_t AliITSRawStreamSPD::IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
475 // returns if the chip is active (seen in data)
476 if (eq>=20 || hs>=6 || chip>=10) {
477 TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
478 AliError(errMess.Data());
479 return kFALSE;
480 }
481 return fActiveChip[eq][hs][chip];
482}
483//__________________________________________________________________________
c42b9ed0 484Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
485 // Reads the half stave present status from the block attributes
b696414b 486 // This is not really needed anymore (kept for now in case it is still used somewhere).
487 // The same information can be reached through the "IsActiveHS" method instead.
c42b9ed0 488 Int_t ddlID = fRawReader->GetDDLID();
489 if (ddlID==-1) {
d9edae7b 490 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
c42b9ed0 491 return kFALSE;
492 }
493 else {
494 if (hs>=6) {
d9edae7b 495 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
c42b9ed0 496 return kFALSE;
497 }
498 UChar_t attr = fRawReader->GetBlockAttributes();
499 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
500 return kFALSE;
501 }
502 else {
503 return kTRUE;
504 }
505 }
506}
d9c68335 507//__________________________________________________________________________
478d804c 508Bool_t AliITSRawStreamSPD::IsEventCounterFullConsistent() const {
509 // checks if the event counter values are consistent within the event
510 Short_t reference = -1;
511 for (UInt_t eq=0; eq<20; eq++) {
512 if (IsActiveEq(eq)) {
513 for (UInt_t hs=0; hs<6; hs++) {
514 if (IsActiveHS(eq,hs)) {
515 for (UInt_t chip=0; chip<10; chip++) {
516 if (fEventCounterFull[eq][hs][chip]!=-1) {
517 if (reference==-1) reference = fEventCounterFull[eq][hs][chip];
518 if (fEventCounterFull[eq][hs][chip] != reference) return kFALSE;
519 }
520 }
521 }
522 }
523 }
524 }
525 return kTRUE;
526}
527//__________________________________________________________________________
528Short_t AliITSRawStreamSPD::GetEventCounterFullEq(UInt_t eq) const {
529 // if the eq is active; returns the event counter value
530 if (eq>=20) {
531 TString errMess = Form("eq (%d) out of bounds",eq);
532 AliError(errMess.Data());
533 return -1;
534 }
535 if (IsActiveEq(eq)) {
536 for (UInt_t hs=0; hs<6; hs++) {
537 if (IsActiveHS(eq,hs)) {
538 for (UInt_t chip=0; chip<10; chip++) {
539 if (fEventCounterFull[eq][hs][chip]!=-1) {
540 return fEventCounterFull[eq][hs][chip];
541 }
542 }
543 }
544 }
545 }
546 return -1;
547}
548//__________________________________________________________________________
549Short_t AliITSRawStreamSPD::GetEventCounterFullHS(UInt_t eq, UInt_t hs) const {
550 // if the eq,hs is active; returns the event counter value
551 if (eq>=20 || hs>=6) {
552 TString errMess = Form("eq,hs (%d,%d) out of bounds",eq,hs);
553 AliError(errMess.Data());
554 return -1;
555 }
556 if (IsActiveEq(eq)) {
557 if (IsActiveHS(eq,hs)) {
558 for (UInt_t chip=0; chip<10; chip++) {
559 if (fEventCounterFull[eq][hs][chip]!=-1) {
560 return fEventCounterFull[eq][hs][chip];
561 }
562 }
563 }
564 }
565 return -1;
566}
567//__________________________________________________________________________
568Short_t AliITSRawStreamSPD::GetEventCounterFullChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
569 // if the eq,hs,chip is active; returns the event counter value
570 if (eq>=20 || hs>=6 || chip>=10) {
571 TString errMess = Form("eq,hs,chip (%d,%d,%d) out of bounds",eq,hs,chip);
572 AliError(errMess.Data());
573 return -1;
574 }
575 if (IsActiveEq(eq)) {
576 if (IsActiveHS(eq,hs)) {
577 if (IsActiveChip(eq,hs,chip)) {
578 return fEventCounterFull[eq][hs][chip];
579 }
580 }
581 }
582 return -1;
583}
584//__________________________________________________________________________
c42b9ed0 585Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
586 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
587 else return kFALSE;
588}
589Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
590 if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
591 else return kFALSE;
592}
593UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
594 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
595 else return 0;
596}
597UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
598 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
599 else return 0;
600}
601UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
602 if (hs<6) return fCalHeadWord[hs+10];
603 else return 0;
604}
1fd93b67 605Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
606 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
607 else return kFALSE;
608}
d9c68335 609//__________________________________________________________________________
6727e2db 610Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
611 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
612 else return 240;
613}
d9c68335 614//__________________________________________________________________________
6727e2db 615Bool_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) {
616 // converts offline coordinates to online
617 eq = GetOnlineEqIdFromOffline(module);
618 hs = GetOnlineHSFromOffline(module);
619 chip = GetOnlineChipFromOffline(module,colM);
620 col = GetOnlineColFromOffline(module,colM);
621 row = GetOnlineRowFromOffline(module,rowM);
622 if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
623 else return kTRUE;
624}
d9c68335 625//__________________________________________________________________________
6727e2db 626Bool_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) {
627 // converts online coordinates to offline
628 module = GetOfflineModuleFromOnline(eq,hs,chip);
629 colM = GetOfflineColFromOnline(eq,hs,chip,col);
630 rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
631 if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
632 else return kTRUE;
633}
d9c68335 634//__________________________________________________________________________
6727e2db 635UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
636 // offline->online (eq)
637 for (UInt_t eqId=0; eqId<20; eqId++) {
638 for (UInt_t iModule=0; iModule<12; iModule++) {
639 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
640 }
641 }
642 return 20; // error
643}
d9c68335 644//__________________________________________________________________________
6727e2db 645UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
646 // offline->online (hs)
647 for (UInt_t eqId=0; eqId<20; eqId++) {
648 for (UInt_t iModule=0; iModule<12; iModule++) {
649 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
650 }
651 }
652 return 6; // error
653}
d9c68335 654//__________________________________________________________________________
6727e2db 655UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
656 // offline->online (chip)
657 for (UInt_t eq=0; eq<20; eq++) {
658 for (UInt_t iModule=0; iModule<12; iModule++) {
659 if (GetModuleNumber(eq,iModule)==(Int_t)module) {
49c66823 660 if (module<80) {
661 if (eq<10) { // side A
662 return (159-colM)/32 + 5*(iModule%2);
663 }
664 else { // side C
665 return colM/32 + 5*(iModule%2);
666 }
63244738 667 }
49c66823 668 else if (module<240) {
669 if (eq<10) { // side A
670 return colM/32 + 5*(iModule%2);
671 }
672 else { // side C
673 return (159-colM)/32 + 5*(iModule%2);
674 }
63244738 675 }
6727e2db 676 }
677 }
678 }
679 return 10; // error
680}
d9c68335 681//__________________________________________________________________________
6727e2db 682UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
683 // offline->online (col)
63244738 684 if (module<80) { // inner layer
685 return colM%32;
686 }
687 else if (module<240) { // outer layer
49c66823 688 return colM%32;
63244738 689 }
690 return 32; // error
6727e2db 691}
d9c68335 692//__________________________________________________________________________
6727e2db 693UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
694 // offline->online (row)
63244738 695 if (module<80) { // inner layer
49c66823 696 return (255-rowM);
63244738 697 }
698 else if (module<240) { // outer layer
699 return (255-rowM);
700 }
701 return 256; // error
6727e2db 702}
d9c68335 703//__________________________________________________________________________
6727e2db 704UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
705 // online->offline (module)
706 if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
707 else return 240;
708}
d9c68335 709//__________________________________________________________________________
6727e2db 710UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
711 // online->offline (col)
712 if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
713 UInt_t offset = 32 * (chip % 5);
63244738 714 if (hs<2) {
715 if (eqId<10) {
716 return 159 - (31-col + offset); // inner layer, side A
717 }
718 else {
719 return col + offset; // inner layer, side C
720 }
721 }
722 else {
723 if (eqId<10) {
49c66823 724 return (col + offset); // outer layer, side A
63244738 725 }
726 else {
49c66823 727 return 159 - (31-col + offset); // outer layer, side C
63244738 728 }
729 }
6727e2db 730}
d9c68335 731//__________________________________________________________________________
6727e2db 732UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
733 // online->offline (row)
734 if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error
49c66823 735 return 255-row;
6727e2db 736}
d9c68335 737
738
739
740