Line data Source code
1 : /**************************************************************************
2 : * This file is property of and copyright by the ALICE HLT Project *
3 : * All rights reserved. *
4 : * *
5 : * Primary Authors: *
6 : * Artur Szostak <artursz@iafrica.com> *
7 : * *
8 : * Permission to use, copy, modify and distribute this software and its *
9 : * documentation strictly for non-commercial purposes is hereby granted *
10 : * without fee, provided that the above copyright notice appears in all *
11 : * copies and that both the copyright notice and this permission notice *
12 : * appear in the supporting documentation. The authors make no claims *
13 : * about the suitability of this software for any purpose. It is *
14 : * provided "as is" without express or implied warranty. *
15 : **************************************************************************/
16 :
17 : /* $Id$ */
18 :
19 : /// \class AliMUONRawStreamTriggerHP
20 : ///
21 : /// Implementation of a streamer interface to the high performance trigger decoder.
22 : /// This is the raw stream class which interfaces between the high performance
23 : /// core decoder for MUON trigger chambers and the AliRawReader class.
24 : /// To gain the most out of the decoder, the Next() method should be used,
25 : /// for example:
26 : /// \code
27 : /// AliMUONRawStreamTriggerHP* rawStream; // assume initialised
28 : /// const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct;
29 : /// while ((localStruct = rawStream->Next()) != NULL)
30 : /// {
31 : /// // Do something with localStruct here.
32 : /// }
33 : /// \endcode
34 : ///
35 : /// This decoder tries to implement as similar an interface as possible to
36 : /// AliMUONRawStreamTrigger where possible. However certain constructs which
37 : /// would slow us down too much are avoided.
38 : ///
39 : /// \author Artur Szostak <artursz@iafrica.com>
40 :
41 : #include "AliMUONRawStreamTriggerHP.h"
42 : #include "AliMUONDarcHeader.h"
43 : #include "AliMUONRegHeader.h"
44 : #include "AliMUONLocalStruct.h"
45 : #include "AliMUONDDLTrigger.h"
46 : #include "AliRawReader.h"
47 : #include "AliLog.h"
48 : #include <cassert>
49 : #include <iostream>
50 : using std::cout;
51 : using std::endl;
52 : using std::hex;
53 : using std::dec;
54 :
55 : /// \cond CLASSIMP
56 18 : ClassImp(AliMUONRawStreamTriggerHP)
57 : /// \endcond
58 :
59 : const Int_t AliMUONRawStreamTriggerHP::fgkMaxDDL = 2;
60 : bool AliMUONRawStreamTriggerHP::AliLocalStruct::fgOverrideId = true;
61 :
62 : const AliMUONRegionalHeaderStruct
63 18 : AliMUONRawStreamTriggerHP::AliDecoderEventHandler::fgkEmptyHeader = {
64 18 : AliMUONTriggerDDLDecoder<AliDecoderEventHandler>::RegionalErrorWord(),
65 : 0,
66 9 : {0, 0},
67 9 : 0
68 : };
69 :
70 :
71 : AliMUONRawStreamTriggerHP::AliMUONRawStreamTriggerHP() :
72 9 : AliMUONVRawStreamTrigger(),
73 9 : fDecoder(),
74 9 : fDDL(0),
75 9 : fBufferSize(8192),
76 18 : fBuffer(new UChar_t[8192]),
77 9 : fkCurrentLocalStruct(NULL),
78 9 : fHadError(kFALSE),
79 9 : fDone(kFALSE),
80 9 : fDDLObject(NULL),
81 9 : fTotalNumberOfDarcEoWErrors(0),
82 9 : fTotalNumberOfGlobalEoWErrors(0),
83 9 : fTotalNumberOfRegEoWErrors(0),
84 9 : fTotalNumberOfLocalEoWErrors(0)
85 45 : {
86 : ///
87 : /// Default constructor.
88 : ///
89 :
90 9 : fDecoder.ExitOnError(false);
91 :
92 18 : fDecoder.GetHandler().SetMaxStructs(
93 9 : fDecoder.MaxRegionals(),
94 9 : fDecoder.MaxLocals()
95 : );
96 :
97 9 : fDecoder.GetHandler().SetRawStream(this);
98 18 : }
99 :
100 :
101 : AliMUONRawStreamTriggerHP::AliMUONRawStreamTriggerHP(AliRawReader* rawReader) :
102 0 : AliMUONVRawStreamTrigger(rawReader),
103 0 : fDecoder(),
104 0 : fDDL(0),
105 0 : fBufferSize(8192),
106 0 : fBuffer(new UChar_t[8192]),
107 0 : fkCurrentLocalStruct(NULL),
108 0 : fHadError(kFALSE),
109 0 : fDone(kFALSE),
110 0 : fDDLObject(NULL),
111 0 : fTotalNumberOfDarcEoWErrors(0),
112 0 : fTotalNumberOfGlobalEoWErrors(0),
113 0 : fTotalNumberOfRegEoWErrors(0),
114 0 : fTotalNumberOfLocalEoWErrors(0)
115 0 : {
116 : ///
117 : /// Constructor with AliRawReader as argument.
118 : ///
119 :
120 0 : fDecoder.ExitOnError(false);
121 :
122 0 : fDecoder.GetHandler().SetMaxStructs(
123 0 : fDecoder.MaxRegionals(),
124 0 : fDecoder.MaxLocals()
125 : );
126 :
127 0 : fDecoder.GetHandler().SetRawStream(this);
128 0 : }
129 :
130 :
131 : AliMUONRawStreamTriggerHP::~AliMUONRawStreamTriggerHP()
132 30 : {
133 : ///
134 : /// Default destructor which cleans up the memory allocated.
135 : ///
136 :
137 5 : if (fBuffer != NULL)
138 : {
139 10 : delete [] fBuffer;
140 : }
141 5 : if (fDDLObject != NULL)
142 : {
143 0 : delete fDDLObject;
144 : }
145 15 : }
146 :
147 :
148 : void AliMUONRawStreamTriggerHP::First()
149 : {
150 : /// Initialise or reset the iterator.
151 : /// The first DDL will be found and decoded.
152 :
153 0 : assert( GetReader() != NULL );
154 :
155 0 : fDDL = 0;
156 0 : fDone = kFALSE;
157 0 : NextDDL();
158 0 : fTotalNumberOfDarcEoWErrors = 0;
159 0 : fTotalNumberOfGlobalEoWErrors = 0;
160 0 : fTotalNumberOfRegEoWErrors = 0;
161 0 : fTotalNumberOfLocalEoWErrors = 0;
162 0 : }
163 :
164 :
165 : Bool_t AliMUONRawStreamTriggerHP::NextDDL()
166 : {
167 : /// Read in the next trigger DDL and decode the payload with the
168 : /// high performance decoder.
169 : /// \return kTRUE if the next DDL was successfully read and kFALSE
170 : /// otherwise.
171 :
172 24 : assert( GetReader() != NULL );
173 :
174 : // The temporary object if generated in GetDDLTracker, is now stale,
175 : // so delete it.
176 12 : if (fDDLObject != NULL)
177 : {
178 0 : delete fDDLObject;
179 0 : fDDLObject = NULL;
180 0 : }
181 :
182 12 : fkCurrentLocalStruct = NULL;
183 :
184 24 : while (fDDL < GetMaxDDL())
185 : {
186 8 : GetReader()->Reset();
187 8 : GetReader()->Select("MUONTRG", fDDL, fDDL); // Select the DDL file to be read.
188 8 : if (GetReader()->ReadHeader()) break;
189 0 : AliDebug(3, Form("Skipping DDL %d which does not seem to be there", fDDL+1));
190 0 : fDDL++;
191 : }
192 :
193 : // If we reach the end of the DDL list for this event then reset the
194 : // DDL counter, mark the iteration as done and exit.
195 12 : if (fDDL >= GetMaxDDL())
196 : {
197 4 : fDDL = 0;
198 4 : fDone = kTRUE;
199 4 : return kFALSE;
200 : }
201 : else
202 : {
203 8 : fDone = kFALSE;
204 : }
205 :
206 24 : AliDebug(3, Form("DDL Number %d\n", fDDL));
207 :
208 8 : Int_t dataSize = GetReader()->GetDataSize(); // in bytes
209 : // Check if we have enough buffer space already in fBuffer. If we do then
210 : // just continue reading otherwise we need to resize the buffer.
211 8 : if (fBufferSize < dataSize)
212 : {
213 0 : if (fBuffer != NULL)
214 : {
215 0 : delete [] fBuffer;
216 0 : fBuffer = NULL;
217 0 : fBufferSize = 0;
218 0 : }
219 : try
220 : {
221 0 : fBuffer = new UChar_t[dataSize];
222 0 : fBufferSize = dataSize;
223 0 : }
224 : catch (const std::bad_alloc&)
225 : {
226 0 : AliError("Could not allocate more buffer space. Cannot decode DDL.");
227 : return kFALSE;
228 0 : }
229 0 : }
230 :
231 8 : if (not GetReader()->ReadNext(fBuffer, dataSize))
232 : {
233 0 : return kFALSE;
234 : }
235 :
236 : #ifndef R__BYTESWAP
237 : Swap(reinterpret_cast<UInt_t*>(fBuffer), dataSize / sizeof(UInt_t)); // Swap needed for mac power pc.
238 : #endif
239 :
240 8 : fDDL++; // Remember to increment index to next DDL before the calls to
241 : // fDecoder.Decode since the callback methods of the decoder might
242 : // use AliMUONRawStreamTriggerHP::GetDDL()
243 :
244 : // Check if this is a scalar event.
245 8 : AliRawReader * reader = GetReader();
246 8 : if (!reader) return kFALSE;
247 :
248 8 : const AliRawDataHeader * cdh = reader->GetDataHeader();
249 8 : const AliRawDataHeaderV3 * cdh3 = reader->GetDataHeaderV3();
250 :
251 8 : if (!cdh && !cdh3) return kFALSE;
252 :
253 24 : bool scalerEvent = ((cdh ? cdh->GetL1TriggerMessage() : cdh3->GetL1TriggerMessage()) & 0x1) == 0x1;
254 :
255 : bool result = false;
256 : try
257 : {
258 : // Since we might allocate memory inside OnNewBuffer in the event
259 : // handler we need to trap any memory allocation exception to be robust.
260 16 : result = fDecoder.Decode(fBuffer, dataSize, scalerEvent);
261 8 : fHadError = (result == true ? kFALSE : kTRUE);
262 8 : fTotalNumberOfDarcEoWErrors += fDecoder.GetHandler().GetDarcEoWErrors();
263 8 : fTotalNumberOfGlobalEoWErrors += fDecoder.GetHandler().GetGlobalEoWErrors();
264 8 : fTotalNumberOfRegEoWErrors += fDecoder.GetHandler().GetRegEoWErrors();
265 8 : fTotalNumberOfLocalEoWErrors += fDecoder.GetHandler().GetLocalEoWErrors();
266 0 : }
267 : catch (const std::bad_alloc&)
268 : {
269 0 : AliError("Could not allocate more buffer space. Cannot decode DDL.");
270 : return kFALSE;
271 0 : }
272 :
273 : // Update the current local structure pointer.
274 8 : fkCurrentLocalStruct = fDecoder.GetHandler().FirstLocalStruct();
275 :
276 8 : return kTRUE;
277 12 : }
278 :
279 :
280 : Bool_t AliMUONRawStreamTriggerHP::IsDone() const
281 : {
282 : /// Indicates whether the iteration is finished or not.
283 : /// \return kTRUE if we already read all the digits and kFALSE if not.
284 :
285 0 : return fDone;
286 : }
287 :
288 :
289 : Bool_t AliMUONRawStreamTriggerHP::Next(
290 : UChar_t& id, UChar_t& dec, Bool_t& trigY,
291 : UChar_t& yPos, UChar_t& sXDev, UChar_t& xDev,
292 : UChar_t& xPos, Bool_t& triggerY, Bool_t& triggerX,
293 : TArrayS& xPattern, TArrayS& yPattern
294 : )
295 : {
296 : /// Advance one step in the iteration. Returns kFALSE if finished.
297 : /// If kTRUE is returned then the output parameters are filled with
298 : /// the values found in the next local trigger circuit structure.
299 :
300 0 : const AliLocalStruct* localStruct = Next();
301 0 : if (localStruct == NULL) return kFALSE;
302 :
303 0 : id = localStruct->GetId();
304 0 : dec = localStruct->GetDec();
305 0 : trigY = localStruct->GetTrigY();
306 0 : yPos = localStruct->GetYPos();
307 0 : sXDev = localStruct->GetSXDev();
308 0 : xDev = localStruct->GetXDev();
309 0 : xPos = localStruct->GetXPos();
310 :
311 0 : triggerX = localStruct->GetTriggerX();
312 0 : triggerY = localStruct->GetTriggerY();
313 :
314 0 : localStruct->GetXPattern(xPattern);
315 0 : localStruct->GetYPattern(yPattern);
316 :
317 0 : return kTRUE;
318 0 : }
319 :
320 :
321 : AliMUONDDLTrigger* AliMUONRawStreamTriggerHP::GetDDLTrigger() const
322 : {
323 : /// Construct and return a pointer to the DDL payload object.
324 : /// \return Pointer to internally constructed AliMUONDDLTrigger object.
325 : /// The object is owned by this class and should not be deleted
326 : /// by the caller.
327 : ///
328 : /// \note This method should not be used just to gain access to the DDL
329 : /// payload, unless there is a good reason to have the AliMUONDDLTrigger
330 : /// object. For example, if you want to modify the data and then save it
331 : /// to another DDL stream. Otherwise it can be an order of magnitude
332 : /// faster to access the DDL headers and data with the GetHeaders,
333 : /// GetRegionalHeader and GetLocalStruct methods for example.
334 : /// Refer to the MUONRawStreamTrigger.C macro to see how to use the fast
335 : /// decoder interface optimally.
336 :
337 0 : if (fDDLObject != NULL) return fDDLObject;
338 :
339 0 : fDDLObject = new AliMUONDDLTrigger;
340 :
341 : // Copy over all DARC, global headers and scalars.
342 0 : AliMUONDarcHeader* darcHeader = fDDLObject->GetDarcHeader();
343 0 : const AliHeader* hdr = GetHeaders();
344 0 : UInt_t word = hdr->GetDarcHeader();
345 0 : memcpy(darcHeader->GetHeader(), &word, sizeof(word));
346 0 : if (hdr->GetDarcScalars() != NULL)
347 : {
348 0 : memcpy(darcHeader->GetDarcScalers(), hdr->GetDarcScalars(), sizeof(AliMUONDarcScalarsStruct));
349 0 : }
350 0 : memcpy(darcHeader->GetGlobalInput(), hdr->GetGlobalHeader(), sizeof(AliMUONGlobalHeaderStruct));
351 0 : if (hdr->GetGlobalScalars() != NULL)
352 : {
353 0 : memcpy(darcHeader->GetGlobalScalers(), hdr->GetGlobalScalars(), sizeof(AliMUONGlobalScalarsStruct));
354 0 : }
355 :
356 0 : for (Int_t iReg = 0; iReg < (Int_t)GetRegionalHeaderCount(); iReg++)
357 : {
358 0 : AliMUONRegHeader regHeader;
359 0 : AliMUONLocalStruct localStruct;
360 :
361 0 : const AliRegionalHeader* rh = GetRegionalHeader(iReg);
362 : // Copy local structure and scalars and add everything into DDL object.
363 0 : memcpy(regHeader.GetHeader(), rh->GetHeader(), sizeof(AliMUONRegionalHeaderStruct));
364 0 : if (rh->GetScalars() != NULL)
365 : {
366 0 : memcpy(regHeader.GetScalers(), rh->GetScalars(), sizeof(AliMUONRegionalScalarsStruct));
367 0 : }
368 0 : fDDLObject->AddRegHeader(regHeader);
369 :
370 0 : const AliLocalStruct* lstruct = rh->GetFirstLocalStruct();
371 0 : while (lstruct != NULL)
372 : {
373 : // Copy local structure and scalars and add everything into DDL object.
374 0 : memcpy(localStruct.GetData(), lstruct->GetData(), sizeof(AliMUONLocalInfoStruct));
375 0 : if (lstruct->GetScalars() != NULL)
376 : {
377 0 : memcpy(localStruct.GetScalers(), lstruct->GetScalars(), sizeof(AliMUONLocalScalarsStruct));
378 0 : }
379 0 : if (AliMUONRawStreamTriggerHP::AliLocalStruct::GetOverrideIdFlag() == true)
380 : {
381 : // Since the override ID flag is set, we need to replace the
382 : // ID in the structure with the calculated one returned by GetId().
383 0 : AliMUONLocalInfoStruct* strptr = reinterpret_cast<AliMUONLocalInfoStruct*>( localStruct.GetData() );
384 0 : UInt_t triggerBits = strptr->fTriggerBits;
385 0 : triggerBits &= ~(0xF << 19);
386 0 : strptr->fTriggerBits = triggerBits | ((lstruct->GetId() & 0xF) << 19);
387 0 : }
388 0 : fDDLObject->AddLocStruct(localStruct, iReg);
389 0 : lstruct = lstruct->Next();
390 : }
391 0 : }
392 :
393 0 : return fDDLObject;
394 0 : }
395 :
396 :
397 : void AliMUONRawStreamTriggerHP::SetMaxReg(Int_t reg)
398 : {
399 : /// Set the maximum allowed number of regional cards in the DDL.
400 :
401 0 : fDecoder.MaxRegionals( (UInt_t) reg );
402 :
403 0 : fDecoder.GetHandler().SetMaxStructs(
404 0 : fDecoder.MaxRegionals(),
405 0 : fDecoder.MaxLocals()
406 : );
407 0 : }
408 :
409 :
410 : void AliMUONRawStreamTriggerHP::SetMaxLoc(Int_t loc)
411 : {
412 : /// Sets the maximum number of local cards in the DDL.
413 :
414 0 : fDecoder.MaxLocals( (UInt_t) loc );
415 :
416 0 : fDecoder.GetHandler().SetMaxStructs(
417 0 : fDecoder.MaxRegionals(),
418 0 : fDecoder.MaxLocals()
419 : );
420 0 : }
421 :
422 : ///////////////////////////////////////////////////////////////////////////////
423 :
424 : void AliMUONRawStreamTriggerHP::AliHeader::Print() const
425 : {
426 : /// Print DARC header, global header and global scalars to screen.
427 :
428 0 : cout << "===== DARC info =====" << endl;
429 0 : cout << "Header bits : 0x" << hex << fDarcHeader << dec << endl;
430 0 : if (fDarcScalars != NULL)
431 : {
432 0 : cout << "L0R : " << fDarcScalars->fL0R << " (0x"
433 0 : << hex << fDarcScalars->fL0R << dec << ")" << endl;
434 0 : cout << "L1P : " << fDarcScalars->fL1P << " (0x"
435 0 : << hex << fDarcScalars->fL1P << dec << ")" << endl;
436 0 : cout << "L1S : " << fDarcScalars->fL1S << " (0x"
437 0 : << hex << fDarcScalars->fL1S << dec << ")" << endl;
438 0 : cout << "L2A : " << fDarcScalars->fL2A << " (0x"
439 0 : << hex << fDarcScalars->fL2A << dec << ")" << endl;
440 0 : cout << "L2R : " << fDarcScalars->fL2R << " (0x"
441 0 : << hex << fDarcScalars->fL2R << dec << ")" << endl;
442 0 : cout << "Clock : " << fDarcScalars->fClk << " (0x"
443 0 : << hex << fDarcScalars->fClk << dec << ")" << endl;
444 0 : cout << "Hold : " << fDarcScalars->fHold << " (0x"
445 0 : << hex << fDarcScalars->fHold << dec << ")" << endl;
446 0 : cout << "Spare : " << fDarcScalars->fSpare << " (0x"
447 0 : << hex << fDarcScalars->fSpare << dec << ")" << endl;
448 0 : }
449 : else
450 : {
451 0 : cout << "Scalars == NULL" << endl;
452 : }
453 :
454 0 : cout << "===== Global info =====" << endl;
455 0 : for (int i = 0; i < 4; i++)
456 : {
457 0 : cout << "Input[" << i << "] : " << fGlobalHeader->fInput[i] << " (0x"
458 0 : << hex << fGlobalHeader->fInput[i] << dec << ")" << endl;
459 : }
460 0 : cout << "Output : " << fGlobalHeader->fOutput << " (0x"
461 0 : << hex << fGlobalHeader->fOutput << dec << ")" << endl;
462 0 : if (fGlobalScalars != NULL)
463 : {
464 0 : cout << "L0 : " << fGlobalScalars->fL0 << " (0x"
465 0 : << hex << fGlobalScalars->fL0 << dec << ")" << endl;
466 0 : cout << "Clock : " << fGlobalScalars->fClk << " (0x"
467 0 : << hex << fGlobalScalars->fClk << dec << ")" << endl;
468 0 : for (int j = 0; j < 4; j++)
469 : {
470 0 : cout << "Scaler[" << j << "] : " << fGlobalScalars->fScaler[j] << " (0x"
471 0 : << hex << fGlobalScalars->fScaler[j] << dec << ")" << endl;
472 : }
473 0 : cout << "Hold : " << fGlobalScalars->fHold << " (0x"
474 0 : << hex << fGlobalScalars->fHold << dec << ")" << endl;
475 0 : cout << "Spare : " << fGlobalScalars->fSpare << " (0x"
476 0 : << hex << fGlobalScalars->fSpare << dec << ")" << endl;
477 0 : }
478 : else
479 : {
480 0 : cout << "Scalars == NULL" << endl;
481 : }
482 0 : }
483 :
484 : void AliMUONRawStreamTriggerHP::AliRegionalHeader::Print() const
485 : {
486 : /// Print the regional header and scalars to screen.
487 :
488 0 : cout << "===== Regional card info =====" << endl;
489 0 : cout << "DarcWord : " << fHeader->fDarcWord << " (0x"
490 0 : << hex << fHeader->fDarcWord << dec << ")" << endl;
491 0 : cout << "Word : " << fHeader->fWord << " (0x"
492 0 : << hex << fHeader->fWord << dec << ")" << endl;
493 0 : cout << "Input[0] : " << fHeader->fInput[0] << " (0x"
494 0 : << hex << fHeader->fInput[0] << dec << ")" << endl;
495 0 : cout << "Input[1] : " << fHeader->fInput[1] << " (0x"
496 0 : << hex << fHeader->fInput[1] << dec << ")" << endl;
497 0 : cout << "L0/Mask : " << fHeader->fL0CountAndMask << " (0x"
498 0 : << hex << fHeader->fL0CountAndMask << dec << ")" << endl;
499 0 : if (fScalars != NULL)
500 : {
501 0 : cout << "Clock : " << fScalars->fClk << " (0x"
502 0 : << hex << fScalars->fClk << dec << ")" << endl;
503 0 : for (int i = 0; i < 8; i++)
504 : {
505 0 : cout << "Scaler[" << i << "] : " << fScalars->fScaler[i] << " (0x"
506 0 : << hex << fScalars->fScaler[i] << dec << ")" << endl;
507 : }
508 0 : cout << "Hold : " << fScalars->fHold << " (0x"
509 0 : << hex << fScalars->fHold << dec << ")" << endl;
510 0 : }
511 : else
512 : {
513 0 : cout << "Scalars == NULL" << endl;
514 : }
515 0 : }
516 :
517 : void AliMUONRawStreamTriggerHP::AliLocalStruct::Print() const
518 : {
519 : /// Print local trigger structure and scalars to screen.
520 :
521 0 : cout << "===== Local card info =====" << endl;
522 0 : cout << "X2X1 : " << fLocalStruct->fX2X1 << " (0x"
523 0 : << hex << fLocalStruct->fX2X1 << dec << ")" << endl;
524 0 : cout << "X4X3 : " << fLocalStruct->fX4X3 << " (0x"
525 0 : << hex << fLocalStruct->fX4X3 << dec << ")" << endl;
526 0 : cout << "Y2Y1 : " << fLocalStruct->fY2Y1 << " (0x"
527 0 : << hex << fLocalStruct->fY2Y1 << dec << ")" << endl;
528 0 : cout << "Y4Y3 : " << fLocalStruct->fY4Y3 << " (0x"
529 0 : << hex << fLocalStruct->fY4Y3 << dec << ")" << endl;
530 0 : cout << "Trigger bits : " << fLocalStruct->fTriggerBits << " (0x"
531 0 : << hex << fLocalStruct->fTriggerBits << dec << ")" << endl;
532 0 : if (fScalars != NULL)
533 : {
534 0 : cout << "L0 : " << fScalars->fL0 << " (0x"
535 0 : << hex << fScalars->fL0 << dec << ")" << endl;
536 0 : cout << "Hold : " << fScalars->fHold << " (0x"
537 0 : << hex << fScalars->fHold << dec << ")" << endl;
538 0 : cout << "Clock : " << fScalars->fClk << " (0x"
539 0 : << hex << fScalars->fClk << dec << ")" << endl;
540 0 : cout << "LPtNTrig : " << fScalars->fLPtNTrig << " (0x"
541 0 : << hex << fScalars->fLPtNTrig << dec << ")" << endl;
542 0 : cout << "HPtNTrig : " << fScalars->fHPtNTrig << " (0x"
543 0 : << hex << fScalars->fHPtNTrig << dec << ")" << endl;
544 0 : cout << "LPtRTrig : " << fScalars->fLPtRTrig << " (0x"
545 0 : << hex << fScalars->fLPtRTrig << dec << ")" << endl;
546 0 : cout << "HPtRTrig : " << fScalars->fHPtRTrig << " (0x"
547 0 : << hex << fScalars->fHPtRTrig << dec << ")" << endl;
548 0 : cout << "LPtLTrig : " << fScalars->fLPtLTrig << " (0x"
549 0 : << hex << fScalars->fLPtLTrig << dec << ")" << endl;
550 0 : cout << "HPtLTrig : " << fScalars->fHPtLTrig << " (0x"
551 0 : << hex << fScalars->fHPtLTrig << dec << ")" << endl;
552 0 : cout << "LPtSTrig : " << fScalars->fLPtSTrig << " (0x"
553 0 : << hex << fScalars->fLPtSTrig << dec << ")" << endl;
554 0 : cout << "HPtSTrig : " << fScalars->fHPtSTrig << " (0x"
555 0 : << hex << fScalars->fHPtSTrig << dec << ")" << endl;
556 0 : for (int i = 0; i < 8*4; i++)
557 : {
558 0 : cout << "Scaler[" << i << "] : " << fScalars->fScaler[i] << " (0x"
559 0 : << hex << fScalars->fScaler[i] << dec << ")" << endl;
560 : }
561 0 : cout << "EOS : " << fScalars->fEOS << " (0x"
562 0 : << hex << fScalars->fEOS << dec << ")" << endl;
563 0 : cout << "Reset : " << fScalars->fReset << " (0x"
564 0 : << hex << fScalars->fReset << dec << ")" << endl;
565 0 : }
566 : else
567 : {
568 0 : cout << "Scalars == NULL" << endl;
569 : }
570 0 : }
571 :
572 : ///////////////////////////////////////////////////////////////////////////////
573 :
574 9 : AliMUONRawStreamTriggerHP::AliDecoderEventHandler::AliDecoderEventHandler() :
575 9 : fRawStream(NULL),
576 9 : fBufferStart(NULL),
577 9 : fDarcHeader(0),
578 9 : fDarcScalars(NULL),
579 9 : fHeaders(),
580 9 : fRegionalsCount(0),
581 9 : fRegionals(NULL),
582 9 : fLocals(NULL),
583 9 : fEndOfLocals(NULL),
584 9 : fCurrentRegional(NULL),
585 9 : fCurrentLocal(NULL),
586 9 : fDarcEoWErrors(0),
587 9 : fGlobalEoWErrors(0),
588 9 : fRegEoWErrors(0),
589 9 : fLocalEoWErrors(0),
590 9 : fWarnings(kTRUE)
591 45 : {
592 : /// Default constructor
593 18 : }
594 :
595 :
596 : AliMUONRawStreamTriggerHP::AliDecoderEventHandler::~AliDecoderEventHandler()
597 20 : {
598 : /// Default destructor cleans up the allocated memory.
599 :
600 60 : if (fRegionals != NULL) delete [] fRegionals;
601 660 : if (fLocals != NULL) delete [] fLocals;
602 10 : }
603 :
604 :
605 : void AliMUONRawStreamTriggerHP::AliDecoderEventHandler::SetMaxStructs(
606 : UInt_t maxRegionals, UInt_t maxLocals
607 : )
608 : {
609 : /// Sets the maximum number of structures allowed.
610 :
611 : // Start by clearing the current arrays.
612 18 : if (fRegionals != NULL)
613 : {
614 0 : delete [] fRegionals;
615 0 : fRegionals = NULL;
616 0 : }
617 9 : if (fLocals != NULL)
618 : {
619 0 : delete [] fLocals;
620 0 : fLocals = NULL;
621 0 : fEndOfLocals = NULL;
622 0 : }
623 9 : fCurrentRegional = NULL;
624 9 : fCurrentLocal = NULL;
625 :
626 : // Allocate new memory.
627 171 : fRegionals = new AliRegionalHeader[maxRegionals];
628 2331 : fLocals = new AliLocalStruct[maxRegionals*maxLocals];
629 9 : fEndOfLocals = fLocals;
630 :
631 9 : fRegionalsCount = maxRegionals;
632 9 : }
633 :
634 :
635 : void AliMUONRawStreamTriggerHP::AliDecoderEventHandler::OnNewBuffer(
636 : const void* buffer, UInt_t /*bufferSize*/
637 : )
638 : {
639 : /// This is called by the high performance decoder when a new DDL payload
640 : /// is about to be decoded.
641 :
642 16 : assert( fRawStream != NULL );
643 :
644 : // remember the start of the buffer to be used in OnError.
645 8 : fBufferStart = buffer;
646 :
647 : // Reset error counters.
648 8 : fDarcEoWErrors = 0;
649 8 : fGlobalEoWErrors = 0;
650 8 : fRegEoWErrors = 0;
651 8 : fLocalEoWErrors = 0;
652 :
653 : // Reset the current local structure pointer which will be used to track
654 : // where we need to fill fLocals. We have to subtract one space because we
655 : // will increment the pointer the first time in the OnLocalStruct method.
656 8 : fCurrentLocal = fLocals-1;
657 :
658 8 : fCurrentRegional = NULL;
659 :
660 : // Reset and link up all the regional structures together.
661 128 : for (UInt_t i = 0; i+1 < fRegionalsCount; i++)
662 : {
663 56 : fRegionals[i] = AliRegionalHeader(fLocals, &fgkEmptyHeader, NULL);
664 56 : fRegionals[i].SetNext(&fRegionals[i+1]);
665 : }
666 : // Reset the last structure.
667 8 : fRegionals[fRegionalsCount-1] = AliRegionalHeader(fLocals, &fgkEmptyHeader, NULL);
668 8 : }
669 :
670 :
671 : void AliMUONRawStreamTriggerHP::AliDecoderEventHandler::OnError(
672 : ErrorCode error, const void* location
673 : )
674 : {
675 : /// This is called by the high performance decoder when a error occurs
676 : /// when trying to decode the DDL payload. This indicates corruption in
677 : /// the data. This method converts the error code to a descriptive message
678 : /// and logs this with the raw reader.
679 : /// \param error The error code indicating the problem.
680 : /// \param location A pointer to the location within the DDL payload buffer
681 : /// being decoded where the problem with the data was found.
682 :
683 0 : assert( fRawStream != NULL );
684 0 : assert( fRawStream->GetReader() != NULL );
685 :
686 : Char_t* message = NULL;
687 : //UInt_t word = 0;
688 :
689 0 : switch (error)
690 : {
691 : case kWrongEventType:
692 0 : message = Form("Wrong event type obtained from the Darc header, take the one of CDH");
693 0 : break;
694 :
695 : case kBadEndOfDarc:
696 0 : fDarcEoWErrors++;
697 0 : message = Form(
698 : "Wrong end of Darc word %x instead of %x\n",
699 0 : *reinterpret_cast<const UInt_t*>(location),
700 0 : AliMUONTriggerDDLDecoder<AliMUONTriggerDDLDecoderEventHandler>::EndOfDarcWord()
701 : );
702 0 : fRawStream->GetReader()->AddMajorErrorLog(kDarcEoWErr, message);
703 0 : break;
704 :
705 : case kBadEndOfGlobal:
706 0 : fGlobalEoWErrors++;
707 0 : message = Form(
708 : "Wrong end of Global word %x instead of %x\n",
709 0 : *reinterpret_cast<const UInt_t*>(location),
710 0 : AliMUONTriggerDDLDecoder<AliMUONTriggerDDLDecoderEventHandler>::EndOfGlobalWord()
711 : );
712 0 : fRawStream->GetReader()->AddMajorErrorLog(kGlobalEoWErr, message);
713 0 : break;
714 :
715 : case kBadEndOfRegional:
716 0 : fRegEoWErrors++;
717 0 : message = Form(
718 : "Wrong end of Regional word %x instead of %x\n",
719 0 : *reinterpret_cast<const UInt_t*>(location),
720 0 : AliMUONTriggerDDLDecoder<AliMUONTriggerDDLDecoderEventHandler>::EndOfRegionalWord()
721 : );
722 0 : fRawStream->GetReader()->AddMajorErrorLog(kRegEoWErr, message);
723 0 : break;
724 :
725 : case kBadEndOfLocal:
726 0 : fLocalEoWErrors++;
727 0 : message = Form(
728 : "Wrong end of Local word %x instead of %x\n",
729 0 : *reinterpret_cast<const UInt_t*>(location),
730 0 : AliMUONTriggerDDLDecoder<AliMUONTriggerDDLDecoderEventHandler>::EndOfLocalWord()
731 : );
732 0 : fRawStream->GetReader()->AddMajorErrorLog(kLocalEoWErr, message);
733 0 : break;
734 :
735 : default:
736 0 : message = Form(
737 : "%s (At byte %lu in DDL.)",
738 0 : ErrorCodeToMessage(error),
739 0 : (unsigned long)location - (unsigned long)fBufferStart + sizeof(AliRawDataHeaderV3)
740 : );
741 0 : fRawStream->GetReader()->AddMajorErrorLog(error, message);
742 0 : break;
743 : }
744 :
745 0 : if (fWarnings)
746 : {
747 0 : AliWarningGeneral(
748 : "AliMUONRawStreamTriggerHP::AliDecoderEventHandler",
749 : message
750 : );
751 0 : }
752 0 : }
753 :
|