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) :
36 fRawReader(rawReader),
46 fRawReader->Select("HMPID");
48 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 AliHMPIDRawStream::AliHMPIDRawStream() :
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57 AliHMPIDRawStream::~AliHMPIDRawStream()
62 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63 void AliHMPIDRawStream::Reset()
65 // reset raw stream params
66 // Reinitalize the containers
70 if (fRawReader) fRawReader->Reset();
72 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73 Bool_t AliHMPIDRawStream::Next()
75 // read next DDL raw data from the HMPID raw data stream
76 // return kFALSE in case of error or no data left
79 if (!fRawReader->ReadNextData(fData)) return kFALSE;
80 } while (fRawReader->GetDataSize() == 0);
84 Event type is selected as in $ALICE_ROOT/RAW/event.h
85 #define START_OF_RUN ((eventTypeType) 1)
86 #define END_OF_RUN ((eventTypeType) 2)
87 #define START_OF_RUN_FILES ((eventTypeType) 3)
88 #define END_OF_RUN_FILES ((eventTypeType) 4)
89 #define START_OF_BURST ((eventTypeType) 5)
90 #define END_OF_BURST ((eventTypeType) 6)
91 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
92 #define CALIBRATION_EVENT ((eventTypeType) 8)
93 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
94 #define START_OF_DATA ((eventTypeType)10)
95 #define END_OF_DATA ((eventTypeType)11)
96 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
97 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
98 #define EVENT_TYPE_MIN 1
99 #define EVENT_TYPE_MAX 13
105 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
106 fDDLNumber = fRawReader->GetDDLID();
107 if(stDeb) Printf("DDL %i started to be decoded!.",fDDLNumber);
108 InitVars(fRawReader->GetDataSize()/4);
109 status = ReadHMPIDRawData();
112 if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
113 else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
114 // DumpData(fRawReader->GetDataSize());
121 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 void AliHMPIDRawStream::InitVars(Int_t n)
125 fCharge = new Int_t[n];
127 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
128 for(Int_t i=0;i<kNDDL;i++) {
129 fNumOfErr[i] = new Int_t [kSumErr];
132 fPos = new Int_t[4*n]; //reset debug
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136 void AliHMPIDRawStream::DelVars()
142 for(Int_t i=0;i<kNDDL;i++) delete [] fNumOfErr[i]; delete [] fNumOfErr;
145 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
148 Int_t cntGlob = fRawReader->GetDataSize()/4;
153 fWord = GetWord(cnt);cnt--;
158 nwSeg = (fWord >> kbit8) & 0xfff;
159 if(!CheckSegment()) return kFALSE;
160 if(!ReadSegment(cntSegment)) return kFALSE;
162 if(nwSeg != cntSegment) {if(stDeb){Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);} return kFALSE;}
163 fWord = GetWord(cntSegment+1,kBwd);
170 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
173 cntSegment = (fWord >> kbit8) & 0xfff;
174 Int_t cnt = cntSegment;
178 fWord = GetWord(cnt,kBwd);
182 cntRow = (fWord >> kbit16) & 0xfff;
183 if(!CheckRowMarker()) return kFALSE;
184 if(!ReadRow(nwRow)) return kFALSE;
186 if(nwRow != cntRow) {if(stDeb){Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);} return kFALSE;}
187 fWord = GetWord(cntRow+1);
197 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
198 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
204 cntRow = (fWord >> kbit16) & 0xfff;
207 fWord = GetWord(cntRow);
211 if(!CheckEoE(nwDil)) return kFALSE;
212 if(!ReadDilogic(cntDilogic)) return kFALSE;
214 if(nwDil != cntDilogic) {if(stDeb){Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);}return kFALSE;}
216 fWord = GetWord(1,kBwd); // go to next Dilogic bank...
218 // Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
226 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
227 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
229 cntDilogic = fWord & 0x7f;
231 Int_t cnt = cntDilogic;
233 // Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
235 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
236 UInt_t dilogic = 0, row = 0;
237 fWord = GetWord(1,kBwd);
238 //check on row number
240 row = (fWord >> kbit22) & 0x1f;
241 if(!CheckRow(row)) continue;
242 //check dilogic number
243 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
244 if(!CheckDilogic(dilogic)) continue;
246 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
247 if(!CheckPad(pad)) continue;
248 Int_t charge = fWord & 0xfff;
249 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
250 fCharge[fNPads] = charge;
257 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
258 Bool_t AliHMPIDRawStream::CheckSegment()
260 UInt_t markSegment = 0xAB0;
263 UInt_t segWord = GetWord();
264 if ((segWord >> 20) != statusSegWord) {
265 fRawReader->AddMajorErrorLog(kBadSegWordErr);
266 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
267 fNumOfErr[kBadSegWordErr]++;
271 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
272 if (segMarker != markSegment ) {
273 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
274 if(stDeb){ AliWarning(Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));}
275 fNumOfErr[fDDLNumber][kWrongSegErr]++;
279 UInt_t segAddress = fWord & 0xff;
280 if (segAddress<1 ||segAddress>3) {
281 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
282 if(stDeb){AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));}
283 fNumOfErr[fDDLNumber][kWrongSegErr]++;
286 // Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
289 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
290 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
292 //check on row number
293 // Printf("ROW %i word %0X",row,fWord);
294 if(row>=1 && row <=kNRows) return kTRUE;
296 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
297 if(stDeb){AliWarning(Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));}
298 fNumOfErr[fDDLNumber][kWrongRowErr]++;
301 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
304 //check dilogic number
305 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
307 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
308 if(stDeb){AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));}
309 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
310 //dilogic = iDILOGIC;
313 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
314 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
317 if (pad < kNPadAdd) return kTRUE;
319 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
320 if(stDeb){AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));}
321 fNumOfErr[fDDLNumber][kWrongPadErr]++;
324 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
327 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
328 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
329 if(stDeb){AliWarning(Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));}
330 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
333 nDil = fWord & 0x7f; //nDil=EoE word count
334 if(nDil < 0 || nDil > 48 ) {
336 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
337 if(stDeb){AliWarning(Form("Wrong end-of-event word-count: %08X",fWord));}
338 fNumOfErr[fDDLNumber][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()
361 UInt_t nMAXwordsInRow = 0x1EA;
362 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
363 //First check on row marker
364 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
366 if(rowControlWord != statusControlRow) {
367 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
368 if(stDeb){AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
369 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
372 //Second check on row marker
373 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
375 if (wordsInRow > nMAXwordsInRow) {
376 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
377 if(stDeb){AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));}
378 fNumOfErr[fDDLNumber][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) {
420 // Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
424 fPos[fPosition] = iPos;
425 // if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
427 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++