CbmRoot
Loading...
Searching...
No Matches
rich/UnpackMS.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig, Dominik Smith [committer] */
4#pragma once
5
6#include "CbmRichDigi.h"
7#include "Definitions.h"
8#include "Timeslice.hpp"
9#include "UnpackMSBase.h"
10
11#include <cstddef>
12#include <cstdint>
13#include <iomanip>
14#include <memory>
15#include <sstream>
16#include <utility>
17
18namespace cbm::algo::rich
19{
20 class MicrosliceReader;
21
22 enum class TdcWordType
23 {
25 Header,
26 Epoch,
27 Trailer,
28 Debug,
29 Error
30 };
31
32
33 struct TdcTimeData {
34 uint32_t fCoarse = 0; // 11 bits
35 uint32_t fIsRisingEdge = 0; // 1 bit
36 uint32_t fFine = 0; // 10 bits
37 uint32_t fChannel = 0; // 7 bits
38 };
39
40
47 std::vector<double> fToTshift;
48 uint64_t fTimeOffset = 0.;
49 };
50
51
57 struct UnpackPar {
58 std::map<uint32_t, UnpackElinkPar> fElinkParams = {};
59 };
60
61
68 uint32_t fNumDebugMessage = 0;
75 uint32_t fNumErrWildEpoch = 0;
76 uint32_t fNumErrWildTdcTime = 0;
77 uint32_t fNumErrTdcErrorWord = 0;
81 uint32_t fNumErrInvalidHubId = 0;
82 uint32_t fNumErrInvalidHubSize = 0;
85
95 std::string print() const
96 {
97 std::stringstream ss;
98 ss << "errors " << fNumDebugMessage << " | " << fNumCtsAndUnmappedDirich << " | " << fNumErrInvalidFirstMessage
99 << " | " << fNumErrInvalidSecondMessage << " | " << fNumErrInvalidLastMessage << " | "
101 << fNumErrWildTdcTime << " | " << fNumErrTdcErrorWord << " | " << fNumErrChannelOutOfBounds << " | "
104 return ss.str();
105 }
106 };
107
115 };
116
117 class UnpackMS : public UnpackMSBase<CbmRichDigi, UnpackMonitorData, UnpackAuxData> {
118
119 public:
121 UnpackMS(const UnpackPar& pars);
122
123
125 ~UnpackMS() override;
126
127
134 Result_t operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
135 const uint64_t tTimeslice) const override;
136
140 void SetParams(std::unique_ptr<UnpackPar> params) { fParams = *(std::move(params)); }
141
142 private:
143 struct MSContext {
144 u64 cbmTimeMS = 0; // CbmTime of MS. Used to get time offset of subtriggers to MS start
147
148 // FIXME: Magic number, should be named.
149 //
150 // Comment from RICH expert (Martin Beyer):
151 // > This number will also be valid for the Cbm Rich, 1 Rich backplane contains max. 12 DiRICHes.
152 // > For the Cbm Rich the number of backplanes will be scaled
153 // > up. Nevertheless it is very likely that fewer DiRiches(maybe not constant)
154 // > per backplane are used in the day1 setup.
155 double prevLastCh0ReTime[13]; // 12 DiRICHes chnl0 + 1 CTS chnl0
156 double mbsCorr = 0.;
157
158 uint16_t currentSubSubEvent = 0;
159
160 std::vector<CbmRichDigi> digis;
162 };
163
164 private:
165 void ProcessTrbPacket(MicrosliceReader& reader, MSContext& ctx) const;
166
167 void ProcessHubBlock(MicrosliceReader& reader, MSContext& ctx) const;
168
169 int ProcessCtsHeader(MicrosliceReader& reader, uint32_t subSubEventSize, uint32_t subSubEventId) const;
170
171 void ProcessSubSubEvent(MicrosliceReader& reader, int nofTimeWords, uint32_t subSubEventId, MSContext& ctx) const;
172
173 bool ProcessTimeDataWord(uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector<double>& raisingTime,
174 MSContext& ctx) const;
175
176 TdcWordType GetTdcWordType(uint32_t tdcWord) const;
177
178 TdcTimeData ProcessTimeData(uint32_t tdcWord) const;
179
180 uint32_t ProcessEpoch(uint32_t tdcWord) const;
181
182 uint16_t ProcessHeader(uint32_t tdcWord) const;
183
184 uint16_t ProcessTrailer(uint32_t tdcWord) const;
185
186 void WriteOutputDigi(int32_t fpgaID, int32_t channel, double time, double tot, MSContext& ctx) const;
187
188 double CalculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine) const;
189
190 int32_t GetPixelUID(int32_t fpgaID, int32_t ch) const;
191
192 bool CheckMaskedDiRICH(int32_t subSubEventId) const;
193
194 private:
196
197 std::vector<int32_t> fMaskedDiRICHes;
198
199 bool fbDoToTCorr = true; //activates ToT correction from parameter file
200
201 // uint64_t fCbmTimeMS;
202 // uint64_t fCbmTimePacket;
203
204 // double fMbsCorr = 0.;
205 // double fPrevLastCh0ReTime[13]; // 12 DiRICHes chnl0 + 1 CTS chnl0
206 // uint16_t fCurrentSubSubEvent = 0;
207
208 double fToTMin = -20.;
209 double fToTMax = 100.;
210 };
211
212
214 private:
215 const uint8_t* fData = nullptr;
216 size_t fSize = 0;
217 size_t fOffset = 0; // offset in bytes
218 size_t fWordCounter = 0;
219 uint32_t fCurWord = 0;
220
221 public:
222 void SetData(const uint8_t* data, size_t size)
223 {
224 fData = data;
225 fSize = size;
226 fOffset = 0;
227 fWordCounter = 0;
228 fCurWord = 0;
229 }
230
231 const uint8_t* GetData() { return fData; }
232 size_t GetSize() { return fSize; }
233 size_t GetOffset() { return fOffset; }
234 size_t GetWordCounter() { return fWordCounter; }
235 uint32_t GetCurWord() { return fCurWord; }
236
237 std::string GetWordAsHexString(uint32_t word)
238 {
239 std::stringstream stream;
240 stream << "0x" << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex << word;
241 return stream.str();
242 }
243
244 uint32_t NextWord()
245 {
246 uint32_t i = ((uint32_t*) (fData + fOffset))[0];
247 //swap bytes
248 i = (i >> 24) | ((i << 8) & 0x00FF0000) | ((i >> 8) & 0x0000FF00) | (i << 24);
249 fOffset += 4;
250 fWordCounter++;
251 fCurWord = i;
252 return i;
253 }
254
256 {
257 uint32_t nextWord = ((uint32_t*) (fData + fOffset))[0];
258 if (nextWord == 0xffffffff) return true;
259 return false;
260 }
261
262 bool IsLastSubSubEvent(uint32_t subSubEventSize)
263 {
264 uint32_t i = ((uint32_t*) (fData + fOffset + 4 * subSubEventSize))[0];
265 i = (i >> 24) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | (i << 24);
266 if (i == 0x00015555) return true;
267 return false;
268 }
269 };
270
271} // namespace cbm::algo::rich
static constexpr size_t size()
Definition KfSimdPseudo.h:2
std::tuple< std::vector< Digi_t >, Monitor_t, Aux_t > Result_t
void SetData(const uint8_t *data, size_t size)
std::string GetWordAsHexString(uint32_t word)
bool IsLastSubSubEvent(uint32_t subSubEventSize)
double CalculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine) const
bool CheckMaskedDiRICH(int32_t subSubEventId) const
UnpackPar fParams
Parameter container.
uint32_t ProcessEpoch(uint32_t tdcWord) const
UnpackMS(const UnpackPar &pars)
Construct from parameters.
std::vector< int32_t > fMaskedDiRICHes
void ProcessTrbPacket(MicrosliceReader &reader, MSContext &ctx) const
void WriteOutputDigi(int32_t fpgaID, int32_t channel, double time, double tot, MSContext &ctx) const
TdcWordType GetTdcWordType(uint32_t tdcWord) const
int ProcessCtsHeader(MicrosliceReader &reader, uint32_t subSubEventSize, uint32_t subSubEventId) const
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
~UnpackMS() override
Destructor.
void ProcessSubSubEvent(MicrosliceReader &reader, int nofTimeWords, uint32_t subSubEventId, MSContext &ctx) const
int32_t GetPixelUID(int32_t fpgaID, int32_t ch) const
TdcTimeData ProcessTimeData(uint32_t tdcWord) const
void SetParams(std::unique_ptr< UnpackPar > params)
Set the parameter container.
void ProcessHubBlock(MicrosliceReader &reader, MSContext &ctx) const
bool ProcessTimeDataWord(uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector< double > &raisingTime, MSContext &ctx) const
uint16_t ProcessTrailer(uint32_t tdcWord) const
uint16_t ProcessHeader(uint32_t tdcWord) const
std::uint64_t u64
Definition Definitions.h:23
RICH Unpacking parameters for one eLink / ASIC.
std::vector< double > fToTshift
TOT shift for different channels.
uint64_t fTimeOffset
Time calibration parameter.
std::vector< CbmRichDigi > digis
Monitoring data for RICH unpacking.
uint32_t fNumErrWildHeaderMessage
TDC header in invalid position.
uint32_t fNumErrInvalidSecondMessage
Second message is not EPOCH.
uint32_t fNumErrWildEpoch
TDC epoch in invalid position.
uint32_t fNumErrInvalidHubSize
Premature end of hub block.
uint32_t fNumErrTdcErrorWord
TDC word of error type.
uint32_t fNumErrChannelOutOfBounds
TDC channel out of bounds.
uint32_t fNumErrOrphanRecovTimeData
TimeData in last position (not TRAILER) but not creating a Digi.
uint32_t fNumErrExcessLastWords
More than expected trailing words.
uint32_t fNumCtsAndUnmappedDirich
Dirich address is unknown (or is of a CTS)
uint32_t fNumErrInvalidLastMessage
Last message is not TRAILER.
uint32_t fNumSkippedSubsubevent
Whenever subsubevent skipped due to error (but not mask)
uint32_t fNumErrInvalidFirstMessage
First message is not HEADER.
uint32_t fNumErrInvalidHubId
"SubSubEvent" has invalid ID
uint32_t fNumErrWildTdcTime
TDC time (digi) in invalid position.
uint32_t fNumDebugMessage
Received debug messages.
uint32_t fNumWarnRecoveredLastDigi
TimeData in last position (not TRAILER) led to recovered Digi.
uint32_t fNumErrWildTrailerMessage
TDC trailer in invalid position.
Parameters required for the RICH unpacking (specific to one component)
std::map< uint32_t, UnpackElinkPar > fElinkParams
Map TRB address to elink params.