1 #ifndef ALIMUONTRIGGERDDLDECODER_H
2 #define ALIMUONTRIGGERDDLDECODER_H
88 template <
class EventHandler>
152 bool Decode(
const void* buffer, UInt_t bufferSize,
bool scalarEvent =
false);
189 void DecodeBuffer(
const UChar_t* start,
const UChar_t* end,
bool scalarEvent);
191 const UChar_t*
DecodeLocalStructs(
const UChar_t* start,
const UChar_t* end,
bool scalarEvent);
194 UInt_t key,
const UChar_t* start,
const UChar_t* end
211 template <
class EventHandler>
213 template <
class EventHandler>
215 template <
class EventHandler>
217 template <
class EventHandler>
219 template <
class EventHandler>
221 template <
class EventHandler>
223 template <
class EventHandler>
225 template <
class EventHandler>
229 template <
class EventHandler>
231 const void* buffer, UInt_t bufferSize,
bool scalarEvent
268 assert( buffer != NULL );
274 const UChar_t* start =
reinterpret_cast<const UChar_t*
>(buffer);
275 const UChar_t* end = start + bufferSize;
277 fHandler.OnNewBuffer(buffer, bufferSize);
278 DecodeBuffer(start, end, scalarEvent);
279 fHandler.OnEndOfBuffer(buffer, bufferSize);
280 return not fHadError;
284 template <
class EventHandler>
286 const UChar_t* start,
const UChar_t* end,
bool scalarEvent
304 const UChar_t* current = start;
307 const UInt_t* darcHeader =
reinterpret_cast<const UInt_t*
>(current);
308 current +=
sizeof(UInt_t);
309 if (current > end or current < start)
313 fHandler.OnError(EventHandler::kNoDarcHeader, darcHeader);
322 if (fAutoDetectScalars)
324 const UInt_t* expectedEndOfDarc =
reinterpret_cast<const UInt_t*
>(
333 if (reinterpret_cast<const UChar_t*>(expectedEndOfDarc+1) <= end and
334 reinterpret_cast<const UChar_t*
>(expectedEndOfDarc+1) > start and
335 EventHandler::GetDarcEventType(*darcHeader) != 0x1
336 and *expectedEndOfDarc == fgkEndOfDarc
349 UInt_t darkType = EventHandler::GetDarcType(*darcHeader);
350 if (darkType == fgkDarcVadorhType)
354 else if (darkType == fgkDarcDefaultType)
360 fNoRegionals = fMaxRegionals;
368 if (fNoRegionals > fMaxRegionals)
370 fHandler.OnError(EventHandler::kTooManyRegionals, darcHeader);
372 if (fExitOnError)
return;
375 fNoRegionals = fMaxRegionals;
380 bool darcShowsScalar = (EventHandler::GetDarcEventType(*darcHeader) != 0x1);
381 if (darcShowsScalar != scalarEvent)
385 fHandler.OnError(EventHandler::kWrongEventType, darcHeader);
387 if (fExitOnError)
return;
396 if (current > end or current < start)
400 if (current < start and fHadError)
return;
404 fHandler.OnError(EventHandler::kNoDarcScalars, darcScalars);
411 const UInt_t* endOfDarc =
reinterpret_cast<const UInt_t*
>(current);
412 current +=
sizeof(UInt_t);
413 if (current > end or current < start)
417 if (current < start and fHadError)
return;
421 fHandler.OnError(EventHandler::kNoEndOfDarc, endOfDarc);
425 if (*endOfDarc != fgkEndOfDarc)
429 fHandler.OnError(EventHandler::kBadEndOfDarc, endOfDarc);
431 if (fExitOnError)
return;
438 const UChar_t* keypos = FindKey(fgkEndOfDarc,
439 reinterpret_cast<const UChar_t*>(darcHeader),
445 current = keypos +
sizeof(UInt_t);
450 fHandler.OnDarcHeader(*darcHeader, darcScalars, current);
456 if (current > end or current < start)
460 if (current < start and fHadError)
return;
464 fHandler.OnError(EventHandler::kNoGlobalHeader, globalHeader);
475 if (current > end or current < start)
479 if (current < start and fHadError)
return;
483 fHandler.OnError(EventHandler::kNoGlobalScalars, globalScalars);
490 const UInt_t* endOfGlobal =
reinterpret_cast<const UInt_t*
>(current);
491 current +=
sizeof(UInt_t);
492 if (current > end or current < start)
496 if (current < start and fHadError)
return;
500 fHandler.OnError(EventHandler::kNoEndOfGlobal, endOfGlobal);
504 if (*endOfGlobal != fgkEndOfGlobal)
508 fHandler.OnError(EventHandler::kBadEndOfGlobal, endOfGlobal);
510 if (fExitOnError)
return;
517 const UChar_t* keypos = FindKey(fgkEndOfGlobal,
518 reinterpret_cast<const UChar_t*>(globalHeader),
524 current = keypos +
sizeof(UInt_t);
529 fHandler.OnGlobalHeader(globalHeader, globalScalars, current);
531 DecodeRegionalStructs(current, end, scalarEvent);
535 template <
class EventHandler>
537 const UChar_t* start,
const UChar_t* end,
bool scalarEvent
557 const UChar_t* current = start;
559 for (UInt_t iReg = 0; iReg < fNoRegionals; iReg++)
565 if (current > end or current < start)
569 if (current < start and fHadError)
return;
573 fHandler.OnError(EventHandler::kNoRegionalHeader, regionalHeader);
579 if (regionalHeader->
fDarcWord == fgkErrorWord)
584 current +=
sizeof(UInt_t);
590 current += fMaxLocals *
sizeof(UInt_t);
601 if (current > end or current < start)
605 if (current < start and fHadError)
return;
609 fHandler.OnError(EventHandler::kNoRegionalScalars, regionalScalars);
616 const UInt_t* endOfRegional =
reinterpret_cast<const UInt_t*
>(current);
617 current +=
sizeof(UInt_t);
618 if (current > end or current < start)
622 if (current < start and fHadError)
return;
626 fHandler.OnError(EventHandler::kNoEndOfRegional, endOfRegional);
630 if (*endOfRegional != fgkEndOfReg)
634 fHandler.OnError(EventHandler::kBadEndOfRegional, endOfRegional);
636 if (fExitOnError)
return;
643 const UChar_t* keypos = FindKey(fgkEndOfReg,
644 reinterpret_cast<const UChar_t*>(regionalHeader),
662 if (keypos != NULL and keypos != current + sizeOfRegional)
664 current = keypos +
sizeof(UInt_t);
673 const UChar_t* startOfLocals = current;
674 fHandler.OnNewRegionalStruct(regionalHeader, regionalScalars, startOfLocals);
675 fHandler.OnNewRegionalStructV2(iReg, regionalHeader, regionalScalars, startOfLocals);
676 current = DecodeLocalStructs(current, end, scalarEvent);
677 fHandler.OnEndOfRegionalStruct(regionalHeader, regionalScalars, startOfLocals);
678 fHandler.OnEndOfRegionalStructV2(iReg, regionalHeader, regionalScalars, startOfLocals);
684 fHandler.OnError(EventHandler::kBufferTooBig, current);
690 template <
class EventHandler>
692 const UChar_t* start,
const UChar_t* end,
bool scalarEvent
710 const UChar_t* current = start;
712 for (UInt_t iLocal = 0; iLocal < fMaxLocals; iLocal++)
718 if (current > end or current < start)
722 if (current < start and fHadError)
return end;
726 fHandler.OnError(EventHandler::kNoLocalStruct, localStruct);
732 if (localStruct->
fX2X1 == fgkDisableWord and
733 localStruct->
fX4X3 == fgkDisableWord and
734 localStruct->
fY2Y1 == fgkDisableWord and
735 localStruct->
fY4Y3 == fgkDisableWord and
742 current +=
sizeof(UInt_t);
752 if (current > end or current < start)
756 if (current < start and fHadError)
return end;
760 fHandler.OnError(EventHandler::kNoLocalScalars, localScalars);
767 const UInt_t* endOfLocal =
reinterpret_cast<const UInt_t*
>(current);
768 current +=
sizeof(UInt_t);
769 if (current > end or current < start)
773 if (current < start and fHadError)
return end;
779 fHandler.OnError(EventHandler::kNoEndOfLocal, endOfLocal);
780 if (not fExitOnError)
782 fHandler.OnLocalStruct(localStruct, localScalars);
787 if (*endOfLocal != fgkEndOfLocal)
791 fHandler.OnError(EventHandler::kBadEndOfLocal, endOfLocal);
793 if (fExitOnError)
return current;
800 const UChar_t* searchPos =
reinterpret_cast<const UChar_t*
>(localStruct);
801 const UChar_t* firstLocalKey = FindKey(fgkEndOfLocal, searchPos, end);
802 const UChar_t* firstRegionalKey = FindKey(fgkEndOfReg, searchPos, end);
812 if (firstLocalKey != NULL and firstRegionalKey != NULL)
814 if (firstLocalKey < firstRegionalKey)
820 if (firstLocalKey != current + sizeOflocalStruct)
821 current = firstLocalKey +
sizeof(UInt_t);
839 fHandler.OnLocalStruct(localStruct, localScalars);
840 fHandler.OnLocalStructV2(iLocal, localStruct, localScalars);
847 template <
class EventHandler>
849 UInt_t key,
const UChar_t* start,
const UChar_t* end
862 if (end +
sizeof(UInt_t) < start)
return NULL;
863 const UChar_t* current = start;
864 while (current +
sizeof(UInt_t) <= end)
866 UInt_t data = *
reinterpret_cast<const UInt_t*
>(current);
867 if (data == key)
return current;
873 #endif // ALIMUONTRIGGERDDLDECODER_H
The optional DARC board scalars.
bool fAutoDetectScalars
Flag to indicate if we should auto-detect if there are scalars in the data.
static const UInt_t fgkEndOfGlobal
Indicates the end of the global header just after the DARC header.
static UInt_t RegionalErrorWord()
Returns the regional error word.
void DecodeBuffer(const UChar_t *start, const UChar_t *end, bool scalarEvent)
UInt_t MaxRegionals() const
Returns the maximum regional structure count expected in the DDL payload.
Optional regional card scalars.
bool fHadError
Indicates if we had an error decoding the data.
A high performance decoder class for MUON trigger DDL data.
bool AutoDetectScalars() const
void TryRecover(bool value)
UInt_t fMaxRegionals
Maximum number of regional card structures allowed in a DDL stream.
void MaxRegionals(UInt_t n)
Sets the maximum regional structure count expected in the DDL payload.
static const UInt_t fgkEndOfLocal
Indicates the end of a local card structure.
Local card trigger information.
static const UInt_t fgkDisableWord
Word used to fill "empty" slots.
Local card trigger scalars.
bool fExitOnError
Indicates if we should exit on the very first error.
const EventHandler & GetHandler() const
Constant method to return the event handler instance.
static UInt_t DarcDefaultType()
Returns value of default DARC type.
UInt_t fY2Y1
16 bits Y2 position in 16 most significant bits and 16 bits of Y1 in least significant bits...
static UInt_t EndOfGlobalWord()
Returns the end of global header marker key.
UInt_t fMaxLocals
Maximum number of local card structures per regional structure allowed in a DDL stream.
static const UInt_t fgkEndOfReg
Indicates the end of a regional card structure.
UInt_t fY4Y3
16 bits Y4 position in 16 most significant bits and 16 bits of Y3 in least significant bits...
UInt_t fX2X1
16 bits X2 position in 16 most significant bits and 16 bits of X1 in least significant bits...
EventHandler & GetHandler()
Returns the event handler instance.
The optional global card scalars.
UInt_t fNoRegionals
The number of regional card structures actually decoded.
UInt_t fX4X3
16 bits X4 position in 16 most significant bits and 16 bits of X3 in least significant bits...
EventHandler fHandler
The event handler which deals with the generated parsing events.
UInt_t RegionalsDecoded() const
Returns the number of regional structures we actually attempted to decode.
Implementation of the high performance trigger DDL decoder event handler.
void ExitOnError(bool value)
static const UInt_t fgkDarcVadorhType
default type for DARC vadorh
static const UInt_t fgkDarcDefaultType
default type for DARC def.
static UInt_t EndOfLocalWord()
Returns the end of local structure marker key.
const UChar_t * DecodeLocalStructs(const UChar_t *start, const UChar_t *end, bool scalarEvent)
static UInt_t DarcVadorhType()
Returns value of Vadorh DARC type.
static const UInt_t fgkErrorWord
The error word when a regional board is missing.
void AutoDetectScalars(bool value)
static UInt_t EndOfDarcWord()
Returns the end of DARC marker key.
static UInt_t EndOfRegionalWord()
Returns the end of regional structure marker key.
void DecodeRegionalStructs(const UChar_t *start, const UChar_t *end, bool scalarEvent)
static const UInt_t fgkEndOfDarc
Indicates the end of the DARC header.
AliMUONTriggerDDLDecoder()
Default contructor.
static UInt_t LocalDisableWord()
Returns the local card disable word.
bool fTryRecover
Indicates if we should try recover from a corrupt structures.
bool Decode(const void *buffer, UInt_t bufferSize, bool scalarEvent=false)
This method decodes the DDL payload contained in the buffer.
const UChar_t * FindKey(UInt_t key, const UChar_t *start, const UChar_t *end)
UInt_t fTriggerBits
Trigger bits and deviation.