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>
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
2835void 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
5865float 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
7380int 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
134141size_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
142149const 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
201208void 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
272279FlatLutData 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
0 commit comments