]>
Commit | Line | Data |
---|---|---|
f8e5b5a0 | 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 base class for reading raw data digits in Altro format. | |
19 | /// The class is able to read the RCU v3 and above formats. | |
20 | /// The main difference between the format V3 and older ones is in | |
21 | /// the coding of the 10-bit Altro payload words. In V3 3 10-bit words | |
22 | /// are coded in one 32-bit word. The bits 30 and 31 are used to identify | |
23 | /// the payload, altro header and RCU trailer contents. | |
24 | /// | |
25 | /// | |
26 | /// cvetan.cheshkov@cern.ch 1/04/2009 | |
27 | /////////////////////////////////////////////////////////////////////////////// | |
28 | ||
29 | #include "AliAltroRawStreamV3.h" | |
30 | #include "AliRawReader.h" | |
31 | #include "AliLog.h" | |
0148e633 | 32 | #include "AliAltroRawStream.h" |
f8e5b5a0 | 33 | |
34 | ClassImp(AliAltroRawStreamV3) | |
35 | ||
36 | ||
37 | //_____________________________________________________________________________ | |
38 | AliAltroRawStreamV3::AliAltroRawStreamV3(AliRawReader* rawReader) : | |
39 | fIsShortDataHeader(kFALSE), | |
40 | fDDLNumber(-1), | |
41 | fRCUId(-1), | |
42 | fHWAddress(-1), | |
43 | fRawReader(rawReader), | |
44 | fData(NULL), | |
45 | fPosition(-1), | |
46 | fCount(-1), | |
47 | fStartTimeBin(-1), | |
48 | fBunchLength(-1), | |
49 | fBadChannel(kFALSE), | |
50 | fPayloadSize(-1), | |
6d4dd848 | 51 | fBunchDataPointer(NULL), |
52 | fBunchDataIndex(-1), | |
f8e5b5a0 | 53 | fRCUTrailerData(NULL), |
54 | fRCUTrailerSize(0), | |
55 | fFECERRA(0), | |
56 | fFECERRB(0), | |
57 | fERRREG2(0), | |
58 | fERRREG3(0), | |
f8e5b5a0 | 59 | fActiveFECsA(0), |
60 | fActiveFECsB(0), | |
61 | fAltroCFG1(0), | |
0148e633 | 62 | fAltroCFG2(0), |
3ce326c0 | 63 | fOldStream(NULL), |
64 | fCheckAltroPayload(kTRUE) | |
f8e5b5a0 | 65 | { |
66 | // Constructor | |
67 | // Create an object to read Altro raw digits in | |
68 | // RCU version 3 and beyond format | |
69 | for(Int_t i = 0; i < kMaxNTimeBins; i++) fBunchData[i] = 0; | |
70 | } | |
71 | ||
72 | //_____________________________________________________________________________ | |
73 | AliAltroRawStreamV3::~AliAltroRawStreamV3() | |
74 | { | |
75 | // destructor | |
0148e633 | 76 | // delete old stream object if one exists |
77 | if (fOldStream) delete fOldStream; | |
f8e5b5a0 | 78 | } |
79 | ||
80 | //_____________________________________________________________________________ | |
81 | AliAltroRawStreamV3::AliAltroRawStreamV3(const AliAltroRawStreamV3& stream) : | |
82 | TObject(stream), | |
83 | fIsShortDataHeader(stream.fIsShortDataHeader), | |
84 | fDDLNumber(stream.fDDLNumber), | |
85 | fRCUId(stream.fRCUId), | |
86 | fHWAddress(stream.fHWAddress), | |
87 | fRawReader(stream.fRawReader), | |
88 | fData(stream.fData), | |
89 | fPosition(stream.fPosition), | |
90 | fCount(stream.fCount), | |
91 | fStartTimeBin(stream.fStartTimeBin), | |
92 | fBunchLength(stream.fBunchLength), | |
93 | fBadChannel(stream.fBadChannel), | |
94 | fPayloadSize(stream.fPayloadSize), | |
6d4dd848 | 95 | fBunchDataPointer(stream.fBunchDataPointer), |
96 | fBunchDataIndex(stream.fBunchDataIndex), | |
f8e5b5a0 | 97 | fRCUTrailerData(stream.fRCUTrailerData), |
98 | fRCUTrailerSize(stream.fRCUTrailerSize), | |
99 | fFECERRA(stream.fFECERRA), | |
100 | fFECERRB(stream.fFECERRB), | |
101 | fERRREG2(stream.fERRREG2), | |
102 | fERRREG3(stream.fERRREG3), | |
f8e5b5a0 | 103 | fActiveFECsA(stream.fActiveFECsA), |
104 | fActiveFECsB(stream.fActiveFECsB), | |
105 | fAltroCFG1(stream.fAltroCFG1), | |
0148e633 | 106 | fAltroCFG2(stream.fAltroCFG2), |
3ce326c0 | 107 | fOldStream(NULL), |
108 | fCheckAltroPayload(stream.fCheckAltroPayload) | |
f8e5b5a0 | 109 | { |
110 | // Copy constructor | |
111 | // Copy the bunch data array | |
112 | for(Int_t i = 0; i < kMaxNTimeBins; i++) fBunchData[i] = stream.fBunchData[i]; | |
0148e633 | 113 | |
114 | if (stream.fOldStream) | |
115 | fOldStream = new AliAltroRawStream(*stream.fOldStream); | |
f8e5b5a0 | 116 | } |
117 | ||
118 | //_____________________________________________________________________________ | |
119 | AliAltroRawStreamV3& AliAltroRawStreamV3::operator = (const AliAltroRawStreamV3& stream) | |
120 | { | |
121 | // assignment operator | |
122 | // ... | |
123 | if(&stream == this) return *this; | |
124 | ||
125 | fIsShortDataHeader = stream.fIsShortDataHeader; | |
126 | fDDLNumber = stream.fDDLNumber; | |
127 | fRCUId = stream.fRCUId; | |
128 | fHWAddress = stream.fHWAddress; | |
129 | fRawReader = stream.fRawReader; | |
130 | fData = stream.fData; | |
131 | fPosition = stream.fPosition; | |
132 | fCount = stream.fCount; | |
133 | fStartTimeBin = stream.fStartTimeBin; | |
134 | fBunchLength = stream.fBunchLength; | |
135 | fBadChannel = stream.fBadChannel; | |
136 | fPayloadSize = stream.fPayloadSize; | |
6d4dd848 | 137 | fBunchDataPointer = stream.fBunchDataPointer; |
138 | fBunchDataIndex = stream.fBunchDataIndex; | |
f8e5b5a0 | 139 | fRCUTrailerData = stream.fRCUTrailerData; |
140 | fRCUTrailerSize = stream.fRCUTrailerSize; | |
141 | fFECERRA = stream.fFECERRA; | |
142 | fFECERRB = stream.fFECERRB; | |
143 | fERRREG2 = stream.fERRREG2; | |
144 | fERRREG3 = stream.fERRREG3; | |
f8e5b5a0 | 145 | fActiveFECsA = stream.fActiveFECsA; |
146 | fActiveFECsB = stream.fActiveFECsB; | |
147 | fAltroCFG1 = stream.fAltroCFG1; | |
148 | fAltroCFG2 = stream.fAltroCFG2; | |
149 | ||
150 | for(Int_t i = 0; i < kMaxNTimeBins; i++) fBunchData[i] = stream.fBunchData[i]; | |
151 | ||
0148e633 | 152 | if (stream.fOldStream) { |
153 | if (fOldStream) delete fOldStream; | |
154 | fOldStream = new AliAltroRawStream(stream.fRawReader); | |
155 | *fOldStream = *stream.fOldStream; | |
156 | } | |
157 | ||
3ce326c0 | 158 | fCheckAltroPayload = stream.fCheckAltroPayload; |
159 | ||
f8e5b5a0 | 160 | return *this; |
161 | } | |
162 | ||
163 | //_____________________________________________________________________________ | |
164 | void AliAltroRawStreamV3::Reset() | |
165 | { | |
166 | // Complete reset of raw stream params | |
167 | // Reset of the raw-reader as well | |
168 | ||
169 | fDDLNumber = fRCUId = fHWAddress = -1; | |
170 | fPosition = fCount = -1; | |
171 | fBunchLength = fStartTimeBin = -1; | |
172 | fBadChannel = kFALSE; | |
173 | fPayloadSize = -1; | |
6d4dd848 | 174 | fBunchDataPointer = NULL; |
175 | fBunchDataIndex = -1; | |
f8e5b5a0 | 176 | |
177 | fRCUTrailerData = NULL; | |
178 | fRCUTrailerSize = 0; | |
179 | ||
9283f3a5 | 180 | fFECERRA = fFECERRB = fERRREG2 = fERRREG3 = fActiveFECsA = fActiveFECsB = fAltroCFG1 = fAltroCFG2 = 0; |
f8e5b5a0 | 181 | |
182 | if (fRawReader) fRawReader->Reset(); | |
183 | ||
0148e633 | 184 | if (fOldStream) fOldStream->Reset(); |
f8e5b5a0 | 185 | } |
186 | ||
187 | //_____________________________________________________________________________ | |
188 | Bool_t AliAltroRawStreamV3::NextDDL() | |
189 | { | |
190 | // Read the next DDL payload (CDH + RCU trailer) | |
191 | // Updates the information which is coming from these | |
192 | // two sources | |
193 | ||
194 | fPosition = 0; | |
195 | // Get next DDL payload | |
196 | // return wtih false in case no more data payloads | |
197 | // are found | |
198 | do { | |
199 | if (!fRawReader->ReadNextData(fData)) return kFALSE; | |
200 | } while (fRawReader->GetDataSize() == 0); | |
201 | ||
202 | fDDLNumber = fRawReader->GetDDLID(); | |
203 | ||
204 | UChar_t rcuVer = fRawReader->GetBlockAttributes(); | |
205 | ||
0148e633 | 206 | if (rcuVer < 2) { |
207 | // old altro format data | |
208 | if (!fOldStream) { | |
209 | fOldStream = new AliAltroRawStream(fRawReader); | |
210 | AliInfo(Form("RCU firmware verion %d detected. Using AliAltroRawStream to decode the data.", | |
211 | rcuVer)); | |
212 | } | |
213 | Bool_t status = fOldStream->NextDDL(fData); | |
214 | if (status) { | |
215 | fRCUId = fOldStream->GetRCUId(); | |
216 | fRCUTrailerSize = fOldStream->GetRCUTrailerSize(); | |
217 | fOldStream->GetRCUTrailerData(fRCUTrailerData); | |
218 | fFECERRA = fOldStream->GetFECERRA(); | |
219 | fFECERRB = fOldStream->GetFECERRB(); | |
220 | fERRREG2 = fOldStream->GetERRREG2(); | |
221 | fERRREG3 = ((UInt_t)fOldStream->GetNChAddrMismatch()) | | |
222 | (((UInt_t)fOldStream->GetNChLengthMismatch()) << 12); | |
223 | fActiveFECsA = fOldStream->GetActiveFECsA(); | |
224 | fActiveFECsB = fOldStream->GetActiveFECsB(); | |
225 | fAltroCFG1 = fOldStream->GetAltroCFG1(); | |
226 | fAltroCFG2 = fOldStream->GetAltroCFG2(); | |
227 | } | |
228 | return status; | |
229 | } | |
f8e5b5a0 | 230 | |
0148e633 | 231 | return ReadRCUTrailer(rcuVer); |
f8e5b5a0 | 232 | } |
233 | ||
234 | //_____________________________________________________________________________ | |
235 | Bool_t AliAltroRawStreamV3::NextChannel() | |
236 | { | |
237 | // Read the next Altro channel from the | |
238 | // raw-data stream | |
239 | // Updates the channel hardware address member and | |
240 | // channel data size. Sets the error flag in case | |
241 | // RCU signals readout error in this channel | |
0148e633 | 242 | if (fOldStream) { |
243 | Bool_t status = fOldStream->NextChannel(); | |
244 | if (status) fHWAddress = fOldStream->GetHWAddress(); | |
245 | return status; | |
246 | } | |
247 | ||
f8e5b5a0 | 248 | fCount = -1; |
249 | fBadChannel = kFALSE; | |
6d4dd848 | 250 | fBunchDataIndex = 0; |
3ce326c0 | 251 | fBunchLength = -1; |
f8e5b5a0 | 252 | |
253 | UInt_t word = 0; | |
254 | do { | |
255 | word = Get32bitWord(fPosition++); | |
6d4dd848 | 256 | if (fPosition > fPayloadSize) return kFALSE; |
f8e5b5a0 | 257 | } |
6d4dd848 | 258 | while ((word >> 30) != 1); |
f8e5b5a0 | 259 | |
260 | // check for readout errors | |
6d4dd848 | 261 | fBadChannel = (word >> 29) & 0x1; |
f8e5b5a0 | 262 | |
263 | // extract channel payload and hw address | |
6d4dd848 | 264 | fCount = (word >> 16) & 0x3FF; |
f8e5b5a0 | 265 | fHWAddress = word & 0xFFF; |
266 | ||
6d4dd848 | 267 | // Now unpack the altro data |
268 | // Revert the order of the samples | |
269 | // inside the bunch so that the | |
270 | // first time is first in the samples | |
271 | // array | |
272 | Int_t isample = 0; | |
273 | Int_t nwords = (fCount+2)/3; | |
274 | for (Int_t iword = 0; iword < nwords; iword++) { | |
275 | word = Get32bitWord(fPosition++); | |
276 | if ((word >> 30) != 0) { | |
277 | // Unexpected end of altro channel payload | |
278 | AliWarning(Form("Unexpected end of payload in altro channel payload! Address=0x%x, word=0x%x", | |
279 | fHWAddress,word)); | |
280 | fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress)); | |
281 | fCount = -1; | |
282 | fPosition--; | |
283 | return kFALSE; | |
284 | } | |
285 | fBunchData[isample++] = (word >> 20) & 0x3FF; | |
286 | fBunchData[isample++] = (word >> 10) & 0x3FF; | |
287 | fBunchData[isample++] = word & 0x3FF; | |
288 | } | |
289 | ||
f8e5b5a0 | 290 | return kTRUE; |
291 | } | |
292 | ||
293 | //_____________________________________________________________________________ | |
294 | Bool_t AliAltroRawStreamV3::NextBunch() | |
295 | { | |
296 | // Read next altro bunch from the | |
297 | // raw-data stream. | |
298 | // Updates the start/end time-bins | |
299 | // and the array with altro samples | |
0148e633 | 300 | if (fOldStream) { |
301 | Bool_t status = fOldStream->NextBunch(fBunchData,fBunchLength,fStartTimeBin); | |
302 | if (status) fBunchDataPointer = &fBunchData[0]; | |
303 | else fBunchDataPointer = NULL; | |
304 | return status; | |
305 | } | |
306 | ||
3ce326c0 | 307 | Int_t prevTimeBin = (fBunchLength > 0) ? fStartTimeBin-fBunchLength+1 : 1024; |
f8e5b5a0 | 308 | fBunchLength = fStartTimeBin = -1; |
6d4dd848 | 309 | fBunchDataPointer = NULL; |
f8e5b5a0 | 310 | |
6d4dd848 | 311 | if ((fBunchDataIndex >= fCount) || fBadChannel) return kFALSE; |
f8e5b5a0 | 312 | |
6d4dd848 | 313 | fBunchLength = fBunchData[fBunchDataIndex]; |
3ce326c0 | 314 | if (fBunchLength <= 2) { |
315 | // Invalid bunch size | |
316 | AliWarning(Form("Too short bunch length (%d) in Address=0x%x !", | |
317 | fBunchLength,fHWAddress)); | |
318 | fRawReader->AddMinorErrorLog(kAltroBunchHeadErr,Form("hw=0x%x",fHWAddress)); | |
319 | fCount = fBunchLength = -1; | |
320 | return kFALSE; | |
321 | } | |
6d4dd848 | 322 | if ((fBunchDataIndex + fBunchLength) > fCount) { |
f8e5b5a0 | 323 | // Too long bunch detected |
6d4dd848 | 324 | AliWarning(Form("Too long bunch detected in Address=0x%x ! Expected <= %d 10-bit words, found %d !", |
325 | fHWAddress,fCount-fBunchDataIndex,fBunchLength)); | |
f8e5b5a0 | 326 | fRawReader->AddMinorErrorLog(kAltroBunchHeadErr,Form("hw=0x%x",fHWAddress)); |
327 | fCount = fBunchLength = -1; | |
328 | return kFALSE; | |
329 | } | |
6d4dd848 | 330 | fBunchDataIndex++; |
f8e5b5a0 | 331 | fBunchLength -= 2; |
332 | ||
6d4dd848 | 333 | fStartTimeBin = fBunchData[fBunchDataIndex++]; |
3ce326c0 | 334 | if (fCheckAltroPayload) { |
335 | if ((fStartTimeBin-fBunchLength+1) < 0) { | |
336 | AliWarning(Form("Invalid start time-bin in Address=0x%x ! (%d-%d+1) < 0", | |
337 | fHWAddress,fStartTimeBin,fBunchLength)); | |
338 | fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress)); | |
339 | fCount = fBunchLength = -1; | |
340 | return kFALSE; | |
341 | } | |
342 | if (fStartTimeBin >= prevTimeBin) { | |
343 | AliWarning(Form("Invalid start time-bin in Address=0x%x ! (%d>=%d)", | |
344 | fHWAddress,fStartTimeBin,prevTimeBin)); | |
345 | fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress)); | |
346 | fCount = fBunchLength = -1; | |
347 | return kFALSE; | |
348 | } | |
349 | } | |
f8e5b5a0 | 350 | |
6d4dd848 | 351 | fBunchDataPointer = &fBunchData[fBunchDataIndex]; |
f8e5b5a0 | 352 | |
6d4dd848 | 353 | fBunchDataIndex += fBunchLength; |
f8e5b5a0 | 354 | |
355 | return kTRUE; | |
356 | } | |
357 | ||
358 | //_____________________________________________________________________________ | |
359 | UInt_t AliAltroRawStreamV3::Get32bitWord(Int_t index) const | |
360 | { | |
361 | // This method returns the 32 bit word at a given | |
362 | // position inside the raw data payload. | |
363 | // The 'index' points to the beginning of the word. | |
364 | // The method is supposed to be endian (platform) | |
365 | // independent. | |
366 | ||
367 | index = (index << 2); | |
368 | UInt_t word = 0; | |
369 | word |= fData[index++]; | |
370 | word |= fData[index++] << 8; | |
371 | word |= fData[index++] << 16; | |
372 | word |= fData[index++] << 24; | |
373 | ||
374 | return word; | |
375 | } | |
376 | ||
377 | ///_____________________________________________________________________________ | |
378 | Bool_t AliAltroRawStreamV3::ReadRCUTrailer(UChar_t rcuVer) | |
379 | { | |
380 | // Read the RCU trailer according | |
381 | // to the RCU formware version | |
382 | // specified in CDH | |
383 | // Cross-check with version found in the | |
384 | // trailer | |
385 | ||
386 | fRCUTrailerData = NULL; | |
387 | fRCUTrailerSize = 0; | |
388 | fPayloadSize = -1; | |
389 | ||
390 | Int_t index = fRawReader->GetDataSize()/4; | |
391 | ||
392 | // First read 32-bit word with the | |
393 | // trailer size (7 bits), RCU ID (9 bits) and | |
394 | // RCU firmware version (8 bits?) | |
395 | // The two major bit should be 11 (identifies | |
396 | // the end of the trailer) | |
397 | UInt_t word = Get32bitWord(--index); | |
398 | ||
399 | if ((word >> 30) != 3) { | |
400 | fRawReader->AddFatalErrorLog(kRCUTrailerErr,""); | |
401 | AliError("Last RCU trailer word not found!"); | |
402 | return kFALSE; | |
403 | } | |
404 | ||
405 | UChar_t ver = (word >> 16) & 0xFF; | |
406 | if (ver != rcuVer) { | |
407 | // Wrong RCU firmware version detected | |
408 | fRawReader->AddMajorErrorLog(kRCUVerErr,Form("%d!=%d", | |
409 | ver,rcuVer)); | |
410 | AliDebug(1,Form("Wrong RCU firmware version detected: %d != %d", | |
411 | ver,rcuVer)); | |
412 | } | |
413 | ||
414 | fRCUId = (Int_t)((word >> 7) & 0x1FF); | |
415 | Int_t trailerSize = (word & 0x7F); | |
416 | ||
417 | // Now read the beginning of the trailer | |
418 | // where the payload size is written | |
419 | if (trailerSize < 2) { | |
420 | fRawReader->AddMajorErrorLog(kRCUTrailerErr,Form("tr=%d bytes", | |
421 | trailerSize*4)); | |
422 | AliWarning(Form("Invalid trailer size found (%d bytes) !", | |
423 | trailerSize*4)); | |
424 | return kFALSE; | |
425 | } | |
426 | ||
427 | trailerSize -= 2; | |
428 | fRCUTrailerSize = trailerSize*4; | |
429 | ||
430 | for (; trailerSize > 0; trailerSize--) { | |
431 | word = Get32bitWord(--index); | |
432 | if ((word >> 30) != 2) { | |
433 | fRawReader->AddMinorErrorLog(kRCUTrailerErr,"missing 10"); | |
434 | AliWarning("Missing RCU trailer identifier pattern!"); | |
435 | continue; | |
436 | } | |
437 | Int_t parCode = (word >> 26) & 0xF; | |
438 | Int_t parData = word & 0x3FFFFFF; | |
439 | switch (parCode) { | |
440 | case 1: | |
441 | // ERR_REG1 | |
442 | fFECERRA = ((parData >> 13) & 0x1FFF) << 7; | |
443 | fFECERRB = ((parData & 0x1FFF)) << 7; | |
444 | break; | |
445 | case 2: | |
446 | // ERR_REG2 | |
447 | fERRREG2 = parData & 0x1FF; | |
448 | break; | |
449 | case 3: | |
450 | // ERR_REG3 | |
9283f3a5 | 451 | fERRREG3 = parData & 0x1FFFFFF; |
f8e5b5a0 | 452 | break; |
453 | case 4: | |
f8e5b5a0 | 454 | // FEC_RO_A |
455 | fActiveFECsA = parData & 0xFFFF; | |
456 | break; | |
9283f3a5 | 457 | case 5: |
f8e5b5a0 | 458 | // FEC_RO_B |
459 | fActiveFECsB = parData & 0xFFFF; | |
460 | break; | |
9283f3a5 | 461 | case 6: |
f8e5b5a0 | 462 | // RDO_CFG1 |
463 | fAltroCFG1 = parData & 0xFFFFF; | |
464 | break; | |
9283f3a5 | 465 | case 7: |
f8e5b5a0 | 466 | // RDO_CFG2 |
467 | fAltroCFG2 = parData & 0x1FFFFFF; | |
468 | break; | |
469 | default: | |
470 | fRawReader->AddMinorErrorLog(kRCUTrailerErr,"undef word"); | |
471 | AliWarning(Form("Undefined parameter code %d, ignore it !", | |
472 | parCode)); | |
473 | break; | |
474 | } | |
475 | } | |
476 | ||
477 | if (index < 1) { | |
478 | fRawReader->AddMajorErrorLog(kRCUTrailerErr,Form("tr=%d raw=%d bytes", | |
479 | fRCUTrailerSize+8, | |
480 | fRawReader->GetDataSize())); | |
481 | AliWarning(Form("Invalid trailer size found (%d bytes) ! The size is bigger than the raw data size (%d bytes)!", | |
482 | fRCUTrailerSize, | |
483 | fRawReader->GetDataSize())); | |
484 | } | |
485 | ||
486 | fRCUTrailerData = fData + index*4; | |
487 | ||
488 | // Now read the payload size | |
489 | // (First word in the RCU trailer) | |
490 | fPayloadSize = Get32bitWord(--index) & 0x3FFFFFF; | |
491 | ||
492 | if ((fRawReader->GetDataSize() - fRCUTrailerSize - 8) != (fPayloadSize*4)) { | |
493 | fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d tr=%d rcu=%d bytes", | |
494 | fRawReader->GetDataSize(), | |
495 | fRCUTrailerSize+8, | |
496 | fPayloadSize*4)); | |
497 | AliWarning(Form("Inconsistent raw data size ! Raw data size - %d bytes (from CDH), RCU trailer - %d bytes, raw data size (from RCU trailer) - %d bytes !", | |
498 | fRawReader->GetDataSize(), | |
499 | fRCUTrailerSize+8, | |
500 | fPayloadSize*4)); | |
501 | } | |
502 | ||
503 | return kTRUE; | |
504 | } | |
505 | ||
506 | //_____________________________________________________________________________ | |
507 | Int_t AliAltroRawStreamV3::GetBranch() const | |
508 | { | |
509 | // The method provides the RCU branch index (0 or 1) | |
510 | // for the current hardware address. | |
511 | // In case the hardware address has not been yet | |
512 | // initialized, the method returns -1 | |
513 | if (fHWAddress == -1) return -1; | |
514 | ||
515 | return ((fHWAddress >> 11) & 0x1); | |
516 | } | |
517 | ||
518 | //_____________________________________________________________________________ | |
519 | Int_t AliAltroRawStreamV3::GetFEC() const | |
520 | { | |
521 | // The method provides the front-end card index | |
522 | // for the current hardware address. | |
523 | // In case the hardware address has not been yet | |
524 | // initialized, the method returns -1 | |
525 | if (fHWAddress == -1) return -1; | |
526 | ||
527 | return ((fHWAddress >> 7) & 0xF); | |
528 | } | |
529 | ||
530 | //_____________________________________________________________________________ | |
531 | Int_t AliAltroRawStreamV3::GetAltro() const | |
532 | { | |
533 | // The method provides the altro chip index | |
534 | // for the current hardware address. | |
535 | // In case the hardware address has not been yet | |
536 | // initialized, the method returns -1 | |
537 | if (fHWAddress == -1) return -1; | |
538 | ||
539 | return ((fHWAddress >> 4) & 0x7); | |
540 | } | |
541 | ||
542 | //_____________________________________________________________________________ | |
543 | Int_t AliAltroRawStreamV3::GetChannel() const | |
544 | { | |
545 | // The method provides the channel index | |
546 | // for the current hardware address. | |
547 | // In case the hardware address has not been yet | |
548 | // initialized, the method returns -1 | |
549 | if (fHWAddress == -1) return -1; | |
550 | ||
551 | return (fHWAddress & 0xF); | |
552 | } | |
553 | ||
554 | //_____________________________________________________________________________ | |
555 | Bool_t AliAltroRawStreamV3::GetRCUTrailerData(UChar_t*& data) const | |
556 | { | |
557 | // Return a pointer to the RCU trailer | |
558 | // data. Should be called always after | |
559 | // the RCU trailer was already processed | |
560 | // in the GetPosition() method | |
561 | if (!fRCUTrailerSize || !fRCUTrailerData) { | |
562 | AliError("No valid RCU trailer data is found !"); | |
563 | data = NULL; | |
564 | return kFALSE; | |
565 | } | |
566 | ||
567 | data = fRCUTrailerData; | |
568 | ||
569 | return kTRUE; | |
570 | } | |
571 | ||
572 | //_____________________________________________________________________________ | |
573 | void AliAltroRawStreamV3::PrintRCUTrailer() const | |
574 | { | |
575 | // Prints the contents of | |
576 | // the RCU trailer data | |
577 | printf("RCU trailer:\n===========\n"); | |
578 | printf("FECERRA: 0x%x\nFECERRB: 0x%x\n",fFECERRA,fFECERRB); | |
579 | printf("ERRREG2: 0x%x\n",fERRREG2); | |
580 | printf("#channels skipped due to address mismatch: %d\n",GetNChAddrMismatch()); | |
581 | printf("#channels skipped due to bad block length: %d\n",GetNChLengthMismatch()); | |
582 | printf("Active FECs (branch A): 0x%x\nActive FECs (branch B): 0x%x\n",fActiveFECsA,fActiveFECsB); | |
583 | printf("Baseline corr: 0x%x\n",GetBaselineCorr()); | |
584 | printf("Number of presamples: %d\nNumber of postsamples: %d\n",GetNPresamples(),GetNPostsamples()); | |
585 | printf("Second baseline corr: %d\n",GetSecondBaselineCorr()); | |
586 | printf("GlitchFilter: %d\n",GetGlitchFilter()); | |
587 | printf("Number of non-ZS postsamples: %d\nNumber of non-ZS presamples: %d\n",GetNNonZSPostsamples(),GetNNonZSPresamples()); | |
588 | printf("Number of ALTRO buffers: %d\n",GetNAltroBuffers()); | |
589 | printf("Number of pretrigger samples: %d\n",GetNPretriggerSamples()); | |
590 | printf("Number of samples per channel: %d\n",GetNSamplesPerCh()); | |
591 | printf("Sparse readout: %d\n",GetSparseRO()); | |
592 | printf("Sampling time: %e s\n",GetTSample()); | |
593 | printf("L1 Phase: %e s\n",GetL1Phase()); | |
594 | printf("AltroCFG1: 0x%x\nAltroCFG2: 0x%x\n",GetAltroCFG1(),GetAltroCFG2()); | |
595 | printf("===========\n"); | |
596 | } | |
597 | ||
598 | //_____________________________________________________________________________ | |
599 | void AliAltroRawStreamV3::SelectRawData(Int_t detId) | |
600 | { | |
601 | // Select the raw data for specific | |
602 | // detector id | |
603 | AliDebug(1,Form("Selecting raw data for detector %d",detId)); | |
604 | fRawReader->Select(detId); | |
605 | } | |
606 | ||
607 | //_____________________________________________________________________________ | |
608 | void AliAltroRawStreamV3::SelectRawData(const char *detName) | |
609 | { | |
610 | // Select the raw data for specific | |
611 | // detector name | |
612 | AliDebug(1,Form("Selecting raw data for detector %s",detName)); | |
613 | fRawReader->Select(detName); | |
614 | } | |
615 | ||
616 | //_____________________________________________________________________________ | |
617 | Double_t AliAltroRawStreamV3::GetTSample() const | |
618 | { | |
619 | // Returns the sampling time | |
620 | // in seconds. In case the rcu trailer | |
621 | // was note read, return an invalid number (0) | |
622 | ||
623 | if (!fRCUTrailerData) return 0.; | |
624 | ||
625 | const Double_t kLHCTimeSample = 25.0e-9; // LHC clocks runs at 40 MHz | |
626 | UChar_t fq = (fAltroCFG2 >> 5) & 0xF; | |
627 | Double_t tSample; | |
628 | switch (fq) { | |
629 | case 0: | |
630 | // 20 MHz | |
631 | tSample = 2.0*kLHCTimeSample; | |
632 | break; | |
633 | case 1: | |
634 | // 10 Mhz | |
635 | tSample = 4.0*kLHCTimeSample; | |
636 | break; | |
637 | case 2: | |
638 | // 5 MHz | |
639 | tSample = 8.0*kLHCTimeSample; | |
640 | break; | |
641 | default: | |
642 | AliWarning(Form("Invalid sampling frequency value %d !", | |
643 | fq)); | |
644 | tSample = 0.; | |
645 | break; | |
646 | } | |
647 | ||
648 | return tSample; | |
649 | } | |
650 | ||
651 | //_____________________________________________________________________________ | |
652 | Double_t AliAltroRawStreamV3::GetL1Phase() const | |
653 | { | |
654 | // Returns the L1 phase w.r.t to the | |
655 | // LHC clock | |
656 | if (!fRCUTrailerData) return 0.; | |
657 | ||
658 | const Double_t kLHCTimeSample = 25.0e-9; // LHC clocks runs at 40 MHz | |
659 | Double_t phase = ((Double_t)(fAltroCFG2 & 0x1F))*kLHCTimeSample; | |
660 | ||
661 | Double_t tSample = GetTSample(); | |
662 | if (phase >= tSample) { | |
663 | AliWarning(Form("Invalid L1 trigger phase (%f >= %d) !", | |
664 | phase,tSample)); | |
665 | phase = 0.; | |
666 | } | |
667 | ||
668 | return phase; | |
669 | } | |
670 | ||
671 | //_____________________________________________________________________________ | |
672 | void AliAltroRawStreamV3::AddMappingErrorLog(const char *message) | |
673 | { | |
674 | // Signal a mapping error | |
675 | // The method can be used by the TPC,PHOS,EMCAL,FMD raw stream | |
676 | // classes in order to log an error related to bad altro mapping | |
677 | ||
678 | if (fRawReader) fRawReader->AddMinorErrorLog(kBadAltroMapping,message); | |
679 | } |