]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliAltroRawStream.cxx
Bug-fix (Artur)
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStream.cxx
CommitLineData
3ea47630 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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides access to Altro digits in raw data.
21///
22/// It loops over all Altro digits in the raw data given by the AliRawReader.
23/// The Next method goes to the next digit. If there are no digits left
24/// it returns kFALSE.
25/// Several getters provide information about the current digit.
26///
27///////////////////////////////////////////////////////////////////////////////
28
29#include "AliAltroRawStream.h"
30#include "AliRawReader.h"
3a291af4 31#include "AliLog.h"
3ea47630 32
33ClassImp(AliAltroRawStream)
34
35
36//_____________________________________________________________________________
37AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
e7fd2555 38 fNoAltroMapping(kTRUE),
1e984421 39 fIsShortDataHeader(kFALSE),
e7fd2555 40 fDDLNumber(-1),
41 fPrevDDLNumber(-1),
5e6235b5 42 fRCUId(-1),
43 fPrevRCUId(-1),
3a291af4 44 fHWAddress(-1),
45 fPrevHWAddress(-1),
3ea47630 46 fTime(-1),
e7fd2555 47 fPrevTime(-1),
3ea47630 48 fSignal(-1),
e7fd2555 49 fTimeBunch(-1),
3ea47630 50 fRawReader(rawReader),
51 fData(NULL),
52 fPosition(0),
53 fCount(0),
5e6235b5 54 fBunchLength(0),
55 fRCUTrailerData(NULL),
31be3849 56 fRCUTrailerSize(0),
57 fFECERRA(0),
58 fFECERRB(0),
59 fERRREG2(0),
7473795a 60 fERRREG3(0),
61 fERRREG4(0),
31be3849 62 fActiveFECsA(0),
63 fActiveFECsB(0),
64 fAltroCFG1(0),
65 fAltroCFG2(0)
3ea47630 66{
67// create an object to read Altro raw digits
e7fd2555 68 fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1;
3ea47630 69}
70
71//_____________________________________________________________________________
72AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
73 TObject(stream),
e7bee78b 74 fNoAltroMapping(stream.fNoAltroMapping),
e7bee78b 75 fIsShortDataHeader(stream.fIsShortDataHeader),
76 fDDLNumber(stream.fDDLNumber),
77 fPrevDDLNumber(stream.fPrevDDLNumber),
78 fRCUId(stream.fRCUId),
79 fPrevRCUId(stream.fPrevRCUId),
80 fHWAddress(stream.fHWAddress),
81 fPrevHWAddress(stream.fPrevHWAddress),
82 fTime(stream.fTime),
83 fPrevTime(stream.fPrevTime),
84 fSignal(stream.fSignal),
85 fTimeBunch(stream.fTimeBunch),
86 fRawReader(stream.fRawReader),
87 fData(stream.fData),
88 fPosition(stream.fPosition),
89 fCount(stream.fCount),
90 fBunchLength(stream.fBunchLength),
91 fRCUTrailerData(stream.fRCUTrailerData),
31be3849 92 fRCUTrailerSize(stream.fRCUTrailerSize),
93 fFECERRA(stream.fFECERRA),
94 fFECERRB(stream.fFECERRB),
95 fERRREG2(stream.fERRREG2),
7473795a 96 fERRREG3(stream.fERRREG3),
97 fERRREG4(stream.fERRREG4),
31be3849 98 fActiveFECsA(stream.fActiveFECsA),
99 fActiveFECsB(stream.fActiveFECsB),
100 fAltroCFG1(stream.fAltroCFG1),
101 fAltroCFG2(stream.fAltroCFG2)
3ea47630 102{
e7bee78b 103 fSegmentation[0] = stream.fSegmentation[0];
104 fSegmentation[1] = stream.fSegmentation[1];
105 fSegmentation[2] = stream.fSegmentation[2];
3ea47630 106}
107
108//_____________________________________________________________________________
3820a703 109AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream& stream)
3ea47630 110{
3820a703 111 if(&stream == this) return *this;
112
113 fNoAltroMapping = stream.fNoAltroMapping;
3820a703 114 fIsShortDataHeader = stream.fIsShortDataHeader;
115 fDDLNumber = stream.fDDLNumber;
116 fPrevDDLNumber = stream.fPrevDDLNumber;
117 fRCUId = stream.fRCUId;
118 fPrevRCUId = stream.fPrevRCUId;
119 fHWAddress = stream.fHWAddress;
120 fPrevHWAddress = stream.fPrevHWAddress;
121 fTime = stream.fTime;
122 fPrevTime = stream.fPrevTime;
123 fSignal = stream.fSignal;
124 fTimeBunch = stream.fTimeBunch;
125 fRawReader = stream.fRawReader;
126 fData = stream.fData;
127 fPosition = stream.fPosition;
128 fCount = stream.fCount;
129 fBunchLength = stream.fBunchLength;
130 fRCUTrailerData = stream.fRCUTrailerData;
131 fRCUTrailerSize = stream.fRCUTrailerSize;
31be3849 132 fFECERRA = stream.fFECERRA;
133 fFECERRB = stream.fFECERRB;
134 fERRREG2 = stream.fERRREG2;
7473795a 135 fERRREG3 = stream.fERRREG3;
136 fERRREG4 = stream.fERRREG4;
31be3849 137 fActiveFECsA = stream.fActiveFECsA;
138 fActiveFECsB = stream.fActiveFECsB;
139 fAltroCFG1 = stream.fAltroCFG1;
140 fAltroCFG2 = stream.fAltroCFG2;
3820a703 141
142 fSegmentation[0] = stream.fSegmentation[0];
143 fSegmentation[1] = stream.fSegmentation[1];
144 fSegmentation[2] = stream.fSegmentation[2];
145
3ea47630 146 return *this;
147}
148
149//_____________________________________________________________________________
150AliAltroRawStream::~AliAltroRawStream()
151{
152// clean up
153
154}
155
3a291af4 156//_____________________________________________________________________________
157void AliAltroRawStream::Reset()
158{
159// reset altro raw stream params
160
161 fPosition = fCount = fBunchLength = 0;
162
5e6235b5 163 fRCUTrailerData = NULL;
164 fRCUTrailerSize = 0;
165
7473795a 166 fFECERRA = fFECERRB = fERRREG2 = fERRREG3 = fERRREG4 = fActiveFECsA = fActiveFECsB = fAltroCFG1 = fAltroCFG2 = 0;
31be3849 167
5e6235b5 168 fDDLNumber = fPrevDDLNumber = fRCUId = fPrevRCUId = fHWAddress = fPrevHWAddress = fTime = fPrevTime = fSignal = fTimeBunch = -1;
3a291af4 169
170 if (fRawReader) fRawReader->Reset();
e7fd2555 171
172 fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1;
3a291af4 173}
3ea47630 174
175//_____________________________________________________________________________
176Bool_t AliAltroRawStream::Next()
177{
178// read the next raw digit
179// returns kFALSE if there is no digit left
180
e7fd2555 181 fPrevDDLNumber = fDDLNumber;
5e6235b5 182 fPrevRCUId = fRCUId;
3a291af4 183 fPrevHWAddress = fHWAddress;
e7fd2555 184 fPrevTime = fTime;
3ea47630 185
186 while (fCount == 0) { // next trailer
7473795a 187 while (fPosition <= 0) { // next payload
3ea47630 188 do {
189 if (!fRawReader->ReadNextData(fData)) return kFALSE;
190 } while (fRawReader->GetDataSize() == 0);
191
e7fd2555 192 fDDLNumber = fRawReader->GetDDLID();
193
3a291af4 194 fPosition = GetPosition();
3ea47630 195 }
3ea47630 196
eb09ec9a 197 ReadTrailer();
3ea47630 198
3a291af4 199 fBunchLength = 0;
3ea47630 200 }
201
3a291af4 202 if (fBunchLength == 0) ReadBunch();
203 else fTime--;
204
205 ReadAmplitude();
3ea47630 206
207 return kTRUE;
208}
209
e7fd2555 210//_____________________________________________________________________________
211void AliAltroRawStream::SelectRawData(Int_t detId)
212{
213 // Select the raw data for specific
214 // detector id
215 AliDebug(1,Form("Selecting raw data for detector %d",detId));
216 fRawReader->Select(detId);
217}
218
362c9d61 219//_____________________________________________________________________________
220void AliAltroRawStream::SelectRawData(const char *detName)
221{
222 // Select the raw data for specific
223 // detector name
224 AliDebug(1,Form("Selecting raw data for detector %s",detName));
225 fRawReader->Select(detName);
226}
227
3ea47630 228//_____________________________________________________________________________
3a291af4 229UShort_t AliAltroRawStream::GetNextWord()
3ea47630 230{
3a291af4 231 // Read the next 10 bit word in backward direction
232 // The input stream access is given by fData and fPosition
3ea47630 233
3a291af4 234 fPosition--;
235
236 Int_t iBit = fPosition * 10;
3ea47630 237 Int_t iByte = iBit / 8;
238 Int_t shift = iBit % 8;
3ea47630 239
5e6235b5 240 // the raw data is written as integers where the low bits are filled first
3ea47630 241 // -> little endian is assumed here !
5e6235b5 242 Int_t iByteLow = iByte;
3ea47630 243 iByte++;
5e6235b5 244 Int_t iByteHigh = iByte;
3a291af4 245 return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF;
246}
247
248//_____________________________________________________________________________
249Bool_t AliAltroRawStream::ReadTrailer()
250{
251 //Read a trailer of 40 bits in the backward reading mode
252 //In case of no mapping is provided, read a dummy trailer
253 if (fNoAltroMapping) {
254 AliError("No ALTRO mapping information is loaded! Reading a dummy trailer!");
255 return ReadDummyTrailer();
256 }
257
258 //First reading filling words
259 UShort_t temp;
260 Int_t nFillWords = 0;
261 while ((temp = GetNextWord()) == 0x2AA) nFillWords++;
776c3b9c 262 if (nFillWords == 0) {
eb09ec9a 263 fRawReader->AddMajorErrorLog(kAltroTrailerErr,"no 0x2AA");
264 // PrintDebug();
7473795a 265 AliWarning(Form("Incorrect trailer found ! Expected 0x2AA not found (0x%x != 0x2AA) ! Current position %d, DDL=%d",
266 temp,fPosition,fDDLNumber));
eb09ec9a 267 // trying to recover and find the next bunch
7473795a 268 while ((fPosition > 2) && (temp != 0x2AA)) temp = GetNextWord();
eb09ec9a 269 if (temp != 0x2AA) {
270 fCount = fPosition = 0;
271 return kFALSE;
272 }
273 temp = GetNextWord();
776c3b9c 274 }
3a291af4 275
276 //Then read the trailer
7473795a 277 if (fPosition < 2) {
eb09ec9a 278 fRawReader->AddMajorErrorLog(kAltroTrailerErr,Form("size %d < 5",
7473795a 279 fPosition));
eb09ec9a 280 // PrintDebug();
281 AliWarning(Form("Incorrect raw data size ! Expected at least 5 words but found %d !",fPosition));
282 fCount = fPosition = 0;
283 return kFALSE;
776c3b9c 284 }
3a291af4 285
286 fCount = (temp << 4) & 0x3FF;
776c3b9c 287 if ((temp >> 6) != 0xA) {
eb09ec9a 288 fRawReader->AddMajorErrorLog(kAltroTrailerErr,"no 0xA");
289 // PrintDebug();
290 AliWarning(Form("Incorrect trailer found ! Expecting 0xA but found 0x%x !",temp >> 6));
291 fCount = 0;
292 return kFALSE;
776c3b9c 293 }
3a291af4 294
295 temp = GetNextWord();
296 fHWAddress = (temp & 0x3) << 10;
776c3b9c 297 if (((temp >> 2) & 0xF) != 0xA) {
eb09ec9a 298 fRawReader->AddMajorErrorLog(kAltroTrailerErr,"no second 0xA");
299 // PrintDebug();
300 AliWarning(Form("Incorrect trailer found ! Expecting second 0xA but found 0x%x !",(temp >> 2) & 0xF));
301 fCount = 0;
302 return kFALSE;
776c3b9c 303 }
3a291af4 304 fCount |= ((temp & 0x3FF) >> 6);
7473795a 305
71c94b28 306 if (fCount >= fPosition) {
307 fRawReader->AddMajorErrorLog(kAltroTrailerErr,"invalid size");
308 // PrintDebug();
309 AliWarning(Form("Incorrect trailer found ! The altro payload size is invalid (%d >= %d) !",fCount,fPosition));
310 fCount = 0;
311 return kFALSE;
312 }
3a291af4 313 temp = GetNextWord();
314 fHWAddress |= temp;
315
316 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
317
3a291af4 318 return kTRUE;
319}
320
321//_____________________________________________________________________________
322Bool_t AliAltroRawStream::ReadDummyTrailer()
323{
324 //Read a trailer of 40 bits in the backward reading mode
325 //In case of no mapping is provided, read a dummy trailer
326 UShort_t temp;
327 while ((temp = GetNextWord()) == 0x2AA);
328
e7fd2555 329 fSegmentation[0] = temp;
330 fSegmentation[1] = GetNextWord();
331 fSegmentation[2] = GetNextWord();
3a291af4 332 fCount = GetNextWord();
333 if (fCount == 0) return kFALSE;
334 fHWAddress = -1;
335
e7fd2555 336 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
337
3a291af4 338 return kTRUE;
339}
340
341//_____________________________________________________________________________
342void AliAltroRawStream::ReadBunch()
343{
344 // Read altro payload in
345 // backward direction
71c94b28 346 if (fCount <= 2) {
eb09ec9a 347 fRawReader->AddMinorErrorLog(kBunchLengthReadErr,"");
348 // PrintDebug();
71c94b28 349 AliWarning(Form("Could not read bunch length and time bin ! Only %d 10-bit words are left !",fCount));
350 fBunchLength = fTimeBunch = fCount = 0;
351 return;
776c3b9c 352 }
3a291af4 353
354 fBunchLength = GetNextWord() - 2;
71c94b28 355 if (fBunchLength > fCount) {
356 fRawReader->AddMinorErrorLog(kBunchLengthReadErr,Form("bl=%d",fBunchLength));
eb09ec9a 357 // PrintDebug();
71c94b28 358 AliWarning(Form("Could not read bunch length ! Bunch length = %d (>%d)",fBunchLength,fCount));
359 fBunchLength = fTimeBunch = fCount = 0;
360 return;
776c3b9c 361 }
71c94b28 362 fTimeBunch = fBunchLength;
363 fCount--;
3a291af4 364
365 fTime = GetNextWord();
366 fCount--;
367
368 return;
369}
370
371//_____________________________________________________________________________
372void AliAltroRawStream::ReadAmplitude()
373{
374 // Read next time bin amplitude
71c94b28 375 if (fCount <= 0) {
eb09ec9a 376 fRawReader->AddMinorErrorLog(kAmplitudeReadErr,"");
377 // PrintDebug();
378 AliWarning("Could not read sample amplitude !");
71c94b28 379 fCount = fSignal = fBunchLength = 0;
380 return;
776c3b9c 381 }
3a291af4 382
383 fSignal = GetNextWord();
71c94b28 384
3a291af4 385 fCount--;
386 fBunchLength--;
387
388 return;
389}
390
391//_____________________________________________________________________________
392Int_t AliAltroRawStream::GetPosition()
393{
394 // Sets the position in the
395 // input stream
5e6235b5 396 // Read the RCU trailer
397 // This includes the trailer size,
398 // RCU identifier and raw data payload.
399 // The RCU trailer format is described
400 // in details in the RCU manual.
401
9a090ccd 402 // We use the last word of the payload
403 // in order to decide which RCU firmware
404 // was used during the data taking.
405 // The firmware v2 adds 0xAAAA as 16
406 // most significant bits and since the
407 // payload size (firmware v1) can not be
408 // that big, we use this as a unique
409 // label of the firmware version.
410
411 Int_t index = fRawReader->GetDataSize();
412 UInt_t word = Get32bitWord(index);
413 if (((word >> 16) == 0xaaaa) || (word == 2)) {
414 // This is RCU formware v2
415 // The statement word==2 is needed only temporary
416 // in order to be able to read previously generated
417 // aliroot raw data
418
419 Int_t trailerSize = 0;
420 if (word == 2) {
421 AliInfo("Old simulated raw data is assumed!");
422 trailerSize = 2;
423 fRCUId = 0;
424 }
425 else {
426 // First read 32-bit word with the
427 // trailer size (7 bits), RCU ID (9 bits) and
428 // 0xAAA (the rest - 16 bits)
429 fRCUId = (Int_t)((word >> 7) & 0x1ff);
430 trailerSize = (word & 0x7F);
431 }
7e18047e 432
433 // Now read the beginning of the trailer
434 // where the payload size is written
776c3b9c 435 if (trailerSize < 2) {
7dcdcfe4 436 fRawReader->AddMajorErrorLog(kRCUTrailerErr,Form("tr=%d bytes",
437 trailerSize*4));
438 AliWarning(Form("Invalid trailer size found (%d bytes) !",
439 trailerSize*4));
776c3b9c 440 }
31be3849 441
442 Int_t position = ReadRCUTrailer(index,trailerSize);
7e18047e 443 // The size is specified in a number of 40bits
444 // Therefore we need to transform it to number of bytes
445 position *= 5;
446
447 // Check the consistency of the header and trailer
7dcdcfe4 448 if (((fRawReader->GetDataSize() - trailerSize*4) < position) ||
449 ((fRawReader->GetDataSize() - trailerSize*4) >= (position + 4))) {
450 fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d tr=%d rcu=%d bytes",
451 fRawReader->GetDataSize(),
452 trailerSize*4,
453 position));
454 AliWarning(Form("Inconsistent raw data size ! Raw data size - %d bytes (from the header), RCU trailer - %d bytes, raw data paylod - %d bytes !",
7e18047e 455 fRawReader->GetDataSize(),
456 trailerSize*4,
457 position));
7dcdcfe4 458 position = fRawReader->GetDataSize() - trailerSize*4;
776c3b9c 459 }
7e18047e 460
461 return position * 8 / 10;
462 }
463 else {
464 // In case of the Old RCU trailer format
465 // we have to read just the size of altro payload
466 // in units of 40-bit words
9a090ccd 467 Int_t position = (Int_t)word;
7e18047e 468
469 fRCUId = -1;
470 fRCUTrailerSize = 0;
471 fRCUTrailerData = NULL;
472
473 // The size is specified in a number of 40bits
474 // Therefore we need to transform it to number of bytes
475 position *= 5;
476
1e984421 477 if (!fIsShortDataHeader) {
7e18047e 478
1e984421 479 // Check the consistency of the header and trailer
7dcdcfe4 480 if (((fRawReader->GetDataSize() - 4) < position) ||
481 ((fRawReader->GetDataSize() - 4) >= (position + 4))) {
eb09ec9a 482 fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d rcu=%d bytes",
483 fRawReader->GetDataSize()-4,
484 position));
485 // PrintDebug();
486 AliWarning(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d bytes (in the RCU trailer)!",
487 fRawReader->GetDataSize()-4,
488 position));
489 position = fRawReader->GetDataSize()-4;
776c3b9c 490 }
1e984421 491 }
492 else {
493 // Check the consistency of the header and trailer
494 // In this case the header is shorter by 4 bytes
7dcdcfe4 495 if ((fRawReader->GetDataSize() < position) ||
496 (fRawReader->GetDataSize() >= (position + 4))) {
eb09ec9a 497 fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d rcu=%d bytes",
498 fRawReader->GetDataSize(),
499 position));
500 // PrintDebug();
501 AliWarning(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d bytes (in the RCU trailer)!",
502 fRawReader->GetDataSize(),
503 position));
504 position = fRawReader->GetDataSize();
776c3b9c 505 }
1e984421 506
507 // 7 32-bit words Common Data Header
508 // therefore we have to shift back by 4 bytes
509 // the pointer to the raw data payload
510 fData -= 4;
511 }
512
7e18047e 513 // Return the position in units of 10-bit words
514 return position*8/10;
515 }
5e6235b5 516}
517
518//_____________________________________________________________________________
519UInt_t AliAltroRawStream::Get32bitWord(Int_t &index)
520{
521 // This method returns the 32 bit word at a given
522 // position inside the raw data payload.
523 // The 'index' points to the beginning of the next word.
524 // The method is supposed to be endian (platform)
525 // independent.
776c3b9c 526 if (!fData) {
527 PrintDebug();
5e6235b5 528 AliFatal("Raw data paylod buffer is not yet initialized !");
776c3b9c 529 }
530
531 if (index < 4) {
eb09ec9a 532 fRawReader->AddFatalErrorLog(k32bitWordReadErr,Form("pos = %d",index));
533 // PrintDebug();
534 AliWarning(Form("Invalid raw data payload position (%d) !",index));
776c3b9c 535 }
5e6235b5 536
537 UInt_t word = 0;
538 word = fData[--index] << 24;
539 word |= fData[--index] << 16;
540 word |= fData[--index] << 8;
541 word |= fData[--index];
542
543 return word;
544}
545
31be3849 546//_____________________________________________________________________________
547Int_t AliAltroRawStream::ReadRCUTrailer(Int_t &index, Int_t trailerSize)
548{
549 // The method decodes the RCU trailer data
550 // according to the RCU fw ver.2 specs
551
552 fRCUTrailerSize = trailerSize*4;
553
554 for (trailerSize -= 2; trailerSize > 0; trailerSize--) {
555 Int_t word = Get32bitWord(index);
556 Int_t parCode = word >> 26;
557 Int_t parData = word & 0x3FFFFFF;
558 switch (parCode) {
559 case 1:
560 // ERR_REG1
561 fFECERRA = ((parData >> 13) & 0x1FFF) << 7;
562 fFECERRB = ((parData & 0x1FFF)) << 7;
563 break;
564 case 2:
565 // ERR_REG2
566 fERRREG2 = parData & 0x1FF;
567 break;
568 case 3:
569 // ERR_REG3
7473795a 570 fERRREG3 = parData & 0xFFF;
31be3849 571 break;
572 case 4:
573 // ERR_REG4
7473795a 574 fERRREG4 = parData & 0xFFF;
31be3849 575 break;
576 case 5:
577 // FEC_RO_A
578 fActiveFECsA = parData & 0xFFFF;
579 break;
580 case 6:
581 // FEC_RO_B
582 fActiveFECsB = parData & 0xFFFF;
583 break;
584 case 7:
585 // RDO_CFG1
586 fAltroCFG1 = parData & 0x7FFFF;
587 break;
588 case 8:
589 // RDO_CFG2
590 fAltroCFG2 = parData & 0x1FFFFFF;
591 break;
592 default:
593 fRawReader->AddMinorErrorLog(kRCUTrailerErr,"undef word");
594 AliWarning(Form("Undefined parameter code %d, ignore it !",
595 parCode));
596 break;
597 }
598 }
599
600 if (index < 4) {
601 fRawReader->AddMajorErrorLog(kRCUTrailerErr,Form("tr=%d raw=%d bytes",
602 trailerSize*4,
603 fRawReader->GetDataSize()));
604 AliWarning(Form("Invalid trailer size found (%d bytes) ! The size is bigger than the raw data size (%d bytes)!",
605 trailerSize*4,
606 fRawReader->GetDataSize()));
607 }
608 fRCUTrailerSize = trailerSize*4;
609 fRCUTrailerData = fData + index;
610
611 Int_t position = Get32bitWord(index);
612
613
614 return position;
615}
616
f683d15c 617//_____________________________________________________________________________
618Double_t AliAltroRawStream::GetTSample() const
619{
620 // Returns the sampling time
621 // in seconds. In case the rcu trailer
622 // was note read, return an invalid number (0)
623
624 if (!fRCUTrailerData) return 0.;
625
626 const Double_t kLHCTimeSample = 25.0e-9; // LHC clocks runs at 40 MHz
627 UChar_t fq = (fAltroCFG2 >> 5) & 0xF;
628 Double_t tSample;
629 switch (fq) {
630 case 0:
631 // 20 MHz
632 tSample = 2.0*kLHCTimeSample;
633 break;
634 case 1:
635 // 10 Mhz
636 tSample = 4.0*kLHCTimeSample;
637 break;
638 case 2:
639 // 5 MHz
640 tSample = 8.0*kLHCTimeSample;
641 break;
642 default:
643 AliWarning(Form("Invalid sampling frequency value %d !",
644 fq));
645 tSample = 0.;
646 break;
647 }
648
649 return tSample;
650}
651
652//_____________________________________________________________________________
653Double_t AliAltroRawStream::GetL1Phase() const
654{
655 // Returns the L1 phase w.r.t to the
656 // LHC clock
657 if (!fRCUTrailerData) return 0.;
658
659 const Double_t kLHCTimeSample = 25.0e-9; // LHC clocks runs at 40 MHz
660 Double_t phase = ((Double_t)(fAltroCFG2 & 0x1F))*kLHCTimeSample;
661
662 Double_t tSample = GetTSample();
663 if (phase >= tSample) {
664 AliWarning(Form("Invalid L1 trigger phase (%f >= %d) !",
665 phase,tSample));
666 phase = 0.;
667 }
668
669 return phase;
670}
671
31be3849 672//_____________________________________________________________________________
673void AliAltroRawStream::PrintRCUTrailer() const
674{
675 // Prints the contents of
676 // the RCU trailer data
677 printf("RCU trailer:\n===========\n");
678 printf("FECERRA: 0x%x\nFECERRB: 0x%x\n",fFECERRA,fFECERRB);
679 printf("ERRREG2: 0x%x\n",fERRREG2);
7473795a 680 printf("#channels skipped due to address mismatch: %d\n",GetNChAddrMismatch());
681 printf("#channels skipped due to bad block length: %d\n",GetNChLengthMismatch());
31be3849 682 printf("Active FECs (branch A): 0x%x\nActive FECs (branch B): 0x%x\n",fActiveFECsA,fActiveFECsB);
683 printf("Baseline corr: 0x%x\n",GetBaselineCorr());
684 printf("Number of presamples: %d\nNumber of postsamples: %d\n",GetNPresamples(),GetNPostsamples());
685 printf("Second baseline corr: %d\n",GetSecondBaselineCorr());
686 printf("GlitchFilter: %d\n",GetGlitchFilter());
687 printf("Number of non-ZS postsamples: %d\nNumber of non-ZS presamples: %d\n",GetNNonZSPostsamples(),GetNNonZSPresamples());
688 printf("Number of ALTRO buffers: %d\n",GetNAltroBuffers());
689 printf("Number of pretrigger samples: %d\n",GetNPretriggerSamples());
690 printf("Number of samples per channel: %d\n",GetNSamplesPerCh());
691 printf("Sparse readout: %d\n",GetSparseRO());
7473795a 692 printf("Sampling time: %e s\n",GetTSample());
693 printf("L1 Phase: %e s\n",GetL1Phase());
694 printf("AltroCFG1: 0x%x\nAltroCFG2: 0x%x\n",GetAltroCFG1(),GetAltroCFG2());
31be3849 695 printf("===========\n");
696}
697
5e6235b5 698//_____________________________________________________________________________
699Bool_t AliAltroRawStream::GetRCUTrailerData(UChar_t*& data) const
700{
701 // Return a pointer to the RCU trailer
702 // data. Should be called always after
703 // the RCU trailer was already processed
704 // in the GetPosition() method
705 if (!fRCUTrailerSize || !fRCUTrailerData) {
706 AliError("No valid RCU trailer data is found !");
707 data = NULL;
708 return kFALSE;
709 }
710
711 data = fRCUTrailerData;
712
713 return kTRUE;
3ea47630 714}
776c3b9c 715
716//_____________________________________________________________________________
717void AliAltroRawStream::PrintDebug() const
718{
719 // The method prints all the available
720 // debug information.
721 // Its is used in case of decoding errors.
722
723 AliError("Start of debug printout\n--------------------");
724
725 Dump();
726 if (fRawReader) fRawReader->Dump();
727
728 AliError("End of debug printout\n--------------------");
729}
e68dc1cf 730
731//_____________________________________________________________________________
732Int_t AliAltroRawStream::GetBranch() const
733{
734 // The method provides the RCU branch index (0 or 1)
735 // for the current hardware address.
736 // In case the hardware address has not been yet
737 // initialized, the method returns -1
738 if (fHWAddress == -1) return -1;
739
740 return ((fHWAddress >> 11) & 0x1);
741}
742
743//_____________________________________________________________________________
744Int_t AliAltroRawStream::GetFEC() const
745{
746 // The method provides the front-end card index
747 // for the current hardware address.
748 // In case the hardware address has not been yet
749 // initialized, the method returns -1
750 if (fHWAddress == -1) return -1;
751
752 return ((fHWAddress >> 7) & 0xF);
753}
754
755//_____________________________________________________________________________
756Int_t AliAltroRawStream::GetAltro() const
757{
758 // The method provides the altro chip index
759 // for the current hardware address.
760 // In case the hardware address has not been yet
761 // initialized, the method returns -1
762 if (fHWAddress == -1) return -1;
763
764 return ((fHWAddress >> 4) & 0x7);
765}
766
767//_____________________________________________________________________________
768Int_t AliAltroRawStream::GetChannel() const
769{
770 // The method provides the channel index
771 // for the current hardware address.
772 // In case the hardware address has not been yet
773 // initialized, the method returns -1
774 if (fHWAddress == -1) return -1;
775
776 return (fHWAddress & 0xF);
777}
eb09ec9a 778
779//_____________________________________________________________________________
780void AliAltroRawStream::AddMappingErrorLog(const char *message)
781{
782 // Signal a mapping error
783 // The method can be used by the TPC,PHOS,EMCAL,FMD raw stream
784 // classes in order to log an error related to bad altro mapping
785
786 if (fRawReader) fRawReader->AddMinorErrorLog(kBadAltroMapping,message);
787}