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