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);
61 auto flag = (frame >> 15) & 0x3;
70 fMonitor->FillHisto(infotype, moduleid);
80 fOptOutBVec->emplace_back(std::make_pair(fLastFulltime, frame));
89 fMonitor->FillHisto(infotype, moduleid);
99 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::CrcValid)) {
102 fMonitor->FillHisto(fles::MicrosliceFlags::CrcValid, moduleid);
105 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::OverflowFlim)) {
106 fNrOverflowFlimFlags++;
108 fMonitor->FillHisto(fles::MicrosliceFlags::OverflowFlim, moduleid);
111 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::OverflowUser)) {
112 fNrOverflowUserFlags++;
114 fMonitor->FillHisto(fles::MicrosliceFlags::OverflowUser, moduleid);
117 if (flags &
static_cast<uint16_t
>(fles::MicrosliceFlags::DataError)) {
120 fMonitor->FillHisto(fles::MicrosliceFlags::DataError, moduleid);
129 LOG(error) << fName <<
"::extractAvgSample can not extract samples from a buffer with less than 9 bits";
142 int16_t sample = 0x07f;
145 sample &= (*adcbuffer >> (*nadcbits + 2));
157 LOG(error) << fName <<
"::extractSample can not extract samples from a buffer with less than 9 bits";
162 int16_t temp = 0x1ff;
163 temp &= (*adcbuffer >> (*nadcbits));
168 int16_t sample = (temp & 0x0100) ? (temp | 0xff00) : temp;
179 <<
" SOM to RDA/EOM eLink mismatches, \n " <<
fNrNonMajorTsMsb <<
" non-major ts_msbs and \n "
188 size_t mask = 0x000FFFFF;
196 if (((frame & mask) >> 18) == 3)
200 if (((frame & mask) >> 17) == 2)
204 if (((frame & mask) >> 17) == 3)
209 if (((frame & mask) >> 17) == 4)
213 if (((frame & mask) >> 17) == 5)
218 LOG(error) << fName <<
"::GetInfoType] unknown type!";
226 uint32_t checkframe = frame;
227 checkframe &= 0xffffff;
228 if ((checkframe >> 21) == 1)
232 else if ((checkframe >> 22) == 1)
236 else if ((checkframe >> 20) == 1)
240 else if ((checkframe >> 22) == 3)
244 else if (0 < (checkframe >> 18) && (checkframe >> 18) <= 3) {
247 else if (checkframe == 0)
260 if ((frame & 0xf) > 0)
264 for (uint iepoch = 0; iepoch < 3; ++iepoch) {
265 tsmsb[iepoch] =
static_cast<uint8_t
>((frame >> (4 + 6 * iepoch) & 0x3f));
269 if (tsmsb[0] == tsmsb[1] || tsmsb[0] == tsmsb[2])
return tsmsb[0];
272 if (tsmsb[1] == tsmsb[2])
return tsmsb[1];
275 <<
"::checkMajorityTsMsb got a vector without a majority ts_msb, so please check what is going on here!";
296 Int_t uniqueModuleId = asicAddress / 1000;
305 ULong64_t time = raw.
GetTime();
307 time -= fSystemTimeOffset;
310 auto digi =
fRTDMethod->MakeDigi(raw.
GetSamples(), padChNr, uniqueModuleId, time, triggerType, errClass);
329 Int_t uniqueModuleId = asicAddress / 1000;
332 auto padChNr =
getChannelId(asicAddress, fw.elink, fw.channel);
338 auto energy =
fSpadic->MaxAdcToEnergyCal(fw.maxAdc);
340 time -= fSystemTimeOffset;
343 auto digi = std::unique_ptr<CbmTrdDigi>(
new CbmTrdDigi(padChNr, uniqueModuleId, energy, time, triggerType, 0));
350 fMonitor->FillHistos(digi.get(),
nullptr);
353 fOutputVec.emplace_back(*std::move(digi));
359 uint16_t elinkId, uint8_t istream)
362 auto chId =
static_cast<uint8_t
>(((frame >> 17) & 0xf));
363 auto timestamp =
static_cast<uint8_t
>((frame >> 9) & 0xff);
364 bool multihit = ((frame >> 8) & 0x1);
365 auto hitType =
static_cast<uint8_t
>((frame >> 6) & 0x3);
366 uint8_t nsamples = 0;
368 std::vector<int16_t> samples = std::vector<int16_t>(0);
374 CbmTrdRawMessageSpadic retval(chId, elinkId, crobId, criId, hitType, nsamples, multihit, fulltime, samples);
382 bool unpackOk =
true;
386 auto msdesc = ts->descriptor(icomp, imslice);
395 auto criId = msdesc.eq_id;
400 const auto mspointer = ts->content(icomp, imslice);
402 const auto mscontent =
reinterpret_cast<const size_t*
>(mspointer);
404 if (msdesc.sys_ver == 0x10) {
417 auto mssize = msdesc.size;
424 auto criId = msdesc.eq_id;
426 bool unpackOk =
true;
428 int8_t currTsMsb = 0;
437 for (uint32_t iword = 0; iword < nwords; ++iword) {
439 size_t word =
static_cast<size_t>(mscontent[iword]);
442 uint32_t frame = (word >> (32 * istream)) & 0xffffffff;
448 auto elinkId = (frame >> 24) & 0x3f;
453 if (((tsmsb - currTsMsb) & 0x3f) == 1 || currTsMsb == -1)
fNrTsMsbVec.at(istream)++;
466 size_t nadcbitstotal = 6;
468 size_t adcbuffer = frame & 0x3f;
474 word =
static_cast<size_t>(mscontent[iword]);
475 frame = (word >> (32 * istream)) & 0xffffffff;
483 elinkId = (frame >> 24) & 0x3f;
486 LOG(debug) << fName <<
"::unpack() SOM eLinkId(" <<
static_cast<uint16_t
>(raw.
GetElinkId())
487 <<
") does not match the RDA eLinkId(" << elinkId <<
")";
492 adcbuffer |=
static_cast<size_t>((frame & 0x3fffff));
497 while (nadcbits >= 9) {
500 if (isample == 0 &&
fSpadic->GetUseBaselineAvg())
507 word =
static_cast<size_t>(mscontent[iword]);
508 frame = (word >> (32 * istream)) & 0xffffffff;
513 elinkId = (frame >> 24) & 0x3f;
516 LOG(debug) << fName <<
"::unpack() SOM eLinkId(" <<
static_cast<uint16_t
>(raw.
GetElinkId())
517 <<
") does not match the RDA eLinkId(" << elinkId <<
")";
521 uint8_t nsamplesindicator = (frame >> 18) & 0x3;
523 uint64_t nreqsamples = (nadcbitstotal + 18) / 9;
524 uint8_t nn = nreqsamples % 4;
525 for (uint8_t itest = 0; itest < 3; itest++) {
526 if (nn == nsamplesindicator || nreqsamples == 0)
break;
528 nn = nreqsamples % 4;
532 if (nreqsamples >= isample) {
534 int8_t nrequiredbits = (nreqsamples - isample) * 9 - nadcbits;
535 adcbuffer <<= nrequiredbits;
538 adcbuffer |=
static_cast<size_t>((frame & 0x3ffff) >> (18 - nrequiredbits));
539 nadcbits += nrequiredbits;
541 while (nadcbits >= 9) {
561 <<
"::unpack() We had a SOM message and hence, desparately need an EOM message but none came. This "
562 "is quite mysterious and a problem!";
567 LOG(debug) << fName <<
"::unpack() Unexpected wild RDA word";
572 LOG(debug) << fName <<
"::unpack() Unexpected wild EOM word";
585 <<
"::unpack() Null Word but "
586 "not at end of Microslice.";
593 <<
"::unpack() Unknown Word. "
594 "Microslice corrupted.";
608template<u
int8_t sys_ver>
612 if constexpr (bytes == 0) {
616 bool unpackOk =
true;
619 auto mssize = msdesc.size;
620 uint32_t nwords = mssize / bytes;
623 auto criId = msdesc.eq_id;
627 for (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...
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
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.
virtual uint32_t getAsicAddress(uint32_t criid, uint32_t crobid, uint32_t elinkid)
Get the Asic Address (CbmAddress scheme) for the given hardware Ids.
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.
uint32_t getChannelId(uint32_t asicaddress, uint32_t elinkid, uint32_t elinkchannelid)
Get the Channel Id (CbmAddress scheme) for the given hardware Ids.
int32_t GetElinkTimeOffset(uint32_t criid, uint8_t elinkid)
Get the time offeset to be substracted from the digis which come from a specific CRI.
size_t fNrUnknownWords
Number of unknown words.
CbmTrdUnpackAlgoBaseR(std::string name)
Create the Cbm Trd Unpack AlgoBase object.
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 micro-Slice.
std::vector< uint8_t > fNrTsMsbVec
Counter for the ts_msb used to reconstruct the time.
static const uint8_t fBytesPerWord
Bytes per spadic frame stored in the microslices.
size_t fNrCorruptEom
Number of corrupted EOM frames.
static const uint8_t fStreamsPerWord
Number of streams per word For the msg format used from 2021 ongoing we have 2 parallel streams per w...
void makeDigi(CbmTrdRawMessageSpadic raw)
Create an actual digi from the raw message.
virtual std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > * GetParContainerRequest(std::string geoTag, uint32_t runId)
Get the requested parameter containers. Return the required parameter containers together with the pa...
CbmTrdUnpackAlgoR()
Create the Cbm Trd Unpack AlgoBase object.
int16_t extractSample(size_t *adcbuffer, size_t *nadcbits)
Extract all adc samples from a given adcbuffer container.
Spadic::MsMessageType getMessageType(const uint32_t frame)
Identify the message type of a given 32bit frame inside a Microslice.
void finishDerived()
Additional explicit finish function of this algo implementation.
bool unpackRaw(const fles::MicrosliceDescriptor msdesc, const size_t *mscontent)
Spadic::MsInfoType digestBufInfoFlags(const uint32_t frame, uint16_t criId, uint8_t crobId, 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...
bool unpackFex(const fles::MicrosliceDescriptor msdesc, const size_t *mscontent)
size_t fNrNonMajorTsMsb
Counter for the ts_msb used to reconstruct the time.
uint8_t getTsMsb(const 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...
virtual ~CbmTrdUnpackAlgoR()
Destroy the Cbm Trd Unpack Task object.
bool unpack(const fles::Timeslice *ts, uint16_t icomp, UInt_t imslice)
Unpack a given microslice.
Spadic::MsInfoType getInfoType(const uint32_t frame, uint16_t criId, uint8_t crobId, uint16_t elinkId)
Identify the InfoType of a 64bit InfoMessage word inside a Microslice.
virtual CbmTrdRawMessageSpadic makeRaw(const uint32_t frame, uint16_t criId, uint8_t crobId, uint16_t elinkId, uint8_t istream)
Create a CbmTrdRawMessageSpadic from the hit message input.
size_t fMsStartTimeRelCC
Start time of the current micro-Slice relative to the Timeslice start time in Spadic CC.
void digestMsFlags(const uint16_t flags, uint16_t criId, uint8_t crobId)
Digest the flags of the currently unpacked micro-Slice.
size_t fNrElinkMis
Number of SOM to RDA/EOM mismatches.
void digestInfoMsg(const uint32_t frame, uint16_t criId, uint8_t crobId, uint16_t elinkId)
Digest a info message run all default information forwarding from the msg.
size_t fMsStartTimeRel
Start time of the current micro-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 uint8_t BytesPerWord()