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 reader.
SetData(mv.content(), msDesc.size);
31 auto mstime = msDesc.idx;
36 if (reader.
GetSize() <= 8)
return true;
46 uint32_t msIndexWord1 = reader.
NextWord();
49 uint32_t msIndexWord2 = reader.
NextWord();
59 uint32_t hubId = word & 0xffff;
60 uint32_t hubSize = (word >> 16) & 0xffff;
62 LOG(debug4) <<
getLogHeader(reader) <<
"hubId:0x" << std::hex << hubId << std::dec <<
" hubSize:" << hubSize;
74 uint32_t subSubEventId = word & 0xffff;
75 uint32_t subSubEventSize = (word >> 16) & 0xffff;
78 totalSize += (1 + subSubEventSize);
81 LOG(debug4) <<
getLogHeader(reader) <<
counter << ((isLast) ?
" CTS" :
" DiRICH") <<
" subSubEventId:0x"
82 << std::hex << subSubEventId << std::dec <<
" subSubEventSize:" << subSubEventSize;
86 if (((subSubEventId >> 12) & 0xF) != 0x7) {
87 LOG(error) <<
getLogHeader(reader) <<
"ERROR: subSubEventId has strange value:0x" << std::hex << subSubEventId
102 if ((totalSize == hubSize && !isLast) || (totalSize != hubSize && isLast)) {
103 if (
isLog()) LOG(error) <<
"ERROR: totalSize OR isLast is wrong";
106 if (totalSize >= hubSize || isLast)
break;
110 int lastWordsCounter = 0;
115 if (word == 0x600dda7a)
break;
116 if (lastWordsCounter >= 7) {
118 <<
"CbmMcbm2018UnpackerAlgoRich::ProcessHubBlock() ERROR: No word == 0x600dda7a";
124 uint32_t subSubEventId)
127 uint32_t ctsState = word & 0xffff;
128 uint32_t nofInputs = (word >> 16) & 0xf;
129 uint32_t nofTrigCh = (word >> 20) & 0x1f;
130 uint32_t inclLastIdle = (word >> 25) & 0x1;
131 uint32_t inclTrigInfo = (word >> 26) & 0x1;
132 uint32_t inclTime = (word >> 27) & 0x1;
133 uint32_t ETM = (word >> 28) & 0x3;
134 uint32_t ctsInfoSize = 2 * nofInputs + 2 * nofTrigCh + 2 * inclLastIdle + 3 * inclTrigInfo + inclTime;
137 case 1: ctsInfoSize += 1;
break;
138 case 2: ctsInfoSize += 4;
break;
141 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"CTS ctsState:" << ctsState <<
" ctsInfoSize:" << ctsInfoSize;
142 for (uint32_t i = 0; i < ctsInfoSize; i++) {
146 int nofTimeWords = subSubEventSize - ctsInfoSize - 1;
151 uint32_t subSubEventId)
155 bool wasHeader =
false;
156 bool wasEpoch =
false;
157 bool wasTime =
false;
158 bool wasTrailer =
false;
160 bool errorInData =
false;
164 std::vector<double> raisingTime(33, -1.);
167 bool DiRICH_masked =
false;
169 DiRICH_masked =
true;
172 for (
int i = 0; i < nofTimeWords; i++) {
174 if (DiRICH_masked)
continue;
178 if (!wasHeader || !wasEpoch || wasTrailer) {
179 LOG(error) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
180 <<
": illegal position of TDC Time (before header/epoch or after trailer)";
188 if (!wasHeader || wasTrailer) {
189 LOG(error) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
190 <<
": illegal position of TDC Epoch (before header or after trailer)";
196 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] epoch:" << epoch;
199 if (wasEpoch || wasTime || wasTrailer) {
200 LOG(error) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
201 <<
": illegal position of TDC Header (after time/epoch/trailer)";
208 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] header";
211 if (!wasEpoch || !wasTime || !wasHeader) {
212 LOG(error) <<
getLogHeader(reader) <<
"DiRICH 0x" << std::hex << subSubEventId << std::dec
213 <<
": illegal position of TDC Trailer (before time/epoch/header)";
220 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << i <<
"] trailer";
226 LOG(error) <<
getLogHeader(reader) <<
"Wrong TDC word!!! marker:" << ((word >> 29) & 0x7);
241 uint32_t trbNum = reader.
NextWord();
250 uint32_t mbsNum = word & 0xffffff;
251 uint32_t nofCtsCh = (word >> 24) & 0xff;
253 LOG(debug4) <<
getLogHeader(reader) <<
"MBS mbsNum:0x" << std::hex << mbsNum << std::dec
254 <<
" nofCtsCh:" << nofCtsCh;
256 for (uint32_t i = 0; i < nofCtsCh; i++) {
257 uint32_t wordEpoch = reader.
NextWord();
259 if (
isLog()) LOG(debug4) <<
getLogHeader(reader) <<
"MBS ch:" << i <<
" epoch:" << epoch;
261 uint32_t wordTime = reader.
NextWord();
280 uint32_t tdcWord, uint32_t subSubEventId, std::vector<double>& raisingTime)
293 <<
" CH0 Last:" << std::setprecision(15) <<
fLastCh0ReTime[subSubEventId]
301 double fullTimeCorr = dT - mbsCorr;
304 <<
" time:" << std::setprecision(15) << fullTime <<
" fullTimeCorr:" << fullTimeCorr;
307 LOG(error) <<
"ERROR: channel number is out of limit. Channel:" << td.
fChannel;
312 raisingTime[td.
fChannel] = fullTimeCorr;
315 if (raisingTime[td.
fChannel] == -1.) {
318 LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
319 <<
"No raising channel was found before. Skip this falling edge time.";
323 double ToT = fullTimeCorr - raisingTime[td.
fChannel];
325 LOG(debug4) <<
getLogHeader(reader) <<
"SubSubEv[" << iTdc <<
"] "
335 if (fullTimeCorr >= 0.0) {
349 Int_t pixelUID = this->
getPixelUID(fpgaID, channel);
351 Double_t finalTime = time + (Double_t)
fMsRefTime - fSystemTimeOffset;
354 fOutputVec.emplace_back(pixelUID, finalTime, tot - ToTcorr);
ClassImp(CbmConverterManager)
CbmRichUnpackAlgoTdcWordType
Baseclass for the TrdR unpacker algorithms.
Double_t GetToTshift(Int_t tdc, Int_t ch) const
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::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)
void processMbs(CbmRichUnpackAlgoMicrosliceReader &reader, bool isPrev)
CbmRichUnpackAlgo()
Create the Cbm Trd Unpack AlgoBase object.
virtual ~CbmRichUnpackAlgo()
Destroy the Cbm Trd Unpack Task object.
void processSubSubEvent(CbmRichUnpackAlgoMicrosliceReader &reader, int nofTimeWords, uint32_t subSubEventId)
std::map< uint32_t, double > fPrevLastCh0ReTime
void processTrbPacket(CbmRichUnpackAlgoMicrosliceReader &reader)
void processTimeDataWord(CbmRichUnpackAlgoMicrosliceReader &reader, int iTdc, uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector< double > &raisingTime)
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.
void processHubBlock(CbmRichUnpackAlgoMicrosliceReader &reader)
void writeOutputDigi(Int_t fpgaID, Int_t channel, Double_t time, Double_t tot)
std::map< uint32_t, double > fLastCh0ReTime