19 template<u
int8_t sys_ver>
22 auto flag = (frame >> 15) & 0x3;
33 template<u
int8_t sys_ver>
45 template<u
int8_t sys_ver>
48 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::CrcValid)) {
51 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::OverflowFlim)) {
54 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::OverflowUser)) {
57 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::DataError)) {
66 template<u
int8_t sys_ver>
70 assert(*nadcbits >= 9);
82 int16_t sample = 0x07f;
85 sample &= (*adcbuffer >> (*nadcbits + 2));
96 template<u
int8_t sys_ver>
100 assert(*nadcbits >= 9);
106 int16_t temp = 0x1ff;
107 temp &= (*adcbuffer >> (*nadcbits));
112 int16_t sample = (temp & 0x0100) ? (temp | 0xff00) : temp;
120 template<u
int8_t sys_ver>
124 size_t mask = 0x000FFFFF;
132 if (((frame & mask) >> 18) == 3)
136 if (((frame & mask) >> 17) == 2)
140 if (((frame & mask) >> 17) == 3)
145 if (((frame & mask) >> 17) == 4)
149 if (((frame & mask) >> 17) == 5)
155 L_(error) <<
"UnpackMS::GetInfoType] unknown type!";
163 template<u
int8_t sys_ver>
166 uint32_t checkframe = frame;
167 checkframe &= 0xffffff;
168 if ((checkframe >> 21) == 1)
172 else if ((checkframe >> 22) == 1)
176 else if ((checkframe >> 20) == 1)
180 else if ((checkframe >> 22) == 3)
184 else if (0 < (checkframe >> 18) && (checkframe >> 18) <= 3) {
187 else if (checkframe == 0)
200 template<u
int8_t sys_ver>
203 if ((frame & 0xf) > 0)
208 for (uint iepoch = 0; iepoch < 3; ++iepoch) {
209 tsmsb[iepoch] =
static_cast<uint8_t
>((frame >> (4 + 6 * iepoch) & 0x3f));
214 if (tsmsb[0] == tsmsb[1] || tsmsb[0] == tsmsb[2])
return tsmsb[0];
218 if (tsmsb[1] == tsmsb[2])
return tsmsb[1];
229 template<u
int8_t sys_ver>
244 int32_t errClass = 0;
249 const uint32_t asicAddress = elinkPar.
fAddress;
255 uint64_t time = (fw.timestamp - fw.prec_time) *
fAsicClockCycle + fMsStartTimeRel;
256 if (time <
static_cast<uint64_t
>(std::abs(elinkPar.
fTimeOffset))) {
264 auto energy = fw.maxAdc *
fParams.fMaxAdcToEnergyCal;
267 int32_t uniqueModuleId = asicAddress / 1000;
278 template<u
int8_t sys_ver>
286 int32_t errClass = 0;
291 const uint32_t asicAddress = elinkPar.
fAddress;
301 if (time <
static_cast<uint64_t
>(std::abs(elinkPar.
fTimeOffset))) {
314 if (time < currentTimeshift) {
319 time = time - currentTimeshift;
328 auto energy = maxadc *
fParams.fMaxAdcToEnergyCal;
331 int32_t uniqueModuleId = asicAddress / 1000;
345 template<u
int8_t sys_ver>
347 uint16_t elinkId, uint8_t istream,
MsContext& ctx)
const
349 auto chId =
static_cast<uint8_t
>(((frame >> 17) & 0xf));
350 auto timestamp =
static_cast<uint8_t
>((frame >> 9) & 0xff);
351 bool multihit = ((frame >> 8) & 0x1);
352 auto hitType =
static_cast<uint8_t
>((frame >> 6) & 0x3);
353 uint8_t nsamples = 0;
355 std::vector<int16_t> samples = std::vector<int16_t>(0);
360 return CbmTrdRawMessageSpadic(chId, elinkId, crobId, criId, hitType, nsamples, multihit, fulltime, samples);
364 uint16_t elinkId, uint8_t istream, MsContext& ctx)
const;
368 template<u
int8_t sys_ver>
387 template<u
int8_t sys_ver>
398 auto nsamples = samples->size();
400 auto itend = std::next(samples->begin(), peakingBinMax);
403 auto itmax = std::max_element(itbegin, itend);
406 float_t charge =
static_cast<float_t
>(*itmax) -
GetBaseline(samples);
411 return charge > 0 ? charge : 0;
417 template<u
int8_t sys_ver>
423 return samples->at(0);
425 float_t baseline = 0.0;
427 if (itend > samples->end()) itend = samples->end();
428 for (
auto isample = samples->begin(); isample < itend; isample++) {
429 baseline += *isample;
439 template<u
int8_t sys_ver>
441 const fles::MicrosliceDescriptor& msDescr,
442 const uint64_t tTimeslice)
const
450 size_t fMsStartTimeRel = (msDescr.idx - tTimeslice);
455 auto mssize = msDescr.size;
456 uint32_t nwords = mssize / bytes;
460 for (uint32_t iword = 0; iword < nwords; ++iword) {
464 std::get<0>(result).push_back(
makeDigi(fw, fMsStartTimeRel, std::get<1>(result)));
471 const fles::MicrosliceDescriptor& msDescr,
472 const uint64_t tTimeslice)
const;
478 const fles::MicrosliceDescriptor& msDescr,
479 const uint64_t tTimeslice)
const
491 int8_t currTsMsb = 0;
498 auto mssize = msDescr.size;
502 auto criId = msDescr.eq_id;
511 const auto mscontent =
reinterpret_cast<const size_t*
>(msContent);
513 std::get<0>(result).reserve(nwords);
518 for (uint32_t iword = 0; iword < nwords; ++iword) {
520 size_t word =
static_cast<size_t>(mscontent[iword]);
523 uint32_t frame = (word >> (32 * istream)) & 0xffffffff;
530 auto elinkId = (frame >> 24) & 0x3f;
534 auto tsmsb =
getTsMsb(frame, std::get<1>(result));
535 if (((tsmsb - currTsMsb) & 0x3f) == 1 || currTsMsb == -1) ctx.
fNrTsMsbVec.at(istream)++;
537 std::get<1>(result).fNumEpochMsgs++;
549 size_t nadcbitstotal = 6;
551 size_t adcbuffer = frame & 0x3f;
557 word =
static_cast<size_t>(mscontent[iword]);
558 frame = (word >> (32 * istream)) & 0xffffffff;
566 elinkId = (frame >> 24) & 0x3f;
568 std::get<1>(result).fNumElinkMis++;
573 adcbuffer |=
static_cast<size_t>((frame & 0x3fffff));
578 while (nadcbits >= 9) {
581 if (isample == 0 &&
fParams.fUseBaselineAvg)
588 word =
static_cast<size_t>(mscontent[iword]);
589 frame = (word >> (32 * istream)) & 0xffffffff;
594 elinkId = (frame >> 24) & 0x3f;
596 std::get<1>(result).fNumElinkMis++;
600 uint8_t nsamplesindicator = (frame >> 18) & 0x3;
602 uint64_t nreqsamples = (nadcbitstotal + 18) / 9;
603 uint8_t nn = nreqsamples % 4;
604 for (uint8_t itest = 0; itest < 3; itest++) {
605 if (nn == nsamplesindicator || nreqsamples == 0)
break;
607 nn = nreqsamples % 4;
612 if (nreqsamples >= isample) {
614 int8_t nrequiredbits = (nreqsamples - isample) * 9 - nadcbits;
615 adcbuffer <<= nrequiredbits;
618 adcbuffer |=
static_cast<size_t>((frame & 0x3ffff) >> (18 - nrequiredbits));
619 nadcbits += nrequiredbits;
621 while (nadcbits >= 9) {
628 std::get<1>(result).fNumCorruptEom++;
630 std::get<1>(result).fNumCreatedRawMsgs++;
635 if (isample > 0) std::get<0>(result).push_back(
makeDigi(raw, ctx, std::get<1>(result)));
640 std::get<1>(result).fNumMissingEom++;
645 std::get<1>(result).fNumWildRda++;
649 std::get<1>(result).fNumWildEom++;
653 std::get<1>(result).fNumCreatedInfoMsgs++;
660 std::get<1>(result).fNumWildNul++;
665 std::get<1>(result).fNumUnknownWords++;
void SetTriggerType(const eTriggerType triggerType)
Set digi trigger type.
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
void SetSample(int16_t value, uint8_t pos)
void IncNrSamples()
increase the number of samples stored in this raw message by one
uint8_t GetHitType() const
uint8_t GetCrobId() const
uint64_t GetFullTime() const
const std::vector< int16_t > * GetSamples() const
uint8_t GetElinkId() const
uint8_t GetChannelId() const
std::tuple< std::vector< Digi_t >, Monitor_t, Aux_t > Result_t
CbmTrdRawMessageSpadic makeRaw(const uint32_t frame, uint16_t criId, uint8_t crobId, uint16_t elinkId, uint8_t istream, MsContext &ctx) const
Create a CbmTrdRawMessageSpadic from the hit message input.
CbmTrdDigi makeDigi(CbmTrdRawMessageSpadic raw, MsContext &ctx, UnpackMonitorData &monitor) const
Create an actual digi from the raw message.
Spadic::MsInfoType getInfoType(const uint32_t frame) const
Identify the InfoType of a 64bit InfoMessage word inside a Microslice.
static constexpr uint8_t fStreamsPerWord
Number of streams per word.
static constexpr size_t fTsMsbLengthCC
length of one ts_msb in [cc]
float_t GetBaseline(const std::vector< int16_t > *samples) const
Get the Baseline value The digi charge is an unsigned. Hence, we need to get the baseline to 0.
Spadic::MsInfoType digestBufInfoFlags(const uint32_t frame) const
Digest the aditional flags stored in the 4 "cccc" bits of the EPO messages.
static CbmTrdDigi::eTriggerType GetDigiTriggerType(Spadic::eTriggerType tt)
Get the Digi Trigger Type from the raw message triggertype.
std::float_t GetMaxAdcValue(const std::vector< int16_t > *samples) const
Get the MaxAdc value.
static constexpr size_t fPeakingBinMax
Last sample to look for the max adc Default value is set based on the Shaping time + 5 samples safety...
void digestMsFlags(const uint16_t flags, UnpackMonitorData &monitor) const
Digest the flags of the currently unpacked micro-Slice.
uint64_t GetBinTimeShift(const std::vector< int16_t > *) const
Get the Bin Time Shift value.
static constexpr size_t fPeakingBinMin
First sample to look for the max adc.
uint8_t getTsMsb(const uint32_t frame, UnpackMonitorData &monitor) const
Get the ts_msb information from the TS_MSB(kEPO) frame. We take the first of the 3 The 3 redundant TS...
Spadic::MsMessageType getMessageType(const uint32_t frame) const
Identify the message type of a given 32bit frame inside a Microslice.
static constexpr size_t fNrOfPresamples
Number of samples not considered for max adc.
static constexpr float_t fAsicClockCycle
Clock length of Spadic in ns.
std::float_t extractAvgSample(size_t *adcbuffer, size_t *nadcbits) const
Extract the baseline average sample from a given adcbuffer. Depending on the Spadic settings sample-0...
static constexpr uint8_t fBytesPerWord
Bytes per spadic frame stored in the microslices.
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
UnpackPar fParams
Parameter container.
void digestInfoMsg(const uint32_t frame) const
Digest a info message run all default information forwarding from the msg.
int16_t extractSample(size_t *adcbuffer, size_t *nadcbits) const
Extract one adc sample from a given adcbuffer.
@ kUNU
Unused request. 100. .... .... .... cccc.
@ kChannelBufM
Channel buffer full and multihit from kEPO msg.
@ kChannelBuf
Channel buffer full from kEPO msg.
@ kBOM
Buffer overflow count. 11nn nnnn nnnn nnnn cccc.
@ kMIS
Missing request. 101. .... .... .... ....
@ kOrdFifoBuf
Multi-hit but ordering buffer full from kEPO msg.
@ kBUF
Buffer full. 011b b... .... .... cccc.
@ kMSB
Message build error. 010. .... .... .... cccc.
@ kNeigh
Neighbor trigger.
@ kSandN
Self and neighbor trigger at the same time.
@ kEPO
Epoch Marker or TS_MSB depending on the hitmessage version.
constexpr uint8_t BytesPerWord()
TRD Unpacking parameters for one CROB.
std::vector< UnpackElinkPar > fElinkParams
Parameters for each eLink.
TRD Unpacking parameters for one eLink.
std::vector< uint32_t > fChanAddress
CbmTrdAddress for different channels.
uint32_t fAddress
Asic address.
int64_t fTimeOffset
Time calibration parameter.
size_t fLastFulltime
Time of the last succesful digest hit message.
std::vector< uint8_t > fNrTsMsbVec
Counter for the ts_msb used to reconstruct the time.
size_t fMsStartTimeRelCC
Start time of the current micro-Slice relative to the Timeslice start time in Spadic CC.
Monitoring data for TRD unpacking.
size_t fNumOverflowFlimFlags
counter for inf/error flags from the micro-Slices
size_t fNumCrcValidFlags
counter for inf/error flags from the micro-Slices
size_t fNumNonMajorTsMsb
Counter for the ts_msb used to reconstruct the time.
size_t fNumOverflowUserFlags
counter for inf/error flags from the micro-Slices
size_t fNumDataErrorFlags
counter for inf/error flags from the micro-Slices
size_t fNumErrTimestampUnderflow
Underflow in 64 bit time stamp if offsetting.