Skip to content

Commit d05c30f

Browse files
committed
add ability to view a span directly
1 parent 349f716 commit d05c30f

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

ALICE3/Core/FlatLutEntry.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ void FlatLutData::view(const uint8_t* buffer, size_t size)
168168
void FlatLutData::validateBuffer(const uint8_t* buffer, size_t size)
169169
{
170170
auto header = PreviewHeader(buffer, size);
171-
if (!header.check_version()) {
172-
throw framework::runtime_error_f("LUT header version mismatch: expected %d, got %d", LUTCOVM_VERSION, header.version);
173-
}
174171
auto mNchBins = header.nchmap.nbins;
175172
auto mRadBins = header.radmap.nbins;
176173
auto mEtaBins = header.etamap.nbins;
@@ -216,6 +213,11 @@ FlatLutData FlatLutData::ViewFromBuffer(const uint8_t* buffer, size_t size)
216213
return data;
217214
}
218215

216+
FlatLutData FlatLutData::ViewFromBuffer(std::span<std::byte> const& span)
217+
{
218+
return ViewFromBuffer(reinterpret_cast<const uint8_t*>(span.data()), span.size_bytes());
219+
}
220+
219221
bool FlatLutData::isLoaded() const
220222
{
221223
return ((!mData.empty()) || (!mDataRef.empty()));

ALICE3/Core/FlatLutEntry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class FlatLutData
143143
*/
144144
static FlatLutData ViewFromBuffer(const uint8_t* buffer, size_t size);
145145

146+
/**
147+
* @brief Construct a new FlatLutData from external span as a view
148+
*/
149+
static FlatLutData ViewFromBuffer(std::span<std::byte> const& span);
150+
146151
/**
147152
* @brief Construct a new FlatLutData from a file
148153
*/

ALICE3/Core/FlatTrackSmearer.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace o2::delphes
2121
{
22-
int TrackSmearer::getIndexPDG(int pdg) const
22+
int TrackSmearer::getIndexPDG(int pdg)
2323
{
2424
switch (std::abs(pdg)) {
2525
case 11:
@@ -45,7 +45,7 @@ int TrackSmearer::getIndexPDG(int pdg) const
4545
}
4646
}
4747

48-
const char* TrackSmearer::getParticleName(int pdg) const
48+
const char* TrackSmearer::getParticleName(int pdg)
4949
{
5050
switch (std::abs(pdg)) {
5151
case 11:
@@ -165,6 +165,11 @@ bool TrackSmearer::viewTable(int pdg, const uint8_t* buffer, size_t size, bool f
165165
return true;
166166
}
167167

168+
bool TrackSmearer::viewTable(int pdg, std::span<std::byte> const& span, bool forceReload)
169+
{
170+
return viewTable(pdg, reinterpret_cast<const uint8_t*>(span.data()), span.size_bytes(), forceReload);
171+
}
172+
168173
bool TrackSmearer::hasTable(int pdg) const
169174
{
170175
const int ipdg = getIndexPDG(pdg);
@@ -213,8 +218,8 @@ const lutEntry_t* TrackSmearer::getLUTEntry(const int pdg, const float nch, cons
213218
auto ipt = header.ptmap.find(pt);
214219

215220
// Interpolate efficiency if requested
216-
auto fraction = header.nchmap.fracPositionWithinBin(nch);
217221
if (mInterpolateEfficiency) {
222+
auto fraction = header.nchmap.fracPositionWithinBin(nch);
218223
static constexpr float kFractionThreshold = 0.5f;
219224
if (fraction > kFractionThreshold) {
220225
switch (mWhatEfficiency) {

ALICE3/Core/FlatTrackSmearer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TrackSmearer
3232
bool loadTable(int pdg, const char* filename, bool forceReload = false);
3333
bool adoptTable(int pdg, const uint8_t* buffer, size_t size, bool forceReload = false);
3434
bool viewTable(int pdg, const uint8_t* buffer, size_t size, bool forceReload = false);
35+
bool viewTable(int pdg, std::span<std::byte> const& span, bool forceReload = false);
3536
bool hasTable(int pdg) const;
3637

3738
void useEfficiency(bool val) { mUseEfficiency = val; }
@@ -51,9 +52,8 @@ class TrackSmearer
5152
double getAbsEtaRes(int pdg, float nch, float eta, float pt) const;
5253
double getEfficiency(int pdg, float nch, float eta, float pt) const;
5354

54-
int getIndexPDG(int pdg) const;
55-
56-
const char* getParticleName(int pdg) const;
55+
static int getIndexPDG(int pdg);
56+
static const char* getParticleName(int pdg);
5757

5858
void setdNdEta(float val) { mdNdEta = val; }
5959
void setCcdbManager(o2::ccdb::BasicCCDBManager* mgr) { mCcdbManager = mgr; }
@@ -71,7 +71,7 @@ class TrackSmearer
7171
private:
7272
o2::ccdb::BasicCCDBManager* mCcdbManager = nullptr;
7373

74-
bool checkSpecialCase(int pdg, lutHeader_t const& header);
74+
static bool checkSpecialCase(int pdg, lutHeader_t const& header);
7575
};
7676

7777
} // namespace o2::delphes

0 commit comments

Comments
 (0)