CbmRoot
Loading...
Searching...
No Matches
trd/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, Dominik Smith [committer], David Schledt */
4
5#pragma once
6
7#include "CbmTrdDigi.h"
10#include "MicrosliceDescriptor.hpp"
11#include "Timeslice.hpp"
12#include "UnpackMSBase.h"
13
14#include <cmath>
15#include <memory>
16#include <sstream>
17
18namespace cbm::algo::trd
19{
26 std::vector<uint32_t> fChanAddress;
27 uint32_t fAddress;
28 uint64_t fTimeOffset = 0.;
29 };
30
37 std::vector<UnpackElinkPar> fElinkParams = {};
38 };
39
45 struct UnpackPar {
46 bool fUseBaselineAvg = true;
47 float_t fMaxAdcToEnergyCal = 1.0;
48 uint32_t fNumChansPerAsic = 0;
49 uint32_t fNumAsicsPerModule = 0;
50 std::vector<UnpackCrobPar> fCrobParams = {};
51 };
52
53
60 size_t fNumNonMajorTsMsb = 0;
61 size_t fNumCreatedRawMsgs = 0;
62 size_t fNumEpochMsgs = 0;
64 size_t fNumElinkMis = 0;
65 size_t fNumCorruptEom = 0;
66 size_t fNumWildRda = 0;
67 size_t fNumWildEom = 0;
68 size_t fNumUnknownWords = 0;
69 size_t fNumMissingEom = 0;
70 size_t fNumWildNul = 0;
71 size_t fNumCrcValidFlags = 0;
74 size_t fNumDataErrorFlags = 0;
75
76 bool HasErrors()
77 {
81 return (numErrors > 0 ? true : false);
82 }
83 std::string print()
84 {
85 std::stringstream ss;
86 ss << " stats " << fNumNonMajorTsMsb << " | " << fNumCreatedRawMsgs << " | " << fNumEpochMsgs << " | "
87 << fNumCreatedInfoMsgs << " errors " << fNumElinkMis << " | " << fNumCorruptEom << " | " << fNumWildRda
88 << " | " << fNumWildEom << " | " << fNumUnknownWords << " | " << fNumMissingEom << " | " << fNumWildNul
89 << " | " << fNumCrcValidFlags << " | " << fNumOverflowFlimFlags << " | " << fNumOverflowUserFlags << " | "
90 << fNumDataErrorFlags << " | ";
91 return ss.str();
92 }
93 };
94
102 };
103
109 template<uint8_t sys_ver>
110 class UnpackMS : public UnpackMSBase<CbmTrdDigi, UnpackMonitorData, UnpackAuxData> {
111
112 public:
114 UnpackMS(const UnpackPar& pars) : fParams(pars) {}
115
116
118 ~UnpackMS() override = default;
119
120
127 Result_t operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
128 const uint64_t tTimeslice) const override;
129
133 void SetParams(std::unique_ptr<UnpackPar> params) { fParams = *(std::move(params)); }
134
135 private: // Types
136 struct MsContext {
139
141 size_t fLastFulltime = 0;
142
144 std::vector<std::uint8_t> fNrTsMsbVec = {};
145 };
146
147 private: // members
149
155 void digestOutput(std::unique_ptr<CbmTrdDigi> digi, CbmTrdRawMessageSpadic raw);
156
162 Spadic::MsInfoType digestBufInfoFlags(const std::uint32_t frame) const;
163
169 void digestMsFlags(const std::uint16_t flags, UnpackMonitorData& monitor) const;
170
175 void digestInfoMsg(const std::uint32_t frame) const;
176
183 std::int16_t extractSample(size_t* adcbuffer, size_t* nadcbits) const;
184
194 std::float_t extractAvgSample(size_t* adcbuffer, size_t* nadcbits) const;
195
197 Spadic::MsInfoType getInfoType(const std::uint32_t frame) const;
198
206 std::uint8_t getTsMsb(const std::uint32_t frame, UnpackMonitorData& monitor) const;
207
217 CbmTrdRawMessageSpadic makeRaw(const std::uint32_t frame, std::uint16_t criId, std::uint8_t crobId,
218 std::uint16_t elinkId, std::uint8_t istream, MsContext& ctx) const;
219
226
232
237 CbmTrdDigi makeDigi(Spadic::FexWord<sys_ver> fw, size_t fMsStartTimeRel) const;
238
244 uint64_t GetBinTimeShift(const std::vector<std::int16_t>* /*samples*/) const { return 0.; };
245
251 std::float_t GetMaxAdcValue(const std::vector<std::int16_t>* samples) const;
252
259 float_t GetBaseline(const std::vector<std::int16_t>* samples) const;
260
262 Spadic::MsMessageType getMessageType(const std::uint32_t frame) const;
263
265 static constexpr std::uint8_t fBytesPerWord = 8;
266
270 static constexpr std::uint8_t fStreamsPerWord = 2;
271
273 static constexpr size_t fNrOfPresamples = 1;
274
276 static constexpr float_t fAsicClockCycle = 62.5;
277
279 static constexpr std::uint16_t fTsMsbLength = 16000;
280
282 static constexpr size_t fTsMsbLengthCC = fTsMsbLength / fAsicClockCycle;
283
285 static constexpr size_t fPeakingBinMin = fNrOfPresamples;
286
293 static constexpr size_t fPeakingBinMax = static_cast<size_t>(120.0 / fAsicClockCycle + fNrOfPresamples + 5);
294 };
295
296} // namespace cbm::algo::trd
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
std::tuple< std::vector< Digi_t >, Monitor_t, Aux_t > Result_t
static constexpr std::uint16_t fTsMsbLength
length of one ts_msb in [ns]
float_t GetBaseline(const std::vector< std::int16_t > *samples) const
Get the Baseline value The digi charge is an unsigned. Hence, we need to get the baseline to 0.
Spadic::MsMessageType getMessageType(const std::uint32_t frame) const
Identify the message type of a given 32bit frame inside a Microslice.
CbmTrdDigi makeDigi(CbmTrdRawMessageSpadic raw, MsContext &ctx) const
Create an actual digi from the raw message.
Spadic::MsInfoType getInfoType(const std::uint32_t frame) const
Identify the InfoType of a 64bit InfoMessage word inside a Microslice.
std::float_t GetMaxAdcValue(const std::vector< std::int16_t > *samples) const
Get the MaxAdc value.
std::int16_t extractSample(size_t *adcbuffer, size_t *nadcbits) const
Extract one adc sample from a given adcbuffer.
static constexpr std::uint8_t fStreamsPerWord
Number of streams per word.
static constexpr size_t fTsMsbLengthCC
length of one ts_msb in [cc]
CbmTrdRawMessageSpadic makeRaw(const std::uint32_t frame, std::uint16_t criId, std::uint8_t crobId, std::uint16_t elinkId, std::uint8_t istream, MsContext &ctx) const
Create a CbmTrdRawMessageSpadic from the hit message input.
Spadic::MsInfoType digestBufInfoFlags(const std::uint32_t frame) const
Digest the aditional flags stored in the 4 "cccc" bits of the EPO messages.
static CbmTrdDigi::eTriggerType GetDigiTriggerType(Spadic::eTriggerType tt)
Get the Digi Trigger Type from the raw message triggertype.
~UnpackMS() override=default
Destructor.
static constexpr size_t fPeakingBinMax
Last sample to look for the max adc Default value is set based on the Shaping time + 5 samples safety...
void SetParams(std::unique_ptr< UnpackPar > params)
Set the parameter container.
uint64_t GetBinTimeShift(const std::vector< std::int16_t > *) const
Get the Bin Time Shift value.
static constexpr size_t fPeakingBinMin
First sample to look for the max adc.
static constexpr size_t fNrOfPresamples
Number of samples not considered for max adc.
static constexpr float_t fAsicClockCycle
Clock length of Spadic in ns.
void digestInfoMsg(const std::uint32_t frame) const
Digest a info message run all default information forwarding from the msg.
std::float_t extractAvgSample(size_t *adcbuffer, size_t *nadcbits) const
Extract the baseline average sample from a given adcbuffer. Depending on the Spadic settings sample-0...
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
UnpackPar fParams
Parameter container.
UnpackMS(const UnpackPar &pars)
Construct from parameters.
std::uint8_t getTsMsb(const std::uint32_t frame, UnpackMonitorData &monitor) const
Get the ts_msb information from the TS_MSB(kEPO) frame. We take the first of the 3 The 3 redundant TS...
static constexpr std::uint8_t fBytesPerWord
Bytes per spadic frame stored in the microslices.
void digestMsFlags(const std::uint16_t flags, UnpackMonitorData &monitor) const
Digest the flags of the currently unpacked µSlice.
void digestOutput(std::unique_ptr< CbmTrdDigi > digi, CbmTrdRawMessageSpadic raw)
Handle the output created by the explicit algorithms. E.g. write to output vectors.
TRD Unpacking parameters for one CROB.
std::vector< UnpackElinkPar > fElinkParams
Parameters for each eLink.
TRD Unpacking parameters for one eLink.
std::vector< uint32_t > fChanAddress
CbmTrdAddress for different channels.
uint32_t fAddress
Asic address.
uint64_t fTimeOffset
Time calibration parameter.
std::vector< std::uint8_t > fNrTsMsbVec
Counter for the ts_msb used to reconstruct the time.
size_t fLastFulltime
Time of the last succesful digest hit message.
size_t fMsStartTimeRelCC
Start time of the current µSlice relative to the Timeslice start time in Spadic CC.
Monitoring data for TRD unpacking.
size_t fNumOverflowFlimFlags
counter for inf/error flags from the µSlices
size_t fNumUnknownWords
Number of unknown words.
size_t fNumCrcValidFlags
counter for inf/error flags from the µSlices
size_t fNumCreatedRawMsgs
counter of created raw messages
size_t fNumWildEom
Number of eom frames outside of a SOM frame range.
size_t fNumNonMajorTsMsb
Counter for the ts_msb used to reconstruct the time.
size_t fNumWildRda
Number of rda frames outside of a SOM frame range.
size_t fNumOverflowUserFlags
counter for inf/error flags from the µSlices
size_t fNumCorruptEom
Number of corrupted EOM frames.
size_t fNumDataErrorFlags
counter for inf/error flags from the µSlices
size_t fNumElinkMis
Number of SOM to RDA/EOM mismatches.
size_t fNumMissingEom
Number of missing EOM frames to finish a SOM frame.
size_t fNumEpochMsgs
counter of created raw messages
size_t fNumWildNul
Number of wild null words, should only appear at the end of a µSlice.
size_t fNumCreatedInfoMsgs
counter of created info messages
Parameters required for the TRD unpacking (specific to one component)
float_t fMaxAdcToEnergyCal
max adc to energy in keV
std::vector< UnpackCrobPar > fCrobParams
Parameters for each CROB.
uint32_t fNumAsicsPerModule
Number of ASICS per module.
uint32_t fNumChansPerAsic
Number of channels per ASIC.
bool fUseBaselineAvg
Is baseline average function of Spadic activated.