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 uint16_t sSubSubEvtIdMsb = (subSubEventId >> 12) & 0xF;
106 if ((sSubSubEvtIdMsb != 0x7) && (sSubSubEvtIdMsb != 0x9)) {
109 if (totalSize == hubSize) {
118 if (totalSize != hubSize || !isLast) {
125 int lastWordsCounter = 0;
129 if (word == 0x600dda7a) {
133 if (lastWordsCounter >= 7) {
142 const uint32_t word = reader.
NextWord();
144 [[maybe_unused]]
const uint32_t ctsState = word & 0xffff;
146 const uint32_t nofInputs = (word >> 16) & 0xf;
147 const uint32_t nofTrigCh = (word >> 20) & 0x1f;
148 const uint32_t inclLastIdle = (word >> 25) & 0x1;
149 const uint32_t inclTrigInfo = (word >> 26) & 0x1;
150 const uint32_t inclTime = (word >> 27) & 0x1;
151 const uint32_t ETM = (word >> 28) & 0x3;
153 uint32_t ctsInfoSize = 2 * nofInputs + 2 * nofTrigCh + 2 * inclLastIdle + 3 * inclTrigInfo + inclTime;
156 case 1: ctsInfoSize += 1;
break;
157 case 2: ctsInfoSize += 4;
break;
160 for (uint32_t i = 0; i < ctsInfoSize; i++) {
163 const int nofTimeWords = subSubEventSize - ctsInfoSize - 1;
170 bool wasHeader =
false;
171 bool wasEpoch =
false;
172 bool wasTime =
false;
173 bool wasTrailer =
false;
179 std::vector<double> raisingTime(33, -1.);
183 for (
int i = 0; i < nofTimeWords; i++) {
191 if (0x8000 != (subSubEventId & 0xF000)) {
193 L_(debug) <<
"Unknown DiRICH ID 0x" << std::hex << subSubEventId << std::dec
194 <<
": Stopping processing of this subsubevent!!!";
198 for (
int i = 0; i < nofTimeWords; i++) {
208 if (nofTimeWords < 3) {
210 for (
int i = 0; i < nofTimeWords; i++) {
219 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
220 <<
": 1st message is not a TDC Header, skipping subsubevent";
223 for (
int i = 1; i < nofTimeWords; i++) {
235 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
236 <<
": 2nd message is not an epoch, skipping subsubevent";
241 for (
int i = 2; i < nofTimeWords; i++) {
252 for (
int i = 2; i < nofTimeWords - 1; i++) {
256 if (!wasHeader || !wasEpoch || wasTrailer) {
257 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
258 <<
": illegal position of TDC Time (before header/epoch or after trailer)";
263 for (; i < nofTimeWords - 1; i++) {
273 if (!wasHeader || wasTrailer) {
274 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
275 <<
": illegal position of TDC Epoch (before header or after trailer)";
278 for (; i < nofTimeWords - 1; i++) {
288 if (wasEpoch || wasTime || wasTrailer) {
289 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
290 <<
": illegal position of TDC Header (after time/epoch/trailer)";
293 for (; i < nofTimeWords - 1; i++) {
302 if (!wasEpoch || !wasTime || !wasHeader) {
303 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
304 <<
": illegal position of TDC Trailer (before time/epoch/header)";
307 for (; i < nofTimeWords - 1; i++) {
312 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec <<
": TDC Trailer too early, "
313 << (nofTimeWords - 1 - i) <<
" word(s) before last";
333 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec <<
": Last word not a TDC trailer";
338 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
339 <<
": Rescuing TimeData in subsubevent with missing Trailer leading to saved Digi";
343 L_(debug) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
344 <<
": Rescuing TimeData in subsubevent with missing Trailer w/o extra digi";
352 std::vector<double>& raisingTime,
MSContext& ctx)
const
357 bool madeDigi =
false;
360 const double subtrigOffset =
362 const double fullTimeCorr = dT - ctx.
mbsCorr + subtrigOffset;
370 raisingTime[td.
fChannel] = fullTimeCorr;
373 if (raisingTime[td.
fChannel] != -1.) {
375 const double ToT = fullTimeCorr - raisingTime[td.
fChannel];
377 if (fullTimeCorr >= 0.0) {
395 return ((
double) epoch) * 2048. * 5. + ((double) coarse) * 5. - ((
double) fine) * 0.005;
406 if (6e9 < finalTime)
return;
408 ctx.
digis.emplace_back(pixelUID, finalTime, tot - ToTcorr);
421 uint32_t tdcTimeDataMarker = (tdcWord >> 31) & 0x1;
422 uint32_t tdcMarker = (tdcWord >> 29) & 0x7;
424 if (tdcTimeDataMarker == 0x1) {
426 if (tdcMarker == 0x4 || tdcMarker == 0x5) {
444 return ((fpgaID << 16) | (ch & 0x00FF));
450 out.
fCoarse =
static_cast<uint32_t
>(tdcWord & 0x7ff);
451 out.
fIsRisingEdge =
static_cast<uint32_t
>((tdcWord >> 11) & 0x1);
452 out.
fFine =
static_cast<uint32_t
>((tdcWord >> 12) & 0x3ff);
453 out.
fChannel =
static_cast<uint32_t
>((tdcWord >> 22) & 0x7f);
461 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.