dcs timeout and number of retrievals set in the configuration instead of in AliShuttl...
[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
e96561a3 28static Bool_t stDeb = kFALSE;
29//static Bool_t stDeb = kTRUE;
d2e2f542 30
31ClassImp(AliHMPIDRawStream)
32
e96561a3 33//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d2e2f542 34AliHMPIDRawStream::AliHMPIDRawStream(AliRawReader* rawReader) :
35 fDDLNumber(-1),
36 fRawReader(rawReader),
37 fData(NULL),
38 fPosition(-1)
39{
40 // Constructor
56c73976 41 fNPads = 0;
42 fCharge = 0x0;
43 fPad =0x0;
d2e2f542 44
45 fRawReader->Reset();
46 fRawReader->Select("HMPID");
47}
e96561a3 48//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21f61e25 49AliHMPIDRawStream::AliHMPIDRawStream() :
50 fDDLNumber(-1),
d3917810 51 fRawReader(0x0),
21f61e25 52 fData(NULL),
53 fPosition(-1)
54{
21f61e25 55}
e96561a3 56//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d2e2f542 57AliHMPIDRawStream::~AliHMPIDRawStream()
58{
59 // destructor
56c73976 60 DelVars();
d2e2f542 61}
fd8bfa30 62//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d2e2f542 63void AliHMPIDRawStream::Reset()
64{
65 // reset raw stream params
d2e2f542 66 // Reinitalize the containers
d2e2f542 67 fDDLNumber = -1;
68 fPosition = -1;
69 fData = NULL;
d2e2f542 70 if (fRawReader) fRawReader->Reset();
71}
fd8bfa30 72//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d2e2f542 73Bool_t AliHMPIDRawStream::Next()
74{
21f61e25 75 // read next DDL raw data from the HMPID raw data stream
d2e2f542 76 // return kFALSE in case of error or no data left
21f61e25 77 AliDebug(1,"Start.");
d2e2f542 78 do {
79 if (!fRawReader->ReadNextData(fData)) return kFALSE;
80 } while (fRawReader->GetDataSize() == 0);
21f61e25 81
fd8bfa30 82
843bde9a 83 /*
84 Event type is selected as in $ALICE_ROOT/RAW/event.h
85 #define START_OF_RUN ((eventTypeType) 1)
86 #define END_OF_RUN ((eventTypeType) 2)
87 #define START_OF_RUN_FILES ((eventTypeType) 3)
88 #define END_OF_RUN_FILES ((eventTypeType) 4)
89 #define START_OF_BURST ((eventTypeType) 5)
90 #define END_OF_BURST ((eventTypeType) 6)
91 #define PHYSICS_EVENT ((eventTypeType) 7) <<---------------
92 #define CALIBRATION_EVENT ((eventTypeType) 8)
93 #define EVENT_FORMAT_ERROR ((eventTypeType) 9)
94 #define START_OF_DATA ((eventTypeType)10)
95 #define END_OF_DATA ((eventTypeType)11)
96 #define SYSTEM_SOFTWARE_TRIGGER_EVENT ((eventTypeType)12)
97 #define DETECTOR_SOFTWARE_TRIGGER_EVENT ((eventTypeType)13)
98 #define EVENT_TYPE_MIN 1
99 #define EVENT_TYPE_MAX 13
100 */
fd8bfa30 101
102 fPosition = 0;
103 Bool_t status;
e96561a3 104
843bde9a 105 if(fRawReader->GetType() == 7) { //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
21f61e25 106 fDDLNumber = fRawReader->GetDDLID();
e96561a3 107 if(stDeb) Printf("DDL %i started to be decoded!.",fDDLNumber);
56c73976 108 InitVars(fRawReader->GetDataSize()/4);
fd8bfa30 109 status = ReadHMPIDRawData();
e96561a3 110
111 if(stDeb) {
112 if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
113 else Printf("Event DDL %i ERROR in decoding!.",fDDLNumber);
114// DumpData(fRawReader->GetDataSize());
115 }
fd8bfa30 116// stDeb=kFALSE;
117 }
56c73976 118// return status;
119 return kTRUE;
fd8bfa30 120}
56c73976 121//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122void AliHMPIDRawStream::InitVars(Int_t n)
123{
124 fNPads = 0;
125 fCharge = new Int_t[n];
126 fPad = new Int_t[n];
e96561a3 127 fNumOfErr = new Int_t*[kNDDL]; // Store the numner of errors for a given error type and a given DD
128 for(Int_t i=0;i<kNDDL;i++) {
129 fNumOfErr[i] = new Int_t [kSumErr];
130 }
56c73976 131 //for debug purpose
e96561a3 132 fPos = new Int_t[4*n]; //reset debug
56c73976 133 iPos = 0;
134}
135//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136void AliHMPIDRawStream::DelVars()
137{
138 fNPads = 0;
139 delete fCharge;
140 delete fPad;
e96561a3 141 delete fNumOfErr;
142 for(Int_t i=0;i<kNDDL;i++) delete [] fNumOfErr[i]; delete [] fNumOfErr;
143 delete fPos;
56c73976 144}
fd8bfa30 145//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
147{
148 Int_t cntGlob = fRawReader->GetDataSize()/4;
149 Int_t cnt = cntGlob;
fd8bfa30 150 Int_t nwSeg;
151 Int_t cntSegment;
152
56c73976 153 fWord = GetWord(cnt);cnt--;
fd8bfa30 154
155
156 while (cnt>0) {
157
56c73976 158 nwSeg = (fWord >> kbit8) & 0xfff;
159 if(!CheckSegment()) return kFALSE;
160 if(!ReadSegment(cntSegment)) return kFALSE;
fd8bfa30 161
e96561a3 162 if(nwSeg != cntSegment) {if(stDeb){Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);} return kFALSE;}
56c73976 163 fWord = GetWord(cntSegment+1,kBwd);
fd8bfa30 164 cnt-=cntSegment+1;
165 }
21f61e25 166
d2e2f542 167 return kTRUE;
fd8bfa30 168
d2e2f542 169}
fd8bfa30 170//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56c73976 171Bool_t AliHMPIDRawStream::ReadSegment(Int_t &cntSegment)
fd8bfa30 172{
56c73976 173 cntSegment = (fWord >> kbit8) & 0xfff;
fd8bfa30 174 Int_t cnt = cntSegment;
175 Int_t cntRow;
176 Int_t nwRow;
d2e2f542 177
56c73976 178 fWord = GetWord(cnt,kBwd);
fd8bfa30 179
180 while (cnt>0) {
181
56c73976 182 cntRow = (fWord >> kbit16) & 0xfff;
183 if(!CheckRowMarker()) return kFALSE;
184 if(!ReadRow(nwRow)) return kFALSE;
fd8bfa30 185
e96561a3 186 if(nwRow != cntRow) {if(stDeb){Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);} return kFALSE;}
56c73976 187 fWord = GetWord(cntRow+1);
fd8bfa30 188 cnt -= cntRow+1;
189
190 }
191
192 cntSegment -= cnt;
193
194 return kTRUE;
195
196}
197//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56c73976 198Bool_t AliHMPIDRawStream::ReadRow(Int_t &cntRow)
fd8bfa30 199{
200 Int_t cnt;
201 Int_t cntDilogic;
202 Int_t nwDil;
203
56c73976 204 cntRow = (fWord >> kbit16) & 0xfff;
fd8bfa30 205 cnt = cntRow;
206
56c73976 207 fWord = GetWord(cntRow);
fd8bfa30 208
209 while (cnt>0) {
210
56c73976 211 if(!CheckEoE(nwDil)) return kFALSE;
212 if(!ReadDilogic(cntDilogic)) return kFALSE;
fd8bfa30 213
e96561a3 214 if(nwDil != cntDilogic) {if(stDeb){Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);}return kFALSE;}
fd8bfa30 215 cnt -= cntDilogic;
56c73976 216 fWord = GetWord(1,kBwd); // go to next Dilogic bank...
fd8bfa30 217 cnt--;
218// Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
219 }
220
221 cntRow -= cnt;
222
223 return kTRUE;
224
225}
226//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56c73976 227Bool_t AliHMPIDRawStream::ReadDilogic(Int_t &cntDilogic)
fd8bfa30 228{
56c73976 229 cntDilogic = fWord & 0x7f;
fd8bfa30 230
231 Int_t cnt = cntDilogic;
56c73976 232
233// Printf(" cnt DILOGIC %i at %i word %08X",cnt,fPosition,fWord);
fd8bfa30 234
235 for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
236 UInt_t dilogic = 0, row = 0;
56c73976 237 fWord = GetWord(1,kBwd);
fd8bfa30 238//check on row number
239 cnt--;
56c73976 240 row = (fWord >> kbit22) & 0x1f;
fd8bfa30 241 if(!CheckRow(row)) continue;
242//check dilogic number
56c73976 243 dilogic = (fWord >> kbit18) & 0xf; //dilogic info in raw word is between bits: 18...21
fd8bfa30 244 if(!CheckDilogic(dilogic)) continue;
245//check pad number
56c73976 246 UInt_t pad = (fWord >> kbit12) & 0x3f; //pad info in raw word is between bits: 12...17
fd8bfa30 247 if(!CheckPad(pad)) continue;
56c73976 248 Int_t charge = fWord & 0xfff;
249 fPad[fNPads] = GetPad(fDDLNumber,row,dilogic,pad);
250 fCharge[fNPads] = charge;
251 fNPads++;
fd8bfa30 252 }
253
254 cntDilogic -= cnt;
255 return kTRUE;
256}
257//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56c73976 258Bool_t AliHMPIDRawStream::CheckSegment()
d2e2f542 259{
fd8bfa30 260 UInt_t markSegment = 0xAB0;
261 /*
262 if (iRow%8 == 0) {
263 UInt_t segWord = GetWord();
264 if ((segWord >> 20) != statusSegWord) {
265 fRawReader->AddMajorErrorLog(kBadSegWordErr);
266 AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
267 fNumOfErr[kBadSegWordErr]++;
268 return kTRUE;
269 }
270*/
56c73976 271 UInt_t segMarker = (fWord >> kbit20) & 0xfff;
fd8bfa30 272 if (segMarker != markSegment ) {
e96561a3 273 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at %i in word %0X!",segMarker,markSegment,fPosition,fWord));
274 if(stDeb){ AliWarning(Form("Segment marker %X wrong (expected %0X)! at %i in word %0X!",segMarker,markSegment,fPosition,fWord));}
275 fNumOfErr[fDDLNumber][kWrongSegErr]++;
fd8bfa30 276 return kFALSE;
277 }
278
56c73976 279 UInt_t segAddress = fWord & 0xff;
fd8bfa30 280 if (segAddress<1 ||segAddress>3) {
e96561a3 281 //fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at %i in word %0X",segAddress,fPosition,fWord));
282 if(stDeb){AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));}
283 fNumOfErr[fDDLNumber][kWrongSegErr]++;
fd8bfa30 284 return kFALSE;
285 }
56c73976 286// Printf("Segment Marker found at %i! Number of segment is %i",fPosition,segAddress);
fd8bfa30 287 return kTRUE;
288}
289//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
290Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
291{
292//check on row number
56c73976 293// Printf("ROW %i word %0X",row,fWord);
fd8bfa30 294 if(row>=1 && row <=kNRows) return kTRUE;
295
e96561a3 296 //fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
297 if(stDeb){AliWarning(Form("Wrong row index: %d, expected (1 -> %d) word %0X at %i...",row,kNRows,fWord,fPosition));}
298 fNumOfErr[fDDLNumber][kWrongRowErr]++;
fd8bfa30 299 return kFALSE;
300}
301//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
303{
304//check dilogic number
305 if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
306
e96561a3 307 //fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
308 if(stDeb){AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));}
309 fNumOfErr[fDDLNumber][kWrongDilogicErr]++;
fd8bfa30 310 //dilogic = iDILOGIC;
311 return kFALSE;
312}
313//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
314Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
315{
316//check pad number
317 if (pad < kNPadAdd) return kTRUE;
318
e96561a3 319 //fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
320 if(stDeb){AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));}
321 fNumOfErr[fDDLNumber][kWrongPadErr]++;
fd8bfa30 322 return kFALSE;
323}
324//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56c73976 325Bool_t AliHMPIDRawStream::CheckEoE(Int_t &nDil)
fd8bfa30 326{
56c73976 327 if (!((fWord >> kbit27) & 0x1)) { //check 27th bit in EoE. It must be 1!
e96561a3 328 //fRawReader->AddMajorErrorLog(kEoEFlagErr);
329 if(stDeb){AliWarning(Form("Missing end-of-event flag! (%08X) at %i",fWord,fPosition));}
330 fNumOfErr[fDDLNumber][kEoEFlagErr]++;
fd8bfa30 331 return kFALSE;
332 }
e96561a3 333 nDil = fWord & 0x7f; //nDil=EoE word count
334 if(nDil < 0 || nDil > 48 ) {
335
336 //fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
337 if(stDeb){AliWarning(Form("Wrong end-of-event word-count: %08X",fWord));}
338 fNumOfErr[fDDLNumber][kEoESizeErr]++;
fd8bfa30 339 return kFALSE;
340 }
341// UInt_t da = (eOfEvent >> 18) & 0xf;
342// if (cntData!=0 && da != dilogic) {
343// fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
344// AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
345// fNumOfErr[kEoEDILOGICErr]++;
346// return kFALSE; AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;
347
348// }
349// UInt_t ca = (eOfEvent >> 22) & 0x1f;
350// if (cntData!=0 && ca != row) {
351// fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
352// AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
353// fNumOfErr[kEoERowErr]++;
354// return kFALSE;
355// }
356 return kTRUE;
357}
358//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56c73976 359Bool_t AliHMPIDRawStream::CheckRowMarker()
fd8bfa30 360{
361 UInt_t nMAXwordsInRow = 0x1EA;
362 UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
363//First check on row marker
56c73976 364 UInt_t rowControlWord = fWord >> kbit0 & 0xfbff;
fd8bfa30 365
366 if(rowControlWord != statusControlRow) {
e96561a3 367 //fRawReader->AddMajorErrorLog(kRowMarkerErr);
368 if(stDeb){AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
369 fNumOfErr[fDDLNumber][kRowMarkerErr]++;
370 return kFALSE; }
371 }
fd8bfa30 372//Second check on row marker
e96561a3 373 UInt_t wordsInRow = fWord >> kbit16 & 0x0fff; // Number of words after the row marker, bit 10 is skipped in this check
fd8bfa30 374
375 if (wordsInRow > nMAXwordsInRow) {
e96561a3 376 //fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
377 if(stDeb){AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));}
378 fNumOfErr[fDDLNumber][kRowMarkerSizeErr]++;
fd8bfa30 379 return kFALSE;
380 }
381
382 return kTRUE;
383}
384//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385UInt_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
386{
387 // This method returns the n-th 32 bit word
d2e2f542 388 // inside the raw data payload.
389 // The method is supposed to be endian (platform)
390 // independent.
391 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
21f61e25 392
d2e2f542 393 UInt_t word = 0;
fd8bfa30 394
395 if(dir==kBwd) n = -n;
396 fPosition+=4*n-4;
397
398 StorePosition();
399
d2e2f542 400 word |= fData[fPosition++];
401 word |= fData[fPosition++] << 8;
402 word |= fData[fPosition++] << 16;
403 word |= fData[fPosition++] << 24;
fd8bfa30 404
d2e2f542 405 return word;
406}
fd8bfa30 407//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
408void AliHMPIDRawStream::DumpData(Int_t nw)
409{
410 for(Int_t i=0;i<nw;i+=4) {
411 if(!(i%16)) printf(" \n %8i) ",i);
412 printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
413 }
414 Printf(" \n -----end of dump ----------- ");
415}
416//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417void AliHMPIDRawStream::StorePosition()
418{
56c73976 419 if(fPos[fPosition]!=0) {
420// Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition);
421 return;
422 }
fd8bfa30 423 iPos++;
424 fPos[fPosition] = iPos;
425// if(stDeb)Printf("%i - Actual position %i",iPos,fPosition);
426}
e96561a3 427//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++