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 if (((subSubEventId >> 12) & 0xF) != 0x7) {
107 LOG(error) <<
getLogHeader(reader) <<
"ERROR: subSubEventId has strange value:0x" << std::hex << subSubEventId
123 if ((totalSize == hubSize && !isLast) || (totalSize != hubSize && isLast)) {
124 if (
isLog()) LOG(error) <<
"ERROR: totalSize OR isLast is wrong";
127 if (totalSize >= hubSize || isLast)
break;
133 int lastWordsCounter = 0;
138 if (word == 0x600dda7a) {
142 if (lastWordsCounter >= 7) {
144 <<
"CbmMcbm2018UnpackerAlgoRich::ProcessHubBlock() ERROR: No word == 0x600dda7a";
150 uint32_t subSubEventId)
153 uint32_t ctsState = word & 0xffff;
154 uint32_t nofInputs = (word >> 16) & 0xf;
155 uint32_t nofTrigCh = (word >> 20) & 0x1f;
156 uint32_t inclLastIdle = (word >> 25) & 0x1;
157 uint32_t inclTrigInfo = (word >> 26) & 0x1;
158 uint32_t inclTime = (word >> 27) & 0x1;
159 uint32_t ETM = (word >> 28) & 0x3;
160 uint32_t ctsInfoSize = 2 * nofInputs + 2 * nofTrigCh + 2 * inclLastIdle + 3 * inclTrigInfo + inclTime;
163 case 1: ctsInfoSize += 1;
break;
164 case 2: ctsInfoSize += 4;
break;
167 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"CTS ctsState:" << ctsState <<
" ctsInfoSize:" << ctsInfoSize;
168 for (uint32_t i = 0; i < ctsInfoSize; i++) {
172 int nofTimeWords = subSubEventSize - ctsInfoSize - 1;
177 uint32_t subSubEventId)
181 bool wasHeader =
false;
182 bool wasEpoch =
false;
183 bool wasTime =
false;
184 bool wasTrailer =
false;
186 bool errorInData =
false;
190 std::vector<double> raisingTime(33, -1.);
193 bool DiRICH_masked =
false;
195 DiRICH_masked =
true;
200 bool DiRICH_unknown =
false;
202 DiRICH_unknown =
true;
203 if (0x8000 != (subSubEventId & 0xF000)) {
205 LOG(debug) <<
"Unknown DiRICH ID 0x" << std::hex << subSubEventId << std::dec;
209 for (
int i = 0; i < nofTimeWords; i++) {
212 if (DiRICH_masked || DiRICH_unknown)
continue;
216 if (!wasHeader || !wasEpoch || wasTrailer) {
217 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
218 <<
": illegal position of TDC Time (before header/epoch or after trailer), skip subsubevent"
219 <<
" " << wasHeader <<
"|" << wasEpoch <<
"|" << wasTrailer;
223 for (; i < nofTimeWords - 1; i++) {
232 if (!wasHeader || wasTrailer) {
233 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
234 <<
": illegal position of TDC Epoch (before header or after trailer), skip subsubevent";
238 for (; i < nofTimeWords - 1; i++) {
245 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] epoch:" << epoch;
248 if (wasEpoch || wasTime || wasTrailer) {
249 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
250 <<
": illegal position of TDC Header (after time/epoch/trailer), skip subsubevent";
252 for (; i < nofTimeWords - 1; i++) {
260 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] header";
263 if (!wasEpoch || !wasTime || !wasHeader) {
264 LOG(debug) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
265 <<
": illegal position of TDC Trailer (before time/epoch/header), skip subsubevent";
267 for (; i < nofTimeWords - 1; i++) {
275 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] trailer";
281 LOG(error) <<
getLogHeader(reader) <<
"Wrong TDC word!!! marker:" << ((word >> 29) & 0x7);
294 uint32_t trigNum_this = reader.
NextWord() & 0xFFFFFF;
299 for (
auto l = 0; l < 2; ++l) {
311 uint32_t cbmtime0 = reader.
NextWord();
312 uint32_t cbmtime1 = reader.
NextWord();
313 uint64_t CbmTimePacket_prev = (uint64_t) cbmtime0 << 32 | cbmtime1;
315 uint32_t trigNum_prevMes = reader.
NextWord() & 0xFFFFFF;
319 LOG(trace) <<
"trigNum_this =" << trigNum_this <<
" trigNum_prevMes = " << trigNum_prevMes
320 <<
" CbmTimePacket_prev = " << CbmTimePacket_prev;
325 for (
auto l = 0; l < 14; ++l) {
342 uint32_t trbNum = reader.
NextWord();
350 uint32_t word_MSB = reader.
NextWord();
351 uint32_t word_LSB = reader.
NextWord();
360 uint32_t tdcWord, uint32_t subSubEventId,
361 std::vector<double>& raisingTime)
372 <<
" CH0 Last:" << std::setprecision(15) << fullTime
381 double fullTimeCorr = dT - mbsCorr + subtrigOffset;
395 <<
" time:" << std::setprecision(15) << fullTime <<
" fullTimeCorr:" << fullTimeCorr;
398 LOG(error) <<
"ERROR: channel number is out of limit. Channel:" << td.
fChannel;
403 raisingTime[td.
fChannel] = fullTimeCorr;
406 if (raisingTime[td.
fChannel] == -1.) {
409 LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
410 <<
"No raising channel was found before. Skip this falling edge time.";
414 double ToT = fullTimeCorr - raisingTime[td.
fChannel];
416 LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
426 if (fullTimeCorr >= 0.0) {
440 Int_t pixelUID = this->
getPixelUID(fpgaID, channel);
442 Double_t finalTime = time + (Double_t)
fMsRefTime - fSystemTimeOffset;
445 if (6e9 < finalTime)
return;
447 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)
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)