1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This class provides access to ITS SPD digits in raw data.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliITSRawStreamSPD.h"
25 #include "AliRawReader.h"
28 ClassImp(AliITSRawStreamSPD)
30 const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
31 { 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93},
32 {12,13, 8, 9, 96, 97,100,101,104,105,108,109},
33 {20,21,16,17,112,113,116,117,120,121,124,125},
34 {28,29,24,25,128,129,132,133,136,137,140,141},
35 {36,37,32,33,144,145,148,149,152,153,156,157},
36 {44,45,40,41,160,161,164,165,168,169,172,173},
37 {52,53,48,49,176,177,180,181,184,185,188,189},
38 {60,61,56,57,192,193,196,197,200,201,204,205},
39 {68,69,64,65,208,209,212,213,216,217,220,221},
40 {76,77,72,73,224,225,228,229,232,233,236,237},
41 { 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94},
42 {15,14,11,10, 99, 98,103,102,107,106,111,110},
43 {23,22,19,18,115,114,119,118,123,122,127,126},
44 {31,30,27,26,131,130,135,134,139,138,143,142},
45 {39,38,35,34,147,146,151,150,155,154,159,158},
46 {47,46,43,42,163,162,167,166,171,170,175,174},
47 {55,54,51,50,179,178,183,182,187,186,191,190},
48 {63,62,59,58,195,194,199,198,203,202,207,206},
49 {71,70,67,66,211,210,215,214,219,218,223,222},
50 {79,78,75,74,227,226,231,230,235,234,239,238}
52 //__________________________________________________________________________
53 AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) :
54 AliITSRawStream(rawReader),
55 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),fCalHeadLen(0),
56 fData(0),fOffset(0),fHitCount(0),
57 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
58 fFirstWord(kTRUE),fPrevEventId(0xffffffff),
59 fEqPLBytesRead(0),fEqPLChipHeadersRead(0),fEqPLChipTrailersRead(0),
60 fHeaderOrTrailerReadLast(kFALSE),fExpectedHeaderTrailerCount(0),
61 fFillOutOfSynch(kFALSE),fDDLID(-1),fLastDDLID(-1),fAdvancedErrorLog(kFALSE),
64 // create an object to read ITS SPD raw digits
66 fRawReader->Select("ITSSPD");
67 // reset calib header words
68 for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) {
69 fCalHeadWord[iword]=0xffffffff;
71 for (UInt_t eq=0; eq<20; eq++) {
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;
83 //__________________________________________________________________________
84 AliITSRawStreamSPD::AliITSRawStreamSPD(const AliITSRawStreamSPD& rstream) :
85 AliITSRawStream(rstream.fRawReader),
86 fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),fCalHeadLen(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),
96 AliError("Copy constructor should not be used.");
98 //__________________________________________________________________________
99 AliITSRawStreamSPD& AliITSRawStreamSPD::operator=(const AliITSRawStreamSPD& rstream) {
100 // assignment operator
101 if (this!=&rstream) {}
102 AliError("Assignment opertator should not be used.");
105 //__________________________________________________________________________
106 Bool_t AliITSRawStreamSPD::ReadNextShort() {
107 // read next 16 bit word into fData
109 Bool_t b1 = fRawReader->ReadNextChar(fDataChar1);
110 if (!b1) return kFALSE;
112 b2 = fRawReader->ReadNextChar(fDataChar2);
113 b3 = fRawReader->ReadNextChar(fDataChar3);
114 b4 = fRawReader->ReadNextChar(fDataChar4);
115 if (!(b2 && b3 && b4)) {
118 fData = fDataChar3+(fDataChar4<<8);
119 const UInt_t *intPtr = fRawReader->GetEventId();
121 if (*intPtr!=fPrevEventId) { // if new event...
123 fPrevEventId=*intPtr;
130 fData = fDataChar1+(fDataChar2<<8);
136 //__________________________________________________________________________
137 Bool_t AliITSRawStreamSPD::ReadNextInt() {
138 // reads next 32 bit into fDataChar1..4
139 // (if first 16 bits read already, just completes the present word)
141 if (ReadNextShort() && ReadNextShort()) {
146 if (ReadNextShort()) {
152 //__________________________________________________________________________
153 void AliITSRawStreamSPD::NewEvent() {
154 // call this to reset flags for a new event
155 for (UInt_t eqId=0; eqId<20; eqId++) {
156 fCalHeadRead[eqId]=kFALSE;
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;
169 //__________________________________________________________________________
170 Int_t AliITSRawStreamSPD::ReadCalibHeader() {
171 // needs to be called in the beginning of each equipment data
172 // read the extra calibration header
173 // returns the length of the header if it is present, -1 otherwise
175 Int_t ddlID = fRawReader->GetDDLID();
176 if (ddlID==-1) { // we may need to read one word to get the blockAttr
177 if (!ReadNextShort()) return -1;
178 ddlID = fRawReader->GetDDLID();
180 // reset flags and counters
182 fEqPLChipHeadersRead = 0;
183 fEqPLChipTrailersRead = 0;
184 fHeaderOrTrailerReadLast = kFALSE;
185 fFillOutOfSynch = kFALSE;
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());
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());
201 if (fRawReader->TestBlockAttribute(7)) { // bunch crossing difference error bit
202 TString errMess = "High Multiplicity Event Flag Set";
203 AliError(errMess.Data());
204 fRawReader->AddMajorErrorLog(kHighMultiplicityFlag,errMess.Data());
205 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHighMultiplicityFlag,ddlID,-1,-1,errMess.Data());
208 // set eq active and the participating half-staves (for access from outside this class),
209 // set what number of chip headers/trailers to expect (for the moment not used)
210 fActiveEq[ddlID]=kTRUE;
211 fExpectedHeaderTrailerCount = 0;
212 for (UInt_t hs=0; hs<6; hs++) {
213 if (!fRawReader->TestBlockAttribute(hs)) {
214 fActiveHS[ddlID][hs]=kTRUE;
215 fExpectedHeaderTrailerCount+=10;
218 fActiveHS[ddlID][hs]=kFALSE;
222 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
223 if (fRawReader->TestBlockAttribute(6)) { // is the calib header present?
225 // length of cal header:
226 fCalHeadLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
227 if (fCalHeadLen>kCalHeadLenMax) {
228 TString errMess = Form("Header length %d > max = %d",fCalHeadLen,kCalHeadLenMax);
229 AliError(errMess.Data());
230 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data());
231 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data());
235 for (UInt_t iword=0; iword<fCalHeadLen; iword++) {
237 fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
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());
254 //__________________________________________________________________________
255 Bool_t AliITSRawStreamSPD::Next() {
256 // read the next raw digit
257 // returns kFALSE if there is no digit left
259 fPrevModuleID = fModuleID;
261 while (ReadNextShort()) {
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
269 // The next line is commented, since we do not have the information how many chips to expect
270 // CheckHeaderAndTrailerCount(fLastDDLID);
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)
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());
283 Short_t hs = ((fData & 0x3800)>>11) ; Short_t chip=(fData & 0x000F); // -> for printouts
285 if ((fData & 0xC000) == 0x4000) { // header
286 if (fHeaderOrTrailerReadLast) {
287 TString errMess = Form("Chip trailer missing - (eq,hs,chip) = (%d,%d,%d)",fDDLID,hs,chip);
288 AliError(errMess.Data());
289 fRawReader->AddMajorErrorLog(kTrailerMissingErr,errMess.Data());
290 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerMissingErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
292 fHeaderOrTrailerReadLast = kTRUE;
293 fEqPLChipHeadersRead++;
295 UShort_t eventCounter = (fData >> 4) & 0x007F;
296 if (fEventCounter < 0) {
297 fEventCounter = eventCounter;
299 else if (eventCounter != fEventCounter) {
301 if (fEqPLChipHeadersRead==1) {
302 errMess = Form("Mismatching event counters between this equipment and the previous: %d != %d - (eq,hs,chip) = (%d,%d,%d)",
303 eventCounter,fEventCounter,fDDLID,hs,chip);
306 errMess = Form("Mismatching event counters between this chip header and the previous: %d != %d - (eq,hs,chip) = (%d,%d,%d)",
307 eventCounter,fEventCounter,fDDLID,hs,chip);
309 fEventCounter = eventCounter;
310 AliError(errMess.Data());
311 fRawReader->AddMajorErrorLog(kEventCounterErr,errMess.Data());
312 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kEventCounterErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
314 fChipAddr = fData & 0x000F;
316 TString errMess = Form("Overflow chip address %d - set to 0 (eq,hs) = (%d,%d)",fChipAddr,fDDLID,hs);
317 AliError(errMess.Data());
318 fRawReader->AddMajorErrorLog(kChipAddrErr,errMess.Data());
319 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kChipAddrErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
322 fHalfStaveNr = (fData & 0x3800)>>11;
323 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
324 TString errMess = Form("Half stave number error: %d - set to 0 - eq %d",fHalfStaveNr,fDDLID);
325 AliError(errMess.Data());
326 fRawReader->AddMajorErrorLog(kHSNumberErr,errMess.Data());
327 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHSNumberErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
330 fActiveChip[fDDLID][fHalfStaveNr][fChipAddr]=kTRUE;
331 fEventCounterFull[fDDLID][fHalfStaveNr][fChipAddr] = eventCounter;
332 // translate ("online") ddl, hs, chip nr to ("offline") module id :
333 fModuleID = GetOfflineModuleFromOnline(fDDLID,fHalfStaveNr,fChipAddr);
336 else if ((fData & 0xC000) == 0x0000) { // trailer
337 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 0 ) {
338 TString errMess = Form("Fill word is missing - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr);
339 AliError(errMess.Data());
340 fRawReader->AddMajorErrorLog(kFillMissingErr,errMess.Data());
341 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
342 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
343 else fFillOutOfSynch = kTRUE;
345 if (!fHeaderOrTrailerReadLast) {
346 TString errMess = Form("Trailer without previous header - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr);
347 AliError(errMess.Data());
348 fRawReader->AddMajorErrorLog(kTrailerWithoutHeaderErr,errMess.Data());
349 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerWithoutHeaderErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
351 fHeaderOrTrailerReadLast = kFALSE;
352 fEqPLChipTrailersRead++;
353 UShort_t hitCount = fData & 0x0FFF;
354 if (hitCount != fHitCount){
355 TString errMess = Form("Number of hits %d, while %d expected - (eq,hs,chip) = (%d,%d,%d)",fHitCount,hitCount,fDDLID,fHalfStaveNr,fChipAddr);
356 AliError(errMess.Data());
357 fRawReader->AddMajorErrorLog(kNumberHitsErr,errMess.Data());
358 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kNumberHitsErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
360 Bool_t errorBit = fData & 0x1000;
362 TString errMess = Form("Trailer error bit set for chip (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr);
363 AliError(errMess.Data());
364 fRawReader->AddMajorErrorLog(kTrailerErrorBitErr,errMess.Data());
365 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerErrorBitErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
367 Bool_t fastorBit = fData & 0x2000;
368 fFastOrSignal[fDDLID][fHalfStaveNr][fChipAddr] = fastorBit;
371 else if ((fData & 0xC000) == 0x8000) { // pixel hit
372 if (!fHeaderOrTrailerReadLast) {
373 TString errMess = Form("Chip header missing - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr);
374 AliError(errMess.Data());
375 fRawReader->AddMajorErrorLog(kHeaderMissingErr,errMess.Data());
376 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
377 fHeaderOrTrailerReadLast = kTRUE;
380 fCol = (fData & 0x001F);
381 fRow = (fData >> 5) & 0x00FF;
383 fCoord1 = GetOfflineColFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fCol);
384 fCoord2 = GetOfflineRowFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fRow);
390 if ((fData & 0xC000) != 0xC000) {
391 TString errMess = Form("Wrong fill word! - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr);
392 AliError(errMess.Data());
393 fRawReader->AddMajorErrorLog(kWrongFillWordErr,errMess.Data());
394 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kWrongFillWordErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
396 if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 2 ) {
397 TString errMess = Form("Fill word is unexpected - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr);
398 AliError(errMess.Data());
399 fRawReader->AddMajorErrorLog(kFillUnexpectErr,errMess.Data());
400 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillUnexpectErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
401 if (fFillOutOfSynch) fFillOutOfSynch = kFALSE;
402 else fFillOutOfSynch = kTRUE;
407 if (fDDLID>=0 && fDDLID<20) {
408 // The next line is commented, since we do not have the information how many chips to expect
409 // CheckHeaderAndTrailerCount(fDDLID);
413 //__________________________________________________________________________
414 void AliITSRawStreamSPD::CheckHeaderAndTrailerCount(Int_t ddlID) {
415 // Checks that the number of header and trailers found for the ddl are as expected
416 if (fEqPLChipHeadersRead != fExpectedHeaderTrailerCount) {
417 TString errMess = Form("Chip header count inconsistent %d != %d (expected) for ddl %d",
418 fEqPLChipHeadersRead,fExpectedHeaderTrailerCount,ddlID);
419 AliError(errMess.Data());
420 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
421 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
423 if (fEqPLChipTrailersRead != fExpectedHeaderTrailerCount) {
424 TString errMess = Form("Chip trailer count inconsistent %d != %d (expected) for ddl %d",
425 fEqPLChipTrailersRead,fExpectedHeaderTrailerCount,ddlID);
426 AliError(errMess.Data());
427 fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
428 if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
431 //__________________________________________________________________________
432 void AliITSRawStreamSPD::ActivateAdvancedErrorLog(Bool_t activate, AliITSRawStreamSPDErrorLog* advLogger) {
433 // Activate the advanced error logging.
434 // Logger object has to be created elsewhere and a pointer sent here.
435 fAdvancedErrorLog=activate;
436 if (activate && advLogger!=NULL) {
437 fAdvLogger = advLogger;
439 if (fAdvLogger==NULL) {
440 fAdvancedErrorLog=kFALSE;
443 //__________________________________________________________________________
444 const Char_t* AliITSRawStreamSPD::GetErrorName(UInt_t errorCode) {
445 // Returns a string for each error code
446 if (errorCode==kTotal) return "All Errors";
447 else if (errorCode==kHeaderMissingErr) return "Header Missing";
448 else if (errorCode==kTrailerMissingErr) return "Trailer Missing";
449 else if (errorCode==kTrailerWithoutHeaderErr) return "Trailer Unexpected";
450 else if (errorCode==kHeaderCountErr) return "Header Count Wrong";
451 else if (errorCode==kTrailerCountErr) return "Trailer Count Wrong";
452 else if (errorCode==kFillUnexpectErr) return "Fill Unexpected";
453 else if (errorCode==kFillMissingErr) return "Fill Missing";
454 else if (errorCode==kWrongFillWordErr) return "Fill Word Wrong";
455 else if (errorCode==kNumberHitsErr) return "Hit Count Wrong";
456 else if (errorCode==kEventCounterErr) return "Event Counter Error";
457 else if (errorCode==kDDLNumberErr) return "DDL Number Error";
458 else if (errorCode==kHSNumberErr) return "HS Number Error";
459 else if (errorCode==kChipAddrErr) return "Chip Address Error";
460 else if (errorCode==kCalHeaderLengthErr) return "Calib Header Length Error";
461 else if (errorCode==kAdvEventCounterErr) return "Event Counter Error (Adv)";
462 else if (errorCode==kAdvEventCounterOrderErr) return "Event Counter Jump Error (Adv)";
463 else if (errorCode==kTrailerErrorBitErr) return "Trailer Error Bit Set";
464 else if (errorCode==kLinkRxDetectorFatalErr) return "LinkRx/Detector Fatal Error Bit Set";
465 else if (errorCode==kTSMtriggerErr) return "TSM Trigger Error Bit Set";
466 else if (errorCode==kHighMultiplicityFlag) return "High Multiplicity Event Flag Set";
469 //__________________________________________________________________________
470 Bool_t AliITSRawStreamSPD::GetFastOrSignal(UInt_t eq, UInt_t hs, UInt_t chip) {
471 // returns if there was a fastor signal from this chip
472 if (eq>=20 || hs>=6 || chip>=10) {
473 TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
474 AliError(errMess.Data());
477 return fFastOrSignal[eq][hs][chip];
479 //__________________________________________________________________________
480 Bool_t AliITSRawStreamSPD::IsActiveEq(UInt_t eq) const {
481 // returns if the eq is active (seen in data)
483 TString errMess = Form("eq = %d out of bounds. Return kFALSE.",eq);
484 AliError(errMess.Data());
487 return fActiveEq[eq];
489 //__________________________________________________________________________
490 Bool_t AliITSRawStreamSPD::IsActiveHS(UInt_t eq, UInt_t hs) const {
491 // returns if the hs is active (info from block attr)
492 if (eq>=20 || hs>=6) {
493 TString errMess = Form("eq,hs = %d,%d out of bounds. Return kFALSE.",eq,hs);
494 AliError(errMess.Data());
497 return fActiveHS[eq][hs];
499 //__________________________________________________________________________
500 Bool_t AliITSRawStreamSPD::IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
501 // returns if the chip is active (seen in data)
502 if (eq>=20 || hs>=6 || chip>=10) {
503 TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
504 AliError(errMess.Data());
507 return fActiveChip[eq][hs][chip];
509 //__________________________________________________________________________
510 Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
511 // Reads the half stave present status from the block attributes
512 // This is not really needed anymore (kept for now in case it is still used somewhere).
513 // The same information can be reached through the "IsActiveHS" method instead.
514 Int_t ddlID = fRawReader->GetDDLID();
516 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
521 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
524 UChar_t attr = fRawReader->GetBlockAttributes();
525 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
533 //__________________________________________________________________________
534 Bool_t AliITSRawStreamSPD::IsEventCounterFullConsistent() const {
535 // checks if the event counter values are consistent within the event
536 Short_t reference = -1;
537 for (UInt_t eq=0; eq<20; eq++) {
538 if (IsActiveEq(eq)) {
539 for (UInt_t hs=0; hs<6; hs++) {
540 if (IsActiveHS(eq,hs)) {
541 for (UInt_t chip=0; chip<10; chip++) {
542 if (fEventCounterFull[eq][hs][chip]!=-1) {
543 if (reference==-1) reference = fEventCounterFull[eq][hs][chip];
544 if (fEventCounterFull[eq][hs][chip] != reference) return kFALSE;
553 //__________________________________________________________________________
554 Short_t AliITSRawStreamSPD::GetEventCounterFullEq(UInt_t eq) const {
555 // if the eq is active; returns the event counter value
557 TString errMess = Form("eq (%d) out of bounds",eq);
558 AliError(errMess.Data());
561 if (IsActiveEq(eq)) {
562 for (UInt_t hs=0; hs<6; hs++) {
563 if (IsActiveHS(eq,hs)) {
564 for (UInt_t chip=0; chip<10; chip++) {
565 if (fEventCounterFull[eq][hs][chip]!=-1) {
566 return fEventCounterFull[eq][hs][chip];
574 //__________________________________________________________________________
575 Short_t AliITSRawStreamSPD::GetEventCounterFullHS(UInt_t eq, UInt_t hs) const {
576 // if the eq,hs is active; returns the event counter value
577 if (eq>=20 || hs>=6) {
578 TString errMess = Form("eq,hs (%d,%d) out of bounds",eq,hs);
579 AliError(errMess.Data());
582 if (IsActiveEq(eq)) {
583 if (IsActiveHS(eq,hs)) {
584 for (UInt_t chip=0; chip<10; chip++) {
585 if (fEventCounterFull[eq][hs][chip]!=-1) {
586 return fEventCounterFull[eq][hs][chip];
593 //__________________________________________________________________________
594 Short_t AliITSRawStreamSPD::GetEventCounterFullChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
595 // if the eq,hs,chip is active; returns the event counter value
596 if (eq>=20 || hs>=6 || chip>=10) {
597 TString errMess = Form("eq,hs,chip (%d,%d,%d) out of bounds",eq,hs,chip);
598 AliError(errMess.Data());
601 if (IsActiveEq(eq)) {
602 if (IsActiveHS(eq,hs)) {
603 if (IsActiveChip(eq,hs,chip)) {
604 return fEventCounterFull[eq][hs][chip];
610 //__________________________________________________________________________
611 Int_t AliITSRawStreamSPD::GetHword(UInt_t index) {
612 if (index<kCalHeadLenMax) return fCalHeadWord[index];
615 Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
616 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
619 Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
620 if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
623 UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
624 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
627 UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
628 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
631 UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
632 if (hs<6) return fCalHeadWord[hs+10];
635 Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
636 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
639 UInt_t AliITSRawStreamSPD::GetFOHnumDacs() const {
640 return (fCalHeadLen-37)/2;
642 UInt_t AliITSRawStreamSPD::GetFOHdacIndex(UInt_t index) const {
643 if (index>=GetFOHnumDacs()) {
644 TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs());
645 AliError(errMess.Data());
648 return fCalHeadWord[7+index*2];
650 UInt_t AliITSRawStreamSPD::GetFOHdacValue(UInt_t index) const {
651 if (index>=GetFOHnumDacs()) {
652 TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs());
653 AliError(errMess.Data());
656 return fCalHeadWord[7+1+index*2];
658 UInt_t AliITSRawStreamSPD::GetFOHchipCount(UInt_t hs, UInt_t chip) const {
659 if (hs<6 && chip<10) {
661 return ((fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] >> 16) & 0x0000ffff);
664 return (fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] & 0x0000ffff);
669 //__________________________________________________________________________
670 Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
671 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
674 //__________________________________________________________________________
675 Bool_t AliITSRawStreamSPD::OfflineToOnline(UInt_t module, UInt_t colM, UInt_t rowM, UInt_t& eq, UInt_t& hs, UInt_t& chip, UInt_t& col, UInt_t& row) {
676 // converts offline coordinates to online
677 eq = GetOnlineEqIdFromOffline(module);
678 hs = GetOnlineHSFromOffline(module);
679 chip = GetOnlineChipFromOffline(module,colM);
680 col = GetOnlineColFromOffline(module,colM);
681 row = GetOnlineRowFromOffline(module,rowM);
682 if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
685 //__________________________________________________________________________
686 Bool_t AliITSRawStreamSPD::OnlineToOffline(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row, UInt_t& module, UInt_t& colM, UInt_t& rowM) {
687 // converts online coordinates to offline
688 module = GetOfflineModuleFromOnline(eq,hs,chip);
689 colM = GetOfflineColFromOnline(eq,hs,chip,col);
690 rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
691 if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
694 //__________________________________________________________________________
695 UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
696 // offline->online (eq)
697 for (UInt_t eqId=0; eqId<20; eqId++) {
698 for (UInt_t iModule=0; iModule<12; iModule++) {
699 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
704 //__________________________________________________________________________
705 UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
706 // offline->online (hs)
707 for (UInt_t eqId=0; eqId<20; eqId++) {
708 for (UInt_t iModule=0; iModule<12; iModule++) {
709 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
714 //__________________________________________________________________________
715 UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
716 // offline->online (chip)
717 for (UInt_t eq=0; eq<20; eq++) {
718 for (UInt_t iModule=0; iModule<12; iModule++) {
719 if (GetModuleNumber(eq,iModule)==(Int_t)module) {
721 if (eq<10) { // side A
722 return (159-colM)/32 + 5*(iModule%2);
725 return colM/32 + 5*(iModule%2);
728 else if (module<240) {
729 if (eq<10) { // side A
730 return colM/32 + 5*(iModule%2);
733 return (159-colM)/32 + 5*(iModule%2);
741 //__________________________________________________________________________
742 UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
743 // offline->online (col)
744 if (module<80) { // inner layer
747 else if (module<240) { // outer layer
752 //__________________________________________________________________________
753 UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
754 // offline->online (row)
755 if (module<80) { // inner layer
758 else if (module<240) { // outer layer
763 //__________________________________________________________________________
764 UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
765 // online->offline (module)
766 if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
769 //__________________________________________________________________________
770 UInt_t AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
771 // online->offline (chip key: 0-1199)
772 if (eqId<20 && hs<6 && chip<10) {
773 UInt_t module = GetOfflineModuleFromOnline(eqId,hs,chip);
774 UInt_t chipInModule = ( chip>4 ? chip-5 : chip );
775 if(eqId>9) chipInModule = 4 - chipInModule; // side C only
776 return (module*5 + chipInModule);
779 //__________________________________________________________________________
780 UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
781 // online->offline (col)
782 if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
783 UInt_t offset = 32 * (chip % 5);
786 return 159 - (31-col + offset); // inner layer, side A
789 return col + offset; // inner layer, side C
794 return (col + offset); // outer layer, side A
797 return 159 - (31-col + offset); // outer layer, side C
801 //__________________________________________________________________________
802 UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
803 // online->offline (row)
804 if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error