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) :
41 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 for(Int_t iddl=0;iddl<kNDDL;iddl++)
59 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
61 fRawReader->Select("HMPID");
63 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
64 AliHMPIDRawStream::AliHMPIDRawStream() :
83 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
84 for(Int_t i=0;i<kNDDL;i++) {
85 fNumOfErr[i] = new Int_t [kSumErr];
87 for(Int_t iddl=0;iddl<kNDDL;iddl++)
88 for(Int_t ierr=0; ierr < kSumErr; ierr++) fNumOfErr[iddl][ierr]=0; //reset errors
91 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
92 AliHMPIDRawStream::~AliHMPIDRawStream()
99 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100 void AliHMPIDRawStream::Reset()
102 // reset raw stream params
103 // Reinitalize the containers
109 if (fRawReader) fRawReader->Reset();
111 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 Bool_t AliHMPIDRawStream::Next()
114 // read next DDL raw data from the HMPID raw data stream
115 // return kFALSE in case of error or no data left
116 AliDebug(1,"Start.");
118 if (!fRawReader->ReadNextData(fData)) return kFALSE;
119 } while (fRawReader->GetDataSize() == 0);
123 Event type is selected as in $ALICE_ROOT/RAW/event.h
124 #define START_OF_RUN ((eventTypeType) 1)
125 #define END_OF_RUN ((eventTypeType) 2)
126 #define START_OF_RUN_FILES ((eventTypeType) 3)
127 #define END_OF_RUN_FILES ((eventTypeType) 4)
128 #define START_OF_BURST ((eventTypeType) 5)
129 #define END_OF_BURST ((eventTypeType) 6)
130 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
131 #define CALIBRATION_EVENT ((eventTypeType) 8)
132 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
133 #define START_OF_DATA ((eventTypeType)10)
134 #define END_OF_DATA ((eventTypeType)11)
135 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
136 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
137 #define EVENT_TYPE_MIN 1
138 #define EVENT_TYPE_MAX 13
144 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
145 fDDLNumber = fRawReader->GetDDLID();
146 fLDCNumber = fRawReader->GetLDCId();
147 fTimeStamp = fRawReader->GetTimestamp();
149 if(stDeb) Printf("DDL %i started to be decoded!",fDDLNumber);
150 rawDataSize=fRawReader->GetDataSize()/4;
151 InitVars(rawDataSize);
153 status = ReadHMPIDRawData();
156 if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
157 else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
158 // DumpData(fRawReader->GetDataSize());
165 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166 void AliHMPIDRawStream::InitVars(Int_t n)
172 fCharge = new Int_t[n];
175 fPos = new Int_t[4*n+4]; //reset debug
178 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
179 void AliHMPIDRawStream::DelVars()
193 if (fCharge) { delete [] fCharge; fCharge = 0x0; }
194 if (fPad) { delete [] fPad; fPad = 0x0; }
195 if (fPos) { delete [] fPos; fPos = 0x0; }
196 for(Int_t i=0;i<kSumErr;i++) delete [] fNumOfErr[i];
202 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
203 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
205 Int_t cntGlob = fRawReader->GetDataSize()/4;
206 if(cntGlob==0) {fNumOfErr[fDDLNumber][kRawDataSizeErr]++; return kFALSE; }
212 if(!GetWord(cnt)) return kFALSE;
218 nwSeg = (fWord >> kbit8) & 0xfff;
219 if(!CheckSegment()) return kFALSE;
220 if(!ReadSegment(cntSegment)) return kFALSE;
222 if(nwSeg != cntSegment) {if(stDeb){Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);} return kFALSE;}
223 if(!GetWord(cntSegment+1,kBwd)) return kFALSE;
230 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
231 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
233 cntSegment = (fWord >> kbit8) & 0xfff;
234 Int_t cnt = cntSegment;
238 if(!GetWord(cnt,kBwd)) return kFALSE;
242 cntRow = (fWord >> kbit16) & 0xfff;
243 if(!CheckRowMarker()) return kFALSE;
244 if(!ReadRow(nwRow)) return kFALSE;
246 if(nwRow != cntRow) {if(stDeb){Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);} return kFALSE;}
247 if(!GetWord(cntRow+1)) return kFALSE;
257 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
258 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
264 cntRow = (fWord >> kbit16) & 0xfff;
267 if(!GetWord(cntRow)) return kFALSE;
271 if(!CheckEoE(nwDil)) return kFALSE;
272 if(!ReadDilogic(cntDilogic)) return kFALSE;
274 if(nwDil != cntDilogic) {if(stDeb){Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);}return kFALSE;}
276 if(!GetWord(1,kBwd)) return kFALSE; // go to next Dilogic bank...
278 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
286 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
287 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
289 cntDilogic = fWord & 0x7f;
291 Int_t cnt = cntDilogic;
293 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
295 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
296 UInt_t dilogic = 0, row = 0;
297 if(!GetWord(1,kBwd)) return kFALSE;
298 //check on row number
300 row = (fWord >> kbit22) & 0x1f;
301 if(!CheckRow(row)) continue;
302 //check dilogic number
303 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
304 if(!CheckDilogic(dilogic)) continue;
306 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
307 if(!CheckPad(pad)) continue;
308 Int_t charge = fWord & 0xfff;
309 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
310 fCharge[fNPads] = charge;
317 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
318 Bool_t AliHMPIDRawStream::CheckSegment()
320 UInt_t markSegment = 0xAB0;
323 UInt_t segWord = GetWord();
324 if ((segWord >> 20) != statusSegWord) {
325 fRawReader->AddMajorErrorLog(kBadSegWordErr);
326 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
327 fNumOfErr[kBadSegWordErr]++;
331 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
332 if (segMarker != markSegment ) {
333 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
334 if(stDeb){ AliWarning(Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));}
335 fNumOfErr[fDDLNumber][kWrongSegErr]++;
339 UInt_t segAddress = fWord & 0xff;
340 if (segAddress<1 ||segAddress>3) {
341 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
342 if(stDeb){AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));}
343 fNumOfErr[fDDLNumber][kWrongSegErr]++;
346 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
349 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
350 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
352 //check on row number
353 // Printf("ROW %i word %0X",row,fWord);
354 if(row>=1 && row <=kNRows) return kTRUE;
356 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
357 if(stDeb){AliWarning(Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));}
358 fNumOfErr[fDDLNumber][kWrongRowErr]++;
361 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
362 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
364 //check dilogic number
365 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
367 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
368 if(stDeb){AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));}
369 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
370 //dilogic = iDILOGIC;
373 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
374 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
377 if (pad < kNPadAdd) return kTRUE;
379 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
380 if(stDeb){AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));}
381 fNumOfErr[fDDLNumber][kWrongPadErr]++;
384 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
387 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
388 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
389 if(stDeb){AliWarning(Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));}
390 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
393 nDil = fWord & 0x7f; //nDil=EoE word count
394 if(nDil < 0 || nDil > 48 ) {
396 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
397 if(stDeb){AliWarning(Form("Wrong end-of-event word-count: %08X",fWord));}
398 fNumOfErr[fDDLNumber][kEoESizeErr]++;
401 // UInt_t da = (eOfEvent >> 18) & 0xf;
402 // if (cntData!=0 && da != dilogic) {
403 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
404 // AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
405 // fNumOfErr[kEoEDILOGICErr]++;
406 // return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
409 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
410 // if (cntData!=0 && ca != row) {
411 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
412 // AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
413 // fNumOfErr[kEoERowErr]++;
418 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
419 Bool_t AliHMPIDRawStream::CheckRowMarker()
421 UInt_t nMAXwordsInRow = 0x1EA;
422 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
423 //First check on row marker
424 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
426 if(rowControlWord != statusControlRow) {
427 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
428 if(stDeb){AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
429 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
432 //Second check on row marker
433 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
435 if (wordsInRow > nMAXwordsInRow) {
436 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
437 if(stDeb){AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));}
438 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
444 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
445 Bool_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
447 // This method returns the n-th 32 bit word
448 // inside the raw data payload.
449 // The method is supposed to be endian (platform)
453 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
455 if(dir==kBwd) n = -n;
458 if(fPosition==-4) return kTRUE;
460 if(fPosition<0 || fPosition > fRawReader->GetDataSize()) {
461 if(stDeb) Printf("fPosition out of boundaries %i",fPosition);
467 fWord |= fData[fPosition++];
468 fWord |= fData[fPosition++] << 8;
469 fWord |= fData[fPosition++] << 16;
470 fWord |= fData[fPosition++] << 24;
474 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
475 void AliHMPIDRawStream::DumpData(Int_t nw)
477 for(Int_t i=0;i<nw;i+=4) {
478 if(!(i%16)) printf(" \n %8i) ",i);
479 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
481 Printf(" \n -----end of dump ----------- ");
483 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
484 void AliHMPIDRawStream::StorePosition()
486 // Printf("@@@@@@@@@ fPos: %x fPosition: %d",fPos,fPosition);
487 if(fPos[fPosition]!=0) {
488 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
492 fPos[fPosition] = fiPos;
493 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
495 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++