]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDRawStream.cxx
The code is now optimized. Errors trace back can be monitored (L.M.)
[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
29 ClassImp(AliHMPIDRawStream)
30
31 //_____________________________________________________________________________
32 AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
33   fDDLNumber(-1),
34   fRawReader(rawReader),
35   fData(NULL),
36   fPosition(-1)
37 {
38   // Constructor
39   Init();
40
41   fRawReader->Reset();
42   fRawReader->Select("HMPID");
43 }
44 //-----------------------------------------------------------------------------
45 AliHMPIDRawStream::AliHMPIDRawStream() :
46   fDDLNumber(-1),
47   fRawReader(0x0),
48   fData(NULL),
49   fPosition(-1)
50 {
51   // Constructor
52   Init();
53 }
54 //_____________________________________________________________________________
55 AliHMPIDRawStream::~AliHMPIDRawStream()
56 {
57   // destructor
58 }
59
60 //_____________________________________________________________________________
61 void AliHMPIDRawStream::Init()
62 {
63   // Initalize the container
64   // with the pad charges
65   for(Int_t h = 0; h < kNDDL; h++) {  
66     for(Int_t i = 0; i < kNRows; i++){
67       for(Int_t j = 0; j < kNDILOGICAdd; j++){
68         for(Int_t k = 0; k < kNPadAdd; k++){
69           fCharge[h][i][j][k] = -1;
70           fPad[h][i][j][k]=-1;
71         }
72       }
73     }
74   }
75   fZeroSup=kTRUE;
76   
77   for(Int_t l=1; l < kSumErr; l++) fNumOfErr[l]=0;               //reset errors
78 }//Init()
79 //_____________________________________________________________________________
80 void AliHMPIDRawStream::Reset()
81 {
82   // reset raw stream params
83   // Reinitalize the containers
84   Init();
85   fDDLNumber = -1;
86   fPosition = -1;
87   fData = NULL;
88   if (fRawReader) fRawReader->Reset();
89 }
90 //_____________________________________________________________________________
91 Bool_t AliHMPIDRawStream::Next()
92 {
93   // read next DDL raw data from the HMPID raw data stream
94   // return kFALSE in case of error or no data left
95   AliDebug(1,"Start.");
96   do {
97     if (!fRawReader->ReadNextData(fData)) return kFALSE;
98   } while (fRawReader->GetDataSize() == 0);
99   
100  
101   /*
102   Event type is selected as in $ALICE_ROOT/RAW/event.h  
103   #define START_OF_RUN                    ((eventTypeType) 1)
104   #define END_OF_RUN                      ((eventTypeType) 2)
105   #define START_OF_RUN_FILES              ((eventTypeType) 3)
106   #define END_OF_RUN_FILES                ((eventTypeType) 4)
107   #define START_OF_BURST                  ((eventTypeType) 5)
108   #define END_OF_BURST                    ((eventTypeType) 6)
109   #define PHYSICS_EVENT                   ((eventTypeType) 7) <<---------------  
110   #define CALIBRATION_EVENT               ((eventTypeType) 8)
111   #define EVENT_FORMAT_ERROR              ((eventTypeType) 9)
112   #define START_OF_DATA                   ((eventTypeType)10)
113   #define END_OF_DATA                     ((eventTypeType)11)
114   #define SYSTEM_SOFTWARE_TRIGGER_EVENT   ((eventTypeType)12)
115   #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
116   #define EVENT_TYPE_MIN                  1
117   #define EVENT_TYPE_MAX                  13 
118   */
119       
120   if(fRawReader->GetType() == 7)  {                             //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
121   
122     fDDLNumber = fRawReader->GetDDLID();
123     fPosition = 0;
124   
125     Init();
126     
127     // Look over rows
128     for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
129       UInt_t rowMarker = GetNextWord();                                 // Read row marker
130       
131       Int_t numRows= rowMarker >> 16 & 0xffffff;                        // Number of words after the row marker
132          
133       if ( numRows > 490 ) {      //The row marker is fixed and we cannot have more than 490 words!!!
134         fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
135         AliWarning(Form("Wrong row marker size %x for row %d, value: %d expected < 490!",rowMarker,iRow,numRows));
136         fNumOfErr[kRowMarkerSizeErr]++;
137         return kTRUE;
138       }//check for row marker
139       
140       if ((rowMarker >> 0 & 0xffff) != 0x32a8  ) {      //The row marker is fixed and we cannot have more than 490 words!!!
141         fRawReader->AddMajorErrorLog(kRowMarkerErr);
142         AliWarning(Form("Wrong row marker %x for row %d, expected 0x32a8!",rowMarker,iRow));
143          fNumOfErr[kRowMarkerErr]++;
144         return kTRUE;
145       }//check for row marker
146       UInt_t dilogic = 0, row = 0;
147       UInt_t cntData=0;
148       UInt_t cntEoE=0;
149       //molnarl: lets read how many rows we have from the marker; 10 dilogic EoE so we can get the number of data words they should be in order
150       for(Int_t iWordInRow=0; iWordInRow<numRows;iWordInRow++) //loop over words 
151         {     
152           UInt_t tmpword=GetNextWord();               
153           UInt_t eOfEvent = tmpword;                     // always assume that it is an EoE. If bit 
154           if (!((eOfEvent >> 27) & 0x1)) {               // if it is not EoE then data!
155             UInt_t data=tmpword;
156             row = (data >> 22) & 0x1f;                                                  //row information in raw word is between bits: 22...26
157             if (row < 1 || row > kNRows) {                                              //select bits from 22 and with 0x1f ask for the next 5 bits 
158               fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
159               AliWarning(Form("Wrong row index: %d, expected (1 -> %d)!",row,kNRows));
160               fNumOfErr[kWrongRowErr]++;
161               // row = iRow;
162             }
163             dilogic = (data >> 18) & 0xf;                                              //dilogic info in raw word is between bits: 18...21
164             if (dilogic < 1 || dilogic > kNDILOGICAdd) {
165               fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
166               AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
167               fNumOfErr[kWrongDilogicErr]++;
168               //dilogic = iDILOGIC;
169             }
170             UInt_t pad = (data >> 12) & 0x3f;                                                    //pad info in raw word is between bits: 12...17
171             if (pad >= kNPadAdd) {
172               fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
173               AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
174               fNumOfErr[kWrongPadErr]++;
175               //pad = iPad;
176             }
177             fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff;  cntData++;
178             
179           }//not EoE but data!
180           //if it is EoE
181           else{
182             if (!((eOfEvent >> 27) & 0x1)) {                                                  //check 27th bit in EoE. It must be 1!
183               fRawReader->AddMajorErrorLog(kEoEFlagErr);
184               AliWarning(Form("Missing end-of-event flag! (%x)",eOfEvent));
185               fNumOfErr[kEoEFlagErr]++;
186               return kTRUE;
187             }
188             UInt_t wc = eOfEvent & 0x7f;
189             if (wc != cntData) {
190               fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
191               AliWarning(Form("Wrong end-of-event word-count: %d, expected: %d!",wc,cntData));
192               fNumOfErr[kEoESizeErr]++;
193               return kTRUE;
194             }
195             UInt_t da = (eOfEvent >> 18) & 0xf;
196             if (cntData!=0 && da != dilogic) {
197               fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
198               AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
199               fNumOfErr[kEoEDILOGICErr]++;
200               return kTRUE;
201             }
202             UInt_t ca = (eOfEvent >> 22) & 0x1f;
203             if (cntData!=0 &&  ca != row) {
204               fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
205               AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
206               fNumOfErr[kEoERowErr]++;
207               return kTRUE;
208             }
209             cntData=0;  cntEoE++;//zero it and wait for new data words
210           } //EoE word
211           
212         } //loop over rows within two markers
213       
214       
215       
216       // Read the segment marker
217       // One maker per 8 rows
218       
219       if (iRow%8 == 0) {
220         UInt_t segWord = GetNextWord();          
221         if ((segWord >> 8) != 0xab0f59) {
222           fRawReader->AddMajorErrorLog(kBadSegWordErr);
223           AliWarning(Form("Wrong segment word signature: %x, expected 0xab0f59!",(segWord >> 8)));
224           fNumOfErr[kBadSegWordErr]++;
225           return kTRUE;
226         }
227         
228         if ((segWord & 0xff) != (((UInt_t)iRow + 7) / 8)) {
229           fRawReader->AddMajorErrorLog(kWrongSegErr,Form("seg %d != %d",segWord & 0xff,(iRow + 7) / 8));
230           AliWarning(Form("Segment index (%d) does not correspond to the one expected from row index (%d)!",segWord & 0xff,(iRow + 7) / 8));
231           fNumOfErr[kWrongSegErr]++;
232           return kTRUE;
233         }
234       }
235     }//loop of Row   
236   }//REal data files selected by data lenght
237   
238   AliDebug(1,"Stop."); 
239   return kTRUE;
240 }
241
242 //_____________________________________________________________________________
243 UInt_t AliHMPIDRawStream::GetNextWord()
244 {
245   // This method returns the next 32 bit word
246   // inside the raw data payload.
247   // The method is supposed to be endian (platform)
248   // independent.
249   if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
250   
251   UInt_t word = 0;
252   word |= fData[fPosition++];
253   word |= fData[fPosition++] << 8;
254   word |= fData[fPosition++] << 16;
255   word |= fData[fPosition++] << 24;
256   
257   return word;
258 }
259
260 //_____________________________________________________________________________