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"
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 int64_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;
76
84 std::string print() const
85 {
86 std::stringstream ss;
87 ss << " stats " << fNumNonMajorTsMsb << " | " << fNumCreatedRawMsgs << " | " << fNumEpochMsgs << " | "
88 << fNumCreatedInfoMsgs << " errors " << fNumElinkMis << " | " << fNumCorruptEom << " | " << fNumWildRda
89 << " | " << fNumWildEom << " | " << fNumUnknownWords << " | " << fNumMissingEom << " | " << fNumWildNul
90 << " | " << fNumCrcValidFlags << " | " << fNumOverflowFlimFlags << " | " << fNumOverflowUserFlags << " | "
91 << fNumDataErrorFlags << " | " << fNumErrTimestampUnderflow << " | ";
92 return ss.str();
93 }
112 };
113
121 };
122
128 template<uint8_t sys_ver>
129 class UnpackMS : public UnpackMSBase<CbmTrdDigi, UnpackMonitorData, UnpackAuxData> {
130
131 public:
133 UnpackMS(const UnpackPar& pars) : fParams(pars) {}
134
135
137 ~UnpackMS() override = default;
138
139
146 Result_t operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
147 const uint64_t tTimeslice) const override;
148
152 void SetParams(std::unique_ptr<UnpackPar> params) { fParams = *(std::move(params)); }
153
154 private: // Types
155 struct MsContext {
158
160 size_t fLastFulltime = 0;
161
163 std::vector<uint8_t> fNrTsMsbVec = {};
164 };
165
166 private: // members
168
174 void digestOutput(std::unique_ptr<CbmTrdDigi> digi, CbmTrdRawMessageSpadic raw);
175
181 Spadic::MsInfoType digestBufInfoFlags(const uint32_t frame) const;
182
188 void digestMsFlags(const uint16_t flags, UnpackMonitorData& monitor) const;
189
194 void digestInfoMsg(const uint32_t frame) const;
195
202 int16_t extractSample(size_t* adcbuffer, size_t* nadcbits) const;
203
213 std::float_t extractAvgSample(size_t* adcbuffer, size_t* nadcbits) const;
214
216 Spadic::MsInfoType getInfoType(const uint32_t frame) const;
217
225 uint8_t getTsMsb(const uint32_t frame, UnpackMonitorData& monitor) const;
226
236 CbmTrdRawMessageSpadic makeRaw(const uint32_t frame, uint16_t criId, uint8_t crobId, uint16_t elinkId,
237 uint8_t istream, MsContext& ctx) const;
238
245
252
258 CbmTrdDigi makeDigi(Spadic::FexWord<sys_ver> fw, size_t fMsStartTimeRel, UnpackMonitorData& monitor) const;
259
265 uint64_t GetBinTimeShift(const std::vector<int16_t>* /*samples*/) const { return 0.; };
266
272 std::float_t GetMaxAdcValue(const std::vector<int16_t>* samples) const;
273
280 float_t GetBaseline(const std::vector<int16_t>* samples) const;
281
283 Spadic::MsMessageType getMessageType(const uint32_t frame) const;
284
286 static constexpr uint8_t fBytesPerWord = 8;
287
291 static constexpr uint8_t fStreamsPerWord = 2;
292
294 static constexpr size_t fNrOfPresamples = 1;
295
297 static constexpr float_t fAsicClockCycle = 62.5;
298
300 static constexpr uint16_t fTsMsbLength = 16000;
301
303 static constexpr size_t fTsMsbLengthCC = fTsMsbLength / fAsicClockCycle;
304
306 static constexpr size_t fPeakingBinMin = fNrOfPresamples;
307
314 static constexpr size_t fPeakingBinMax = static_cast<size_t>(120.0 / fAsicClockCycle + fNrOfPresamples + 5);
315 };
316
317} // 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
CbmTrdRawMessageSpadic makeRaw(const uint32_t frame, uint16_t criId, uint8_t crobId, uint16_t elinkId, uint8_t istream, MsContext &ctx) const
Create a CbmTrdRawMessageSpadic from the hit message input.
CbmTrdDigi makeDigi(CbmTrdRawMessageSpadic raw, MsContext &ctx, UnpackMonitorData &monitor) const
Create an actual digi from the raw message.
Spadic::MsInfoType getInfoType(const uint32_t frame) const
Identify the InfoType of a 64bit InfoMessage word inside a Microslice.
static constexpr uint8_t fStreamsPerWord
Number of streams per word.
static constexpr size_t fTsMsbLengthCC
length of one ts_msb in [cc]
float_t GetBaseline(const std::vector< int16_t > *samples) const
Get the Baseline value The digi charge is an unsigned. Hence, we need to get the baseline to 0.
Spadic::MsInfoType digestBufInfoFlags(const 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.
std::float_t GetMaxAdcValue(const std::vector< int16_t > *samples) const
Get the MaxAdc value.
~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.
void digestMsFlags(const uint16_t flags, UnpackMonitorData &monitor) const
Digest the flags of the currently unpacked micro-Slice.
uint64_t GetBinTimeShift(const std::vector< int16_t > *) const
Get the Bin Time Shift value.
static constexpr size_t fPeakingBinMin
First sample to look for the max adc.
uint8_t getTsMsb(const 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...
Spadic::MsMessageType getMessageType(const uint32_t frame) const
Identify the message type of a given 32bit frame inside a Microslice.
static constexpr size_t fNrOfPresamples
Number of samples not considered for max adc.
static constexpr float_t fAsicClockCycle
Clock length of Spadic in ns.
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...
static constexpr uint8_t fBytesPerWord
Bytes per spadic frame stored in the microslices.
Result_t operator()(const uint8_t *msContent, const fles::MicrosliceDescriptor &msDescr, const uint64_t tTimeslice) const override
Algorithm execution.
UnpackPar fParams
Parameter container.
static constexpr uint16_t fTsMsbLength
length of one ts_msb in [ns]
UnpackMS(const UnpackPar &pars)
Construct from parameters.
void digestInfoMsg(const uint32_t frame) const
Digest a info message run all default information forwarding from the msg.
void digestOutput(std::unique_ptr< CbmTrdDigi > digi, CbmTrdRawMessageSpadic raw)
Handle the output created by the explicit algorithms. E.g. write to output vectors.
int16_t extractSample(size_t *adcbuffer, size_t *nadcbits) const
Extract one adc sample from a given adcbuffer.
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.
int64_t fTimeOffset
Time calibration parameter.
size_t fLastFulltime
Time of the last succesful digest hit message.
std::vector< uint8_t > fNrTsMsbVec
Counter for the ts_msb used to reconstruct the time.
size_t fMsStartTimeRelCC
Start time of the current micro-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 micro-Slices
size_t fNumUnknownWords
Number of unknown words.
size_t fNumCrcValidFlags
counter for inf/error flags from the micro-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 micro-Slices
size_t fNumCorruptEom
Number of corrupted EOM frames.
size_t fNumDataErrorFlags
counter for inf/error flags from the micro-Slices
size_t fNumErrTimestampUnderflow
Underflow in 64 bit time stamp if offsetting.
void add(const UnpackMonitorData &rhs)
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 micro-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.