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
2629{
2730
2831void 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
5861float 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
7371int 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
134132size_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
142140const 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
154152const 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
159157lutHeader_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
164162void FlatLutData::updateRef ()
@@ -200,26 +198,26 @@ void FlatLutData::view(const uint8_t* buffer, size_t size)
200198
201199void 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
272270FlatLutData 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
0 commit comments