Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Detectors/TPC/base/include/TPCBase/CalArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#include <boost/format.hpp>
#endif

#ifdef NDEBUG
#undef NDEBUG
#include <cassert>
#endif

namespace o2
{
namespace tpc
Expand Down Expand Up @@ -93,7 +98,11 @@ class CalArray
int getPadSubsetNumber() const { return mPadSubsetNumber; }

void setValue(const size_t channel, const T& value) { mData[channel] = value; }
const T getValue(const size_t channel) const { return mData[channel]; }
const T getValue(const size_t channel) const
{
assert(channel < mData.size());
return mData[channel];
}

void setValue(const size_t row, const size_t pad, const T& value);
const T getValue(const size_t row, const size_t pad) const;
Expand Down
27 changes: 26 additions & 1 deletion Detectors/TPC/base/include/TPCBase/CalDet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
#include "Rtypes.h"
#endif

#ifndef NDEBUG
#undef NDEBUG
// always enable assert
#include <cassert>
#endif

namespace o2
{
namespace tpc
Expand Down Expand Up @@ -211,7 +217,26 @@ inline const T CalDet<T>::getValue(const ROC roc, const size_t row, const size_t
}
case PadSubset::Region: {
const auto globalRow = roc.isOROC() ? mappedRow + mapper.getNumberOfRowsROC(ROC(0)) : mappedRow;
return mData[Mapper::REGION[globalRow] + roc.getSector() * Mapper::NREGIONS].getValue(Mapper::OFFSETCRUGLOBAL[globalRow] + mappedPad);
const auto dataRow = Mapper::REGION[globalRow] + roc.getSector() * Mapper::NREGIONS;
const auto index = Mapper::OFFSETCRUGLOBAL[globalRow] + mappedPad;
assert(dataRow < mData.size());
if (index >= mData[dataRow].getData().size()) {
// S. Wenzel: We shouldn't come here but we do. For instance for CalDet calibrations loaded from
// creator.loadIDCPadFlags(1731274461770);

// In this case there is an index overflow, leading to invalid reads and potentially a segfault.
// To increase stability, for now returning a trivial answer. This can be removed once either the algorithm
// or the calibration data has been fixed.
#ifndef GPUCA_ALIGPUCODE // hide from GPU standalone compilation
static bool printMsg = true;
if (printMsg) {
LOG(error) << "Out of bound access in TPC CalDet ROC " << roc << " row " << row << " pad " << pad << " (no more messages printed)";
}
printMsg = false;
#endif
return T{};
}
return mData[dataRow].getValue(index);
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion Detectors/TPC/base/src/TPCFlagsMemberCustomStreamer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ static __attribute__((used)) int _R__dummyStreamer_3 =
([]() {
auto cl = TClass::GetClass<o2::tpc::CalArray<o2::tpc::PadFlags>>();
if (cl) {
cl->AdoptMemberStreamer("mData", new TMemberStreamer(MemberVectorPadFlagsStreamer));
if (!getenv("TPC_PADFLAGS_STREAMER_OFF")) {
cl->AdoptMemberStreamer("mData", new TMemberStreamer(MemberVectorPadFlagsStreamer));
}
} else {
// we should never come here ... and if we do we should assert/fail
assert(false);
Expand Down