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 //-----------------------------------------------------------------------------
46 AliHMPIDRawStream::AliHMPIDRawStream() :
55 //_____________________________________________________________________________
56 AliHMPIDRawStream::~AliHMPIDRawStream()
61 //_____________________________________________________________________________
62 void AliHMPIDRawStream::Init()
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;
78 //_____________________________________________________________________________
79 void AliHMPIDRawStream::Reset()
81 // reset raw stream params
82 // Reinitalize the containers
87 if (fRawReader) fRawReader->Reset();
89 //_____________________________________________________________________________
90 Bool_t AliHMPIDRawStream::Next()
92 // read next DDL raw data from the HMPID raw data stream
93 // return kFALSE in case of error or no data left
96 if (!fRawReader->ReadNextData(fData)) return kFALSE;
97 } while (fRawReader->GetDataSize() == 0);
99 if ( fRawReader->GetDataSize() > 47148) {
100 AliWarning(Form("Raw data event size is larger (%d) than possible for HMPID!!!! ",fRawReader->GetDataSize()));
103 else if (fRawReader->GetDataSize() == 47148) {
104 fDDLNumber = fRawReader->GetDDLID();
110 for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
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));
117 }//check for row marker
118 UInt_t dilogic = 0, row = 0;
119 for(Int_t iDILOGIC = 1; iDILOGIC <= kNDILOGICAdd; iDILOGIC++) {
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));
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));
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));
141 fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff;
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));
150 UInt_t wc = eOfEvent & 0x7f;
152 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
153 AliWarning(Form("Wrong end-of-event word-count:%d, expected 48!",wc));
156 UInt_t da = (eOfEvent >> 18) & 0xf;
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));
162 UInt_t ca = (eOfEvent >> 22) & 0x1f;
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));
170 // Read the segment marker
171 // One maker per 8 rows
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)));
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));
188 }//Pedestal files selected by data lenght
190 else { //Raw data size is not 0 and not 47148 (pedestal)
191 fDDLNumber = fRawReader->GetDDLID();
197 for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
199 UInt_t rowMarker = GetNextWord(); // Read row marker
201 Int_t numRows= rowMarker >> 16 & 0xffffff;
203 if ((rowMarker >> 0 & 0xffff) != 0x32a8) {
204 fRawReader->AddMajorErrorLog(kRowMarkerErr);
205 AliWarning(Form("Wrong row marker %x for row %d, expected 0x32a8!",rowMarker,iRow));
207 }//check for row marker
208 UInt_t dilogic = 0, row = 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
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!
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));
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;
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));
236 fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff; cntData++;
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));
247 UInt_t wc = eOfEvent & 0x7f;
249 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
250 AliWarning(Form("Wrong end-of-event word-count:%d, expected 48!",wc));
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));
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));
265 cntData=0; cntEoE++;//zero it and wait for new data words
268 } //loop over rows within two markers
272 // Read the segment marker
273 // One maker per 8 rows
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)));
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));
290 }//REal data files selected by data lenght
296 //_____________________________________________________________________________
297 UInt_t AliHMPIDRawStream::GetNextWord()
299 // This method returns the next 32 bit word
300 // inside the raw data payload.
301 // The method is supposed to be endian (platform)
303 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
306 word |= fData[fPosition++];
307 word |= fData[fPosition++] << 8;
308 word |= fData[fPosition++] << 16;
309 word |= fData[fPosition++] << 24;
314 //_____________________________________________________________________________