]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDRawStream.cxx
typo fixed: HMP_DET/HMP_ENV/HMP_ENV_TENV.actual.value
[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 }//Init()
77 //_____________________________________________________________________________
78 void AliHMPIDRawStream::Reset()
79 {
80   // reset raw stream params
81   // Reinitalize the containers
82   Init();
83   fDDLNumber = -1;
84   fPosition = -1;
85   fData = NULL;
86   if (fRawReader) fRawReader->Reset();
87 }
88 //_____________________________________________________________________________
89 Bool_t AliHMPIDRawStream::Next()
90 {
91   // read next DDL raw data from the HMPID raw data stream
92   // return kFALSE in case of error or no data left
93   AliDebug(1,"Start.");
94   do {
95     if (!fRawReader->ReadNextData(fData)) return kFALSE;
96   } while (fRawReader->GetDataSize() == 0);
97   
98   if ( fRawReader->GetDataSize() > 47148) {
99     AliWarning(Form("Raw data event size is larger (%d) than possible for HMPID!!!! ",fRawReader->GetDataSize()));
100   }
101   
102   else if (fRawReader->GetDataSize() == 47148) {
103     fDDLNumber = fRawReader->GetDDLID();
104     fPosition = 0;
105     
106     Init();
107     
108     // Look over rows
109     for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
110       // Read row marker
111       UInt_t rowMarker = GetNextWord() & 0x1ffffff;
112       if (rowMarker != 0x1ea32a8) {
113         fRawReader->AddMajorErrorLog(kRowMarkerErr);
114         AliWarning(Form("Wrong row marker %x for row %d, expected 0x1ea32a8!",rowMarker,iRow));
115         return kTRUE;
116       }//check for row marker
117       UInt_t dilogic = 0, row = 0;
118       for(Int_t iDILOGIC = 1; iDILOGIC <= kNDILOGICAdd; iDILOGIC++) {
119         // Read pad charges
120         for(Int_t iPad = 0; iPad < kNPadAdd; iPad++) {
121           UInt_t data = GetNextWord();
122           row = (data >> 22) & 0x1f;                                                      //row information in raw word is between bits: 22...26
123           if (row < 1 || row > kNRows) {
124             fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
125             AliWarning(Form("Wrong row index: %d, expected (1 -> %d)!",row,kNRows));
126             row = iRow;
127           }
128           dilogic = (data >> 18) & 0xf;                                                   //dilogic info in raw word is between bits: 18...21
129           if (dilogic < 1 || dilogic > kNDILOGICAdd) {
130             fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
131             AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
132             dilogic = iDILOGIC;
133           }
134           UInt_t pad = (data >> 12) & 0x3f;                                               //pad info in raw word is between bits: 12...17
135           if (pad >= kNPadAdd) {
136             fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
137             AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
138             pad = iPad;
139           }
140           fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff;
141         }
142         // Now read the end-of-event word
143         UInt_t eOfEvent = GetNextWord() & 0xfffffff;
144         if (!((eOfEvent >> 27) & 0x1)) {                                                  //check 27th bit in EoE. It must be 1!
145           fRawReader->AddMajorErrorLog(kEoEFlagErr);
146           AliWarning(Form("Missing end-of-event flag! (%x)",eOfEvent));
147           return kTRUE;
148         }
149         UInt_t wc = eOfEvent & 0x7f;
150         if (wc != 48) {
151           fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
152           AliWarning(Form("Wrong end-of-event word-count:%d, expected 48!",wc));
153           return kTRUE;
154         }
155         UInt_t da = (eOfEvent >> 18) & 0xf;
156         if (da != dilogic) {
157           fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
158           AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
159           return kTRUE;
160         }
161         UInt_t ca = (eOfEvent >> 22) & 0x1f;
162         if (ca != row) {
163           fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
164           AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
165           return kTRUE;
166         }
167       }//DILOGIC loop
168       
169       // Read the segment marker
170       // One maker per 8 rows
171       
172       if (iRow%8 == 0) {
173         UInt_t segWord = GetNextWord();
174         if ((segWord >> 8) != 0xab0f59) {
175           fRawReader->AddMajorErrorLog(kBadSegWordErr);
176           AliWarning(Form("Wrong segment word signature: %x, expected 0xab0f59!",(segWord >> 8)));
177           return kTRUE;
178         }
179         
180         if ((segWord & 0xff) != (((UInt_t)iRow + 7) / 8)) {
181           fRawReader->AddMajorErrorLog(kWrongSegErr,Form("seg %d != %d",segWord & 0xff,(iRow + 7) / 8));
182           AliWarning(Form("Segment index (%d) does not correspond to the one expected from row index (%d)!",segWord & 0xff,(iRow + 7) / 8));
183           return kTRUE;
184         }
185       }
186     }//loop of Row   
187   }//Pedestal files selected by data lenght
188
189   else {                                                                  //Raw data size is not 0 and not 47148 (pedestal)
190     fDDLNumber = fRawReader->GetDDLID();
191     fPosition = 0;
192   
193     Init();
194     
195     // Look over rows
196     for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
197       
198       UInt_t rowMarker = GetNextWord();                                 // Read row marker
199       
200       Int_t numRows= rowMarker >> 16 & 0xffffff;
201       
202       if ((rowMarker >> 0 & 0xffff) != 0x32a8) {
203         fRawReader->AddMajorErrorLog(kRowMarkerErr);
204         AliWarning(Form("Wrong row marker %x for row %d, expected 0x32a8!",rowMarker,iRow));
205         return kTRUE;
206       }//check for row marker
207       UInt_t dilogic = 0, row = 0;
208       UInt_t cntData=0;
209       UInt_t cntEoE=0;
210       //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
211       for(Int_t iWordInRow=0; iWordInRow<numRows;iWordInRow++) //loop over words 
212         {     
213           UInt_t tmpword=GetNextWord();               
214           UInt_t eOfEvent = tmpword;                     // always assume that it is an EoE. If bit 
215           if (!((eOfEvent >> 27) & 0x1)) {               // if it is not EoE then data!
216             UInt_t data=tmpword;
217             row = (data >> 22) & 0x1f;                                                  //row information in raw word is between bits: 22...26
218             if (row < 1 || row > kNRows) {                                              //select bits from 22 and with 0x1f ask for the next 5 bits 
219               fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
220               AliWarning(Form("Wrong row index: %d, expected (1 -> %d)!",row,kNRows));
221               // row = iRow;
222             }
223             dilogic = (data >> 18) & 0xf;                                              //dilogic info in raw word is between bits: 18...21
224             if (dilogic < 1 || dilogic > kNDILOGICAdd) {
225               fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
226               AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
227               //dilogic = iDILOGIC;
228             }
229             UInt_t pad = (data >> 12) & 0x3f;                                                    //pad info in raw word is between bits: 12...17
230             if (pad >= kNPadAdd) {
231               fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
232               AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
233               //pad = iPad;
234             }
235             fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff;  cntData++;
236             
237           }//not EoE but data!
238           //if it is EoE
239           else{
240             //Printf("EoE word");
241             if (!((eOfEvent >> 27) & 0x1)) {                                                  //check 27th bit in EoE. It must be 1!
242               fRawReader->AddMajorErrorLog(kEoEFlagErr);
243               AliWarning(Form("Missing end-of-event flag! (%x)",eOfEvent));
244               return kTRUE;
245             }
246             UInt_t wc = eOfEvent & 0x7f;
247             if (wc != cntData) {
248               fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
249               AliWarning(Form("Wrong end-of-event word-count:%d, expected 48!",wc));
250               return kTRUE;
251             }
252             UInt_t da = (eOfEvent >> 18) & 0xf;
253             if (cntData!=0 && da != dilogic) {
254               fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
255               AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
256               return kTRUE;
257             }
258             UInt_t ca = (eOfEvent >> 22) & 0x1f;
259             if (cntData!=0 &&  ca != row) {
260               fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
261               AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
262               return kTRUE;
263             }
264             cntData=0;  cntEoE++;//zero it and wait for new data words
265           } //EoE word
266           
267         } //loop over rows within two markers
268       
269       
270       
271       // Read the segment marker
272       // One maker per 8 rows
273       
274       if (iRow%8 == 0) {
275         UInt_t segWord = GetNextWord();
276         if ((segWord >> 8) != 0xab0f59) {
277           fRawReader->AddMajorErrorLog(kBadSegWordErr);
278           AliWarning(Form("Wrong segment word signature: %x, expected 0xab0f59!",(segWord >> 8)));
279           return kTRUE;
280         }
281         
282         if ((segWord & 0xff) != (((UInt_t)iRow + 7) / 8)) {
283           fRawReader->AddMajorErrorLog(kWrongSegErr,Form("seg %d != %d",segWord & 0xff,(iRow + 7) / 8));
284           AliWarning(Form("Segment index (%d) does not correspond to the one expected from row index (%d)!",segWord & 0xff,(iRow + 7) / 8));
285           return kTRUE;
286         }
287       }
288     }//loop of Row   
289   }//REal data files selected by data lenght
290   
291   AliDebug(1,"Stop."); 
292   return kTRUE;
293 }
294
295 //_____________________________________________________________________________
296 UInt_t AliHMPIDRawStream::GetNextWord()
297 {
298   // This method returns the next 32 bit word
299   // inside the raw data payload.
300   // The method is supposed to be endian (platform)
301   // independent.
302   if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
303   
304   UInt_t word = 0;
305   word |= fData[fPosition++];
306   word |= fData[fPosition++] << 8;
307   word |= fData[fPosition++] << 16;
308   word |= fData[fPosition++] << 24;
309   
310   return word;
311 }
312
313 //_____________________________________________________________________________