]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSPD.cxx
Possibilty to assocate good PID flag to tracks not good for PID eliminated
[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),
de12e454 55 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),fCalHeadLen(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),
de12e454 86 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),fCalHeadLen(0),
d9c68335 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
de12e454 187 // check router error bits:
188 UInt_t statusBits = fRawReader->GetStatusBits();
189 if ((statusBits >> 5) & 1) { // linkrx/detector fatal error bit
190 TString errMess = "LinkRx Error Bit Set";
191 AliError(errMess.Data());
192 fRawReader->AddMajorErrorLog(kLinkRxDetectorFatalErr,errMess.Data());
193 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kLinkRxDetectorFatalErr,ddlID,-1,-1,errMess.Data());
194 }
195 if ((statusBits >> 12) & 1) { // trigger sequence monitor error bit
196 TString errMess = "TSM Trigger Error Bit Set";
197 AliError(errMess.Data());
198 fRawReader->AddMajorErrorLog(kTSMtriggerErr,errMess.Data());
199 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTSMtriggerErr,ddlID,-1,-1,errMess.Data());
200 }
201 if (fRawReader->TestBlockAttribute(7)) { // bunch crossing difference error bit
202 TString errMess = "BC Difference Error Bit Set";
203 AliError(errMess.Data());
204 fRawReader->AddMajorErrorLog(kBCdiffErr,errMess.Data());
205 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kBCdiffErr,ddlID,-1,-1,errMess.Data());
206 }
207
b696414b 208 // set eq active and the participating half-staves (for access from outside this class),
478d804c 209 // set what number of chip headers/trailers to expect (for the moment not used)
b696414b 210 fActiveEq[ddlID]=kTRUE;
d9c68335 211 fExpectedHeaderTrailerCount = 0;
212 for (UInt_t hs=0; hs<6; hs++) {
b696414b 213 if (!fRawReader->TestBlockAttribute(hs)) {
214 fActiveHS[ddlID][hs]=kTRUE;
215 fExpectedHeaderTrailerCount+=10;
216 }
217 else {
218 fActiveHS[ddlID][hs]=kFALSE;
219 }
d9c68335 220 }
221
c42b9ed0 222 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
d9c68335 223 if (fRawReader->TestBlockAttribute(6)) { // is the calib header present?
c42b9ed0 224 if (ReadNextInt()) {
72600597 225 // length of cal header:
de12e454 226 fCalHeadLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
227 if (fCalHeadLen>kCalHeadLenMax) {
228 TString errMess = Form("Header length %d > max = %d",fCalHeadLen,kCalHeadLenMax);
d9c68335 229 AliError(errMess.Data());
230 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
231 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
3f917533 232 return -1;
c42b9ed0 233 }
d9c68335 234 else {
de12e454 235 for (UInt_t iword=0; iword<fCalHeadLen; iword++) {
c42b9ed0 236 if (ReadNextInt()) {
237 fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
238 }
239 else {
d9c68335 240 TString errMess = "Header length problem";
241 AliError(errMess.Data());
242 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
243 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
3f917533 244 return -1;
c42b9ed0 245 }
246 }
de12e454 247 return fCalHeadLen;
72600597 248 }
249 }
250 }
c42b9ed0 251
3f917533 252 return -1;
72600597 253}
d9c68335 254//__________________________________________________________________________
255Bool_t AliITSRawStreamSPD::Next() {
2906f4c2 256// read the next raw digit
257// returns kFALSE if there is no digit left
258
259 fPrevModuleID = fModuleID;
c42b9ed0 260
72600597 261 while (ReadNextShort()) {
c42b9ed0 262
d9c68335 263 fLastDDLID = fDDLID;
264 fDDLID = fRawReader->GetDDLID();
265 if (fDDLID>=0 && fDDLID<20) {
266 if (!fCalHeadRead[fDDLID]) {
267 if (fLastDDLID!=-1) { // if not the first equipment for this event
268 fEqPLBytesRead -= 2;
b696414b 269 // The next line is commented, since we do not have the information how many chips to expect
270 // CheckHeaderAndTrailerCount(fLastDDLID);
d9c68335 271 }
b696414b 272 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 273 }
274 }
275 else {
d9c68335 276 TString errMess = Form("Error in DDL number (=%d) , setting it to 19",fDDLID);
277 AliError(errMess.Data());
278 fRawReader->AddMajorErrorLog(kDDLNumberErr,errMess.Data());
279 if (fAdvancedErrorLog) fAdvLogger->AddMessage(errMess.Data());
280 fDDLID=19;
c42b9ed0 281 }
282
72600597 283 if ((fData & 0xC000) == 0x4000) { // header
d9c68335 284 if (fHeaderOrTrailerReadLast) {
285 TString errMess = "Chip trailer missing";
286 AliError(errMess.Data());
287 fRawReader->AddMajorErrorLog(kTrailerMissingErr,errMess.Data());
288 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerMissingErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
289 }
290 fHeaderOrTrailerReadLast = kTRUE;
291 fEqPLChipHeadersRead++;
2906f4c2 292 fHitCount = 0;
d9c68335 293 UShort_t eventCounter = (fData >> 4) & 0x007F;
294 if (fEventCounter < 0) {
295 fEventCounter = eventCounter;
72600597 296 }
d9c68335 297 else if (eventCounter != fEventCounter) {
298 TString errMess;
299 if (fEqPLChipHeadersRead==1) {
300 errMess = Form("Mismatching event counters between this equipment and the previous: %d != %d",
301 eventCounter,fEventCounter);
302 }
303 else {
304 errMess = Form("Mismatching event counters between this chip header and the previous: %d != %d",
305 eventCounter,fEventCounter);
306 }
307 fEventCounter = eventCounter;
308 AliError(errMess.Data());
309 fRawReader->AddMajorErrorLog(kEventCounterErr,errMess.Data());
310 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kEventCounterErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
2906f4c2 311 }
c42b9ed0 312 fChipAddr = fData & 0x000F;
313 if (fChipAddr>9) {
d9c68335 314 TString errMess = Form("Overflow chip address %d - set to 0",fChipAddr);
315 AliError(errMess.Data());
316 fRawReader->AddMajorErrorLog(kChipAddrErr,errMess.Data());
317 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kChipAddrErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
318 fChipAddr=0;
2906f4c2 319 }
c42b9ed0 320 fHalfStaveNr = (fData & 0x3800)>>11;
321 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
d9c68335 322 TString errMess = Form("Half stave number error: %d - set to 0",fHalfStaveNr);
323 AliError(errMess.Data());
324 fRawReader->AddMajorErrorLog(kHSNumberErr,errMess.Data());
325 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHSNumberErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
326 fHalfStaveNr=0;
2906f4c2 327 }
478d804c 328 fActiveChip[fDDLID][fHalfStaveNr][fChipAddr]=kTRUE;
329 fEventCounterFull[fDDLID][fHalfStaveNr][fChipAddr] = eventCounter;
c42b9ed0 330 // translate ("online") ddl, hs, chip nr to ("offline") module id :
d9c68335 331 fModuleID = GetOfflineModuleFromOnline(fDDLID,fHalfStaveNr,fChipAddr);
4f98b62b 332 }
333
72600597 334 else if ((fData & 0xC000) == 0x0000) { // trailer
d9c68335 335 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 0 ) {
336 TString errMess = "Fill word is missing";
337 AliError(errMess.Data());
338 fRawReader->AddMajorErrorLog(kFillMissingErr,errMess.Data());
339 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
340 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
341 else fFillOutOfSynch = kTRUE;
342 }
343 if (!fHeaderOrTrailerReadLast) {
344 TString errMess = "Trailer without previous header";
345 AliError(errMess.Data());
346 fRawReader->AddMajorErrorLog(kTrailerWithoutHeaderErr,errMess.Data());
347 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerWithoutHeaderErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
348 }
349 fHeaderOrTrailerReadLast = kFALSE;
350 fEqPLChipTrailersRead++;
4f98b62b 351 UShort_t hitCount = fData & 0x0FFF;
d9edae7b 352 if (hitCount != fHitCount){
d9c68335 353 TString errMess = Form("Number of hits %d, while %d expected",fHitCount,hitCount);
354 AliError(errMess.Data());
355 fRawReader->AddMajorErrorLog(kNumberHitsErr,errMess.Data());
356 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kNumberHitsErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
d9edae7b 357 }
4f98b62b 358 Bool_t errorBit = fData & 0x1000;
359 if (errorBit) {
360 TString errMess = Form("Trailer error bit set for chip %d,%d,%d",fDDLID,fHalfStaveNr,fChipAddr);
361 AliError(errMess.Data());
362 fRawReader->AddMajorErrorLog(kTrailerErrorBitErr,errMess.Data());
363 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerErrorBitErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
364 }
365 Bool_t fastorBit = fData & 0x2000;
366 fFastOrSignal[fDDLID][fHalfStaveNr][fChipAddr] = fastorBit;
d9edae7b 367 }
4f98b62b 368
72600597 369 else if ((fData & 0xC000) == 0x8000) { // pixel hit
d9c68335 370 if (!fHeaderOrTrailerReadLast) {
371 TString errMess = "Chip header missing";
372 AliError(errMess.Data());
373 fRawReader->AddMajorErrorLog(kHeaderMissingErr,errMess.Data());
374 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
375 fHeaderOrTrailerReadLast = kTRUE;
376 }
2906f4c2 377 fHitCount++;
c42b9ed0 378 fCol = (fData & 0x001F);
379 fRow = (fData >> 5) & 0x00FF;
380
d9c68335 381 fCoord1 = GetOfflineColFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fCol);
382 fCoord2 = GetOfflineRowFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fRow);
c42b9ed0 383
2906f4c2 384 return kTRUE;
4f98b62b 385 }
386
72600597 387 else { // fill word
d9edae7b 388 if ((fData & 0xC000) != 0xC000) {
d9c68335 389 TString errMess = "Wrong fill word!";
390 AliError(errMess.Data());
391 fRawReader->AddMajorErrorLog(kWrongFillWordErr,errMess.Data());
392 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kWrongFillWordErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
393 }
394 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 2 ) {
395 TString errMess = "Fill word is unexpected";
396 AliError(errMess.Data());
397 fRawReader->AddMajorErrorLog(kFillUnexpectErr,errMess.Data());
398 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillUnexpectErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
399 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
400 else fFillOutOfSynch = kTRUE;
d9edae7b 401 }
2906f4c2 402 }
403
404 }
d9c68335 405 if (fDDLID>=0 && fDDLID<20) {
b696414b 406 // The next line is commented, since we do not have the information how many chips to expect
407 // CheckHeaderAndTrailerCount(fDDLID);
d9c68335 408 }
2906f4c2 409 return kFALSE;
410}
d9c68335 411//__________________________________________________________________________
412void AliITSRawStreamSPD::CheckHeaderAndTrailerCount(Int_t ddlID) {
413 // Checks that the number of header and trailers found for the ddl are as expected
414 if (fEqPLChipHeadersRead != fExpectedHeaderTrailerCount) {
415 TString errMess = Form("Chip header count inconsistent %d != %d (expected) for ddl %d",
416 fEqPLChipHeadersRead,fExpectedHeaderTrailerCount,ddlID);
417 AliError(errMess.Data());
418 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
478d804c 419 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
d9c68335 420 }
421 if (fEqPLChipTrailersRead != fExpectedHeaderTrailerCount) {
422 TString errMess = Form("Chip trailer count inconsistent %d != %d (expected) for ddl %d",
423 fEqPLChipTrailersRead,fExpectedHeaderTrailerCount,ddlID);
424 AliError(errMess.Data());
425 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
478d804c 426 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
d9c68335 427 }
428}
429//__________________________________________________________________________
430void AliITSRawStreamSPD::ActivateAdvancedErrorLog(Bool_t activate, AliITSRawStreamSPDErrorLog* advLogger) {
431 // Activate the advanced error logging.
432 // Logger object has to be created elsewhere and a pointer sent here.
433 fAdvancedErrorLog=activate;
434 if (activate && advLogger!=NULL) {
435 fAdvLogger = advLogger;
436 }
437 if (fAdvLogger==NULL) {
438 fAdvancedErrorLog=kFALSE;
439 }
440}
441//__________________________________________________________________________
442const Char_t* AliITSRawStreamSPD::GetErrorName(UInt_t errorCode) {
443 // Returns a string for each error code
444 if (errorCode==kTotal) return "All Errors";
445 else if (errorCode==kHeaderMissingErr) return "Header Missing";
446 else if (errorCode==kTrailerMissingErr) return "Trailer Missing";
447 else if (errorCode==kTrailerWithoutHeaderErr) return "Trailer Unexpected";
448 else if (errorCode==kHeaderCountErr) return "Header Count Wrong";
449 else if (errorCode==kTrailerCountErr) return "Trailer Count Wrong";
450 else if (errorCode==kFillUnexpectErr) return "Fill Unexpected";
451 else if (errorCode==kFillMissingErr) return "Fill Missing";
452 else if (errorCode==kWrongFillWordErr) return "Fill Word Wrong";
453 else if (errorCode==kNumberHitsErr) return "Hit Count Wrong";
454 else if (errorCode==kEventCounterErr) return "Event Counter Error";
455 else if (errorCode==kDDLNumberErr) return "DDL Number Error";
456 else if (errorCode==kHSNumberErr) return "HS Number Error";
457 else if (errorCode==kChipAddrErr) return "Chip Address Error";
458 else if (errorCode==kCalHeaderLengthErr) return "Calib Header Length Error";
b696414b 459 else if (errorCode==kAdvEventCounterErr) return "Event Counter Error (Adv)";
460 else if (errorCode==kAdvEventCounterOrderErr) return "Event Counter Jump Error (Adv)";
4f98b62b 461 else if (errorCode==kTrailerErrorBitErr) return "Trailer Error Bit Set";
de12e454 462 else if (errorCode==kLinkRxDetectorFatalErr) return "LinkRx/Detector Fatal Error Bit Set";
463 else if (errorCode==kTSMtriggerErr) return "TSM Trigger Error Bit Set";
464 else if (errorCode==kBCdiffErr) return "BC Difference Error Bit Set";
d9c68335 465 else return "";
466}
467//__________________________________________________________________________
4f98b62b 468Bool_t AliITSRawStreamSPD::GetFastOrSignal(UInt_t eq, UInt_t hs, UInt_t chip) {
469 // returns if there was a fastor signal from this chip
470 if (eq>=20 || hs>=6 || chip>=10) {
471 TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
472 AliError(errMess.Data());
473 return kFALSE;
474 }
475 return fFastOrSignal[eq][hs][chip];
476}
477//__________________________________________________________________________
478d804c 478Bool_t AliITSRawStreamSPD::IsActiveEq(UInt_t eq) const {
479 // returns if the eq is active (seen in data)
480 if (eq>=20) {
481 TString errMess = Form("eq = %d out of bounds. Return kFALSE.",eq);
482 AliError(errMess.Data());
483 return kFALSE;
484 }
485 return fActiveEq[eq];
486}
487//__________________________________________________________________________
488Bool_t AliITSRawStreamSPD::IsActiveHS(UInt_t eq, UInt_t hs) const {
489 // returns if the hs is active (info from block attr)
490 if (eq>=20 || hs>=6) {
491 TString errMess = Form("eq,hs = %d,%d out of bounds. Return kFALSE.",eq,hs);
492 AliError(errMess.Data());
493 return kFALSE;
494 }
495 return fActiveHS[eq][hs];
496}
497//__________________________________________________________________________
498Bool_t AliITSRawStreamSPD::IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
499 // returns if the chip is active (seen in data)
500 if (eq>=20 || hs>=6 || chip>=10) {
501 TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
502 AliError(errMess.Data());
503 return kFALSE;
504 }
505 return fActiveChip[eq][hs][chip];
506}
507//__________________________________________________________________________
c42b9ed0 508Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
509 // Reads the half stave present status from the block attributes
b696414b 510 // This is not really needed anymore (kept for now in case it is still used somewhere).
511 // The same information can be reached through the "IsActiveHS" method instead.
c42b9ed0 512 Int_t ddlID = fRawReader->GetDDLID();
513 if (ddlID==-1) {
d9edae7b 514 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
c42b9ed0 515 return kFALSE;
516 }
517 else {
518 if (hs>=6) {
d9edae7b 519 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
c42b9ed0 520 return kFALSE;
521 }
522 UChar_t attr = fRawReader->GetBlockAttributes();
523 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
524 return kFALSE;
525 }
526 else {
527 return kTRUE;
528 }
529 }
530}
d9c68335 531//__________________________________________________________________________
478d804c 532Bool_t AliITSRawStreamSPD::IsEventCounterFullConsistent() const {
533 // checks if the event counter values are consistent within the event
534 Short_t reference = -1;
535 for (UInt_t eq=0; eq<20; eq++) {
536 if (IsActiveEq(eq)) {
537 for (UInt_t hs=0; hs<6; hs++) {
538 if (IsActiveHS(eq,hs)) {
539 for (UInt_t chip=0; chip<10; chip++) {
540 if (fEventCounterFull[eq][hs][chip]!=-1) {
541 if (reference==-1) reference = fEventCounterFull[eq][hs][chip];
542 if (fEventCounterFull[eq][hs][chip] != reference) return kFALSE;
543 }
544 }
545 }
546 }
547 }
548 }
549 return kTRUE;
550}
551//__________________________________________________________________________
552Short_t AliITSRawStreamSPD::GetEventCounterFullEq(UInt_t eq) const {
553 // if the eq is active; returns the event counter value
554 if (eq>=20) {
555 TString errMess = Form("eq (%d) out of bounds",eq);
556 AliError(errMess.Data());
557 return -1;
558 }
559 if (IsActiveEq(eq)) {
560 for (UInt_t hs=0; hs<6; hs++) {
561 if (IsActiveHS(eq,hs)) {
562 for (UInt_t chip=0; chip<10; chip++) {
563 if (fEventCounterFull[eq][hs][chip]!=-1) {
564 return fEventCounterFull[eq][hs][chip];
565 }
566 }
567 }
568 }
569 }
570 return -1;
571}
572//__________________________________________________________________________
573Short_t AliITSRawStreamSPD::GetEventCounterFullHS(UInt_t eq, UInt_t hs) const {
574 // if the eq,hs is active; returns the event counter value
575 if (eq>=20 || hs>=6) {
576 TString errMess = Form("eq,hs (%d,%d) out of bounds",eq,hs);
577 AliError(errMess.Data());
578 return -1;
579 }
580 if (IsActiveEq(eq)) {
581 if (IsActiveHS(eq,hs)) {
582 for (UInt_t chip=0; chip<10; chip++) {
583 if (fEventCounterFull[eq][hs][chip]!=-1) {
584 return fEventCounterFull[eq][hs][chip];
585 }
586 }
587 }
588 }
589 return -1;
590}
591//__________________________________________________________________________
592Short_t AliITSRawStreamSPD::GetEventCounterFullChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
593 // if the eq,hs,chip is active; returns the event counter value
594 if (eq>=20 || hs>=6 || chip>=10) {
595 TString errMess = Form("eq,hs,chip (%d,%d,%d) out of bounds",eq,hs,chip);
596 AliError(errMess.Data());
597 return -1;
598 }
599 if (IsActiveEq(eq)) {
600 if (IsActiveHS(eq,hs)) {
601 if (IsActiveChip(eq,hs,chip)) {
602 return fEventCounterFull[eq][hs][chip];
603 }
604 }
605 }
606 return -1;
607}
608//__________________________________________________________________________
de12e454 609Int_t AliITSRawStreamSPD::GetHword(UInt_t index) {
610 if (index<kCalHeadLenMax) return fCalHeadWord[index];
611 else return 0;
612}
c42b9ed0 613Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
614 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
615 else return kFALSE;
616}
617Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
618 if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
619 else return kFALSE;
620}
621UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
622 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
623 else return 0;
624}
625UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
626 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
627 else return 0;
628}
629UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
630 if (hs<6) return fCalHeadWord[hs+10];
631 else return 0;
632}
1fd93b67 633Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
634 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
635 else return kFALSE;
636}
de12e454 637UInt_t AliITSRawStreamSPD::GetFOHnumDacs() const {
638 return (fCalHeadLen-37)/2;
639}
640UInt_t AliITSRawStreamSPD::GetFOHdacIndex(UInt_t index) const {
641 if (index>=GetFOHnumDacs()) {
642 TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs());
643 AliError(errMess.Data());
644 return 0;
645 }
646 return fCalHeadWord[7+index*2];
647}
648UInt_t AliITSRawStreamSPD::GetFOHdacValue(UInt_t index) const {
649 if (index>=GetFOHnumDacs()) {
650 TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs());
651 AliError(errMess.Data());
652 return 0;
653 }
654 return fCalHeadWord[7+1+index*2];
655}
656UInt_t AliITSRawStreamSPD::GetFOHchipCount(UInt_t hs, UInt_t chip) const {
657 if (hs<6 && chip<10) {
658 if (chip%2==0) {
659 return ((fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] >> 16) & 0x0000ffff);
660 }
661 else {
662 return (fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] & 0x0000ffff);
663 }
664 }
665 else return 0;
666}
d9c68335 667//__________________________________________________________________________
6727e2db 668Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
669 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
670 else return 240;
671}
d9c68335 672//__________________________________________________________________________
6727e2db 673Bool_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) {
674 // converts offline coordinates to online
675 eq = GetOnlineEqIdFromOffline(module);
676 hs = GetOnlineHSFromOffline(module);
677 chip = GetOnlineChipFromOffline(module,colM);
678 col = GetOnlineColFromOffline(module,colM);
679 row = GetOnlineRowFromOffline(module,rowM);
680 if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
681 else return kTRUE;
682}
d9c68335 683//__________________________________________________________________________
6727e2db 684Bool_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) {
685 // converts online coordinates to offline
686 module = GetOfflineModuleFromOnline(eq,hs,chip);
687 colM = GetOfflineColFromOnline(eq,hs,chip,col);
688 rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
689 if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
690 else return kTRUE;
691}
d9c68335 692//__________________________________________________________________________
6727e2db 693UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
694 // offline->online (eq)
695 for (UInt_t eqId=0; eqId<20; eqId++) {
696 for (UInt_t iModule=0; iModule<12; iModule++) {
697 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
698 }
699 }
700 return 20; // error
701}
d9c68335 702//__________________________________________________________________________
6727e2db 703UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
704 // offline->online (hs)
705 for (UInt_t eqId=0; eqId<20; eqId++) {
706 for (UInt_t iModule=0; iModule<12; iModule++) {
707 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
708 }
709 }
710 return 6; // error
711}
d9c68335 712//__________________________________________________________________________
6727e2db 713UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
714 // offline->online (chip)
715 for (UInt_t eq=0; eq<20; eq++) {
716 for (UInt_t iModule=0; iModule<12; iModule++) {
717 if (GetModuleNumber(eq,iModule)==(Int_t)module) {
49c66823 718 if (module<80) {
719 if (eq<10) { // side A
720 return (159-colM)/32 + 5*(iModule%2);
721 }
722 else { // side C
723 return colM/32 + 5*(iModule%2);
724 }
63244738 725 }
49c66823 726 else if (module<240) {
727 if (eq<10) { // side A
728 return colM/32 + 5*(iModule%2);
729 }
730 else { // side C
731 return (159-colM)/32 + 5*(iModule%2);
732 }
63244738 733 }
6727e2db 734 }
735 }
736 }
737 return 10; // error
738}
d9c68335 739//__________________________________________________________________________
6727e2db 740UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
741 // offline->online (col)
63244738 742 if (module<80) { // inner layer
743 return colM%32;
744 }
745 else if (module<240) { // outer layer
49c66823 746 return colM%32;
63244738 747 }
748 return 32; // error
6727e2db 749}
d9c68335 750//__________________________________________________________________________
6727e2db 751UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
752 // offline->online (row)
63244738 753 if (module<80) { // inner layer
49c66823 754 return (255-rowM);
63244738 755 }
756 else if (module<240) { // outer layer
757 return (255-rowM);
758 }
759 return 256; // error
6727e2db 760}
d9c68335 761//__________________________________________________________________________
6727e2db 762UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
763 // online->offline (module)
764 if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
765 else return 240;
766}
d9c68335 767//__________________________________________________________________________
b457135f 768UInt_t AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
769 // online->offline (chip key: 0-1199)
770 if (eqId<20 && hs<6 && chip<10) {
771 UInt_t module = GetOfflineModuleFromOnline(eqId,hs,chip);
772 UInt_t chipInModule = ( chip>4 ? chip-5 : chip );
773 if(eqId>9) chipInModule = 4 - chipInModule; // side C only
774 return (module*5 + chipInModule);
775 } else return 1200;
776}
777//__________________________________________________________________________
6727e2db 778UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
779 // online->offline (col)
780 if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
781 UInt_t offset = 32 * (chip % 5);
63244738 782 if (hs<2) {
783 if (eqId<10) {
784 return 159 - (31-col + offset); // inner layer, side A
785 }
786 else {
787 return col + offset; // inner layer, side C
788 }
789 }
790 else {
791 if (eqId<10) {
49c66823 792 return (col + offset); // outer layer, side A
63244738 793 }
794 else {
49c66823 795 return 159 - (31-col + offset); // outer layer, side C
63244738 796 }
797 }
6727e2db 798}
d9c68335 799//__________________________________________________________________________
6727e2db 800UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
801 // online->offline (row)
802 if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error
49c66823 803 return 255-row;
6727e2db 804}
de12e454 805