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"
30 //static Bool_t stDeb = kTRUE;
32 ClassImp(AliHMPIDRawStream)
34 //_____________________________________________________________________________
35 AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
37 fRawReader(rawReader),
45 fRawReader->Select("HMPID");
47 //-----------------------------------------------------------------------------
48 AliHMPIDRawStream::AliHMPIDRawStream() :
57 //_____________________________________________________________________________
58 AliHMPIDRawStream::~AliHMPIDRawStream()
63 //_____________________________________________________________________________
64 void AliHMPIDRawStream::Init()
66 // Initalize the container
67 // with the pad charges
70 for(Int_t h = 0; h < kNDDL; h++) {
71 for(Int_t i = 0; i < kNRows; i++){
72 for(Int_t j = 0; j < kNDILOGICAdd; j++){
73 for(Int_t k = 0; k < kNPadAdd; k++){
74 fCharge[h][i][j][k] = -1;
83 for(Int_t l=1; l < kSumErr; l++) fNumOfErr[l]=0; //reset errors
85 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86 void AliHMPIDRawStream::Reset()
88 // reset raw stream params
89 // Reinitalize the containers
94 if (fRawReader) fRawReader->Reset();
96 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
97 Bool_t AliHMPIDRawStream::Next()
99 // read next DDL raw data from the HMPID raw data stream
100 // return kFALSE in case of error or no data left
101 AliDebug(1,"Start.");
103 if (!fRawReader->ReadNextData(fData)) return kFALSE;
104 } while (fRawReader->GetDataSize() == 0);
108 Event type is selected as in $ALICE_ROOT/RAW/event.h
109 #define START_OF_RUN ((eventTypeType) 1)
110 #define END_OF_RUN ((eventTypeType) 2)
111 #define START_OF_RUN_FILES ((eventTypeType) 3)
112 #define END_OF_RUN_FILES ((eventTypeType) 4)
113 #define START_OF_BURST ((eventTypeType) 5)
114 #define END_OF_BURST ((eventTypeType) 6)
115 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
116 #define CALIBRATION_EVENT ((eventTypeType) 8)
117 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
118 #define START_OF_DATA ((eventTypeType)10)
119 #define END_OF_DATA ((eventTypeType)11)
120 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
121 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
122 #define EVENT_TYPE_MIN 1
123 #define EVENT_TYPE_MAX 13
129 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
131 fDDLNumber = fRawReader->GetDDLID();
135 status = ReadHMPIDRawData();
136 // if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
138 // for(Int_t i=0;i<fRawReader->GetDataSize()/4;i++) {
143 // if(stDeb) DumpData(fRawReader->GetDataSize());
149 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
152 Int_t cntGlob = fRawReader->GetDataSize()/4;
158 word32 = GetWord(cnt);cnt--;
163 nwSeg = (word32 >> kbit8) & 0xfff;
164 if(!CheckSegment(word32)) return kFALSE;
165 if(!ReadSegment(word32,cntSegment)) return kFALSE;
167 if(nwSeg != cntSegment) {Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);return kFALSE;}
168 Printf(" cnt %i cntSegment %i",cnt,cntSegment);
169 word32 = GetWord(cntSegment+1,kBwd);
176 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
177 Bool_t AliHMPIDRawStream::ReadSegment(UInt_t word32,Int_t &cntSegment)
179 cntSegment = (word32 >> kbit8) & 0xfff;
180 Int_t cnt = cntSegment;
184 word32 = GetWord(cnt,kBwd);
188 cntRow = (word32 >> kbit16) & 0xfff;
189 if(!CheckRowMarker(word32)) return kFALSE;
190 if(!ReadRow(word32,nwRow)) return kFALSE;
192 if(nwRow != cntRow) {Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);return kFALSE;}
193 word32 = GetWord(cntRow+1);
203 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
204 Bool_t AliHMPIDRawStream::ReadRow(UInt_t word32,Int_t &cntRow)
210 cntRow = (word32 >> kbit16) & 0xfff;
213 word32 = GetWord(cntRow);
217 if(!CheckEoE(word32,nwDil)) return kFALSE;
218 if(!ReadDilogic(word32,cntDilogic)) return kFALSE;
220 if(nwDil != cntDilogic) {Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);return kFALSE;}
222 word32 = GetWord(1,kBwd); // go to next Dilogic bank...
224 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
232 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
233 Bool_t AliHMPIDRawStream::ReadDilogic(UInt_t word32,Int_t &cntDilogic)
235 cntDilogic = word32 & 0x7f;
237 Int_t cnt = cntDilogic;
239 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
240 UInt_t dilogic = 0, row = 0;
241 word32 = GetWord(1,kBwd);
242 //check on row number
244 row = (word32 >> kbit22) & 0xf;
245 if(!CheckRow(row)) continue;
246 //check dilogic number
247 dilogic = (word32 >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
248 if(!CheckDilogic(dilogic)) continue;
250 UInt_t pad = (word32 >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
251 if(!CheckPad(pad)) continue;
252 fCharge[fDDLNumber][row][dilogic][pad] = word32 & 0xfff;
253 // Printf(" (word %08X) DDL %i row %i dil %i pad %i ",word32,fDDLNumber,row,dilogic,pad);
259 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
260 Bool_t AliHMPIDRawStream::CheckSegment(UInt_t word)
262 UInt_t markSegment = 0xAB0;
265 UInt_t segWord = GetWord();
266 if ((segWord >> 20) != statusSegWord) {
267 fRawReader->AddMajorErrorLog(kBadSegWordErr);
268 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
269 fNumOfErr[kBadSegWordErr]++;
273 UInt_t segMarker = (word >> kbit20) & 0xfff;
274 if (segMarker != markSegment ) {
275 fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at address %i in word %0X!",segMarker,markSegment,fPosition/4,word));
276 AliWarning(Form("Segment marker %X wrong (expected %0X)! at address %i in word %0X!",segMarker,markSegment,fPosition/4,word));
277 fNumOfErr[kWrongSegErr]++;
281 UInt_t segAddress = word & 0xff;
282 if (segAddress<1 ||segAddress>3) {
283 fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at address %i in word %0X",segAddress,fPosition/4,word));
284 AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));
285 fNumOfErr[kWrongSegErr]++;
288 Printf("Segment Marker found! Number of segment is %i",segAddress);
291 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
292 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
294 //check on row number
295 if(row>=1 && row <=kNRows) return kTRUE;
297 fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
298 AliWarning(Form("Wrong row index: %d, expected (1 -> %d)!",row,kNRows));
299 fNumOfErr[kWrongRowErr]++;
302 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
303 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
305 //check dilogic number
306 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
308 fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
309 AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
310 fNumOfErr[kWrongDilogicErr]++;
311 //dilogic = iDILOGIC;
314 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
315 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
318 if (pad < kNPadAdd) return kTRUE;
320 fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
321 AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
322 fNumOfErr[kWrongPadErr]++;
325 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
326 Bool_t AliHMPIDRawStream::CheckEoE(UInt_t word,Int_t &nDil)
328 if (!((word >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
329 fRawReader->AddMajorErrorLog(kEoEFlagErr);
330 AliWarning(Form("Missing end-of-event flag! (%08X)",word));
331 fNumOfErr[kEoEFlagErr]++;
335 if(nDil < 1 || nDil > 48 ) {
336 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
337 AliWarning(Form("Wrong end-of-event word-count: %08X",word));
338 fNumOfErr[kEoESizeErr]++;
341 // UInt_t da = (eOfEvent >> 18) & 0xf;
342 // if (cntData!=0 && da != dilogic) {
343 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
344 // AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
345 // fNumOfErr[kEoEDILOGICErr]++;
346 // return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
349 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
350 // if (cntData!=0 && ca != row) {
351 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
352 // AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
353 // fNumOfErr[kEoERowErr]++;
358 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359 Bool_t AliHMPIDRawStream::CheckRowMarker(UInt_t word)
361 UInt_t nMAXwordsInRow = 0x1EA;
362 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
363 //First check on row marker
364 UInt_t rowControlWord = word >> kbit0 & 0xfbff;
366 if(rowControlWord != statusControlRow) {
367 fRawReader->AddMajorErrorLog(kRowMarkerErr);
368 AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
369 fNumOfErr[kRowMarkerErr]++;
372 //Second check on row marker
373 UInt_t wordsInRow = word >> kbit16 & 0x0fff; // Number of words after the row marker
375 if (wordsInRow > nMAXwordsInRow) {
376 fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
377 AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));
378 fNumOfErr[kRowMarkerSizeErr]++;
384 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385 UInt_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
387 // This method returns the n-th 32 bit word
388 // inside the raw data payload.
389 // The method is supposed to be endian (platform)
391 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
395 if(dir==kBwd) n = -n;
400 word |= fData[fPosition++];
401 word |= fData[fPosition++] << 8;
402 word |= fData[fPosition++] << 16;
403 word |= fData[fPosition++] << 24;
407 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
408 void AliHMPIDRawStream::DumpData(Int_t nw)
410 for(Int_t i=0;i<nw;i+=4) {
411 if(!(i%16)) printf(" \n %8i) ",i);
412 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
414 Printf(" \n -----end of dump ----------- ");
416 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417 void AliHMPIDRawStream::StorePosition()
419 // if(fPos[fPosition]!=0) {Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition); return;}
421 fPos[fPosition] = iPos;
422 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);