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