7#include <FairParGenericSet.h>
12#include <RtypesCore.h>
25 const fles::MicrosliceView mv = ts->get_microslice(icomp, imslice);
26 const fles::MicrosliceDescriptor& msDesc = mv.desc();
29 if (msDesc.sys_ver != 0x3) {
30 LOG(fatal) <<
"CbmRichUnpackAlgo2022: System Version of the microslice is not compatible with this unpacker!";
38 reader.
SetData(mv.content(), msDesc.size);
40 auto mstime = msDesc.idx;
45 if (reader.
GetSize() <= 8)
return true;
55 uint32_t msIndexWord1 = reader.
NextWord();
58 uint32_t msIndexWord2 = reader.
NextWord();
63 for (
auto itHit = fOutputVec.begin(); itHit != fOutputVec.end(); ++itHit) {
64 fMonitor->FillDigisTimeInRun(itHit->GetTime());
65 fMonitor->FillDigisToT(itHit->GetToT());
66 fMonitor->FillDigisToTDiRICH(itHit->GetAddress(), itHit->GetToT());
68 fMonitor->FillVectorSize(ts->index(), fOutputVec.size());
77 uint32_t hubId = word & 0xffff;
78 uint32_t hubSize = (word >> 16) & 0xffff;
80 LOG(debug4) <<
getLogHeader(reader) <<
"hubId:0x" << std::hex << hubId << std::dec <<
" hubSize:" << hubSize;
94 uint32_t subSubEventId = word & 0xffff;
95 uint32_t subSubEventSize = (word >> 16) & 0xffff;
98 totalSize += (1 + subSubEventSize);
101 LOG(debug4) <<
getLogHeader(reader) <<
counter << ((isLast) ?
" CTS" :
" DiRICH") <<
" subSubEventId:0x"
102 << std::hex << subSubEventId << std::dec <<
" subSubEventSize:" << subSubEventSize;
106 uint16_t sSubSubEvtIdMsb = (subSubEventId >> 12) & 0xF;
107 if ((sSubSubEvtIdMsb != 0x7) && (sSubSubEvtIdMsb != 0x9)) {
109 LOG(error) <<
getLogHeader(reader) <<
"ERROR: subSubEventId has strange value:0x" << std::hex << subSubEventId
127 if ((totalSize == hubSize && !isLast) || (totalSize != hubSize && isLast)) {
128 if (
isLog()) LOG(error) <<
"ERROR: totalSize OR isLast is wrong";
131 if (totalSize >= hubSize || isLast)
break;
137 int lastWordsCounter = 0;
142 if (word == 0x600dda7a) {
146 if (lastWordsCounter >= 7) {
148 <<
"CbmMcbm2018UnpackerAlgoRich::ProcessHubBlock() ERROR: No word == 0x600dda7a";
154 uint32_t subSubEventId)
157 uint32_t ctsState = word & 0xffff;
158 uint32_t nofInputs = (word >> 16) & 0xf;
159 uint32_t nofTrigCh = (word >> 20) & 0x1f;
160 uint32_t inclLastIdle = (word >> 25) & 0x1;
161 uint32_t inclTrigInfo = (word >> 26) & 0x1;
162 uint32_t inclTime = (word >> 27) & 0x1;
163 uint32_t ETM = (word >> 28) & 0x3;
164 uint32_t ctsInfoSize = 2 * nofInputs + 2 * nofTrigCh + 2 * inclLastIdle + 3 * inclTrigInfo + inclTime;
167 case 1: ctsInfoSize += 1;
break;
168 case 2: ctsInfoSize += 4;
break;
171 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"CTS ctsState:" << ctsState <<
" ctsInfoSize:" << ctsInfoSize;
172 for (uint32_t i = 0; i < ctsInfoSize; i++) {
176 int nofTimeWords = subSubEventSize - ctsInfoSize - 1;
181 uint32_t subSubEventId)
185 bool wasHeader =
false;
186 bool wasEpoch =
false;
187 bool wasTime =
false;
188 bool wasTrailer =
false;
190 bool errorInData =
false;
194 std::vector<double> raisingTime(33, -1.);
197 bool DiRICH_masked =
false;
199 DiRICH_masked =
true;
204 bool DiRICH_unknown =
false;
206 DiRICH_unknown =
true;
207 if (0x8000 != (subSubEventId & 0xF000)) {
209 LOG(debug) <<
"Unknown DiRICH ID 0x" << std::hex << subSubEventId << std::dec;
213 for (
int i = 0; i < nofTimeWords; i++) {
216 if (DiRICH_masked || DiRICH_unknown)
continue;
220 if (!wasHeader || !wasEpoch || wasTrailer) {
221 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
222 <<
": illegal position of TDC Time (before header/epoch or after trailer), skip subsubevent"
223 <<
" " << wasHeader <<
"|" << wasEpoch <<
"|" << wasTrailer;
227 for (; i < nofTimeWords - 1; i++) {
236 if (!wasHeader || wasTrailer) {
237 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
238 <<
": illegal position of TDC Epoch (before header or after trailer), skip subsubevent";
242 for (; i < nofTimeWords - 1; i++) {
249 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] epoch:" << epoch;
252 if (wasEpoch || wasTime || wasTrailer) {
253 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
254 <<
": illegal position of TDC Header (after time/epoch/trailer), skip subsubevent";
256 for (; i < nofTimeWords - 1; i++) {
264 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] header";
267 if (!wasEpoch || !wasTime || !wasHeader) {
268 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
269 <<
": illegal position of TDC Trailer (before time/epoch/header), skip subsubevent";
271 for (; i < nofTimeWords - 1; i++) {
279 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] trailer";
285 LOG(error) <<
getLogHeader(reader) <<
"Wrong TDC word!!! marker:" << ((word >> 29) & 0x7);
298 uint32_t trigNum_this = reader.
NextWord() & 0xFFFFFF;
303 for (
auto l = 0; l < 2; ++l) {
315 uint32_t cbmtime0 = reader.
NextWord();
316 uint32_t cbmtime1 = reader.
NextWord();
317 uint64_t CbmTimePacket_prev = (uint64_t) cbmtime0 << 32 | cbmtime1;
319 uint32_t trigNum_prevMes = reader.
NextWord() & 0xFFFFFF;
323 LOG(trace) <<
"trigNum_this =" << trigNum_this <<
" trigNum_prevMes = " << trigNum_prevMes
324 <<
" CbmTimePacket_prev = " << CbmTimePacket_prev;
329 for (
auto l = 0; l < 14; ++l) {
346 uint32_t trbNum = reader.
NextWord();
354 uint32_t word_MSB = reader.
NextWord();
355 uint32_t word_LSB = reader.
NextWord();
364 uint32_t tdcWord, uint32_t subSubEventId,
365 std::vector<double>& raisingTime)
376 <<
" CH0 Last:" << std::setprecision(15) << fullTime
385 double fullTimeCorr = dT - mbsCorr + subtrigOffset;
399 <<
" time:" << std::setprecision(15) << fullTime <<
" fullTimeCorr:" << fullTimeCorr;
402 LOG(error) <<
"ERROR: channel number is out of limit. Channel:" << td.
fChannel;
407 raisingTime[td.
fChannel] = fullTimeCorr;
410 if (raisingTime[td.
fChannel] == -1.) {
413 LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
414 <<
"No raising channel was found before. Skip this falling edge time.";
418 double ToT = fullTimeCorr - raisingTime[td.
fChannel];
420 LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
430 if (fullTimeCorr >= 0.0) {
446 Double_t finalTime = time + (Double_t)
fMsRefTime - fSystemTimeOffset;
449 if (6e9 < finalTime)
return;
451 fOutputVec.emplace_back(pixelUID, finalTime, tot - ToTcorr);
ClassImp(CbmConverterManager)
CbmRichUnpackAlgoTdcWordType
Double_t GetToTshift(Int_t tdc, Int_t ch) const
Int_t GetAddressIdx(Int_t addr, bool bVerbose=true) const
void processCtsSubSubEvent(CbmRichUnpackAlgoMicrosliceReader &reader, uint32_t subSubEventSize, uint32_t subSubEventId)
bool unpack(const fles::Timeslice *ts, std::uint16_t icomp, UInt_t imslice)
Unpack a given microslice. To be implemented in the derived unpacker algos.
virtual ~CbmRichUnpackAlgo2022()
Destroy the Cbm Trd Unpack Task object.
void processHubBlock(CbmRichUnpackAlgoMicrosliceReader &reader)
std::unordered_set< uint16_t > fUnexpectedIds
void processTrbPacket(CbmRichUnpackAlgoMicrosliceReader &reader)
void processTimeDataWord(CbmRichUnpackAlgoMicrosliceReader &reader, int iTdc, uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector< double > &raisingTime)
double fMbsPrevTimeCh0
Parameters for the unpacking.
CbmRichUnpackAlgo2022()
Create the Cbm Trd Unpack AlgoBase object.
void processCBMtime(CbmRichUnpackAlgoMicrosliceReader &reader)
double fPrevLastCh0ReTime[13]
void writeOutputDigi(Int_t fpgaID, Int_t channel, Double_t time, Double_t tot)
void processSubSubEvent(CbmRichUnpackAlgoMicrosliceReader &reader, int nofTimeWords, uint32_t subSubEventId)
bool checkMaskedDiRICH(Int_t subSubEventId)
Unpack a given microslice. To be implemented in the derived unpacker algos.
CbmMcbm2018RichPar fUnpackPar
Parameters for the unpacking.
double calculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine)
Int_t getPixelUID(Int_t fpgaID, Int_t ch) const
std::shared_ptr< CbmRichUnpackMonitor > fMonitor
Potential (online) monitor for the unpacking process.
std::string getLogHeader(CbmRichUnpackAlgoMicrosliceReader &reader)
std::string GetWordAsHexString(uint32_t word)
bool IsLastSubSubEvent(uint32_t subSubEventSize)
void SetData(const uint8_t *data, size_t size)
static CbmRichUnpackAlgoTdcWordType GetTdcWordType(uint32_t tdcWord)
static void ProcessTimeData(uint32_t tdcWord, CbmRichUnpackAlgoTdcTimeData &outData)
static uint32_t ProcessEpoch(uint32_t tdcWord)