Skip to content

Commit 0c7f410

Browse files
committed
[ALICE3] cleanup DelphesO2 legacy code, fix warnings
- Remove legacy DelphesO2 LUT and Smearer - Fix code check warnings
1 parent 498bb05 commit 0c7f410

9 files changed

Lines changed: 332 additions & 292 deletions

File tree

‎ALICE3/Core/FlatLutEntry.cxx‎

Lines changed: 34 additions & 27 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,37 @@
2225
#include <ios>
2326
#include <span>
2427

25-
namespace o2::delphes
28+
namespace o2::fastsim
29+
{
30+
namespace
2631
{
32+
constexpr float kBinCenterOffset = 0.5f;
33+
} // namespace
2734

2835
void lutEntry_t::print() const
2936
{
3037
LOGF(info, " nch = %f, eta = %f, pt = %f, valid = %s\n", nch, eta, pt, valid ? "true" : "false");
3138
LOGF(info, " eff = %f, eff2 = %f, itof = %f, otof = %f\n", eff, eff2, itof, otof);
3239
LOGF(info, " covm: ");
33-
for (int i = 0; i < 15; ++i) {
40+
for (int i = 0; i < kNumCovarianceTerms; ++i) {
3441
LOGF(info, "%f ", covm[i]);
3542
}
3643
LOGF(info, "\n");
3744
LOGF(info, " eigval: ");
38-
for (int i = 0; i < 5; ++i) {
45+
for (int i = 0; i < kNumEigenModes; ++i) {
3946
LOGF(info, "%f ", eigval[i]);
4047
}
4148
LOGF(info, "\n");
4249
LOGF(info, " eigvec:\n");
43-
for (int i = 0; i < 5; ++i) {
44-
for (int j = 0; j < 5; ++j) {
50+
for (int i = 0; i < kNumEigenModes; ++i) {
51+
for (int j = 0; j < kNumEigenModes; ++j) {
4552
LOGF(info, "%f ", eigvec[i][j]);
4653
}
4754
LOGF(info, "\n");
4855
}
4956
LOGF(info, " eiginv:\n");
50-
for (int i = 0; i < 5; ++i) {
51-
for (int j = 0; j < 5; ++j) {
57+
for (int i = 0; i < kNumEigenModes; ++i) {
58+
for (int j = 0; j < kNumEigenModes; ++j) {
5259
LOGF(info, "%f ", eiginv[i][j]);
5360
}
5461
LOGF(info, "\n");
@@ -58,8 +65,8 @@ void lutEntry_t::print() const
5865
float map_t::fracPositionWithinBin(float val) const
5966
{
6067
float width = (max - min) / nbins;
61-
int bin;
62-
float returnVal = 0.5f;
68+
int bin = 0;
69+
float returnVal = kBinCenterOffset;
6370
if (log) {
6471
bin = static_cast<int>((std::log10(val) - min) / width);
6572
returnVal = ((std::log10(val) - min) / width) - bin;
@@ -73,7 +80,7 @@ float map_t::fracPositionWithinBin(float val) const
7380
int map_t::find(float val) const
7481
{
7582
float width = (max - min) / nbins;
76-
int bin;
83+
int bin = 0;
7784
if (log) {
7885
bin = static_cast<int>((std::log10(val) - min) / width);
7986
} else {
@@ -93,7 +100,7 @@ void map_t::print() const
93100
LOGF(info, "nbins = %d, min = %f, max = %f, log = %s \n", nbins, min, max, log ? "on" : "off");
94101
}
95102

96-
bool lutHeader_t::check_version() const
103+
bool lutHeader_t::checkVersion() const
97104
{
98105
return (version == LUTCOVM_VERSION);
99106
}
@@ -120,7 +127,7 @@ void FlatLutData::initialize(const lutHeader_t& header)
120127
mEtaBins = header.etamap.nbins;
121128
mPtBins = header.ptmap.nbins;
122129

123-
const size_t headerSize = sizeof(lutHeader_t);
130+
constexpr size_t headerSize = sizeof(lutHeader_t);
124131
const size_t numEntries = static_cast<size_t>(mNchBins) * mRadBins * mEtaBins * mPtBins;
125132
const size_t entriesSize = numEntries * sizeof(lutEntry_t);
126133
const size_t totalSize = headerSize + entriesSize;
@@ -133,10 +140,10 @@ void FlatLutData::initialize(const lutHeader_t& header)
133140

134141
size_t FlatLutData::getEntryOffset(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const
135142
{
136-
static constexpr size_t headerSize = sizeof(lutHeader_t);
143+
static constexpr size_t HeaderSize = sizeof(lutHeader_t);
137144
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;
145+
static constexpr size_t EntrySize = sizeof(lutEntry_t);
146+
return HeaderSize + linearIdx * EntrySize;
140147
}
141148

142149
const lutEntry_t* FlatLutData::getEntryRef(int nch_bin, int rad_bin, int eta_bin, int pt_bin) const
@@ -200,26 +207,26 @@ void FlatLutData::view(const uint8_t* buffer, size_t size)
200207

201208
void FlatLutData::validateBuffer(const uint8_t* buffer, size_t size)
202209
{
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;
210+
auto header = previewHeader(buffer, size);
211+
const auto nchBins = header.nchmap.nbins;
212+
const auto radBins = header.radmap.nbins;
213+
const auto etaBins = header.etamap.nbins;
214+
const auto ptBins = header.ptmap.nbins;
208215

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

211218
if (size < expectedSize) {
212219
throw framework::runtime_error_f("Buffer size mismatch: expected %zu, got %zu", expectedSize, size);
213220
}
214221
}
215222

216-
lutHeader_t FlatLutData::PreviewHeader(const uint8_t* buffer, size_t size)
223+
lutHeader_t FlatLutData::previewHeader(const uint8_t* buffer, size_t size)
217224
{
218225
if (size < sizeof(lutHeader_t)) {
219226
throw framework::runtime_error_f("Buffer too small for LUT header: expected at least %zu, got %zu", sizeof(lutHeader_t), size);
220227
}
221228
const auto* header = reinterpret_cast<const lutHeader_t*>(buffer);
222-
if (!header->check_version()) {
229+
if (!header->checkVersion()) {
223230
throw framework::runtime_error_f("LUT header version mismatch: expected %d, got %d", LUTCOVM_VERSION, header->version);
224231
}
225232
return *header;
@@ -256,14 +263,14 @@ bool FlatLutData::isLoaded() const
256263
return ((!mData.empty()) || (!mDataRef.empty()));
257264
}
258265

259-
lutHeader_t FlatLutData::PreviewHeader(std::ifstream& file, const char* filename)
266+
lutHeader_t FlatLutData::previewHeader(std::ifstream& file, const char* filename)
260267
{
261268
lutHeader_t tempHeader;
262269
file.read(reinterpret_cast<char*>(&tempHeader), sizeof(lutHeader_t));
263270
if (file.gcount() != static_cast<std::streamsize>(sizeof(lutHeader_t))) {
264271
throw framework::runtime_error_f("Failed to read LUT header from %s", filename);
265272
}
266-
if (!tempHeader.check_version()) {
273+
if (!tempHeader.checkVersion()) {
267274
throw framework::runtime_error_f("LUT header version mismatch: expected %d, got %d", LUTCOVM_VERSION, tempHeader.version);
268275
}
269276
return tempHeader;
@@ -272,7 +279,7 @@ lutHeader_t FlatLutData::PreviewHeader(std::ifstream& file, const char* filename
272279
FlatLutData FlatLutData::loadFromFile(std::ifstream& file, const char* filename)
273280
{
274281
// Read header first
275-
lutHeader_t tempHeader = PreviewHeader(file, filename);
282+
lutHeader_t tempHeader = previewHeader(file, filename);
276283

277284
FlatLutData data;
278285

@@ -300,4 +307,4 @@ void FlatLutData::reset()
300307
resetDimensions();
301308
}
302309

303-
} // namespace o2::delphes
310+
} // 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)