18 const uint64_t tTimeslice)
const
24 ctx.
digis.reserve(msDescr.size /
sizeof(
u32));
27 reader.
SetData(msContent, msDescr.size);
29 const auto mstime = msDescr.idx;
30 ctx.
refTime = mstime - tTimeslice;
34 if (reader.
GetSize() <= 8)
return {};
45 [[maybe_unused]] uint32_t msIndexWord1 = reader.
NextWord();
46 [[maybe_unused]] uint32_t msIndexWord2 = reader.
NextWord();
55 const uint32_t word_MSB = reader.
NextWord();
56 const uint32_t word_LSB = reader.
NextWord();
61 for (
auto l = 0; l < 10; ++l) {
66 for (
auto l = 0; l < 14; ++l) {
67 const uint32_t wordEpoch = reader.
NextWord();
69 const uint32_t wordTime = reader.
NextWord();
78 [[maybe_unused]]
const uint32_t trbNum = reader.
NextWord();
87 [[maybe_unused]]
const uint32_t hubId = word & 0xffff;
88 const uint32_t hubSize = (word >> 16) & 0xffff;
94 uint32_t subSubEventId = 0, subSubEventSize = 0;
97 while (totalSize < hubSize) {
99 subSubEventId = word & 0xffff;
100 subSubEventSize = (word >> 16) & 0xffff;
102 totalSize += (1 + subSubEventSize);
105 if (((subSubEventId >> 12) & 0xF) != 0x7) {
108 if (totalSize == hubSize) {
117 if (totalSize != hubSize || !isLast) {
124 int lastWordsCounter = 0;
128 if (word == 0x600dda7a) {
132 if (lastWordsCounter >= 7) {
141 const uint32_t word = reader.
NextWord();
143 [[maybe_unused]]
const uint32_t ctsState = word & 0xffff;
145 const uint32_t nofInputs = (word >> 16) & 0xf;
146 const uint32_t nofTrigCh = (word >> 20) & 0x1f;
147 const uint32_t inclLastIdle = (word >> 25) & 0x1;
148 const uint32_t inclTrigInfo = (word >> 26) & 0x1;
149 const uint32_t inclTime = (word >> 27) & 0x1;
150 const uint32_t ETM = (word >> 28) & 0x3;
152 uint32_t ctsInfoSize = 2 * nofInputs + 2 * nofTrigCh + 2 * inclLastIdle + 3 * inclTrigInfo + inclTime;
155 case 1: ctsInfoSize += 1;
break;
156 case 2: ctsInfoSize += 4;
break;
159 for (uint32_t i = 0; i < ctsInfoSize; i++) {
162 const int nofTimeWords = subSubEventSize - ctsInfoSize - 1;
169 bool wasHeader =
false;
170 bool wasEpoch =
false;
171 bool wasTime =
false;
172 bool wasTrailer =
false;
178 std::vector<double> raisingTime(33, -1.);
182 for (
int i = 0; i < nofTimeWords; i++) {
190 if (0x8000 != (subSubEventId & 0xF000)) {
192 L_(debug) <<
"Unknown DiRICH ID 0x" << std::hex << subSubEventId << std::dec
193 <<
": Stopping processing of this subsubevent!!!";
197 for (
int i = 0; i < nofTimeWords; i++) {
207 if (nofTimeWords < 3) {
209 for (
int i = 0; i < nofTimeWords; i++) {
218 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
219 <<
": 1st message is not a TDC Header, skipping subsubevent";
222 for (
int i = 1; i < nofTimeWords; i++) {
234 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
235 <<
": 2nd message is not an epoch, skipping subsubevent";
240 for (
int i = 2; i < nofTimeWords; i++) {
251 for (
int i = 2; i < nofTimeWords - 1; i++) {
255 if (!wasHeader || !wasEpoch || wasTrailer) {
256 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
257 <<
": illegal position of TDC Time (before header/epoch or after trailer)";
262 for (; i < nofTimeWords - 1; i++) {
272 if (!wasHeader || wasTrailer) {
273 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
274 <<
": illegal position of TDC Epoch (before header or after trailer)";
277 for (; i < nofTimeWords - 1; i++) {
287 if (wasEpoch || wasTime || wasTrailer) {
288 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
289 <<
": illegal position of TDC Header (after time/epoch/trailer)";
292 for (; i < nofTimeWords - 1; i++) {
301 if (!wasEpoch || !wasTime || !wasHeader) {
302 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
303 <<
": illegal position of TDC Trailer (before time/epoch/header)";
306 for (; i < nofTimeWords - 1; i++) {
311 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec <<
": TDC Trailer too early, "
312 << (nofTimeWords - 1 - i) <<
" word(s) before last";
332 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec <<
": Last word not a TDC trailer";
337 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
338 <<
": Rescuing TimeData in subsubevent with missing Trailer leading to saved Digi";
342 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
343 <<
": Rescuing TimeData in subsubevent with missing Trailer w/o extra digi";
351 std::vector<double>& raisingTime,
MSContext& ctx)
const
356 bool madeDigi =
false;
359 const double subtrigOffset =
361 const double fullTimeCorr = dT - ctx.
mbsCorr + subtrigOffset;
369 raisingTime[td.
fChannel] = fullTimeCorr;
372 if (raisingTime[td.
fChannel] != -1.) {
374 const double ToT = fullTimeCorr - raisingTime[td.
fChannel];
376 if (fullTimeCorr >= 0.0) {
394 return ((
double) epoch) * 2048. * 5. + ((double) coarse) * 5. - ((
double) fine) * 0.005;
405 if (6e9 < finalTime)
return;
407 ctx.
digis.emplace_back(pixelUID, finalTime, tot - ToTcorr);
420 uint32_t tdcTimeDataMarker = (tdcWord >> 31) & 0x1;
421 uint32_t tdcMarker = (tdcWord >> 29) & 0x7;
423 if (tdcTimeDataMarker == 0x1) {
425 if (tdcMarker == 0x4 || tdcMarker == 0x5) {
443 return ((fpgaID << 16) | (ch & 0x00FF));
449 out.
fCoarse =
static_cast<uint32_t
>(tdcWord & 0x7ff);
450 out.
fIsRisingEdge =
static_cast<uint32_t
>((tdcWord >> 11) & 0x1);
451 out.
fFine =
static_cast<uint32_t
>((tdcWord >> 12) & 0x3ff);
452 out.
fChannel =
static_cast<uint32_t
>((tdcWord >> 22) & 0x7f);
460 return static_cast<uint16_t
>(tdcWord & 0xff);
std::tuple< std::vector< Digi_t >, Monitor_t, Aux_t > Result_t
void SetData(const uint8_t *data, size_t size)
bool IsLastSubSubEvent(uint32_t subSubEventSize)
double CalculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine) const
bool CheckMaskedDiRICH(int32_t subSubEventId) const
UnpackPar fParams
Parameter container.
uint32_t ProcessEpoch(uint32_t tdcWord) const
UnpackMS(const UnpackPar &pars)
Construct from parameters.
std::vector< int32_t > fMaskedDiRICHes
void ProcessTrbPacket(MicrosliceReader &reader, MSContext &ctx) const
void WriteOutputDigi(int32_t fpgaID, int32_t channel, double time, double tot, MSContext &ctx) const
TdcWordType GetTdcWordType(uint32_t tdcWord) const
int ProcessCtsHeader(MicrosliceReader &reader, uint32_t subSubEventSize, uint32_t subSubEventId) const
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
~UnpackMS() override
Destructor.
void ProcessSubSubEvent(MicrosliceReader &reader, int nofTimeWords, uint32_t subSubEventId, MSContext &ctx) const
int32_t GetPixelUID(int32_t fpgaID, int32_t ch) const
TdcTimeData ProcessTimeData(uint32_t tdcWord) const
void ProcessHubBlock(MicrosliceReader &reader, MSContext &ctx) const
bool ProcessTimeDataWord(uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector< double > &raisingTime, MSContext &ctx) const
uint16_t ProcessTrailer(uint32_t tdcWord) const
uint16_t ProcessHeader(uint32_t tdcWord) const
uint16_t currentSubSubEvent
UnpackMonitorData monitor
double prevLastCh0ReTime[13]
std::vector< CbmRichDigi > digis
uint32_t fNumErrWildHeaderMessage
TDC header in invalid position.
uint32_t fNumErrInvalidSecondMessage
Second message is not EPOCH.
uint32_t fNumErrWildEpoch
TDC epoch in invalid position.
uint32_t fNumErrInvalidHubSize
Premature end of hub block.
uint32_t fNumErrTdcErrorWord
TDC word of error type.
uint32_t fNumErrChannelOutOfBounds
TDC channel out of bounds.
uint32_t fNumErrOrphanRecovTimeData
TimeData in last position (not TRAILER) but not creating a Digi.
uint32_t fNumErrExcessLastWords
More than expected trailing words.
uint32_t fNumCtsAndUnmappedDirich
Dirich address is unknown (or is of a CTS)
uint32_t fNumErrInvalidLastMessage
Last message is not TRAILER.
uint32_t fNumSkippedSubsubevent
Whenever subsubevent skipped due to error (but not mask)
uint32_t fNumErrInvalidFirstMessage
First message is not HEADER.
uint32_t fNumErrInvalidHubId
"SubSubEvent" has invalid ID
uint32_t fNumErrWildTdcTime
TDC time (digi) in invalid position.
uint32_t fNumDebugMessage
Received debug messages.
uint32_t fNumWarnRecoveredLastDigi
TimeData in last position (not TRAILER) led to recovered Digi.
uint32_t fNumErrWildTrailerMessage
TDC trailer in invalid position.
Parameters required for the RICH unpacking (specific to one component)
std::map< uint32_t, UnpackElinkPar > fElinkParams
Map TRB address to elink params.