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),
46 for(Int_t l=1; l < kSumErr; l++) fNumOfErr[l]=0; //reset errors
49 fRawReader->Select("HMPID");
51 //-----------------------------------------------------------------------------
52 AliHMPIDRawStream::AliHMPIDRawStream() :
59 for(Int_t l=1; l < kSumErr; l++) fNumOfErr[l]=0; //reset errors
61 //_____________________________________________________________________________
62 AliHMPIDRawStream::~AliHMPIDRawStream()
67 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
68 void AliHMPIDRawStream::Reset()
70 // reset raw stream params
71 // Reinitalize the containers
75 if (fRawReader) fRawReader->Reset();
77 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
78 Bool_t AliHMPIDRawStream::Next()
80 // read next DDL raw data from the HMPID raw data stream
81 // return kFALSE in case of error or no data left
84 if (!fRawReader->ReadNextData(fData)) return kFALSE;
85 } while (fRawReader->GetDataSize() == 0);
89 Event type is selected as in $ALICE_ROOT/RAW/event.h
90 #define START_OF_RUN ((eventTypeType) 1)
91 #define END_OF_RUN ((eventTypeType) 2)
92 #define START_OF_RUN_FILES ((eventTypeType) 3)
93 #define END_OF_RUN_FILES ((eventTypeType) 4)
94 #define START_OF_BURST ((eventTypeType) 5)
95 #define END_OF_BURST ((eventTypeType) 6)
96 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
97 #define CALIBRATION_EVENT ((eventTypeType) 8)
98 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
99 #define START_OF_DATA ((eventTypeType)10)
100 #define END_OF_DATA ((eventTypeType)11)
101 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
102 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
103 #define EVENT_TYPE_MIN 1
104 #define EVENT_TYPE_MAX 13
110 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
111 fDDLNumber = fRawReader->GetDDLID();
112 Printf("DDL %i started to be decoded!.",fDDLNumber);
113 InitVars(fRawReader->GetDataSize()/4);
114 status = ReadHMPIDRawData();
115 if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
116 else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
117 if(stDeb) DumpData(fRawReader->GetDataSize());
123 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124 void AliHMPIDRawStream::InitVars(Int_t n)
127 fCharge = new Int_t[n];
130 for(Int_t i=0; i < 170000; i++) fPos[i]=0; //reset debug
133 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
134 void AliHMPIDRawStream::DelVars()
140 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
143 Int_t cntGlob = fRawReader->GetDataSize()/4;
148 fWord = GetWord(cnt);cnt--;
153 nwSeg = (fWord >> kbit8) & 0xfff;
154 if(!CheckSegment()) return kFALSE;
155 if(!ReadSegment(cntSegment)) return kFALSE;
157 if(nwSeg != cntSegment) {Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);return kFALSE;}
158 // Printf(" cnt %i cntSegment %i",cnt,cntSegment);
159 fWord = GetWord(cntSegment+1,kBwd);
166 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
169 cntSegment = (fWord >> kbit8) & 0xfff;
170 Int_t cnt = cntSegment;
174 fWord = GetWord(cnt,kBwd);
178 cntRow = (fWord >> kbit16) & 0xfff;
179 if(!CheckRowMarker()) return kFALSE;
180 if(!ReadRow(nwRow)) return kFALSE;
182 if(nwRow != cntRow) {Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);return kFALSE;}
183 fWord = GetWord(cntRow+1);
193 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
194 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
200 cntRow = (fWord >> kbit16) & 0xfff;
203 fWord = GetWord(cntRow);
207 if(!CheckEoE(nwDil)) return kFALSE;
208 if(!ReadDilogic(cntDilogic)) return kFALSE;
210 if(nwDil != cntDilogic) {Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);return kFALSE;}
212 fWord = GetWord(1,kBwd); // go to next Dilogic bank...
214 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
222 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
223 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
225 cntDilogic = fWord & 0x7f;
227 Int_t cnt = cntDilogic;
229 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
231 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
232 UInt_t dilogic = 0, row = 0;
233 fWord = GetWord(1,kBwd);
234 //check on row number
236 row = (fWord >> kbit22) & 0x1f;
237 if(!CheckRow(row)) continue;
238 //check dilogic number
239 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
240 if(!CheckDilogic(dilogic)) continue;
242 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
243 if(!CheckPad(pad)) continue;
244 Int_t charge = fWord & 0xfff;
245 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
246 fCharge[fNPads] = charge;
253 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
254 Bool_t AliHMPIDRawStream::CheckSegment()
256 UInt_t markSegment = 0xAB0;
259 UInt_t segWord = GetWord();
260 if ((segWord >> 20) != statusSegWord) {
261 fRawReader->AddMajorErrorLog(kBadSegWordErr);
262 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
263 fNumOfErr[kBadSegWordErr]++;
267 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
268 if (segMarker != markSegment ) {
269 fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
270 AliWarning(Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
271 fNumOfErr[kWrongSegErr]++;
275 UInt_t segAddress = fWord & 0xff;
276 if (segAddress<1 ||segAddress>3) {
277 fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
278 AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));
279 fNumOfErr[kWrongSegErr]++;
282 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
285 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
286 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
288 //check on row number
289 // Printf("ROW %i word %0X",row,fWord);
290 if(row>=1 && row <=kNRows) return kTRUE;
292 fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
293 AliWarning(Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));
294 fNumOfErr[kWrongRowErr]++;
297 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
298 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
300 //check dilogic number
301 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
303 fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
304 AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
305 fNumOfErr[kWrongDilogicErr]++;
306 //dilogic = iDILOGIC;
309 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
310 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
313 if (pad < kNPadAdd) return kTRUE;
315 fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
316 AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
317 fNumOfErr[kWrongPadErr]++;
320 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
321 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
323 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
324 fRawReader->AddMajorErrorLog(kEoEFlagErr);
325 AliWarning(Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));
326 fNumOfErr[kEoEFlagErr]++;
330 if(nDil < 0 || nDil > 48 ) {
331 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
332 AliWarning(Form("Wrong end-of-event word-count: %08X",fWord));
333 fNumOfErr[kEoESizeErr]++;
336 // UInt_t da = (eOfEvent >> 18) & 0xf;
337 // if (cntData!=0 && da != dilogic) {
338 // fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
339 // AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
340 // fNumOfErr[kEoEDILOGICErr]++;
341 // return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
344 // UInt_t ca = (eOfEvent >> 22) & 0x1f;
345 // if (cntData!=0 && ca != row) {
346 // fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
347 // AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
348 // fNumOfErr[kEoERowErr]++;
353 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
354 Bool_t AliHMPIDRawStream::CheckRowMarker()
356 UInt_t nMAXwordsInRow = 0x1EA;
357 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
358 //First check on row marker
359 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
361 if(rowControlWord != statusControlRow) {
362 fRawReader->AddMajorErrorLog(kRowMarkerErr);
363 AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
364 fNumOfErr[kRowMarkerErr]++;
367 //Second check on row marker
368 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker
370 if (wordsInRow > nMAXwordsInRow) {
371 fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
372 AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));
373 fNumOfErr[kRowMarkerSizeErr]++;
379 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
380 UInt_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
382 // This method returns the n-th 32 bit word
383 // inside the raw data payload.
384 // The method is supposed to be endian (platform)
386 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
390 if(dir==kBwd) n = -n;
395 word |= fData[fPosition++];
396 word |= fData[fPosition++] << 8;
397 word |= fData[fPosition++] << 16;
398 word |= fData[fPosition++] << 24;
402 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
403 void AliHMPIDRawStream::DumpData(Int_t nw)
405 for(Int_t i=0;i<nw;i+=4) {
406 if(!(i%16)) printf(" \n %8i) ",i);
407 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
409 Printf(" \n -----end of dump ----------- ");
411 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412 void AliHMPIDRawStream::StorePosition()
414 if(fPos[fPosition]!=0) {
415 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
419 fPos[fPosition] = iPos;
420 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);