]>
Commit | Line | Data |
---|---|---|
c0751163 | 1 | /************************************************************************** |
33434f31 | 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 | **************************************************************************/ | |
c0751163 | 15 | |
c4ee792d | 16 | /* $Id $ */ |
17 | ||
c0751163 | 18 | |
3d1463c8 | 19 | //----------------------------------------------------------------------------- |
c4ee792d | 20 | /// \class AliMUONRawStreamTracker |
c0751163 | 21 | /// This class provides access to MUON digits in raw data. |
22 | /// | |
23 | /// It loops over all MUON digits in the raw data given by the AliRawReader. | |
24 | /// The Next method goes to the next digit. If there are no digits left | |
dabf5427 | 25 | /// it returns kFALSE |
313a427d | 26 | /// It can loop also over DDL and store the decoded rawdata in TClonesArray |
27 | /// in Payload class. | |
c0751163 | 28 | /// |
dabf5427 | 29 | /// Implement for Tracker |
c0751163 | 30 | /// |
3c7f5307 | 31 | /// \author Christian Finck & Laurent Aphecetche |
3d1463c8 | 32 | //----------------------------------------------------------------------------- |
c0751163 | 33 | |
34 | #include "AliMUONRawStreamTracker.h" | |
35 | ||
dabf5427 | 36 | #include "AliMUONLogger.h" |
c0751163 | 37 | #include "AliRawReader.h" |
38 | #include "AliRawDataHeader.h" | |
9e378ff4 | 39 | #include "AliDAQ.h" |
c0751163 | 40 | #include "AliLog.h" |
33434f31 | 41 | #include "AliMUONPayloadTracker.h" |
42 | #include "AliMUONBlockHeader.h" | |
43 | #include "AliMUONDspHeader.h" | |
44 | #include "AliMUONBusStruct.h" | |
45 | #include "AliMUONDDLTracker.h" | |
46 | #include "Riostream.h" | |
236f997c | 47 | #include <cassert> |
c0751163 | 48 | |
00e86732 | 49 | /// \cond CLASSIMP |
c0751163 | 50 | ClassImp(AliMUONRawStreamTracker) |
00e86732 | 51 | /// \endcond |
c0751163 | 52 | |
dabf5427 | 53 | const Int_t AliMUONRawStreamTracker::fgkMaxDDL = 20; |
54 | ||
55 | ||
56 | //___________________________________________ | |
c0751163 | 57 | AliMUONRawStreamTracker::AliMUONRawStreamTracker() |
dabf5427 | 58 | : AliMUONRawStream(), |
59 | fPayload(new AliMUONPayloadTracker()), | |
60 | fCurrentDDL(0), | |
61 | fCurrentDDLIndex(fgkMaxDDL), | |
62 | fCurrentBlockHeader(0), | |
63 | fCurrentBlockHeaderIndex(0), | |
64 | fCurrentDspHeader(0), | |
65 | fCurrentDspHeaderIndex(0), | |
66 | fCurrentBusStruct(0), | |
67 | fCurrentBusStructIndex(0), | |
68 | fCurrentDataIndex(0), | |
69 | fDDL(0) | |
c0751163 | 70 | { |
00e86732 | 71 | /// |
72 | /// create an object to read MUON raw digits | |
73 | /// Default ctor for monitoring purposes | |
74 | /// | |
33434f31 | 75 | |
76 | ||
c0751163 | 77 | } |
78 | ||
79 | //_________________________________________________________________ | |
80 | AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader) | |
dabf5427 | 81 | : AliMUONRawStream(rawReader), |
3c7f5307 | 82 | fPayload(new AliMUONPayloadTracker()), |
dabf5427 | 83 | fCurrentDDL(0), |
84 | fCurrentDDLIndex(fgkMaxDDL), | |
3c7f5307 | 85 | fCurrentBlockHeader(0), |
86 | fCurrentBlockHeaderIndex(0), | |
87 | fCurrentDspHeader(0), | |
88 | fCurrentDspHeaderIndex(0), | |
89 | fCurrentBusStruct(0), | |
90 | fCurrentBusStructIndex(0), | |
91 | fCurrentDataIndex(0), | |
dabf5427 | 92 | fDDL(0) |
c0751163 | 93 | { |
00e86732 | 94 | /// |
95 | /// ctor with AliRawReader as argument | |
96 | /// for reconstruction purpose | |
97 | /// | |
33434f31 | 98 | |
99 | ||
c0751163 | 100 | } |
101 | ||
c0751163 | 102 | //___________________________________ |
103 | AliMUONRawStreamTracker::~AliMUONRawStreamTracker() | |
104 | { | |
00e86732 | 105 | /// |
106 | /// clean up | |
107 | /// | |
313a427d | 108 | delete fPayload; |
c0751163 | 109 | } |
110 | ||
111 | //_____________________________________________________________ | |
33434f31 | 112 | Bool_t |
113 | AliMUONRawStreamTracker::Next(Int_t& busPatchId, | |
114 | UShort_t& manuId, UChar_t& manuChannel, | |
115 | UShort_t& adc) | |
c0751163 | 116 | { |
00e86732 | 117 | /// |
118 | /// read the next raw digit (buspatch structure) | |
119 | /// returns kFALSE if there is no digit left | |
236f997c | 120 | /// Should call First() before this method to start the iteration. |
33434f31 | 121 | /// |
122 | ||
123 | if ( IsDone() ) return kFALSE; | |
124 | ||
125 | if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 ) | |
126 | { | |
127 | Bool_t ok = GetNextBusStruct(); | |
128 | if (!ok) | |
129 | { | |
130 | // this is the end | |
131 | return kFALSE; | |
132 | } | |
133 | } | |
134 | ||
135 | ++fCurrentDataIndex; | |
136 | ||
137 | busPatchId = fCurrentBusStruct->GetBusPatchId(); | |
138 | manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex); | |
139 | manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex); | |
140 | adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex); | |
141 | ||
142 | return kTRUE; | |
c0751163 | 143 | } |
144 | ||
145 | //______________________________________________________ | |
33434f31 | 146 | Bool_t |
147 | AliMUONRawStreamTracker::IsDone() const | |
c0751163 | 148 | { |
33434f31 | 149 | /// Whether the iteration is finished or not |
150 | return (fCurrentBusStruct==0); | |
151 | } | |
c0751163 | 152 | |
33434f31 | 153 | //______________________________________________________ |
154 | void | |
155 | AliMUONRawStreamTracker::First() | |
156 | { | |
236f997c | 157 | /// Initialize the iteration process. |
33434f31 | 158 | |
159 | fCurrentDDLIndex = -1; | |
236f997c | 160 | // fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods. |
161 | // fCurrentBusStructIndex = -1; | |
162 | ||
163 | // Must reset all the pointers because if we return before calling | |
164 | // GetNextBusStruct() the user might call CurrentDDL(), CurrentBlockHeader(), | |
165 | // CurrentDspHeader() or CurrentBusStruct() which should return reasonable | |
166 | // results in that case. | |
167 | fCurrentDDL = 0; | |
168 | fCurrentBlockHeader = 0; | |
33434f31 | 169 | fCurrentDspHeader = 0; |
170 | fCurrentBusStruct = 0; | |
171 | ||
172 | // Find the first non-empty structure | |
236f997c | 173 | if (not GetNextDDL()) return; |
174 | if (not GetNextBlockHeader()) return; | |
175 | if (not GetNextDspHeader()) return; | |
33434f31 | 176 | GetNextBusStruct(); |
177 | } | |
c0751163 | 178 | |
33434f31 | 179 | //______________________________________________________ |
180 | Bool_t | |
181 | AliMUONRawStreamTracker::GetNextDDL() | |
182 | { | |
183 | /// Returns the next DDL present | |
184 | ||
dabf5427 | 185 | assert( GetReader() != 0 ); |
236f997c | 186 | |
33434f31 | 187 | Bool_t kFound(kFALSE); |
188 | ||
dabf5427 | 189 | while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound ) |
33434f31 | 190 | { |
191 | ++fCurrentDDLIndex; | |
dabf5427 | 192 | GetReader()->Reset(); |
193 | GetReader()->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex); | |
194 | if ( GetReader()->ReadHeader() ) | |
33434f31 | 195 | { |
196 | kFound = kTRUE; | |
197 | } | |
198 | } | |
199 | ||
200 | if ( !kFound ) | |
201 | { | |
dabf5427 | 202 | // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately |
236f997c | 203 | // for a subsequent call to this method, unless NextEvent is called in between. |
dabf5427 | 204 | fCurrentDDLIndex = fgkMaxDDL; |
236f997c | 205 | // We have not actually been able to complete the loading of the new DDL so |
206 | // we are still on the old one. In this case we do not need to reset fCurrentDDL. | |
207 | //fCurrentDDL = 0; | |
c0751163 | 208 | return kFALSE; |
209 | } | |
33434f31 | 210 | |
dabf5427 | 211 | Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes |
33434f31 | 212 | |
213 | AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex, | |
214 | totalDataWord)); | |
dabf5427 | 215 | |
313a427d | 216 | UInt_t *buffer = new UInt_t[totalDataWord/4]; |
33434f31 | 217 | |
dabf5427 | 218 | if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) ) |
33434f31 | 219 | { |
236f997c | 220 | // We have not actually been able to complete the loading of the new DDL so |
221 | // we are still on the old one. In this case we do not need to reset fCurrentDDL. | |
222 | //fCurrentDDL = 0; | |
223 | delete [] buffer; | |
33434f31 | 224 | return kFALSE; |
225 | } | |
226 | fPayload->ResetDDL(); | |
227 | ||
dabf5427 | 228 | #ifndef R__BYTESWAP |
229 | swap(buffer, totalDataWord); // swap needed for mac power pc | |
230 | #endif | |
231 | ||
33434f31 | 232 | Bool_t ok = fPayload->Decode(buffer, totalDataWord/4); |
233 | ||
dabf5427 | 234 | if (IsErrorLogger()) AddErrorMessage(); |
ea59383d | 235 | |
33434f31 | 236 | delete[] buffer; |
237 | ||
238 | fCurrentDDL = fPayload->GetDDLTracker(); | |
239 | ||
240 | fCurrentBlockHeaderIndex = -1; | |
241 | ||
242 | return ok; | |
243 | } | |
c0751163 | 244 | |
33434f31 | 245 | //______________________________________________________ |
246 | Bool_t | |
247 | AliMUONRawStreamTracker::GetNextBlockHeader() | |
248 | { | |
249 | /// Returns the next block Header present | |
236f997c | 250 | |
251 | assert( fCurrentDDL != 0 ); | |
c0751163 | 252 | |
33434f31 | 253 | fCurrentBlockHeader = 0; |
c0751163 | 254 | |
33434f31 | 255 | Int_t i(fCurrentBlockHeaderIndex); |
256 | ||
257 | while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 ) | |
258 | { | |
259 | ++i; | |
260 | fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i); | |
261 | } | |
262 | ||
263 | if ( !fCurrentBlockHeader ) | |
264 | { | |
265 | Bool_t ok = GetNextDDL(); | |
266 | if (!ok) | |
267 | { | |
268 | return kFALSE; | |
269 | } | |
270 | else | |
271 | { | |
272 | return GetNextBlockHeader(); | |
273 | } | |
274 | } | |
275 | ||
276 | fCurrentBlockHeaderIndex = i; | |
277 | ||
278 | fCurrentDspHeaderIndex = -1; | |
279 | ||
280 | return kTRUE; | |
281 | } | |
c0751163 | 282 | |
33434f31 | 283 | //______________________________________________________ |
284 | Bool_t | |
285 | AliMUONRawStreamTracker::GetNextDspHeader() | |
286 | { | |
287 | /// Returns the next Dsp Header present | |
288 | ||
236f997c | 289 | assert( fCurrentBlockHeader != 0 ); |
290 | ||
33434f31 | 291 | fCurrentDspHeader = 0; |
292 | ||
293 | Int_t i(fCurrentDspHeaderIndex); | |
294 | ||
295 | while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 ) | |
296 | { | |
297 | ++i; | |
298 | fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i); | |
299 | } | |
300 | ||
301 | if ( !fCurrentDspHeader ) | |
302 | { | |
303 | Bool_t ok = GetNextBlockHeader(); | |
304 | if (!ok) | |
305 | { | |
306 | return kFALSE; | |
307 | } | |
308 | else | |
309 | { | |
310 | return GetNextDspHeader(); | |
311 | } | |
312 | } | |
313 | ||
314 | fCurrentDspHeaderIndex = i; | |
315 | ||
316 | fCurrentBusStructIndex = -1; | |
317 | ||
318 | return kTRUE; | |
319 | } | |
c0751163 | 320 | |
33434f31 | 321 | //______________________________________________________ |
322 | Bool_t | |
323 | AliMUONRawStreamTracker::GetNextBusStruct() | |
324 | { | |
325 | /// Find the next non-empty busPatch structure | |
326 | ||
236f997c | 327 | assert( fCurrentDspHeader != 0 ); |
328 | ||
33434f31 | 329 | fCurrentBusStruct = 0; |
330 | ||
331 | Int_t i(fCurrentBusStructIndex); | |
332 | ||
333 | while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 ) | |
334 | { | |
335 | ++i; | |
336 | fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i); | |
337 | } | |
338 | ||
339 | if ( !fCurrentBusStruct ) | |
340 | { | |
341 | Bool_t ok = GetNextDspHeader(); | |
342 | if (!ok) | |
343 | { | |
344 | return kFALSE; | |
345 | } | |
346 | else | |
347 | { | |
348 | return GetNextBusStruct(); | |
349 | } | |
350 | } | |
351 | ||
352 | fCurrentBusStructIndex = i; | |
353 | ||
354 | fCurrentDataIndex = -1; | |
355 | ||
c0751163 | 356 | return kTRUE; |
357 | } | |
c0751163 | 358 | |
33434f31 | 359 | //______________________________________________________ |
360 | Bool_t AliMUONRawStreamTracker::NextDDL() | |
361 | { | |
362 | /// reading tracker DDL | |
363 | ||
dabf5427 | 364 | assert( GetReader() != 0 ); |
236f997c | 365 | |
33434f31 | 366 | fPayload->ResetDDL(); |
367 | ||
dabf5427 | 368 | while ( fDDL < fgkMaxDDL ) |
33434f31 | 369 | { |
dabf5427 | 370 | GetReader()->Reset(); |
371 | GetReader()->Select("MUONTRK", fDDL, fDDL); //Select the DDL file to be read | |
372 | if (GetReader()->ReadHeader()) break; | |
33434f31 | 373 | AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL)); |
374 | ++fDDL; | |
375 | } | |
376 | ||
dabf5427 | 377 | if ( fDDL == fgkMaxDDL ) |
33434f31 | 378 | { |
379 | fDDL = 0; | |
380 | return kFALSE; | |
381 | } | |
382 | ||
383 | AliDebug(3, Form("DDL Number %d\n", fDDL )); | |
384 | ||
dabf5427 | 385 | Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes |
33434f31 | 386 | |
387 | UInt_t *buffer = new UInt_t[totalDataWord/4]; | |
dabf5427 | 388 | |
389 | if(!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) | |
33434f31 | 390 | { |
ea59383d | 391 | delete[] buffer; |
33434f31 | 392 | return kFALSE; |
393 | } | |
dabf5427 | 394 | |
395 | #ifndef R__BYTESWAP | |
396 | swap(buffer, totalDataWord); // swap needed for mac power pc | |
397 | #endif | |
33434f31 | 398 | |
399 | Bool_t ok = fPayload->Decode(buffer, totalDataWord/4); | |
ea59383d | 400 | |
dabf5427 | 401 | if ( IsErrorLogger()) AddErrorMessage(); |
ea59383d | 402 | |
33434f31 | 403 | delete[] buffer; |
404 | ||
405 | fDDL++; | |
406 | ||
407 | return ok; | |
408 | } | |
409 | ||
c0751163 | 410 | //______________________________________________________ |
411 | void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk) | |
412 | { | |
00e86732 | 413 | /// set regional card number |
313a427d | 414 | fPayload->SetMaxBlock(blk); |
c0751163 | 415 | } |
ea59383d | 416 | |
417 | //______________________________________________________ | |
418 | void AliMUONRawStreamTracker::AddErrorMessage() | |
419 | { | |
dabf5427 | 420 | /// add message into logger of AliRawReader per event |
ea59383d | 421 | |
dabf5427 | 422 | assert( GetReader() != 0 ); |
423 | TString msg = 0; | |
424 | Int_t occurance = 0; | |
425 | AliMUONLogger* log = fPayload->GetErrorLogger(); | |
426 | ||
427 | log->ResetItr(); | |
428 | while(log->Next(msg, occurance)) | |
429 | { | |
430 | if (msg.Contains("Parity")) | |
431 | GetReader()->AddMinorErrorLog(kParityErr, msg.Data()); | |
236f997c | 432 | |
dabf5427 | 433 | if (msg.Contains("Glitch")) |
434 | GetReader()->AddMajorErrorLog(kGlitchErr, msg.Data()); | |
ea59383d | 435 | |
dabf5427 | 436 | if (msg.Contains("Padding")) |
437 | GetReader()->AddMinorErrorLog(kPaddingWordErr, msg.Data()); | |
438 | } | |
439 | } | |
ea59383d | 440 | |
dabf5427 | 441 | //______________________________________________________ |
442 | Bool_t AliMUONRawStreamTracker::IsErrorMessage() const | |
443 | { | |
444 | /// true if there is any error/warning | |
445 | if (GetPayLoad()->GetParityErrors() || | |
446 | GetPayLoad()->GetGlitchErrors() || | |
447 | GetPayLoad()->GetPaddingErrors()) | |
448 | return kTRUE; | |
449 | ||
450 | return kFALSE; | |
451 | } | |
452 | ||
453 | ||
454 | ||
455 | ||
ea59383d | 456 |