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) :
39 fRawReader(rawReader),
51 fRawReader->Select("HMPID");
53 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54 AliHMPIDRawStream::AliHMPIDRawStream() :
69 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70 AliHMPIDRawStream::~AliHMPIDRawStream()
75 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76 void AliHMPIDRawStream::Reset()
78 // reset raw stream params
79 // Reinitalize the containers
83 if (fRawReader) fRawReader->Reset();
85 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86 Bool_t AliHMPIDRawStream::Next()
88 // read next DDL raw data from the HMPID raw data stream
89 // return kFALSE in case of error or no data left
92 if (!fRawReader->ReadNextData(fData)) return kFALSE;
93 } while (fRawReader->GetDataSize() == 0);
97 Event type is selected as in $ALICE_ROOT/RAW/event.h
98 #define START_OF_RUN ((eventTypeType) 1)
99 #define END_OF_RUN ((eventTypeType) 2)
100 #define START_OF_RUN_FILES ((eventTypeType) 3)
101 #define END_OF_RUN_FILES ((eventTypeType) 4)
102 #define START_OF_BURST ((eventTypeType) 5)
103 #define END_OF_BURST ((eventTypeType) 6)
104 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
105 #define CALIBRATION_EVENT ((eventTypeType) 8)
106 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
107 #define START_OF_DATA ((eventTypeType)10)
108 #define END_OF_DATA ((eventTypeType)11)
109 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
110 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
111 #define EVENT_TYPE_MIN 1
112 #define EVENT_TYPE_MAX 13
118 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
119 fDDLNumber = fRawReader->GetDDLID();
121 AliWarning("Negative DDL number!");
125 if(stDeb) Printf("DDL %i started to be decoded!.",fDDLNumber);
126 InitVars(fRawReader->GetDataSize()/4);
127 status = ReadHMPIDRawData();
130 if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
131 else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
132 // DumpData(fRawReader->GetDataSize());
140 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141 void AliHMPIDRawStream::InitVars(Int_t n)
144 if (n>0) fCharge = new Int_t[n];
145 if (n>0) fPad = new Int_t[n];
146 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
147 for(Int_t i=0;i<kNDDL;i++) {
148 fNumOfErr[i] = new Int_t [kSumErr];
149 for (Int_t j=0; j<kSumErr; j++) fNumOfErr[i][j] = 0;
152 if (n>0) fPos = new Int_t[4*n]; //reset debug
155 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156 void AliHMPIDRawStream::DelVars()
168 for(Int_t i=0;i<kNDDL;i++) if(fNumOfErr[i]) delete [] fNumOfErr[i];
177 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
180 Int_t cntGlob = fRawReader->GetDataSize()/4;
185 fWord = GetWord(cnt);cnt--;
190 nwSeg = (fWord >> kbit8) & 0xfff;
191 if(!CheckSegment()) return kFALSE;
192 if(!ReadSegment(cntSegment)) return kFALSE;
194 if(nwSeg != cntSegment) {if(stDeb){Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);} return kFALSE;}
195 fWord = GetWord(cntSegment+1,kBwd);
202 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
203 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
205 cntSegment = (fWord >> kbit8) & 0xfff;
206 Int_t cnt = cntSegment;
210 fWord = GetWord(cnt,kBwd);
214 cntRow = (fWord >> kbit16) & 0xfff;
215 if(!CheckRowMarker()) return kFALSE;
216 if(!ReadRow(nwRow)) return kFALSE;
218 if(nwRow != cntRow) {if(stDeb){Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);} return kFALSE;}
219 fWord = GetWord(cntRow+1);
229 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
230 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
236 cntRow = (fWord >> kbit16) & 0xfff;
239 fWord = GetWord(cntRow);
243 if(!CheckEoE(nwDil)) return kFALSE;
244 if(!ReadDilogic(cntDilogic)) return kFALSE;
246 if(nwDil != cntDilogic) {if(stDeb){Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);}return kFALSE;}
248 fWord = GetWord(1,kBwd); // go to next Dilogic bank...
250 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
258 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
259 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
261 cntDilogic = fWord & 0x7f;
263 Int_t cnt = cntDilogic;
265 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
267 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
268 UInt_t dilogic = 0, row = 0;
269 fWord = GetWord(1,kBwd);
270 //check on row number
272 row = (fWord >> kbit22) & 0x1f;
273 if(!CheckRow(row)) continue;
274 //check dilogic number
275 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
276 if(!CheckDilogic(dilogic)) continue;
278 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
279 if(!CheckPad(pad)) continue;
280 Int_t charge = fWord & 0xfff;
281 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
282 fCharge[fNPads] = charge;
289 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
290 Bool_t AliHMPIDRawStream::CheckSegment()
292 UInt_t markSegment = 0xAB0;
295 UInt_t segWord = GetWord();
296 if ((segWord >> 20) != statusSegWord) {
297 fRawReader->AddMajorErrorLog(kBadSegWordErr);
298 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
299 fNumOfErr[kBadSegWordErr]++;
303 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
304 if (segMarker != markSegment ) {
305 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
306 if(stDeb){ AliWarning(Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));}
307 fNumOfErr[fDDLNumber][kWrongSegErr]++;
311 UInt_t segAddress = fWord & 0xff;
312 if (segAddress<1 ||segAddress>3) {
313 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
314 if(stDeb){AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));}
315 fNumOfErr[fDDLNumber][kWrongSegErr]++;
318 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
321 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
322 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
324 //check on row number
325 // Printf("ROW %i word %0X",row,fWord);
326 if(row>=1 && row <=kNRows) return kTRUE;
328 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
329 if(stDeb){AliWarning(Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));}
330 fNumOfErr[fDDLNumber][kWrongRowErr]++;
333 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
334 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
336 //check dilogic number
337 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
339 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
340 if(stDeb){AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));}
341 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
342 //dilogic = iDILOGIC;
345 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
346 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
349 if (pad < kNPadAdd) return kTRUE;
351 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
352 if(stDeb){AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));}
353 fNumOfErr[fDDLNumber][kWrongPadErr]++;
356 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
359 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
360 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
361 if(stDeb){AliWarning(Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));}
362 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
365 nDil = fWord & 0x7f; //nDil=EoE word count
366 if(nDil < 0 || nDil > 48 ) {
368 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
369 if(stDeb){AliWarning(Form("Wrong end-of-event word-count: %08X",fWord));}
370 fNumOfErr[fDDLNumber][kEoESizeErr]++;
373 // UInt_t da = (eOfEvent >> 18) & 0xf;
374 // if (cntData!=0 && da != dilogic) {
375 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
376 // AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
377 // fNumOfErr[kEoEDILOGICErr]++;
378 // return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
381 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
382 // if (cntData!=0 && ca != row) {
383 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
384 // AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
385 // fNumOfErr[kEoERowErr]++;
390 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
391 Bool_t AliHMPIDRawStream::CheckRowMarker()
393 UInt_t nMAXwordsInRow = 0x1EA;
394 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
395 //First check on row marker
396 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
398 if(rowControlWord != statusControlRow) {
399 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
400 if(stDeb){AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
401 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
404 //Second check on row marker
405 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
407 if (wordsInRow > nMAXwordsInRow) {
408 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
409 if(stDeb){AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));}
410 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
416 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417 UInt_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
419 // This method returns the n-th 32 bit word
420 // inside the raw data payload.
421 // The method is supposed to be endian (platform)
423 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
427 if(dir==kBwd) n = -n;
432 word |= fData[fPosition++];
433 word |= fData[fPosition++] << 8;
434 word |= fData[fPosition++] << 16;
435 word |= fData[fPosition++] << 24;
439 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
440 void AliHMPIDRawStream::DumpData(Int_t nw)
442 for(Int_t i=0;i<nw;i+=4) {
443 if(!(i%16)) printf(" \n %8i) ",i);
444 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
446 Printf(" \n -----end of dump ----------- ");
448 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
449 void AliHMPIDRawStream::StorePosition()
451 if(fPos[fPosition]!=0) {
452 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
456 fPos[fPosition] = iPos;
457 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
459 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++