13#include <boost/format.hpp>
14#include "InfoLogger/InfoLogger.hxx"
21#include <fairlogger/Logger.h>
26 std::vector<o2::phos::Cell>& currentCellContainer, std::vector<o2::phos::Cell>& currentTRUContainer)
28 mOutputHWErrors.clear();
29 mOutputFitChi.clear();
33 mddl = o2::raw::RDHUtils::getFEEID(header);
39 if (payloadwords.size() == 0) {
44 gsl::span<const uint32_t> tmp(payloadwords.data(), payloadwords.size());
47 mOutputHWErrors.emplace_back(mddl, kGeneralSRUErr,
static_cast<char>(e.
getErrorType()));
52 readChannels(payloadwords, rawFitter, currentCellContainer, currentTRUContainer);
54 mOutputHWErrors.emplace_back(mddl, kGeneralTRUErr,
static_cast<char>(e));
61 std::vector<o2::phos::Cell>& currentCellContainer, std::vector<o2::phos::Cell>& currentTRUContainer)
66 mFlag4x4Bitset.reset();
67 mFlag2x2Bitset.reset();
73 while (currentpos < payloadend) {
74 auto currentword =
buffer[currentpos++];
76 if (header.
mMark != 1) {
77 if (currentword != 0) {
83 fec += kGeneralTRUErr * branch;
84 mOutputHWErrors.emplace_back(mddl, fec, 5);
90 if (numberofwords > payloadend - currentpos) {
96 fec += kGeneralTRUErr * branch;
97 mOutputHWErrors.emplace_back(mddl, fec, 6);
103 currentword =
buffer[currentpos++];
104 if ((currentword >> 30) != 0) {
109 fec = kGeneralSRUErr;
111 fec += kGeneralTRUErr * branch;
112 mOutputHWErrors.emplace_back(mddl, fec, 6);
115 mBunchwords.push_back((currentword >> 20) & 0x3FF);
118 mBunchwords.push_back((currentword >> 10) & 0x3FF);
121 mBunchwords.push_back(currentword & 0x3FF);
137 fec = kGeneralSRUErr;
139 fec += kGeneralTRUErr * branch;
140 mOutputHWErrors.emplace_back(mddl, fec, 7);
147 int currentsample = 0;
149 int bunchlength = mBunchwords[currentsample] - 2,
150 starttime = mBunchwords[currentsample + 1];
151 if (bunchlength < 0) {
154 fec += kGeneralTRUErr * branch;
155 mOutputHWErrors.emplace_back(mddl, fec, 6);
159 CaloRawFitter::FitStatus fitResult = rawFitter->
evaluate(gsl::span<uint16_t>(&mBunchwords[currentsample + 2], std::min((
unsigned long)bunchlength, mBunchwords.size() - currentsample - 2)));
160 currentsample += bunchlength + 2;
162 short chiAddr = absId;
163 chiAddr |= caloFlag << 14;
164 mOutputFitChi.emplace_back(chiAddr);
165 mOutputFitChi.emplace_back(
short(std::min(5.f * rawFitter->
getChi2(),
float(SHRT_MAX - 1))));
170 currentCellContainer.emplace_back(absId, std::max(rawFitter->
getAmp() -
offset, float(0)),
174 currentCellContainer.emplace_back(absId, std::max(rawFitter->
getAmp() -
offset, float(0)),
199 for (
const Cell cFlag : mTRUFlags) {
200 currentTRUContainer.emplace_back(cFlag);
201 currentTRUContainer.back().setType(
TRU4x4);
204 for (
int itru = 0; itru < 224; itru++) {
205 if (mTRUDigits[itru] > 0) {
207 truDigitPack dp = {mTRUDigits[itru]};
208 float a = dp.mAmp, t = dp.mTime;
209 currentTRUContainer.emplace_back(absId,
a, t,
TRU2x2);
218 for (
const Cell cFlag : mTRUFlags) {
220 if (matchTruDigits(cFlag,
sum)) {
221 currentTRUContainer.emplace_back(cFlag);
222 currentTRUContainer.back().setEnergy(
sum);
228bool AltroDecoder::hwToAbsAddress(
short hwAddr,
short& absId,
Mapping::CaloFlag& caloFlag)
236 short chip = hwAddr >> 4 & 0x7;
237 short fec = hwAddr >> 7 & 0xf;
238 short branch = hwAddr >> 11 & 0x1;
243 fec = kGeneralSRUErr;
244 mOutputHWErrors.emplace_back(mddl, fec + branch * kGeneralTRUErr, 2);
246 if (fec != 0 && (chip < 0 || chip > 4 || chip == 1)) {
248 mOutputHWErrors.emplace_back(mddl, fec + branch * kGeneralTRUErr, 3);
258 mOutputHWErrors.emplace_back(mddl, branch * kGeneralTRUErr + kGeneralSRUErr, 4);
264void AltroDecoder::readTRUDigits(
short absId,
int payloadSize)
266 int currentsample = 0;
269 while (currentsample < payloadSize) {
270 int bunchlength = mBunchwords[currentsample] - 2;
271 if (bunchlength < 0) {
273 mOutputHWErrors.emplace_back(mddl, kGeneralTRUErr,
static_cast<char>(1));
276 timeBin = mBunchwords[currentsample + 1] - bunchlength;
277 int istart = currentsample + 2;
278 int iend = std::min(istart + bunchlength - 2,
static_cast<int>(mBunchwords.size()));
279 for (
int i = istart;
i < iend;
i++) {
280 if (maxAmp < mBunchwords[
i]) {
281 maxAmp = mBunchwords[
i];
284 currentsample += bunchlength + 2;
286 truDigitPack dp = {0};
291 mTRUDigits[chId] = dp.mDataWord;
293void AltroDecoder::readTRUFlags(
short hwAddress,
int payloadSize)
305 const int kWordLength = 10;
306 int currentsample = 0;
307 while (currentsample < payloadSize) {
308 int bunchlength = mBunchwords[currentsample] - 2;
309 if (bunchlength < 1) {
311 mOutputHWErrors.emplace_back(mddl, kGeneralTRUErr,
static_cast<char>(1));
314 int timeBin = mBunchwords[currentsample + 1] + 1;
315 int istart = currentsample + 2;
316 int iend = istart + std::min(bunchlength,
static_cast<int>(mBunchwords.size()) - currentsample - 2);
317 currentsample += bunchlength + 2;
319 if (timeBin >= 128 || timeBin < 1) {
321 mOutputHWErrors.emplace_back(mddl, kGeneralTRUErr,
static_cast<char>(2));
325 if (timeBin <= iend - istart) {
327 mOutputHWErrors.emplace_back(mddl, kGeneralTRUErr,
static_cast<char>(2));
331 for (
int i = iend - 1;
i >= istart;
i--) {
333 short a = mBunchwords[
i];
336 for (Int_t bitIndex = 0; bitIndex < kWordLength; bitIndex++) {
342 if (hwAddress < 128) {
349 if ((
a & (1 << 2)) > 0) {
350 mFlag4x4Bitset[timeBin] = 1;
352 if ((
a & (1 << 3)) > 0) {
353 mFlag2x2Bitset[timeBin] = 1;
358 if (
a & (1 << bitIndex)) {
360 if (mFlag4x4Bitset[timeBin]) {
362 if ((channel > 90 && channel < 112) || channel > 202) {
366 if (mFlag2x2Bitset[timeBin]) {
374 if (mTRUFlags.size() > 0 && mTRUFlags.back().getTRUId() == absId) {
385bool AltroDecoder::matchTruDigits(
const Cell& cTruFlag,
float& sumAmp)
393 if (mTRUDigits[ch] > 0) {
394 truDigitPack dp = {mTRUDigits[ch]};
409 if (mTRUDigits[ch] != 0) {
410 truDigitPack dp = {mTRUDigits[ch]};
417 if (mTRUDigits[ch] != 0) {
418 truDigitPack dp = {mTRUDigits[ch]};
425 if (mTRUDigits[ch] != 0) {
426 truDigitPack dp = {mTRUDigits[ch]};
433 if (mTRUDigits[ch] != 0) {
434 truDigitPack dp = {mTRUDigits[ch]};
static const PHOSSimParams & Instance()
@ RCU_TRAILER_ERROR
RCU trailer cannot be decoded or invalid.
AltroDecoderError::ErrorType_t decode(RawReaderMemory &rawreader, CaloRawFitter *rawFitter, std::vector< o2::phos::Cell > &cellContainer, std::vector< o2::phos::Cell > &truContainer)
Decode the ALTRO stream.
void readChannels(const std::vector< uint32_t > &payloadwords, CaloRawFitter *rawFitter, std::vector< o2::phos::Cell > &cellContainer, std::vector< o2::phos::Cell > &truContainer)
Read channels for the current event in the raw buffer.
bool isOverflow() const
is last fitted sample has overflow
virtual FitStatus evaluate(gsl::span< short unsigned int > signal)
Evaluation Amplitude and TOF return status -1: not evaluated/empty bunch; 0: OK; 1: overflow; 4: sing...
float getChi2() const
Chi2/NDF of last performed fit.
float getTime() const
time in last fitted sample
float getAmp() const
amplitude in last fitted sample
ChannelType_t getType() const
static short truRelToAbsNumbering(const char *relId, short trigType)
static bool truAbsToRelNumbering(short truId, short trigType, char *relid)
static constexpr short NDDL
Total number of DDLs.
static Mapping * Instance()
static constexpr short NTRUBranchReadoutChannels
Number of TRU readout channels per branch.
static bool isTRUReadoutchannel(short hwAddress)
static constexpr short NCHANNELS
Number of channels starting from 1.
static constexpr short TRUFinalProductionChannel
ErrorStatus hwToAbsId(short ddl, short hw, short &absId, CaloFlag &caloFlag) const
convert hardware address to absId and caloFlag
ErrorType_t getErrorType() const noexcept
Access to error code.
void constructFromRawPayload(const gsl::span< const uint32_t > payloadwords)
Decode RCU trailer from the 32-bit words in the raw buffer.
unsigned int getTrailerSize() const
unsigned int getAltroCFGReg1() const
const std::vector< uint32_t > & getPayloadWords() const
Get the payload words (as 32 bit words) contributing to the current payload.
Reader for raw data produced by the Readout application in in-memory format.
const o2::header::RDHAny & getRawHeader() const
access to the raw header of the current page
const RawPayload & getPayload() const
access to the full raw payload (single or multiple DMA pages)
float sum(float s, o2::dcs::DataPointValue v)
GLsizei const GLfloat * value
GLboolean GLboolean GLboolean GLboolean a
@ TRU4x4
TRU channel, 4x4 trigger.
@ TRU2x2
TRU channel, 2x2 trigger.
float mTimeTick
ns to PHOS digitization step conversion