]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HMPID/AliHMPIDRawStream.cxx
Delta electrons are properly set.
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDRawStream.cxx
CommitLineData
d2e2f542 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"
21f61e25 27
d2e2f542 28
29ClassImp(AliHMPIDRawStream)
30
31//_____________________________________________________________________________
32AliHMPIDRawStream::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}
21f61e25 44//-----------------------------------------------------------------------------
21f61e25 45AliHMPIDRawStream::AliHMPIDRawStream() :
46 fDDLNumber(-1),
d3917810 47 fRawReader(0x0),
21f61e25 48 fData(NULL),
49 fPosition(-1)
50{
51 // Constructor
52 Init();
53}
d2e2f542 54//_____________________________________________________________________________
55AliHMPIDRawStream::~AliHMPIDRawStream()
56{
57 // destructor
58}
59
60//_____________________________________________________________________________
61void AliHMPIDRawStream::Init()
62{
63 // Initalize the container
64 // with the pad charges
21f61e25 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;
843bde9a 76
77 for(Int_t l=1; l < kSumErr; l++) fNumOfErr[l]=0; //reset errors
21f61e25 78}//Init()
d2e2f542 79//_____________________________________________________________________________
80void AliHMPIDRawStream::Reset()
81{
82 // reset raw stream params
d2e2f542 83 // Reinitalize the containers
84 Init();
d2e2f542 85 fDDLNumber = -1;
86 fPosition = -1;
87 fData = NULL;
d2e2f542 88 if (fRawReader) fRawReader->Reset();
89}
d2e2f542 90//_____________________________________________________________________________
91Bool_t AliHMPIDRawStream::Next()
92{
21f61e25 93 // read next DDL raw data from the HMPID raw data stream
d2e2f542 94 // return kFALSE in case of error or no data left
21f61e25 95 AliDebug(1,"Start.");
d2e2f542 96 do {
97 if (!fRawReader->ReadNextData(fData)) return kFALSE;
98 } while (fRawReader->GetDataSize() == 0);
21f61e25 99
843bde9a 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 */
21f61e25 119
843bde9a 120 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
121
21f61e25 122 fDDLNumber = fRawReader->GetDDLID();
123 fPosition = 0;
124
125 Init();
126
127 // Look over rows
128 for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
21f61e25 129 UInt_t rowMarker = GetNextWord(); // Read row marker
130
2ec7b52f 131 Int_t numRows= rowMarker >> 16 & 0xfff; // Number of words after the row marker
132
843bde9a 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
21f61e25 139
843bde9a 140 if ((rowMarker >> 0 & 0xffff) != 0x32a8 ) { //The row marker is fixed and we cannot have more than 490 words!!!
21f61e25 141 fRawReader->AddMajorErrorLog(kRowMarkerErr);
142 AliWarning(Form("Wrong row marker %x for row %d, expected 0x32a8!",rowMarker,iRow));
843bde9a 143 fNumOfErr[kRowMarkerErr]++;
d2e2f542 144 return kTRUE;
21f61e25 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));
843bde9a 160 fNumOfErr[kWrongRowErr]++;
21f61e25 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));
843bde9a 167 fNumOfErr[kWrongDilogicErr]++;
21f61e25 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));
843bde9a 174 fNumOfErr[kWrongPadErr]++;
21f61e25 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{
21f61e25 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));
843bde9a 185 fNumOfErr[kEoEFlagErr]++;
21f61e25 186 return kTRUE;
187 }
188 UInt_t wc = eOfEvent & 0x7f;
189 if (wc != cntData) {
190 fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
843bde9a 191 AliWarning(Form("Wrong end-of-event word-count: %d, expected: %d!",wc,cntData));
192 fNumOfErr[kEoESizeErr]++;
21f61e25 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));
843bde9a 199 fNumOfErr[kEoEDILOGICErr]++;
21f61e25 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));
843bde9a 206 fNumOfErr[kEoERowErr]++;
21f61e25 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) {
843bde9a 220 UInt_t segWord = GetNextWord();
28a64395 221 if ((segWord >> 8) != 0xab0f59) {
21f61e25 222 fRawReader->AddMajorErrorLog(kBadSegWordErr);
28a64395 223 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0f59!",(segWord >> 8)));
843bde9a 224 fNumOfErr[kBadSegWordErr]++;
21f61e25 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));
843bde9a 231 fNumOfErr[kWrongSegErr]++;
21f61e25 232 return kTRUE;
233 }
d2e2f542 234 }
21f61e25 235 }//loop of Row
236 }//REal data files selected by data lenght
237
238 AliDebug(1,"Stop.");
d2e2f542 239 return kTRUE;
240}
241
242//_____________________________________________________________________________
243UInt_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 !");
21f61e25 250
d2e2f542 251 UInt_t word = 0;
252 word |= fData[fPosition++];
253 word |= fData[fPosition++] << 8;
254 word |= fData[fPosition++] << 16;
255 word |= fData[fPosition++] << 24;
21f61e25 256
d2e2f542 257 return word;
258}
259
260//_____________________________________________________________________________