]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDRawStream.cxx
Updated error definitions.
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDRawStream.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 ///////////////////////////////////////////////////////////////////////////////
17 ///
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.
21 ///
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliHMPIDRawStream.h"
25 #include "AliRawReader.h"
26 #include "AliLog.h"
27
28 static Bool_t stDeb = kFALSE;      
29 //static Bool_t stDeb = kTRUE;      
30
31 ClassImp(AliHMPIDRawStream)
32
33 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
35   fDDLNumber(-1),
36   fRawReader(rawReader),
37   fData(NULL),
38   fPosition(-1)
39 {
40   // Constructor
41   fNPads = 0;
42   fCharge = 0x0;
43   fPad =0x0;
44
45   fRawReader->Reset();
46   fRawReader->Select("HMPID");
47 }
48 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 AliHMPIDRawStream::AliHMPIDRawStream() :
50   fDDLNumber(-1),
51   fRawReader(0x0),
52   fData(NULL),
53   fPosition(-1)
54 {
55 }
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57 AliHMPIDRawStream::~AliHMPIDRawStream()
58 {
59   // destructor
60     DelVars();
61 }
62 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63 void AliHMPIDRawStream::Reset()
64 {
65   // reset raw stream params
66   // Reinitalize the containers
67   fDDLNumber = -1;
68   fPosition = -1;
69   fData = NULL;
70   if (fRawReader) fRawReader->Reset();
71 }
72 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73 Bool_t AliHMPIDRawStream::Next()
74 {
75   // read next DDL raw data from the HMPID raw data stream
76   // return kFALSE in case of error or no data left
77   AliDebug(1,"Start.");
78   do {
79     if (!fRawReader->ReadNextData(fData)) return kFALSE;
80   } while (fRawReader->GetDataSize() == 0);
81   
82      
83   /*
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 
100   */
101
102   fPosition = 0;
103   Bool_t status;
104           
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();
110    
111     if(stDeb) {
112       if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
113       else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
114 //      DumpData(fRawReader->GetDataSize());
115     }
116 //    stDeb=kFALSE;
117   }
118 //  return status;
119   return kTRUE;
120 }
121 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 void AliHMPIDRawStream::InitVars(Int_t n)
123 {
124   fNPads = 0;
125   fCharge = new Int_t[n];
126   fPad = 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];
130   }
131   //for debug purpose
132   fPos = new Int_t[4*n];                     //reset debug
133   iPos = 0;
134 }    
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136 void AliHMPIDRawStream::DelVars()
137 {
138   fNPads = 0;
139   delete fCharge;
140   delete fPad;
141   delete fNumOfErr;
142   for(Int_t i=0;i<kNDDL;i++) delete [] fNumOfErr[i]; delete [] fNumOfErr;
143   delete fPos;
144 }    
145 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146 Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
147 {
148   Int_t cntGlob = fRawReader->GetDataSize()/4;
149   Int_t cnt = cntGlob;
150   Int_t nwSeg;
151   Int_t cntSegment;
152
153   fWord = GetWord(cnt);cnt--;
154
155   
156   while (cnt>0) {
157     
158     nwSeg = (fWord >> kbit8) & 0xfff;
159     if(!CheckSegment()) return kFALSE;
160     if(!ReadSegment(cntSegment)) return kFALSE;
161
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);
164     cnt-=cntSegment+1;
165   }
166   
167   return kTRUE;
168   
169 }
170 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
172 {
173   cntSegment = (fWord >> kbit8) & 0xfff;
174   Int_t cnt = cntSegment;
175   Int_t cntRow;
176   Int_t nwRow;
177
178   fWord = GetWord(cnt,kBwd);
179   
180   while (cnt>0) {
181
182     cntRow  = (fWord >> kbit16) & 0xfff;
183     if(!CheckRowMarker()) return kFALSE;
184     if(!ReadRow(nwRow)) return kFALSE;
185
186     if(nwRow != cntRow) {if(stDeb){Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);} return kFALSE;}
187     fWord = GetWord(cntRow+1);
188     cnt -= cntRow+1;
189     
190   }
191
192   cntSegment -= cnt;
193   
194   return kTRUE;
195     
196 }    
197 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
198 Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
199 {
200   Int_t cnt;
201   Int_t cntDilogic;
202   Int_t nwDil;
203   
204   cntRow  = (fWord >> kbit16) & 0xfff;
205   cnt = cntRow;  
206   
207   fWord = GetWord(cntRow);
208   
209   while (cnt>0) {
210     
211     if(!CheckEoE(nwDil)) return kFALSE;
212     if(!ReadDilogic(cntDilogic)) return kFALSE;
213     
214     if(nwDil != cntDilogic) {if(stDeb){Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);}return kFALSE;}
215     cnt -= cntDilogic;
216     fWord = GetWord(1,kBwd); // go to next Dilogic bank...
217     cnt--;
218 //    Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
219   }
220   
221   cntRow -= cnt;  
222   
223   return kTRUE;
224   
225 }
226 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
227 Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
228 {
229   cntDilogic = fWord & 0x7f;
230   
231   Int_t cnt = cntDilogic;
232   
233 //  Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
234
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      
239     cnt--;
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;
245 //check pad number
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;
251     fNPads++;
252   }
253
254   cntDilogic -= cnt;  
255   return kTRUE;  
256 }
257 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
258 Bool_t AliHMPIDRawStream::CheckSegment()
259 {
260   UInt_t markSegment = 0xAB0;
261   /*
262   if (iRow%8 == 0) {
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]++;
268       return kTRUE;
269     }
270 */
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]++;
276     return kFALSE;
277   }
278   
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]++;
284     return kFALSE;
285   }
286 //  Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
287   return kTRUE;
288 }
289 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
290 Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
291 {
292 //check on row number      
293 //  Printf("ROW %i word %0X",row,fWord);
294   if(row>=1 && row <=kNRows) return kTRUE;
295   
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]++;
299   return kFALSE;
300 }
301 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302 Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
303 {
304 //check dilogic number     
305   if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
306
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;
311   return kFALSE;
312 }      
313 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
314 Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
315 {
316 //check pad number     
317   if (pad < kNPadAdd) return kTRUE;
318   
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]++;
322   return kFALSE;
323 }    
324 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325 Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
326 {
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]++;
331     return kFALSE;
332   }
333   nDil = fWord & 0x7f;                                               //nDil=EoE word count
334   if(nDil < 0 || nDil > 48 ) { 
335
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]++;
339     return kFALSE;
340   }
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) ;  
347
348 //  }
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]++;
354 //    return kFALSE;
355 //  }
356   return kTRUE;
357 }
358 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359 Bool_t AliHMPIDRawStream::CheckRowMarker()
360 {
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;
365   
366   if(rowControlWord != statusControlRow) {
367     //fRawReader->AddMajorErrorLog(kRowMarkerErr);
368     if(stDeb){AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
369               fNumOfErr[fDDLNumber][kRowMarkerErr]++;
370               return kFALSE; }
371    }
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
374   
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]++;
379     return kFALSE;
380   }
381   
382   return kTRUE;
383 }
384 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385 UInt_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
386 {
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)
390   // independent.
391   if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
392   
393   UInt_t word = 0;
394   
395   if(dir==kBwd) n = -n; 
396   fPosition+=4*n-4;
397   
398   StorePosition();
399   
400   word |= fData[fPosition++];
401   word |= fData[fPosition++] << 8;
402   word |= fData[fPosition++] << 16;
403   word |= fData[fPosition++] << 24;
404
405   return word;
406 }
407 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
408 void AliHMPIDRawStream::DumpData(Int_t nw)
409 {
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]);
413    }
414    Printf(" \n -----end of dump ----------- ");
415 }
416 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417 void AliHMPIDRawStream::StorePosition()
418 {
419   if(fPos[fPosition]!=0) {
420 //    Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition); 
421     return;
422   }
423   iPos++;
424   fPos[fPosition] = iPos;
425 //  if(stDeb)Printf("%i - Actual position %i",iPos,fPosition); 
426 }
427 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++