Skip to content

Commit 4ca72cf

Browse files
authored
[ALICE3] Fix code-check warnings (#17988)
1 parent 8e8285b commit 4ca72cf

10 files changed

Lines changed: 482 additions & 423 deletions

ALICE3/Core/FlatLutEntry.cxx

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
/// \file FlatLutEntry.cxx
13+
/// \brief Flat LUT implementation for compact helper tables used by the ALICE3 track smearing workflow.
14+
1215
#include "FlatLutEntry.h"
1316

1417
#include <Framework/Logger.h>
@@ -22,33 +25,33 @@
2225
#include <ios>
2326
#include <span>
2427

25-
namespace o2::delphes
28+
namespace o2::fastsim
2629
{
2730

2831
void lutEntry_t::print() const
2932
{
3033
LOGF(info, " nch = %f, eta = %f, pt = %f, valid = %s\n", nch, eta, pt, valid ? "true" : "false");
3134
LOGF(info, " eff = %f, eff2 = %f, itof = %f, otof = %f\n", eff, eff2, itof, otof);
3235
LOGF(info, " covm: ");
33-
for (int i = 0; i < 15; ++i) {
36+
for (int i = 0; i < kNumCovarianceTerms; ++i) {
3437
LOGF(info, "%f ", covm[i]);
3538
}
3639
LOGF(info, "\n");
3740
LOGF(info, " eigval: ");
38-
for (int i = 0; i < 5; ++i) {
41+
for (int i = 0; i < kNumEigenModes; ++i) {
3942
LOGF(info, "%f ", eigval[i]);
4043
}
4144
LOGF(info, "\n");
4245
LOGF(info, " eigvec:\n");
43-
for (int i = 0; i < 5; ++i) {
44-
for (int j = 0; j < 5; ++j) {
46+
for (int i = 0; i < kNumEigenModes; ++i) {
47+
for (int j = 0; j < kNumEigenModes; ++j) {
4548
LOGF(info, "%f ", eigvec[i][j]);
4649
}
4750
LOGF(info, "\n");
4851
}
4952
LOGF(info, " eiginv:\n");
50-
for (int i = 0; i < 5; ++i) {
51-
for (int j = 0; j < 5; ++j) {
53+
for (int i = 0; i < kNumEigenModes; ++i) {
54+
for (int j = 0; j < kNumEigenModes; ++j) {
5255
LOGF(info, "%f ", eiginv[i][j]);
5356
}
5457
LOGF(info, "\n");
@@ -57,23 +60,18 @@ void lutEntry_t::print() const
5760

5861
float map_t::fracPositionWithinBin(float val) const
5962
{
60-
float width = (max - min) / nbins;
61-
int bin;
62-
float returnVal = 0.5f;
63+
const float width = (max - min) / nbins;
64+
const int bin = find(val);
6365
if (log) {
64-
bin = static_cast<int>((std::log10(val) - min) / width);
65-
returnVal = ((std::log10(val) - min) / width) - bin;
66-
} else {
67-
bin = static_cast<int>((val - min) / width);
68-
returnVal = val / width - bin;
66+
return ((std::log10(val) - min) / width) - bin;
6967
}
70-
return returnVal;
68+
return val / width - bin;
7169
}
7270

7371
int map_t::find(float val) const
7472
{
75-
float width = (max - min) / nbins;
76-
int bin;
73+
const float width = (max - min) / nbins;
74+
int bin = 0;
7775
if (log) {
7876
bin = static_cast<int>((std::log10(val) - min) / width);
7977
} else {
@@ -93,7 +91,7 @@ void map_t::print() const
9391
LOGF(info, "nbins = %d, min = %f, max = %f, log = %s \n", nbins, min, max, log ? "on" : "off");
9492
}
9593

96-
bool lutHeader_t::check_version() const
94+
bool lutHeader_t::checkVersion() const
9795
{
9896
return (version == LUTCOVM_VERSION);
9997
}
@@ -120,7 +118,7 @@ void FlatLutData::initialize(const lutHeader_t& header)
120118
mEtaBins = header.etamap.nbins;
121119
mPtBins = header.ptmap.nbins;
122120

123-
const size_t headerSize = sizeof(lutHeader_t);
121+
constexpr size_t headerSize = sizeof(lutHeader_t);
124122
const size_t numEntries = static_cast<size_t>(mNchBins) * mRadBins * mEtaBins * mPtBins;
125123
const size_t entriesSize = numEntries * sizeof(lutEntry_t);
126124
const size_t totalSize = headerSize + entriesSize;
@@ -133,10 +131,10 @@ void FlatLutData::initialize(const lutHeader_t& header)
133131

134132
size_t FlatLutData::getEntryOffset(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const
135133
{
136-
static constexpr size_t headerSize = sizeof(lutHeader_t);
134+
static constexpr size_t HeaderSize = sizeof(lutHeader_t);
137135
const size_t linearIdx = getEntryIndex(nch_bin, rad_bin, eta_bin, pt_bin);
138-
static constexpr size_t entrySize = sizeof(lutEntry_t);
139-
return headerSize + linearIdx * entrySize;
136+
static constexpr size_t EntrySize = sizeof(lutEntry_t);
137+
return HeaderSize + linearIdx * EntrySize;
140138
}
141139

142140
const lutEntry_t* FlatLutData::getEntryRef(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const
@@ -153,12 +151,12 @@ lutEntry_t* FlatLutData::getEntry(int nch_bin, int rad_bin, int eta_bin, int pt_
153151

154152
const lutHeader_t& FlatLutData::getHeaderRef() const
155153
{
156-
return *reinterpret_cast<const lutHeader_t*>(mDataRef.data());
154+
return *static_cast<const lutHeader_t*>(static_cast<const void*>(mDataRef.data()));
157155
}
158156

159157
lutHeader_t& FlatLutData::getHeader()
160158
{
161-
return *reinterpret_cast<lutHeader_t*>(mData.data());
159+
return *static_cast<lutHeader_t*>(static_cast<void*>(mData.data()));
162160
}
163161

164162
void FlatLutData::updateRef()
@@ -200,26 +198,26 @@ void FlatLutData::view(const uint8_t* buffer, size_t size)
200198

201199
void FlatLutData::validateBuffer(const uint8_t* buffer, size_t size)
202200
{
203-
auto header = PreviewHeader(buffer, size);
204-
auto mNchBins = header.nchmap.nbins;
205-
auto mRadBins = header.radmap.nbins;
206-
auto mEtaBins = header.etamap.nbins;
207-
auto mPtBins = header.ptmap.nbins;
201+
auto header = previewHeader(buffer, size);
202+
const auto nchBins = header.nchmap.nbins;
203+
const auto radBins = header.radmap.nbins;
204+
const auto etaBins = header.etamap.nbins;
205+
const auto ptBins = header.ptmap.nbins;
208206

209-
size_t expectedSize = sizeof(lutHeader_t) + static_cast<size_t>(mNchBins) * mRadBins * mEtaBins * mPtBins * sizeof(lutEntry_t);
207+
const size_t expectedSize = sizeof(lutHeader_t) + static_cast<size_t>(nchBins) * radBins * etaBins * ptBins * sizeof(lutEntry_t);
210208

211209
if (size < expectedSize) {
212210
throw framework::runtime_error_f("Buffer size mismatch: expected %zu, got %zu", expectedSize, size);
213211
}
214212
}
215213

216-
lutHeader_t FlatLutData::PreviewHeader(const uint8_t* buffer, size_t size)
214+
lutHeader_t FlatLutData::previewHeader(const uint8_t* buffer, size_t size)
217215
{
218216
if (size < sizeof(lutHeader_t)) {
219217
throw framework::runtime_error_f("Buffer too small for LUT header: expected at least %zu, got %zu", sizeof(lutHeader_t), size);
220218
}
221-
const auto* header = reinterpret_cast<const lutHeader_t*>(buffer);
222-
if (!header->check_version()) {
219+
const auto* header = static_cast<const lutHeader_t*>(static_cast<const void*>(buffer));
220+
if (!header->checkVersion()) {
223221
throw framework::runtime_error_f("LUT header version mismatch: expected %d, got %d", LUTCOVM_VERSION, header->version);
224222
}
225223
return *header;
@@ -256,14 +254,14 @@ bool FlatLutData::isLoaded() const
256254
return ((!mData.empty()) || (!mDataRef.empty()));
257255
}
258256

259-
lutHeader_t FlatLutData::PreviewHeader(std::ifstream& file, const char* filename)
257+
lutHeader_t FlatLutData::previewHeader(std::ifstream& file, const char* filename)
260258
{
261259
lutHeader_t tempHeader;
262260
file.read(reinterpret_cast<char*>(&tempHeader), sizeof(lutHeader_t));
263261
if (file.gcount() != static_cast<std::streamsize>(sizeof(lutHeader_t))) {
264262
throw framework::runtime_error_f("Failed to read LUT header from %s", filename);
265263
}
266-
if (!tempHeader.check_version()) {
264+
if (!tempHeader.checkVersion()) {
267265
throw framework::runtime_error_f("LUT header version mismatch: expected %d, got %d", LUTCOVM_VERSION, tempHeader.version);
268266
}
269267
return tempHeader;
@@ -272,7 +270,7 @@ lutHeader_t FlatLutData::PreviewHeader(std::ifstream& file, const char* filename
272270
FlatLutData FlatLutData::loadFromFile(std::ifstream& file, const char* filename)
273271
{
274272
// Read header first
275-
lutHeader_t tempHeader = PreviewHeader(file, filename);
273+
lutHeader_t tempHeader = previewHeader(file, filename);
276274

277275
FlatLutData data;
278276

@@ -300,4 +298,4 @@ void FlatLutData::reset()
300298
resetDimensions();
301299
}
302300

303-
} // namespace o2::delphes
301+
} // namespace o2::fastsim

ALICE3/Core/FlatLutEntry.h

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,36 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
/// \file FlatLutEntry.h
13+
/// \brief Flat LUT data structures and buffer handling for the ALICE3 fast smearing backend.
14+
1215
#ifndef ALICE3_CORE_FLATLUTENTRY_H_
1316
#define ALICE3_CORE_FLATLUTENTRY_H_
1417

18+
#include <array>
1519
#include <cmath>
1620
#include <cstddef>
1721
#include <cstdint>
1822
#include <fstream>
1923
#include <span>
2024
#include <vector>
2125

22-
#define LUTCOVM_VERSION 20210801
26+
static constexpr int LUTCOVM_VERSION = 20210801;
2327

24-
namespace o2::delphes
28+
namespace o2::fastsim
2529
{
2630

31+
constexpr int kNumCovarianceTerms = 15;
32+
constexpr int kNumEigenModes = 5;
33+
typedef std::array<float, kNumCovarianceTerms> CovarianceArray;
34+
typedef std::array<float, kNumEigenModes> EigenArray;
35+
typedef std::array<double, kNumEigenModes> EigenArrayDouble;
36+
typedef std::array<std::array<float, kNumEigenModes>, kNumEigenModes> EigenMatrix;
37+
2738
/**
28-
* @brief Flat LUT entry structure
39+
* @brief Flat LUT entry structure.
2940
*/
30-
struct lutEntry_t {
41+
struct LutEntry {
3142
float nch = 0.f;
3243
float eta = 0.f;
3344
float pt = 0.f;
@@ -36,41 +47,46 @@ struct lutEntry_t {
3647
float eff2 = 0.f;
3748
float itof = 0.f;
3849
float otof = 0.f;
39-
float covm[15] = {0.f};
40-
float eigval[5] = {0.f};
41-
float eigvec[5][5] = {{0.f}};
42-
float eiginv[5][5] = {{0.f}};
50+
CovarianceArray covm = {0.f};
51+
EigenArray eigval = {0.f};
52+
EigenMatrix eigvec = {{{0.f}}};
53+
EigenMatrix eiginv = {{{0.f}}};
4354

4455
void print() const;
4556
};
4657

58+
using lutEntry_t = LutEntry;
59+
4760
/**
48-
* @brief Binning map
61+
* @brief Binning map.
4962
*/
50-
struct map_t {
63+
struct Map {
5164
int nbins = 1;
5265
float min = 0.f;
5366
float max = 1.e6f;
5467
bool log = false;
5568

56-
float eval(int bin) const
69+
[[nodiscard]] float eval(int bin) const
5770
{
5871
float width = (max - min) / nbins;
5972
float val = min + (bin + 0.5f) * width;
60-
if (log)
73+
if (log) {
6174
return std::pow(10.f, val);
75+
}
6276
return val;
6377
}
6478

65-
float fracPositionWithinBin(float val) const;
66-
int find(float val) const;
79+
[[nodiscard]] float fracPositionWithinBin(float val) const;
80+
[[nodiscard]] int find(float val) const;
6781
void print() const;
6882
};
6983

84+
using map_t = Map;
85+
7086
/**
71-
* @brief LUT header
87+
* @brief LUT header.
7288
*/
73-
struct lutHeader_t {
89+
struct LutHeader {
7490
int version = LUTCOVM_VERSION;
7591
int pdg = 0;
7692
float mass = 0.f;
@@ -80,12 +96,14 @@ struct lutHeader_t {
8096
map_t etamap;
8197
map_t ptmap;
8298

83-
bool check_version() const;
99+
[[nodiscard]] bool checkVersion() const;
84100
void print() const;
85101
};
86102

103+
using lutHeader_t = LutHeader;
104+
87105
/**
88-
* @brief Flat LUT data container - single contiguous buffer
106+
* @brief Flat LUT data container - single contiguous buffer.
89107
* Memory layout: [header][entry_0][entry_1]...[entry_N]
90108
*
91109
* All entries stored sequentially in a single allocation.
@@ -104,7 +122,7 @@ class FlatLutData
104122
*/
105123
void initialize(const lutHeader_t& header);
106124

107-
size_t getEntryIndex(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const
125+
[[nodiscard]] size_t getEntryIndex(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const
108126
{
109127
// Linear index: nch varies slowest, pt varies fastest
110128
// idx = nch * (rad*eta*pt) + rad * (eta*pt) + eta * pt + pt
@@ -114,7 +132,7 @@ class FlatLutData
114132
/**
115133
* @brief Get LUT entry by bin indices (view)
116134
*/
117-
const lutEntry_t* getEntryRef(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const;
135+
[[nodiscard]] const lutEntry_t* getEntryRef(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const;
118136

119137
/**
120138
* @brief Get LUT entry by bin indices (owned)
@@ -124,7 +142,7 @@ class FlatLutData
124142
/**
125143
* @brief Get LUT header (view)
126144
*/
127-
const lutHeader_t& getHeaderRef() const;
145+
[[nodiscard]] const lutHeader_t& getHeaderRef() const;
128146

129147
/**
130148
* @brief Get LUT header (owned)
@@ -134,13 +152,13 @@ class FlatLutData
134152
/**
135153
* @brief Get raw data buffer
136154
*/
137-
uint8_t* data() { return mData.data(); } // owned
138-
const uint8_t* data() const { return mDataRef.data(); } // view
155+
uint8_t* data() { return mData.data(); } // owned
156+
[[nodiscard]] const uint8_t* data() const { return mDataRef.data(); } // view
139157

140158
/**
141159
* @brief Total size in bytes
142160
*/
143-
size_t bytes() const { return mDataRef.size(); }
161+
[[nodiscard]] size_t bytes() const { return mDataRef.size(); }
144162

145163
/**
146164
* @brief Construct a new FlatLutData from external buffer as a copy
@@ -165,17 +183,17 @@ class FlatLutData
165183
/**
166184
* @brief Preview buffer header for version and other compatibility checks
167185
*/
168-
static lutHeader_t PreviewHeader(const uint8_t* buffer, size_t size);
186+
static lutHeader_t previewHeader(const uint8_t* buffer, size_t size);
169187

170188
/**
171189
* @brief Preview file-stored header for version and other compatibility checks
172190
*/
173-
static lutHeader_t PreviewHeader(std::ifstream& file, const char* filename);
191+
static lutHeader_t previewHeader(std::ifstream& file, const char* filename);
174192

175193
/**
176194
* @brief Check if the LUT is loaded
177195
*/
178-
bool isLoaded() const;
196+
[[nodiscard]] bool isLoaded() const;
179197

180198
/**
181199
* @brief Reset LUT to empty
@@ -186,7 +204,7 @@ class FlatLutData
186204
/**
187205
* @brief Linear index calculation for entry access
188206
*/
189-
size_t getEntryOffset(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const;
207+
[[nodiscard]] size_t getEntryOffset(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const;
190208

191209
/**
192210
* @brief Update dimensions from the current header
@@ -224,6 +242,6 @@ class FlatLutData
224242
int mPtBins = 0;
225243
};
226244

227-
} // namespace o2::delphes
245+
} // namespace o2::fastsim
228246

229247
#endif // ALICE3_CORE_FLATLUTENTRY_H_

0 commit comments

Comments
 (0)