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