Project
Loading...
Searching...
No Matches
StuDecoder.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#include <cstring>
12#include <iomanip>
13#include <iostream>
14#include <boost/format.hpp>
15#include "InfoLogger/InfoLogger.hxx"
20
21using namespace o2::emcal;
22using namespace o2::emcal::STUparam;
23
24StuDecoder::StuDecoder(RawReaderMemory& reader) : mRawReader(reader)
25{
26}
27
28void StuDecoder::init()
29{
30
31 auto& header = mRawReader.getRawHeader();
32 auto feeID = o2::raw::RDHUtils::getFEEID(header);
33
34 if (!((feeID == FeeID[STUtype_t::ESTU]) || (feeID == FeeID[STUtype_t::DSTU]))) {
36 }
37
38 mSTU = STUtype_t::ESTU;
39 if (feeID == FeeID[STUtype_t::DSTU]) {
40 mSTU = STUtype_t::DSTU;
41 }
42
43 // STU payload structure is described in JIRA-EMCAL-562
44 auto& buffer = mRawReader.getPayload().getPayloadWords();
45 bool vbit = ((buffer[0] >> 31) & 0x1); // payload version control bit
46 if (!vbit) { // old payloads version cannot be decoded with this method; discard 2022 early data
48 }
49
50 mIsFullPayload = (buffer[1] & 0x1);
51
52 auto payloadsize = mRawReader.getPayload().getPayloadWords().size();
53
54 if (mIsFullPayload) {
55 if (payloadsize != getPaloadSizeFull()) {
56 // std::cout << "ERROR: Wrong payload size (=" << std::dec << payloadsize << ") for FullPaload \n";
58 }
59 }
60
61 else {
62 if (payloadsize != getPaloadSizeShort()) {
63 // std::cout << "ERROR: Wrong payload size (=" << std::dec << payloadsize << ") for ShortPaload \n";
65 }
66 }
67
68 if (mDebug >= 3) {
69 std::cout << "==== paylaod size ===\n";
70 int currentpos = 0;
71 while ((currentpos < buffer.size())) {
72 auto currentword = buffer[currentpos++];
73 std::cout << std::dec << (currentpos - 1) << ") 0x" << std::hex << currentword << std::endl;
74 }
75 }
76}
77
79{
80
81 init();
82
83 auto& buffer = mRawReader.getPayload().getPayloadWords();
84
85 mCFGWord0 = buffer[0];
86 mCFGWord1 = buffer[1];
87 mL0mask = buffer[2];
88 mL1GammaHighThreshold = buffer[3];
89 mShortPayloadRate = buffer[4];
90 mL0bits = buffer[5];
91 mL1JetHighThreshold = buffer[6];
92 mL1GammaLowThreshold = buffer[9];
93 mL1JetLowThreshold = buffer[12];
94 mCFGword13 = buffer[13];
95 mRegionEnable = buffer[14];
96 mFrameReceived = buffer[15];
97 mCFGword16 = buffer[16];
98
99 // decode L1Jet High/Low indices
100 int offset = getCFGWords();
101 decodeL1JetPatchIndices(&buffer[offset]);
102
103 // decode L1Gamma High/Low indices
104 offset += (2 * getL1JetIndexWords() + getL0indexWords());
105 decodeL1GammaPatchIndices(&buffer[offset]);
106
107 if (!isFullPayload()) {
108 return;
109 }
110
111 // decode FastOR data
112 offset += (2 * getL1GammaIndexWords());
113 decodeFastOrADC(&buffer[offset]);
114
115 // std::cout << "lastWord = 0x" << std::hex << buffer[offset + getRawWords()] << std::endl;
116 return;
117}
118
119void StuDecoder::decodeL1JetPatchIndices(const uint32_t* buffer)
120{
121 int offset = getL1JetIndexWords(); // offset for Jet Low threshold
122
123 if (mDebug >= 2) {
124 for (int i = 0; i < offset; i++) {
125 std::cout << std::dec << i << ") 0x" << std::hex << buffer[i] << " <- Jet-high-word\n";
126 }
127 for (int i = 0; i < offset; i++) {
128 std::cout << std::dec << i << ") 0x" << std::hex << buffer[offset + i] << " <- Jet-low-word\n";
129 }
130 }
131
132 int nSubregionEta = getSubregionsEta();
133 int nSubregionPhi = getSubregionsPhi();
134 bool isFired = false;
135
136 int jetSize = 2 + getParchSize(); // 2 for 2x2-patch, 4 for 4x4=patch
137
138 for (Int_t ix = 0; ix < nSubregionEta - (jetSize - 1); ix++) {
139 uint32_t row_JetHigh = buffer[ix];
140 uint32_t row_JetLow = buffer[ix + offset];
141 for (Int_t iy = 0; iy < nSubregionPhi - (jetSize - 1); iy++) {
142 isFired = (mSTU == STUtype_t::ESTU) ? (row_JetHigh & (1 << (nSubregionPhi - jetSize - iy))) : (row_JetHigh & (1 << iy));
143 if (isFired) {
144 mL1JetHighPatchIndex.push_back(((ix << 8) & 0xFF00) | (iy & 0xFF));
145 }
146 isFired = (mSTU == STUtype_t::ESTU) ? (row_JetLow & (1 << (nSubregionPhi - jetSize - iy))) : (row_JetLow & (1 << iy));
147 if (isFired) {
148 mL1JetLowPatchIndex.push_back(((ix << 8) & 0xFF00) | (iy & 0xFF));
149 }
150 }
151 }
152
153 return;
154}
155
156void StuDecoder::decodeL1GammaPatchIndices(const uint32_t* buffer)
157{
158 const int offset = getL1GammaIndexWords(); // offset for Gamma Low threshold
159
160 if (mDebug >= 2) {
161 for (int i = 0; i < offset; i++) {
162 std::cout << std::dec << i << ") 0x" << std::hex << buffer[i] << " <- Gamma-high-word\n";
163 }
164 for (int i = 0; i < offset; i++) {
165 std::cout << std::dec << i << ") 0x" << std::hex << buffer[offset + i] << " <- Gamma-low-word\n";
166 }
167 }
168
169 const int nTRU = getNumberOfTRUs();
170 const int nTRU2 = getNumberOfTRUs() / 2;
171
172 unsigned short gammaHigh[nTRU][TRUparam::NchannelsOverPhi];
173 unsigned short gammaLow[nTRU][TRUparam::NchannelsOverPhi];
174
175 for (Int_t iphi = 0; iphi < TRUparam::NchannelsOverPhi / 2; iphi++) {
176 for (Int_t itru = 0; itru < nTRU2; itru++) {
177 gammaHigh[2 * itru][2 * iphi] = (buffer[iphi * nTRU2 + itru] >> 0 & 0xFF);
178 gammaHigh[2 * itru][2 * iphi + 1] = (buffer[iphi * nTRU2 + itru] >> 8 & 0xFF);
179 gammaHigh[2 * itru + 1][2 * iphi] = (buffer[iphi * nTRU2 + itru] >> 16 & 0xFF);
180 gammaHigh[2 * itru + 1][2 * iphi + 1] = (buffer[iphi * nTRU2 + itru] >> 24 & 0xFF);
181
182 gammaLow[2 * itru][2 * iphi] = (buffer[offset + iphi * nTRU2 + itru] >> 0 & 0xFF);
183 gammaLow[2 * itru][2 * iphi + 1] = (buffer[offset + iphi * nTRU2 + itru] >> 8 & 0xFF);
184 gammaLow[2 * itru + 1][2 * iphi] = (buffer[offset + iphi * nTRU2 + itru] >> 16 & 0xFF);
185 gammaLow[2 * itru + 1][2 * iphi + 1] = (buffer[offset + iphi * nTRU2 + itru] >> 24 & 0xFF);
186 }
187 }
188
189 for (Int_t iphi = 0; iphi < TRUparam::NchannelsOverPhi; iphi++) {
190 for (Int_t ieta = 0; ieta < TRUparam::NchannelsOverEta; ieta++) {
191 // loop over TRUs of Full or 2/3-size SMs
192 for (Int_t itru = 0; itru < (nTRU - 2); itru++) {
193 if ((gammaHigh[itru][iphi] >> ieta) & 0x1) {
194 mL1GammaHighPatchIndex.push_back(((iphi << 10) & 0x7C00) | ((ieta << 5) & 0x03E0) | ((itru << 0) & 0x001F));
195 }
196 if ((gammaLow[itru][iphi] >> ieta) & 0x1) {
197 mL1GammaLowPatchIndex.push_back(((iphi << 10) & 0x7C00) | ((ieta << 5) & 0x03E0) | ((itru << 0) & 0x001F));
198 }
199 }
200 // loop over TRUs of 1/3-size SMs
201 for (Int_t itru = (nTRU - 2); itru < nTRU; itru++) {
202 short iphi_tmp = (iphi % 2 + 2 * (int)(iphi / 6));
203 short ieta_tmp = (ieta + 8 * ((int)(iphi / 2) % 3));
204 if ((gammaHigh[itru][iphi] >> ieta) & 0x1) {
205 mL1GammaHighPatchIndex.push_back(((iphi_tmp << 10) & 0x7C00) | ((ieta_tmp << 5) & 0x03E0) | ((itru << 0) & 0x001F));
206 }
207 if ((gammaLow[itru][iphi] >> ieta) & 0x1) {
208 mL1GammaLowPatchIndex.push_back(((iphi_tmp << 10) & 0x7C00) | ((ieta_tmp << 5) & 0x03E0) | ((itru << 0) & 0x001F));
209 }
210 }
211 }
212 }
213
214 return;
215}
216
217void StuDecoder::decodeFastOrADC(const uint32_t* buffer)
218{
219 for (int i = 0; i < getRawWords(); i++) {
220 if (mDebug >= 2) {
221 std::cout << std::dec << i << ") 0x" << std::hex << buffer[i] << " <- FasrOR-word\n";
222 }
223 mFastOrADC.push_back(int16_t(buffer[i] & 0xFFFF));
224 mFastOrADC.push_back(int16_t(buffer[i] >> 16) & 0xFFFF);
225 }
226
227 return;
228}
229
231{
232
233 std::cout << "L1GammaHighThreshold:" << std::dec << getL1GammaHighThreshold() << std::endl;
234 std::cout << "L1JetHighThreshold :" << std::dec << getL1JetHighThreshold() << std::endl;
235 std::cout << "L1GammaLowThreshold :" << std::dec << getL1GammaLowThreshold() << std::endl;
236 std::cout << "L1JetLowThreshold :" << std::dec << getL1JetLowThreshold() << std::endl;
237 std::cout << "Rho :" << std::dec << getRho() << std::endl;
238 std::cout << "FrameReceivedSTU :" << std::dec << getFrameReceivedSTU() << std::endl;
239 std::cout << "RegionEnable :" << std::hex << "0x" << getRegionEnable() << std::endl;
240 std::cout << "FrameReceived :" << std::dec << getFrameReceived() << std::endl;
241 std::cout << "ParchSize :" << std::dec << getParchSize() << std::endl;
242 std::cout << "FWversion :" << std::hex << "0x" << getFWversion() << std::endl;
243
244 std::cout << "\n";
245}
int32_t i
const std::vector< uint32_t > & getPayloadWords() const
Get the payload words (as 32 bit words) contributing to the current payload.
Definition RawPayload.h:67
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)
Handling of STU reconstruction errors.
@ SHORT_PAYLOAD_SIZE_UNEXPECTED
short payload size unexpected
@ OLD_PAYLOAD_VERSION
unsupported old payload version
@ FEEID_UNEXPECTED
FeeID index unexpected.
@ FULL_PAYLOAD_SIZE_UNEXPECTED
full payload size unexpected
int32_t getL1GammaLowThreshold() const
Definition StuDecoder.h:47
StuDecoder(RawReaderMemory &reader)
Constructor.
int32_t getFrameReceivedSTU() const
Definition StuDecoder.h:50
bool isFullPayload() const
Definition StuDecoder.h:83
int32_t getRho() const
Definition StuDecoder.h:49
int32_t getFWversion() const
Definition StuDecoder.h:54
int32_t getL1GammaHighThreshold() const
Definition StuDecoder.h:45
int32_t getFrameReceived() const
Definition StuDecoder.h:52
int32_t getL1JetHighThreshold() const
Definition StuDecoder.h:46
int32_t getL1JetLowThreshold() const
Definition StuDecoder.h:48
int32_t getParchSize() const
Definition StuDecoder.h:53
void dumpSTUcfg() const
void decode()
Decode the STU stream.
int getNumberOfTRUs() const
Definition StuDecoder.h:58
int32_t getRegionEnable() const
Definition StuDecoder.h:51
GLuint buffer
Definition glcorearb.h:655
GLintptr offset
Definition glcorearb.h:660
constexpr int FeeID[2]
FEE_ID in RDH.
Definition Constants.h:125
constexpr int NchannelsOverEta
number of FastORs over Eta for full- and 2/3-size SMs
Definition Constants.h:141
constexpr int NchannelsOverPhi
number of FastORs over Phi for full- and 2/3-size SMs
Definition Constants.h:142
@ DSTU
DCAL STU.
Definition Constants.h:120
@ ESTU
EMCAL STU.
Definition Constants.h:119
const int iy
Definition TrackUtils.h:69
const int ix
Definition TrackUtils.h:69