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),
52 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
53 for(Int_t i=0;i<kNDDL;i++) {
54 fNumOfErr[i] = new Int_t [kSumErr];
57 fnDDLInStream=new Int_t[kNDDL];
58 fnDDLOutStream=new Int_t[kNDDL];
59 for(Int_t iddl=0;iddl<kNDDL;iddl++) { fnDDLInStream[iddl]=-1;fnDDLOutStream[iddl]=-1;}
61 for(Int_t iddl=0;iddl<kNDDL;iddl++)
62 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
64 fRawReader->Select("HMPID");
69 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70 AliHMPIDRawStream::AliHMPIDRawStream() :
91 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
92 for(Int_t i=0;i<kNDDL;i++) {
93 fNumOfErr[i] = new Int_t [kSumErr];
95 fnDDLInStream=new Int_t[kNDDL];
96 fnDDLOutStream=new Int_t[kNDDL];
97 for(Int_t iddl=0;iddl<kNDDL;iddl++) { fnDDLInStream[iddl]=-1;fnDDLOutStream[iddl]=-1;}
100 for(Int_t iddl=0;iddl<kNDDL;iddl++)
101 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105 AliHMPIDRawStream::~AliHMPIDRawStream()
120 for(Int_t i=0;i<kSumErr;i++) delete [] fNumOfErr[i];
123 if(fnDDLInStream) { delete [] fnDDLInStream; fnDDLInStream = 0x0; }
125 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
126 void AliHMPIDRawStream::Reset()
128 // reset raw stream params
129 // Reinitalize the containers
135 if (fRawReader) fRawReader->Reset();
137 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
138 Bool_t AliHMPIDRawStream::Next()
140 // read next DDL raw data from the HMPID raw data stream
141 // return kFALSE in case of error or no data left
142 AliDebug(1,"Start.");
144 if (!fRawReader->ReadNextData(fData)) return kFALSE;
145 } while (fRawReader->GetDataSize() == 0);
149 Event type is selected as in $ALICE_ROOT/RAW/event.h
150 #define START_OF_RUN ((eventTypeType) 1)
151 #define END_OF_RUN ((eventTypeType) 2)
152 #define START_OF_RUN_FILES ((eventTypeType) 3)
153 #define END_OF_RUN_FILES ((eventTypeType) 4)
154 #define START_OF_BURST ((eventTypeType) 5)
155 #define END_OF_BURST ((eventTypeType) 6)
156 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
157 #define CALIBRATION_EVENT ((eventTypeType) 8)
158 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
159 #define START_OF_DATA ((eventTypeType)10)
160 #define END_OF_DATA ((eventTypeType)11)
161 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
162 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
163 #define EVENT_TYPE_MIN 1
164 #define EVENT_TYPE_MAX 13
170 if(fRawReader->GetType() == 7 || fRawReader->GetType() == 8 ) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
171 fDDLNumber = fRawReader->GetDDLID();
172 fnDDLInStream[fDDLNumber]=1; fnDDLOutStream[fDDLNumber]=0;
174 fLDCNumber = fRawReader->GetLDCId();
175 fTimeStamp = fRawReader->GetTimestamp();
177 AliDebug(1,Form("DDL %i started to be decoded!",fDDLNumber));
178 rawDataSize=fRawReader->GetDataSize()/4;
179 DelVars(); //We have to delete the variables initialized in the InitVars before recall IntiVars!!!
180 InitVars(rawDataSize); //To read the charge and pads we cannot delete before the status return
182 status = ReadHMPIDRawData();
184 if(status) AliDebug(1,Form("Event DDL %i successfully decoded!.",fDDLNumber));
185 else AliDebug(1,Form("Event DDL %i ERROR in decoding!.",fDDLNumber));
186 // DumpData(fRawReader->GetDataSize());
190 if(status==kTRUE) {fnDDLOutStream[fDDLNumber]++; }//Printf("fnDDLOutStream[%d]=%d",fDDLNumber,fnDDLOutStream[fDDLNumber]); } //Count the number of events when the DDL was succesfully decoded
192 // return status; // temporary solution...
195 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
196 void AliHMPIDRawStream::InitVars(Int_t n)
202 fCharge = new Int_t[n];
205 fPos = new Int_t[4*n+4]; //reset debug
208 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
209 void AliHMPIDRawStream::DelVars()
214 //Clean the initvars!!!!!!!!
216 if (fCharge) { delete [] fCharge; fCharge = 0x0; }
217 if (fPad) { delete [] fPad; fPad = 0x0; }
218 if (fPos) { delete [] fPos; fPos = 0x0; }
224 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
225 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
227 //Here the loop on the decoding the raw bank
228 //for one ddl starts.
229 //It returns: kFALSE if any error occurs
231 Int_t cntGlob = fRawReader->GetDataSize()/4;
232 if(cntGlob==0) {fNumOfErr[fDDLNumber][kRawDataSizeErr]++; return kFALSE; }
238 if(!GetWord(cnt)) return kFALSE;
244 nwSeg = (fWord >> kbit8) & 0xfff;
245 if(!CheckSegment()) return kFALSE;
246 if(!ReadSegment(cntSegment)) return kFALSE;
248 if(nwSeg != cntSegment) {AliDebug(1,Form("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment)); return kFALSE;}
249 if(!GetWord(cntSegment+1,kBwd)) return kFALSE;
256 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
257 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
260 //It returns: kFALSE if any error occurs
262 cntSegment = (fWord >> kbit8) & 0xfff;
263 Int_t cnt = cntSegment;
267 if(!GetWord(cnt,kBwd)) return kFALSE;
271 cntRow = (fWord >> kbit16) & 0xfff;
272 if(!CheckRowMarker()) return kFALSE;
273 if(!ReadRow(nwRow)) return kFALSE;
275 if(nwRow != cntRow) {AliDebug(1,Form("Error in Row counters: %i different wrt %i",nwRow,cntRow)); return kFALSE;}
276 if(!GetWord(cntRow+1)) return kFALSE;
286 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
287 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
290 //It returns: kFALSE if any error occurs
297 cntRow = (fWord >> kbit16) & 0xfff;
300 if(!GetWord(cntRow)) return kFALSE;
304 if(!CheckEoE(nwDil)) return kFALSE;
305 if(!ReadDilogic(cntDilogic)) return kFALSE;
307 if(nwDil != cntDilogic) {AliDebug(1,Form("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic));return kFALSE;}
309 if(!GetWord(1,kBwd)) return kFALSE; // go to next Dilogic bank...
311 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
319 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
320 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
322 // Read the dilogic bank
323 //It returns: kFALSE if any error occurs
326 cntDilogic = fWord & 0x7f;
328 Int_t cnt = cntDilogic;
330 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
332 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
333 UInt_t dilogic = 0, row = 0;
334 if(!GetWord(1,kBwd)) return kFALSE;
335 //check on row number
337 row = (fWord >> kbit22) & 0x1f;
338 if(!CheckRow(row)) continue;
339 //check dilogic number
340 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
341 if(!CheckDilogic(dilogic)) continue;
343 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
344 if(!CheckPad(pad)) continue;
345 Int_t charge = fWord & 0xfff;
346 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
347 fCharge[fNPads] = charge;
352 AliDebug(1,Form("If PEDESTAL run -> WARNING: ZERO charge is read from DDL: %d row: %d dil: %d pad: %d",fDDLNumber,row,dilogic,pad));
353 fNumOfErr[fDDLNumber][kPedQZero]++;
361 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
362 Bool_t AliHMPIDRawStream::CheckSegment()
364 // Check the segment marker
365 //It returns: kFALSE if any error occurs
368 UInt_t markSegment = 0xAB0;
371 UInt_t segWord = GetWord();
372 if ((segWord >> 20) != statusSegWord) {
373 fRawReader->AddMajorErrorLog(kBadSegWordErr);
374 AliDebug(1,Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
375 fNumOfErr[kBadSegWordErr]++;
379 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
380 if (segMarker != markSegment ) {
381 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
382 AliDebug(1,Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
383 fNumOfErr[fDDLNumber][kWrongSegErr]++;
387 UInt_t segAddress = fWord & 0xff;
388 if (segAddress<1 ||segAddress>3) {
389 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
390 AliDebug(1,Form("Segment address %d not in the valid range [1-3]",segAddress));
391 fNumOfErr[fDDLNumber][kWrongSegErr]++;
394 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
397 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
398 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
400 //check on row number
401 //It returns: kFALSE if any error occurs
403 // Printf("ROW %i word %0X",row,fWord);
404 if(row>=1 && row <=kNRows) return kTRUE;
406 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
407 AliDebug(1,Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));
408 fNumOfErr[fDDLNumber][kWrongRowErr]++;
411 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
414 //check dilogic number
415 //It returns: kFALSE if any error occurs
417 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
419 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
420 AliDebug(1,Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
421 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
422 //dilogic = iDILOGIC;
425 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
426 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
429 //It returns: kFALSE if any error occurs
431 if (pad < kNPadAdd) return kTRUE;
433 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
434 AliDebug(1,Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
435 fNumOfErr[fDDLNumber][kWrongPadErr]++;
438 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
439 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
441 //check the End of Event
442 //It returns: kFALSE if any error occurs
444 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
445 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
446 AliDebug(1,Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));
447 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
450 nDil = fWord & 0x7f; //nDil=EoE word count
451 if(nDil < 0 || nDil > 48 ) {
453 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
454 AliDebug(1,Form("Wrong end-of-event word-count: %08X",fWord));
455 fNumOfErr[fDDLNumber][kEoESizeErr]++;
458 // UInt_t da = (eOfEvent >> 18) & 0xf;
459 // if (cntData!=0 && da != dilogic) {
460 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
461 // AliDebug(1,Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
462 // fNumOfErr[kEoEDILOGICErr]++;
463 // return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
466 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
467 // if (cntData!=0 && ca != row) {
468 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
469 // AliDebug(1,Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
470 // fNumOfErr[kEoERowErr]++;
475 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
476 Bool_t AliHMPIDRawStream::CheckRowMarker()
478 //check the row marker
479 //It returns: kFALSE if any error occurs
481 UInt_t nMAXwordsInRow = 0x1EA;
482 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
483 //First check on row marker
484 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
486 if(rowControlWord != statusControlRow) {
487 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
488 AliDebug(1,Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
489 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
492 //Second check on row marker
493 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
495 if (wordsInRow > nMAXwordsInRow) {
496 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
497 AliDebug(1,Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));
498 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
504 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
505 Bool_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
507 // This method returns the n-th 32 bit word
508 // inside the raw data payload.
509 // The method is supposed to be endian (platform)
513 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
515 if(dir==kBwd) n = -n;
518 if(fPosition==-4) return kTRUE;
520 if(fPosition<0 || fPosition > fRawReader->GetDataSize()) {
521 AliDebug(1,Form("fPosition out of boundaries %i",fPosition));
527 fWord |= fData[fPosition++];
528 fWord |= fData[fPosition++] << 8;
529 fWord |= fData[fPosition++] << 16;
530 fWord |= fData[fPosition++] << 24;
534 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
535 void AliHMPIDRawStream::DumpData(Int_t nw)
537 //just a simple raw data dump
538 // in () is the position in bytes
540 for(Int_t i=0;i<nw;i+=4) {
541 if(!(i%16)) printf(" \n %8i) ",i);
542 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
544 Printf(" \n -----end of dump ----------- ");
546 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
547 void AliHMPIDRawStream::StorePosition()
549 //just for debug purpose
550 // it stores the position
551 //read for the first time
552 // Printf("@@@@@@@@@ fPos: %x fPosition: %d",fPos,fPosition);
553 if(fPos[fPosition]!=0) {
554 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
558 fPos[fPosition] = fiPos;
559 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
561 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++