1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 /// This is a class for reading the HMPID raw data
19 /// The format of the raw data corresponds to the one
20 /// which was documented by Paolo Martinengo.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliHMPIDRawStream.h"
25 #include "AliRawReader.h"
28 ClassImp(AliHMPIDRawStream)
30 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
40 fRawReader(rawReader),
53 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
54 for(Int_t i=0;i<kNDDL;i++) {
55 fNumOfErr[i] = new Int_t [kSumErr];
58 fnDDLInStream=new Int_t[kNDDL];
59 fnDDLOutStream=new Int_t[kNDDL];
60 for(Int_t iddl=0;iddl<kNDDL;iddl++) { fnDDLInStream[iddl]=-1;fnDDLOutStream[iddl]=-1;}
62 for(Int_t iddl=0;iddl<kNDDL;iddl++)
63 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
65 fRawReader->Select("HMPID");
70 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
71 AliHMPIDRawStream::AliHMPIDRawStream() :
93 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
94 for(Int_t i=0;i<kNDDL;i++) {
95 fNumOfErr[i] = new Int_t [kSumErr];
97 fnDDLInStream=new Int_t[kNDDL];
98 fnDDLOutStream=new Int_t[kNDDL];
99 for(Int_t iddl=0;iddl<kNDDL;iddl++) { fnDDLInStream[iddl]=-1;fnDDLOutStream[iddl]=-1;}
102 for(Int_t iddl=0;iddl<kNDDL;iddl++)
103 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
106 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 AliHMPIDRawStream::~AliHMPIDRawStream()
122 for(Int_t i=0;i<kNDDL;i++) delete [] fNumOfErr[i];
125 delete [] fnDDLInStream;
126 delete [] fnDDLOutStream;
128 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
129 void AliHMPIDRawStream::Reset()
131 // reset raw stream params
132 // Reinitalize the containers
138 if (fRawReader) fRawReader->Reset();
140 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141 Bool_t AliHMPIDRawStream::Turbo()
144 Int_t row,dilogic;UInt_t pad;
145 Int_t cntGlob = fRawReader->GetDataSize()/4;
149 for(Int_t i=1;i<cntGlob;i++) {
150 if(!GetWord(1)) return kFALSE;
151 if (((fWord >> kbit27) & 1)) continue;
152 UInt_t statusControlRow = 0x32a8;
153 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
154 if(rowControlWord == statusControlRow) continue;
156 row = (fWord >> kbit22) & 0x1f;
157 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
159 pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
160 if(!CheckPad(pad)) continue;
161 Int_t charge = fWord & 0xfff;
162 if(GetPad(fDDLNumber,row,dilogic,pad)<0) continue;
163 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
164 fCharge[fNPads] = charge;
166 if(charge==0) fNumOfErr[fDDLNumber][kPedQZero]++;
168 //Printf("Size: %i DDL %i row %i dilogic %i pad %i fPos %i fNPads: %i Charge: %d Word %4.4x GoodW: %i",cntGlob,fDDLNumber,row,dilogic,pad,fPosition,fNPads,fCharge[fNPads-1],fWord,gw++);
171 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172 Bool_t AliHMPIDRawStream::Next()
174 // read next DDL raw data from the HMPID raw data stream
175 // return kFALSE in case of error or no data left
176 AliDebug(1,"Start.");
178 if (!fRawReader->ReadNextData(fData)) return kFALSE;
179 } while (fRawReader->GetDataSize() == 0);
183 Event type is selected as in $ALICE_ROOT/RAW/event.h
184 #define START_OF_RUN ((eventTypeType) 1)
185 #define END_OF_RUN ((eventTypeType) 2)
186 #define START_OF_RUN_FILES ((eventTypeType) 3)
187 #define END_OF_RUN_FILES ((eventTypeType) 4)
188 #define START_OF_BURST ((eventTypeType) 5)
189 #define END_OF_BURST ((eventTypeType) 6)
190 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
191 #define CALIBRATION_EVENT ((eventTypeType) 8)
192 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
193 #define START_OF_DATA ((eventTypeType)10)
194 #define END_OF_DATA ((eventTypeType)11)
195 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
196 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
197 #define EVENT_TYPE_MIN 1
198 #define EVENT_TYPE_MAX 13
202 Bool_t status=kFALSE;
204 fDDLNumber = fRawReader->GetDDLID();
205 if(fRawReader->GetType() == 7 || fRawReader->GetType() == 8 ) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
206 fnDDLInStream[fDDLNumber]=1; fnDDLOutStream[fDDLNumber]=0;
208 fLDCNumber = fRawReader->GetLDCId();
209 fTimeStamp = fRawReader->GetTimestamp();
211 AliDebug(1,Form("DDL %i started to be decoded!",fDDLNumber));
212 rawDataSize=fRawReader->GetDataSize()/4;
213 DelVars(); //We have to delete the variables initialized in the InitVars before recall IntiVars!!!
214 InitVars(rawDataSize); //To read the charge and pads we cannot delete before the status return
216 if(fTurbo==kTRUE) status=Turbo();
217 else status = ReadHMPIDRawData();
219 if(status) AliDebug(1,Form("Event DDL %i successfully decoded!.",fDDLNumber));
220 else AliDebug(1,Form("Event DDL %i ERROR in decoding!.",fDDLNumber));
221 // DumpData(fRawReader->GetDataSize());
225 if(status==kTRUE) {fnDDLOutStream[fDDLNumber]++; }//Printf("fnDDLOutStream[%d]=%d",fDDLNumber,fnDDLOutStream[fDDLNumber]); } //Count the number of events when the DDL was succesfully decoded
227 // return status; // temporary solution...
230 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
231 void AliHMPIDRawStream::InitVars(Int_t n)
237 fCharge = new Int_t[n];
240 fPos = new Int_t[4*n+4]; //reset debug
243 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
244 void AliHMPIDRawStream::DelVars()
249 //Clean the initvars!!!!!!!!
251 if (fCharge) { delete [] fCharge; fCharge = 0x0; }
252 if (fPad) { delete [] fPad; fPad = 0x0; }
253 if (fPos) { delete [] fPos; fPos = 0x0; }
259 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
260 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
262 //Here the loop on the decoding the raw bank
263 //for one ddl starts.
264 //It returns: kFALSE if any error occurs
266 Int_t cntGlob = fRawReader->GetDataSize()/4;
267 if(cntGlob==0) {fNumOfErr[fDDLNumber][kRawDataSizeErr]++; return kFALSE; }
273 if(!GetWord(cnt)) return kFALSE;
279 nwSeg = (fWord >> kbit8) & 0xfff;
280 if(!CheckSegment()) return kFALSE;
281 if(!ReadSegment(cntSegment)) return kFALSE;
283 if(nwSeg != cntSegment) {AliDebug(1,Form("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment)); return kFALSE;}
284 if(!GetWord(cntSegment+1,kBwd)) return kFALSE;
291 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
292 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
295 //It returns: kFALSE if any error occurs
297 cntSegment = (fWord >> kbit8) & 0xfff;
298 Int_t cnt = cntSegment;
302 if(!GetWord(cnt,kBwd)) return kFALSE;
306 cntRow = (fWord >> kbit16) & 0xfff;
307 if(!CheckRowMarker()) return kFALSE;
308 if(!ReadRow(nwRow)) return kFALSE;
310 if(nwRow != cntRow) {AliDebug(1,Form("Error in Row counters: %i different wrt %i",nwRow,cntRow)); return kFALSE;}
311 if(!GetWord(cntRow+1)) return kFALSE;
321 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
322 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
325 //It returns: kFALSE if any error occurs
332 cntRow = (fWord >> kbit16) & 0xfff;
335 if(!GetWord(cntRow)) return kFALSE;
339 if(!CheckEoE(nwDil)) return kFALSE;
340 if(!ReadDilogic(cntDilogic)) return kFALSE;
342 if(nwDil != cntDilogic) {AliDebug(1,Form("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic));return kFALSE;}
344 if(!GetWord(1,kBwd)) return kFALSE; // go to next Dilogic bank...
346 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
354 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
355 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
357 // Read the dilogic bank
358 //It returns: kFALSE if any error occurs
361 cntDilogic = fWord & 0x7f;
363 Int_t cnt = cntDilogic;
365 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
367 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
368 UInt_t dilogic = 0, row = 0;
369 if(!GetWord(1,kBwd)) return kFALSE;
370 //check on row number
372 row = (fWord >> kbit22) & 0x1f;
373 if(!CheckRow(row)) continue;
374 //check dilogic number
375 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
376 if(!CheckDilogic(dilogic)) continue;
378 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
379 if(!CheckPad(pad)) continue;
380 Int_t charge = fWord & 0xfff;
381 if(GetPad(fDDLNumber,row,dilogic,pad)<0) continue;
382 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
383 fCharge[fNPads] = charge;
388 AliDebug(1,Form("If PEDESTAL run -> WARNING: ZERO charge is read from DDL: %d row: %d dil: %d pad: %d",fDDLNumber,row,dilogic,pad));
389 fNumOfErr[fDDLNumber][kPedQZero]++;
397 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
398 Bool_t AliHMPIDRawStream::CheckSegment()
400 // Check the segment marker
401 //It returns: kFALSE if any error occurs
404 UInt_t markSegment = 0xAB0;
407 UInt_t segWord = GetWord();
408 if ((segWord >> 20) != statusSegWord) {
409 fRawReader->AddMajorErrorLog(kBadSegWordErr);
410 AliDebug(1,Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
411 fNumOfErr[kBadSegWordErr]++;
415 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
416 if (segMarker != markSegment ) {
417 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
418 AliDebug(1,Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
419 fNumOfErr[fDDLNumber][kWrongSegErr]++;
423 UInt_t segAddress = fWord & 0xff;
424 if (segAddress<1 ||segAddress>3) {
425 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
426 AliDebug(1,Form("Segment address %d not in the valid range [1-3]",segAddress));
427 fNumOfErr[fDDLNumber][kWrongSegErr]++;
430 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
433 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
434 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
436 //check on row number
437 //It returns: kFALSE if any error occurs
439 // Printf("ROW %i word %0X",row,fWord);
440 if(row>=1 && row <=kNRows) return kTRUE;
442 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
443 AliDebug(1,Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));
444 fNumOfErr[fDDLNumber][kWrongRowErr]++;
447 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
448 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
450 //check dilogic number
451 //It returns: kFALSE if any error occurs
453 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
455 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
456 AliDebug(1,Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
457 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
458 //dilogic = iDILOGIC;
461 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
462 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
465 //It returns: kFALSE if any error occurs
467 if (pad < kNPadAdd) return kTRUE;
469 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
470 AliDebug(1,Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
471 fNumOfErr[fDDLNumber][kWrongPadErr]++;
474 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
475 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
477 //check the End of Event
478 //It returns: kFALSE if any error occurs
480 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
481 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
482 AliDebug(1,Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));
483 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
486 nDil = fWord & 0x7f; //nDil=EoE word count
487 if(nDil < 0 || nDil > 48 ) {
489 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
490 AliDebug(1,Form("Wrong end-of-event word-count: %08X",fWord));
491 fNumOfErr[fDDLNumber][kEoESizeErr]++;
494 // UInt_t da = (eOfEvent >> 18) & 0xf;
495 // if (cntData!=0 && da != dilogic) {
496 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
497 // AliDebug(1,Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
498 // fNumOfErr[kEoEDILOGICErr]++;
499 // return kFALSE; AliQAChecker::Instance()->Run(AliQAv1::kHMPID, task, obj) ;
502 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
503 // if (cntData!=0 && ca != row) {
504 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
505 // AliDebug(1,Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
506 // fNumOfErr[kEoERowErr]++;
511 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
512 Bool_t AliHMPIDRawStream::CheckRowMarker()
514 //check the row marker
515 //It returns: kFALSE if any error occurs
517 UInt_t nMAXwordsInRow = 0x1EA;
518 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
519 //First check on row marker
520 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
522 if(rowControlWord != statusControlRow) {
523 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
524 AliDebug(1,Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
525 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
528 //Second check on row marker
529 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
531 if (wordsInRow > nMAXwordsInRow) {
532 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
533 AliDebug(1,Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));
534 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
540 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
541 Bool_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
543 // This method returns the n-th 32 bit word
544 // inside the raw data payload.
545 // The method is supposed to be endian (platform)
550 AliError("fPosition < 0 !!! Event skipped.");
551 fRawReader->AddMajorErrorLog(kRawDataSizeErr,"fPosition<0");
555 if(dir==kBwd) n = -n;
558 if(fPosition==-4) return kTRUE;
560 if(fPosition<0 || fPosition > fRawReader->GetDataSize()) {
561 AliWarning(Form("fPosition out of boundaries %i",fPosition));
567 fWord |= fData[fPosition++];
568 fWord |= fData[fPosition++] << 8;
569 fWord |= fData[fPosition++] << 16;
570 fWord |= fData[fPosition++] << 24;
574 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
575 void AliHMPIDRawStream::DumpData(Int_t nw)
577 //just a simple raw data dump
578 // in () is the position in bytes
580 for(Int_t i=0;i<nw;i+=4) {
581 if(!(i%16)) printf(" \n %8i) ",i);
582 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
584 Printf(" \n -----end of dump ----------- ");
586 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
587 void AliHMPIDRawStream::StorePosition()
589 //just for debug purpose
590 // it stores the position
591 //read for the first time
592 // Printf("@@@@@@@@@ fPos: %x fPosition: %d",fPos,fPosition);
593 if(fPos[fPosition]!=0) {
594 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
598 fPos[fPosition] = fiPos;
599 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
601 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++