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 static Bool_t stDeb = kFALSE;
29 //static Bool_t stDeb = kTRUE;
31 ClassImp(AliHMPIDRawStream)
33 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
43 fRawReader(rawReader),
55 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
56 for(Int_t i=0;i<kNDDL;i++) {
57 fNumOfErr[i] = new Int_t [kSumErr];
60 fnDDLInStream=new Int_t[kNDDL];
61 fnDDLOutStream=new Int_t[kNDDL];
62 for(Int_t iddl=0;iddl<kNDDL;iddl++) { fnDDLInStream[iddl]=-1;fnDDLOutStream[iddl]=-1;}
64 for(Int_t iddl=0;iddl<kNDDL;iddl++)
65 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
67 fRawReader->Select("HMPID");
72 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73 AliHMPIDRawStream::AliHMPIDRawStream() :
94 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
95 for(Int_t i=0;i<kNDDL;i++) {
96 fNumOfErr[i] = new Int_t [kSumErr];
98 fnDDLInStream=new Int_t[kNDDL];
99 fnDDLOutStream=new Int_t[kNDDL];
100 for(Int_t iddl=0;iddl<kNDDL;iddl++) { fnDDLInStream[iddl]=-1;fnDDLOutStream[iddl]=-1;}
103 for(Int_t iddl=0;iddl<kNDDL;iddl++)
104 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
107 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108 AliHMPIDRawStream::~AliHMPIDRawStream()
123 for(Int_t i=0;i<kSumErr;i++) delete [] fNumOfErr[i];
126 if(fnDDLInStream) { delete [] fnDDLInStream; fnDDLInStream = 0x0; }
128 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
129 void AliHMPIDRawStream::Reset()
131 // reset raw stream params
132 // Reinitalize the containers
138 if (fRawReader) fRawReader->Reset();
140 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141 Bool_t AliHMPIDRawStream::Next()
143 // read next DDL raw data from the HMPID raw data stream
144 // return kFALSE in case of error or no data left
145 AliDebug(1,"Start.");
147 if (!fRawReader->ReadNextData(fData)) return kFALSE;
148 } while (fRawReader->GetDataSize() == 0);
152 Event type is selected as in $ALICE_ROOT/RAW/event.h
153 #define START_OF_RUN ((eventTypeType) 1)
154 #define END_OF_RUN ((eventTypeType) 2)
155 #define START_OF_RUN_FILES ((eventTypeType) 3)
156 #define END_OF_RUN_FILES ((eventTypeType) 4)
157 #define START_OF_BURST ((eventTypeType) 5)
158 #define END_OF_BURST ((eventTypeType) 6)
159 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
160 #define CALIBRATION_EVENT ((eventTypeType) 8)
161 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
162 #define START_OF_DATA ((eventTypeType)10)
163 #define END_OF_DATA ((eventTypeType)11)
164 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
165 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
166 #define EVENT_TYPE_MIN 1
167 #define EVENT_TYPE_MAX 13
173 if(fRawReader->GetType() == 7 || fRawReader->GetType() == 8 ) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
174 fDDLNumber = fRawReader->GetDDLID();
175 fnDDLInStream[fDDLNumber]=1; fnDDLOutStream[fDDLNumber]=0;
177 fLDCNumber = fRawReader->GetLDCId();
178 fTimeStamp = fRawReader->GetTimestamp();
180 if(stDeb) Printf("DDL %i started to be decoded!",fDDLNumber);
181 rawDataSize=fRawReader->GetDataSize()/4;
182 DelVars(); //We have to delete the variables initialized in the InitVars before recall IntiVars!!!
183 InitVars(rawDataSize); //To read the charge and pads we cannot delete before the status return
185 status = ReadHMPIDRawData();
188 if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
189 else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
190 // DumpData(fRawReader->GetDataSize());
196 if(status==kTRUE) {fnDDLOutStream[fDDLNumber]++; }//Printf("fnDDLOutStream[%d]=%d",fDDLNumber,fnDDLOutStream[fDDLNumber]); } //Count the number of events when the DDL was succesfully decoded
201 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
202 void AliHMPIDRawStream::InitVars(Int_t n)
208 fCharge = new Int_t[n];
211 fPos = new Int_t[4*n+4]; //reset debug
214 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
215 void AliHMPIDRawStream::DelVars()
220 //Clean the initvars!!!!!!!!
222 if (fCharge) { delete [] fCharge; fCharge = 0x0; }
223 if (fPad) { delete [] fPad; fPad = 0x0; }
224 if (fPos) { delete [] fPos; fPos = 0x0; }
230 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
231 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
233 Int_t cntGlob = fRawReader->GetDataSize()/4;
234 if(cntGlob==0) {fNumOfErr[fDDLNumber][kRawDataSizeErr]++; return kFALSE; }
240 if(!GetWord(cnt)) return kFALSE;
246 nwSeg = (fWord >> kbit8) & 0xfff;
247 if(!CheckSegment()) return kFALSE;
248 if(!ReadSegment(cntSegment)) return kFALSE;
250 if(nwSeg != cntSegment) {if(stDeb){Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);} return kFALSE;}
251 if(!GetWord(cntSegment+1,kBwd)) return kFALSE;
258 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
259 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
261 cntSegment = (fWord >> kbit8) & 0xfff;
262 Int_t cnt = cntSegment;
266 if(!GetWord(cnt,kBwd)) return kFALSE;
270 cntRow = (fWord >> kbit16) & 0xfff;
271 if(!CheckRowMarker()) return kFALSE;
272 if(!ReadRow(nwRow)) return kFALSE;
274 if(nwRow != cntRow) {if(stDeb){Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);} return kFALSE;}
275 if(!GetWord(cntRow+1)) return kFALSE;
285 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
286 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
292 cntRow = (fWord >> kbit16) & 0xfff;
295 if(!GetWord(cntRow)) return kFALSE;
299 if(!CheckEoE(nwDil)) return kFALSE;
300 if(!ReadDilogic(cntDilogic)) return kFALSE;
302 if(nwDil != cntDilogic) {if(stDeb){Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);}return kFALSE;}
304 if(!GetWord(1,kBwd)) return kFALSE; // go to next Dilogic bank...
306 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
314 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
315 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
317 cntDilogic = fWord & 0x7f;
319 Int_t cnt = cntDilogic;
321 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
323 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
324 UInt_t dilogic = 0, row = 0;
325 if(!GetWord(1,kBwd)) return kFALSE;
326 //check on row number
328 row = (fWord >> kbit22) & 0x1f;
329 if(!CheckRow(row)) continue;
330 //check dilogic number
331 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
332 if(!CheckDilogic(dilogic)) continue;
334 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
335 if(!CheckPad(pad)) continue;
336 Int_t charge = fWord & 0xfff;
337 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
338 fCharge[fNPads] = charge;
343 if(stDeb){AliWarning(Form("If PEDESTAL run -> WARNING: ZERO charge is read from DDL: %d row: %d dil: %d pad: %d",fDDLNumber,row,dilogic,pad));}
344 fNumOfErr[fDDLNumber][kPedQZero]++;
352 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
353 Bool_t AliHMPIDRawStream::CheckSegment()
355 UInt_t markSegment = 0xAB0;
358 UInt_t segWord = GetWord();
359 if ((segWord >> 20) != statusSegWord) {
360 fRawReader->AddMajorErrorLog(kBadSegWordErr);
361 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
362 fNumOfErr[kBadSegWordErr]++;
366 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
367 if (segMarker != markSegment ) {
368 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
369 if(stDeb){ AliWarning(Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));}
370 fNumOfErr[fDDLNumber][kWrongSegErr]++;
374 UInt_t segAddress = fWord & 0xff;
375 if (segAddress<1 ||segAddress>3) {
376 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
377 if(stDeb){AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));}
378 fNumOfErr[fDDLNumber][kWrongSegErr]++;
381 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
384 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
387 //check on row number
388 // Printf("ROW %i word %0X",row,fWord);
389 if(row>=1 && row <=kNRows) return kTRUE;
391 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
392 if(stDeb){AliWarning(Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));}
393 fNumOfErr[fDDLNumber][kWrongRowErr]++;
396 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
397 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
399 //check dilogic number
400 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
402 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
403 if(stDeb){AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));}
404 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
405 //dilogic = iDILOGIC;
408 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
409 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
412 if (pad < kNPadAdd) return kTRUE;
414 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
415 if(stDeb){AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));}
416 fNumOfErr[fDDLNumber][kWrongPadErr]++;
419 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
420 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
422 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
423 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
424 if(stDeb){AliWarning(Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));}
425 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
428 nDil = fWord & 0x7f; //nDil=EoE word count
429 if(nDil < 0 || nDil > 48 ) {
431 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
432 if(stDeb){AliWarning(Form("Wrong end-of-event word-count: %08X",fWord));}
433 fNumOfErr[fDDLNumber][kEoESizeErr]++;
436 // UInt_t da = (eOfEvent >> 18) & 0xf;
437 // if (cntData!=0 && da != dilogic) {
438 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
439 // AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
440 // fNumOfErr[kEoEDILOGICErr]++;
441 // return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
444 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
445 // if (cntData!=0 && ca != row) {
446 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
447 // AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
448 // fNumOfErr[kEoERowErr]++;
453 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
454 Bool_t AliHMPIDRawStream::CheckRowMarker()
456 UInt_t nMAXwordsInRow = 0x1EA;
457 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
458 //First check on row marker
459 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
461 if(rowControlWord != statusControlRow) {
462 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
463 if(stDeb){AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
464 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
467 //Second check on row marker
468 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
470 if (wordsInRow > nMAXwordsInRow) {
471 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
472 if(stDeb){AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));}
473 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
479 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
480 Bool_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
482 // This method returns the n-th 32 bit word
483 // inside the raw data payload.
484 // The method is supposed to be endian (platform)
488 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
490 if(dir==kBwd) n = -n;
493 if(fPosition==-4) return kTRUE;
495 if(fPosition<0 || fPosition > fRawReader->GetDataSize()) {
496 if(stDeb) Printf("fPosition out of boundaries %i",fPosition);
502 fWord |= fData[fPosition++];
503 fWord |= fData[fPosition++] << 8;
504 fWord |= fData[fPosition++] << 16;
505 fWord |= fData[fPosition++] << 24;
509 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
510 void AliHMPIDRawStream::DumpData(Int_t nw)
512 for(Int_t i=0;i<nw;i+=4) {
513 if(!(i%16)) printf(" \n %8i) ",i);
514 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
516 Printf(" \n -----end of dump ----------- ");
518 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
519 void AliHMPIDRawStream::StorePosition()
521 // Printf("@@@@@@@@@ fPos: %x fPosition: %d",fPos,fPosition);
522 if(fPos[fPosition]!=0) {
523 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
527 fPos[fPosition] = fiPos;
528 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
530 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++