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"
29 ClassImp(AliHMPIDRawStream)
31 //_____________________________________________________________________________
32 AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
34 fRawReader(rawReader),
42 fRawReader->Select("HMPID");
44 //-----------------------------------------------------------------------------
45 AliHMPIDRawStream::AliHMPIDRawStream() :
54 //_____________________________________________________________________________
55 AliHMPIDRawStream::~AliHMPIDRawStream()
60 //_____________________________________________________________________________
61 void AliHMPIDRawStream::Init()
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;
77 //_____________________________________________________________________________
78 void AliHMPIDRawStream::Reset()
80 // reset raw stream params
81 // Reinitalize the containers
86 if (fRawReader) fRawReader->Reset();
88 //_____________________________________________________________________________
89 Bool_t AliHMPIDRawStream::Next()
91 // read next DDL raw data from the HMPID raw data stream
92 // return kFALSE in case of error or no data left
95 if (!fRawReader->ReadNextData(fData)) return kFALSE;
96 } while (fRawReader->GetDataSize() == 0);
98 if ( fRawReader->GetDataSize() > 47148) {
99 AliWarning(Form("Raw data event size is larger (%d) than possible for HMPID!!!! ",fRawReader->GetDataSize()));
102 else if (fRawReader->GetDataSize() == 47148) {
103 fDDLNumber = fRawReader->GetDDLID();
109 for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
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));
116 }//check for row marker
117 UInt_t dilogic = 0, row = 0;
118 for(Int_t iDILOGIC = 1; iDILOGIC <= kNDILOGICAdd; iDILOGIC++) {
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));
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));
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));
140 fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff;
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));
149 UInt_t wc = eOfEvent & 0x7f;
151 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
152 AliWarning(Form("Wrong end-of-event word-count:%d, expected 48!",wc));
155 UInt_t da = (eOfEvent >> 18) & 0xf;
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));
161 UInt_t ca = (eOfEvent >> 22) & 0x1f;
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));
169 // Read the segment marker
170 // One maker per 8 rows
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)));
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));
187 }//Pedestal files selected by data lenght
189 else { //Raw data size is not 0 and not 47148 (pedestal)
190 fDDLNumber = fRawReader->GetDDLID();
196 for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
198 UInt_t rowMarker = GetNextWord(); // Read row marker
200 Int_t numRows= rowMarker >> 16 & 0xffffff;
202 if ((rowMarker >> 0 & 0xffff) != 0x32a8) {
203 fRawReader->AddMajorErrorLog(kRowMarkerErr);
204 AliWarning(Form("Wrong row marker %x for row %d, expected 0x32a8!",rowMarker,iRow));
206 }//check for row marker
207 UInt_t dilogic = 0, row = 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
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!
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));
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;
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));
235 fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff; cntData++;
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));
246 UInt_t wc = eOfEvent & 0x7f;
248 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
249 AliWarning(Form("Wrong end-of-event word-count:%d, expected 48!",wc));
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));
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));
264 cntData=0; cntEoE++;//zero it and wait for new data words
267 } //loop over rows within two markers
271 // Read the segment marker
272 // One maker per 8 rows
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)));
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));
289 }//REal data files selected by data lenght
295 //_____________________________________________________________________________
296 UInt_t AliHMPIDRawStream::GetNextWord()
298 // This method returns the next 32 bit word
299 // inside the raw data payload.
300 // The method is supposed to be endian (platform)
302 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
305 word |= fData[fPosition++];
306 word |= fData[fPosition++] << 8;
307 word |= fData[fPosition++] << 16;
308 word |= fData[fPosition++] << 24;
313 //_____________________________________________________________________________