15#include <RtypesCore.h>
29std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>*
33 std::string basepath = Form(
"%s/trd_%s", fParFilesBasePath.data(), geoTag.data());
34 std::string temppath =
"";
37 std::string runpath =
"";
39 runpath =
".run" + std::to_string(runId);
43 temppath = basepath + runpath +
".asic" +
".par";
44 fParContVec.emplace_back(std::make_pair(temppath, std::make_shared<CbmTrdParSetAsic>()));
48 temppath = basepath + runpath +
".digi" +
".par";
49 auto pair = std::make_pair(temppath, std::make_shared<CbmTrdParSetDigi>());
50 fParContVec.emplace_back(pair);
59 std::uint8_t crobId, std::uint16_t elinkId)
61 auto flag = (frame >> 15) & 0x3;
70 fMonitor->FillHisto(infotype, moduleid);
77 std::uint16_t elinkId)
81 fOptOutBVec->emplace_back(std::make_pair(fLastFulltime, frame));
90 fMonitor->FillHisto(infotype, moduleid);
100 if (flags &
static_cast<std::uint16_t
>(fles::MicrosliceFlags::CrcValid)) {
103 fMonitor->FillHisto(fles::MicrosliceFlags::CrcValid, moduleid);
106 if (flags &
static_cast<std::uint16_t
>(fles::MicrosliceFlags::OverflowFlim)) {
107 fNrOverflowFlimFlags++;
109 fMonitor->FillHisto(fles::MicrosliceFlags::OverflowFlim, moduleid);
112 if (flags &
static_cast<std::uint16_t
>(fles::MicrosliceFlags::OverflowUser)) {
113 fNrOverflowUserFlags++;
115 fMonitor->FillHisto(fles::MicrosliceFlags::OverflowUser, moduleid);
118 if (flags &
static_cast<std::uint16_t
>(fles::MicrosliceFlags::DataError)) {
121 fMonitor->FillHisto(fles::MicrosliceFlags::DataError, moduleid);
130 LOG(error) << fName <<
"::extractAvgSample can not extract samples from a buffer with less than 9 bits";
143 std::int16_t sample = 0x07f;
146 sample &= (*adcbuffer >> (*nadcbits + 2));
158 LOG(error) << fName <<
"::extractSample can not extract samples from a buffer with less than 9 bits";
163 std::int16_t temp = 0x1ff;
164 temp &= (*adcbuffer >> (*nadcbits));
169 std::int16_t sample = (temp & 0x0100) ? (temp | 0xff00) : temp;
180 <<
" SOM to RDA/EOM eLink mismatches, \n " <<
fNrNonMajorTsMsb <<
" non-major ts_msbs and \n "
186 std::uint16_t elinkId)
189 size_t mask = 0x000FFFFF;
197 if (((frame & mask) >> 18) == 3)
201 if (((frame & mask) >> 17) == 2)
205 if (((frame & mask) >> 17) == 3)
210 if (((frame & mask) >> 17) == 4)
214 if (((frame & mask) >> 17) == 5)
219 LOG(error) << fName <<
"::GetInfoType] unknown type!";
227 std::uint32_t checkframe = frame;
228 checkframe &= 0xffffff;
229 if ((checkframe >> 21) == 1)
233 else if ((checkframe >> 22) == 1)
237 else if ((checkframe >> 20) == 1)
241 else if ((checkframe >> 22) == 3)
245 else if (0 < (checkframe >> 18) && (checkframe >> 18) <= 3) {
248 else if (checkframe == 0)
261 if ((frame & 0xf) > 0)
264 std::uint8_t tsmsb[3];
265 for (uint iepoch = 0; iepoch < 3; ++iepoch) {
266 tsmsb[iepoch] =
static_cast<std::uint8_t
>((frame >> (4 + 6 * iepoch) & 0x3f));
270 if (tsmsb[0] == tsmsb[1] || tsmsb[0] == tsmsb[2])
return tsmsb[0];
273 if (tsmsb[1] == tsmsb[2])
return tsmsb[1];
276 <<
"::checkMajorityTsMsb got a vector without a majority ts_msb, so please check what is going on here!";
297 Int_t uniqueModuleId = asicAddress / 1000;
306 ULong64_t time = raw.
GetTime();
308 time -= fSystemTimeOffset;
311 auto digi =
fRTDMethod->MakeDigi(raw.
GetSamples(), padChNr, uniqueModuleId, time, triggerType, errClass);
330 Int_t uniqueModuleId = asicAddress / 1000;
333 auto padChNr =
getChannelId(asicAddress, fw.elink, fw.channel);
339 auto energy =
fSpadic->MaxAdcToEnergyCal(fw.maxAdc);
341 time -= fSystemTimeOffset;
344 auto digi = std::unique_ptr<CbmTrdDigi>(
new CbmTrdDigi(padChNr, uniqueModuleId, energy, time, triggerType, 0));
351 fMonitor->FillHistos(digi.get(),
nullptr);
354 fOutputVec.emplace_back(*std::move(digi));
360 std::uint16_t elinkId, std::uint8_t istream)
363 auto chId =
static_cast<std::uint8_t
>(((frame >> 17) & 0xf));
364 auto timestamp =
static_cast<std::uint8_t
>((frame >> 9) & 0xff);
365 bool multihit = ((frame >> 8) & 0x1);
366 auto hitType =
static_cast<std::uint8_t
>((frame >> 6) & 0x3);
367 std::uint8_t nsamples = 0;
369 std::vector<std::int16_t> samples = std::vector<std::int16_t>(0);
375 CbmTrdRawMessageSpadic retval(chId, elinkId, crobId, criId, hitType, nsamples, multihit, fulltime, samples);
383 bool unpackOk =
true;
387 auto msdesc = ts->descriptor(icomp, imslice);
395 std::uint8_t crobId = 0;
396 auto criId = msdesc.eq_id;
401 const auto mspointer = ts->content(icomp, imslice);
403 const auto mscontent =
reinterpret_cast<const size_t*
>(mspointer);
405 if (msdesc.sys_ver == 0x10) {
418 auto mssize = msdesc.size;
424 std::uint8_t crobId = 0;
425 auto criId = msdesc.eq_id;
427 bool unpackOk =
true;
429 std::int8_t currTsMsb = 0;
436 for (std::uint32_t istream = 0; istream <
fStreamsPerWord; istream++) {
438 for (std::uint32_t iword = 0; iword < nwords; ++iword) {
440 size_t word =
static_cast<size_t>(mscontent[iword]);
443 std::uint32_t frame = (word >> (32 * istream)) & 0xffffffff;
449 auto elinkId = (frame >> 24) & 0x3f;
454 if (((tsmsb - currTsMsb) & 0x3f) == 1 || currTsMsb == -1)
fNrTsMsbVec.at(istream)++;
467 size_t nadcbitstotal = 6;
469 size_t adcbuffer = frame & 0x3f;
475 word =
static_cast<size_t>(mscontent[iword]);
476 frame = (word >> (32 * istream)) & 0xffffffff;
484 elinkId = (frame >> 24) & 0x3f;
487 LOG(debug) << fName <<
"::unpack() SOM eLinkId(" <<
static_cast<std::uint16_t
>(raw.
GetElinkId())
488 <<
") does not match the RDA eLinkId(" << elinkId <<
")";
493 adcbuffer |=
static_cast<size_t>((frame & 0x3fffff));
498 while (nadcbits >= 9) {
501 if (isample == 0 &&
fSpadic->GetUseBaselineAvg())
508 word =
static_cast<size_t>(mscontent[iword]);
509 frame = (word >> (32 * istream)) & 0xffffffff;
514 elinkId = (frame >> 24) & 0x3f;
517 LOG(debug) << fName <<
"::unpack() SOM eLinkId(" <<
static_cast<std::uint16_t
>(raw.
GetElinkId())
518 <<
") does not match the RDA eLinkId(" << elinkId <<
")";
522 std::uint8_t nsamplesindicator = (frame >> 18) & 0x3;
524 std::uint64_t nreqsamples = (nadcbitstotal + 18) / 9;
525 std::uint8_t nn = nreqsamples % 4;
526 for (std::uint8_t itest = 0; itest < 3; itest++) {
527 if (nn == nsamplesindicator || nreqsamples == 0)
break;
529 nn = nreqsamples % 4;
533 if (nreqsamples >= isample) {
535 std::int8_t nrequiredbits = (nreqsamples - isample) * 9 - nadcbits;
536 adcbuffer <<= nrequiredbits;
539 adcbuffer |=
static_cast<size_t>((frame & 0x3ffff) >> (18 - nrequiredbits));
540 nadcbits += nrequiredbits;
542 while (nadcbits >= 9) {
562 <<
"::unpack() We had a SOM message and hence, desparately need an EOM message but none came. This "
563 "is quite mysterious and a problem!";
568 LOG(debug) << fName <<
"::unpack() Unexpected wild RDA word";
573 LOG(debug) << fName <<
"::unpack() Unexpected wild EOM word";
586 <<
"::unpack() Null Word but "
587 "not at end of Microslice.";
594 <<
"::unpack() Unknown Word. "
595 "Microslice corrupted.";
609template<std::u
int8_t sys_ver>
613 if constexpr (bytes == 0) {
617 bool unpackOk =
true;
620 auto mssize = msdesc.size;
621 std::uint32_t nwords = mssize / bytes;
623 std::uint8_t crobId = 0;
624 auto criId = msdesc.eq_id;
628 for (std::uint32_t iword = 0; iword < nwords; ++iword) {
ClassImp(CbmConverterManager)
Assign pad layout to TRD Modules.
Software representation of the SPADIC v2.2+.
Unpacker algorithm for the TrdR 2021 data.
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
std::uint64_t GetFullTime() const
const std::vector< std::int16_t > * GetSamples() const
void IncNrSamples()
increase the number of samples stored in this raw message by one
std::uint8_t GetChannelId() const
void SetSample(std::int16_t value, std::uint8_t pos)
std::uint8_t GetCrobId() const
std::uint8_t GetHitType() const
std::uint8_t GetElinkId() const
std::uint16_t GetCriId() const
static CbmTrdDigi::eTriggerType GetDigiTriggerType(Spadic::eTriggerType tt)
Get the Digi Trigger Type from the raw message triggertype.
std::shared_ptr< CbmTrdRawToDigiBaseR > fRTDMethod
raw to digi extraction method, set in the task
void digestOutput(std::unique_ptr< CbmTrdDigi > digi, CbmTrdRawMessageSpadic raw)
Handle the output created by the explicit algorithms. E.g. write to output vectors.
size_t fNrMissingEom
Number of missing EOM frames to finish a SOM frame.
size_t fTsMsbLengthCC
length of one ts_msb in [cc]
std::shared_ptr< CbmTrdUnpackMonitor > fMonitor
Potential (online) monitor for the unpacking process.
std::shared_ptr< CbmTrdSpadic > fSpadic
Spadic software reprensentation object.
size_t fNrWildRda
Number of rda frames outside of a SOM frame range.
size_t fNrUnknownWords
Number of unknown words.
std::int32_t GetElinkTimeOffset(std::uint32_t criid, std::uint8_t elinkid)
Get the time offeset to be substracted from the digis which come from a specific CRI.
virtual std::uint32_t getAsicAddress(std::uint32_t criid, std::uint32_t crobid, std::uint32_t elinkid)
Get the Asic Address (CbmAddress scheme) for the given hardware Ids.
std::uint32_t getChannelId(std::uint32_t asicaddress, std::uint32_t elinkid, std::uint32_t elinkchannelid)
Get the Channel Id (CbmAddress scheme) for the given hardware Ids.
size_t fNrWildEom
Number of eom frames outside of a SOM frame range.
size_t fNrWildNul
Number of wild null words, should only appear at the end of a µSlice.
size_t fNrCorruptEom
Number of corrupted EOM frames.
static const std::uint8_t fStreamsPerWord
Number of streams per word For the msg format used from 2021 ongoing we have 2 parallel streams per w...
virtual CbmTrdRawMessageSpadic makeRaw(const std::uint32_t frame, std::uint16_t criId, std::uint8_t crobId, std::uint16_t elinkId, std::uint8_t istream)
Create a CbmTrdRawMessageSpadic from the hit message input.
void makeDigi(CbmTrdRawMessageSpadic raw)
Create an actual digi from the raw message.
CbmTrdUnpackAlgoR()
Create the Cbm Trd Unpack AlgoBase object.
Spadic::MsMessageType getMessageType(const std::uint32_t frame)
Identify the message type of a given 32bit frame inside a Microslice.
std::int16_t extractSample(size_t *adcbuffer, size_t *nadcbits)
Extract all adc samples from a given adcbuffer container.
std::uint8_t getTsMsb(const std::uint32_t frame)
Get the ts_msb information from the TS_MSB(kEPO) frame. We take the first of the 3 The 3 redundant TS...
void finishDerived()
Additional explicit finish function of this algo implementation.
bool unpackRaw(const fles::MicrosliceDescriptor msdesc, const size_t *mscontent)
Spadic::MsInfoType digestBufInfoFlags(const std::uint32_t frame, std::uint16_t criId, std::uint8_t crobId, std::uint16_t elinkId)
Digest the aditional flags stored in the 4 "cccc" bits of the EPO messages.
std::float_t extractAvgSample(size_t *adcbuffer, size_t *nadcbits)
Extract the baseline average sample from a given adcbuffer. Depending on the Spadic settings sample-0...
virtual std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > * GetParContainerRequest(std::string geoTag, std::uint32_t runId)
Get the requested parameter containers. Return the required parameter containers together with the pa...
bool unpackFex(const fles::MicrosliceDescriptor msdesc, const size_t *mscontent)
std::vector< std::uint8_t > fNrTsMsbVec
Counter for the ts_msb used to reconstruct the time.
size_t fNrNonMajorTsMsb
Counter for the ts_msb used to reconstruct the time.
void digestInfoMsg(const std::uint32_t frame, std::uint16_t criId, std::uint8_t crobId, std::uint16_t elinkId)
Digest a info message run all default information forwarding from the msg.
void digestMsFlags(const std::uint16_t flags, std::uint16_t criId, std::uint8_t crobId)
Digest the flags of the currently unpacked µSlice.
virtual ~CbmTrdUnpackAlgoR()
Destroy the Cbm Trd Unpack Task object.
static const std::uint8_t fBytesPerWord
Bytes per spadic frame stored in the microslices.
Spadic::MsInfoType getInfoType(const std::uint32_t frame, std::uint16_t criId, std::uint8_t crobId, std::uint16_t elinkId)
Identify the InfoType of a 64bit InfoMessage word inside a Microslice.
size_t fMsStartTimeRelCC
Start time of the current µSlice relative to the Timeslice start time in Spadic CC.
bool unpack(const fles::Timeslice *ts, std::uint16_t icomp, UInt_t imslice)
Unpack a given microslice.
size_t fNrElinkMis
Number of SOM to RDA/EOM mismatches.
size_t fMsStartTimeRel
Start time of the current µSlice relative to the Timeslice start time in ns.
@ 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.
@ kEPO
Epoch Marker or TS_MSB depending on the hitmessage version.
constexpr std::uint8_t BytesPerWord()