CbmRoot
Loading...
Searching...
No Matches
trd2d/UnpackMS.h
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig, Alexandru Bercuci, Dominik Smith [committer] */
4#pragma once
5
6#include "CbmTrdDigi.h"
7#include "MicrosliceDescriptor.hpp"
8#include "UnpackMSBase.h"
9
10#include <array>
11#include <memory>
12#include <sstream>
13
14#define NFASPMOD 180
15#define NROBMOD 5
16#define NFASPROB NFASPMOD / NROBMOD
17#define NFASPCH 16
18#define NFASPPAD NFASPCH / 2
19
20#define FASP_EPOCH_LENGTH 128 // the length in clks of FASP epoch [1600ns @ 40MHz]
21
22namespace cbm::algo::trd2d
23{
24 enum class eMessageLength : int
25 {
26 kMessCh = 4,
27 kMessType = 1,
28 kMessTlab = 7,
29 kMessData = 14,
30 kMessFasp = 6,
31 kMessEpoch = 21
32 };
33
34 enum class eMessageVersion : uint8_t
35 {
36 kMessLegacy = 2,
37 kMess24 = 3,
38 };
39
40 enum class eMessageType : int
41 {
42 kData = 0,
43 kEpoch = 1,
44 kNone
45 };
46
48 static constexpr uint fAsicClockPeriod = 25;
49
51 // Constants
81 struct FaspMessage {
82 FaspMessage() = default;
83 FaspMessage(const FaspMessage&) = default;
84 FaspMessage(uint8_t c, uint8_t typ, uint8_t t, uint16_t d, uint8_t asic);
85
89 template<std::uint8_t mess_ver>
90 static eMessageType getType(uint32_t w);
91
92 std::string print() const;
93
97 template<std::uint8_t mess_ver>
98 void readDW(uint32_t w);
99
103 template<std::uint8_t mess_ver>
104 void readEW(uint32_t w);
105
106 uint8_t ch = 0;
108 uint8_t tlab = 0;
109 uint16_t data = 0;
110 uint32_t epoch = 0;
111 uint8_t fasp = 0;
112 };
113
120 int32_t fPadAddress;
121 bool fMask;
122 int8_t fDaqOffset = 0;
123 uint16_t fSignalThres = 0;
124 };
125
132 std::vector<UnpackChannelPar> fChanParams;
133 };
134
141 uint16_t tDelay = 0;
142 uint16_t tWindow = 0;
143 uint16_t lThreshold = 0;
144 uint16_t fSignalThres = 0;
145 };
146
153 bool fMask = false;
154 int8_t fDaqOffset = 0;
155 float fBaseline = 0.;
156 float fGainFee = -1.;
158 };
159
165 struct UnpackPar {
166 int32_t fSystemTimeOffset = 0;
167 uint16_t fModId = 0;
168 uint16_t fEqAdd = 0;
169 uint8_t fEqId = 0xff;
170 float fRefSignal = 900;
171 std::map<uint8_t, UnpackAsicPar> fAsicParams = {};
172 std::array<CalibChannelPar, NFASPMOD* NFASPCH> fCalibParams =
173 {};
175
177 void dump() const;
178
184 template<uint8_t ver>
185 uint8_t mapFaspId2Mod(uint8_t fasp_id) const;
186 };
187
188
196 uint32_t fNumIncompleteDigis = 0;
197 uint32_t fNumErrEndBitSet = 0;
198
200 {
201 uint32_t numErrors = fNumErrEndBitSet;
202 return (numErrors > 0 ? true : false);
203 }
204 std::string print()
205 {
206 std::stringstream ss;
207 ss << "stats " << fNumSelfTriggeredData << " | " << fNumIncompleteDigis << " | errors " << fNumErrEndBitSet
208 << " | ";
209 return ss.str();
210 }
211 };
212
220 };
221
227 template<std::uint8_t sys_ver>
228 class UnpackMS : public UnpackMSBase<CbmTrdDigi, UnpackMonitorData, UnpackAuxData> {
229
230 public:
232 UnpackMS(const UnpackPar& pars) : fParams(pars) {}
233
235 ~UnpackMS() override = default;
236
243 Result_t operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
244 const uint64_t tTimeslice) const override;
245
249 void SetParams(std::unique_ptr<UnpackPar> params) { fParams = *(std::move(params)); }
250
251 private: // Types
252 struct MsContext {
254
255 std::array<std::vector<CbmTrdDigi>, NFASPMOD* NFASPCH> fDigiBuffer = {
256 {}};
257 };
258
259 private: // members
261
262 bool pushDigis(std::vector<FaspMessage> messages, const uint64_t time, MsContext& ctx) const;
263
265 std::vector<CbmTrdDigi> FinalizeComponent(MsContext& ctx) const;
266 };
267
268
277 template<>
279 public UnpackMSBase<CbmTrdDigi, UnpackMonitorData, UnpackAuxData> {
280
281 public:
283 UnpackMS(const UnpackPar& pars) : fParams(pars) {}
284
286 ~UnpackMS() override = default;
287
288
295 Result_t operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
296 const uint64_t tTimeslice) const override;
297
301 void SetParams(std::unique_ptr<UnpackPar> params) { fParams = *(std::move(params)); }
302
303 private: // Types
304 struct MsContext {
306 std::array<std::vector<CbmTrdDigi>, NFASPMOD* NFASPPAD> fRobDigi = {
307 {}};
309 };
310
311 private: // members
312 bool pushDigis(std::vector<FaspMessage> messages, const uint64_t time, MsContext& ctx) const;
313
315 };
316
317} // namespace cbm::algo::trd2d
std::tuple< std::vector< Digi_t >, Monitor_t, Aux_t > Result_t
bool pushDigis(std::vector< FaspMessage > messages, const uint64_t time, MsContext &ctx) const
UnpackMS(const UnpackPar &pars)
Construct from parameters.
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
void SetParams(std::unique_ptr< UnpackPar > params)
Set the parameter container.
Unpack algorithm for TRD2D.
~UnpackMS() override=default
Destructor.
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
void SetParams(std::unique_ptr< UnpackPar > params)
Set the parameter container.
std::vector< CbmTrdDigi > FinalizeComponent(MsContext &ctx) const
Finalize component (e.g. copy from temp buffers)
UnpackMS(const UnpackPar &pars)
Construct from parameters.
bool pushDigis(std::vector< FaspMessage > messages, const uint64_t time, MsContext &ctx) const
UnpackPar fParams
Parameter container.
static constexpr uint fAsicClockPeriod
Clock period of FASP 12.5ns. Use 25ns follow by division by 2.
@ kMess24
unpacker version for 2-board FASPRO+GETS HW
TRD2D Calibration parameters for one Asic channel.
float fGainFee
gain correction wrt to reference
bool fMask
Flag for channel masking.
int8_t fDaqOffset
Time calibration parameter.
NoiseChannelPar noise
noise channel parametrisation
float fBaseline
baseline correction
Data structure for unpacking the FASP word.
uint8_t tlab
time of the digi inside the epoch
void readDW(uint32_t w)
Read DATA WORD and store the content locally.
uint32_t epoch
epoch id (not used for the moment)
uint8_t ch
ch id in the FASP
void readEW(uint32_t w)
Read EPOCH WORD and store the content locally.
uint8_t fasp
FASP id in the module.
eMessageType type
message type 0 = data, 1 = epoch (not used for the moment)
static eMessageType getType(uint32_t w)
Implementation of message type descriptor according to message version.
FaspMessage(const FaspMessage &)=default
TRD2D noise parameters for one Asic channel.
uint16_t fSignalThres
Signal threshold for independent - static noise.
uint16_t tWindow
time [clk] delay wrt to causing primary signal
uint16_t lThreshold
time [clk] window to search for noisy signal
TRD2D Unpacking parameters for one Asic.
std::vector< UnpackChannelPar > fChanParams
Parameters for different channels.
TRD2D Unpacking parameters for one Asic channel.
int32_t fPadAddress
Pad address for channel.
uint16_t fSignalThres
Signal threshold to remove ringing channels.
bool fMask
Flag for channel masking.
int8_t fDaqOffset
Time calibration parameter.
UnpackMonitorData fMonitor
Container for monitoring data.
std::array< std::vector< CbmTrdDigi >, NFASPMOD *NFASPCH > fDigiBuffer
uint32_t fNumSelfTriggeredData
word fulfills data & 0x2000
uint32_t fNumIncompleteDigis
incomplete digis left in pads after finalization
uint32_t fNumErrEndBitSet
Corrupted data with end bit set.
Parameters required for the TRD2D unpacking (specific to one component)
void dump() const
Write to the debug stream the content of the current param object.
uint8_t fEqId
Equipment (optical fiber) ID of component.
uint16_t fModId
Module ID of component.
int toff[NFASPMOD *NFASPPAD]
int32_t fSystemTimeOffset
Time calibration parameter.
float fRefSignal
reference signal for calibration
std::map< uint8_t, UnpackAsicPar > fAsicParams
Parameters for each ASIC.
std::array< CalibChannelPar, NFASPMOD *NFASPCH > fCalibParams
Parameters for each ASIC channel for each module.
uint8_t mapFaspId2Mod(uint8_t fasp_id) const
Calculate the module wise FASP id from the FASP id provided at the level of equipment Id (optical fib...
uint16_t fEqAdd
Equipment (optical fiber) address [HEX].
#define NFASPCH
#define NFASPPAD
#define NFASPMOD