Skip to content

Commit 05f1457

Browse files
jokonigjokonig
andauthored
[EMCAL-1135] Throw exception in case of to large starttime for TRU channel (#13326)
- A case was found where the starttime was larger than the maximum possible bunch length of a TRU channel - For REC channel, the maximum length is 15, while for TRU channel, it is 14. - A possible bit-flip could cause a FEC channel to be flagged as TRU channel, however if that channel than has a starttime of 14, it will write into unallocated memory as it exceeds the length of the vector - Added an exception and implemented a unit test for the exception Co-authored-by: jokonig <jokonig@cern.ch>
1 parent deff6ce commit 05f1457

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef ALICEO2_EMCAL_TRUDECODINGERRORS_H
13+
#define ALICEO2_EMCAL_TRUDECODINGERRORS_H
14+
15+
#include <exception>
16+
#include <string>
17+
18+
namespace o2
19+
{
20+
21+
namespace emcal
22+
{
23+
24+
/// \class FastOrStartTimeInvalidException
25+
/// \brief Handling of error if starttime is to large (>=14). This is most likely caused by a corrupted channel header where a FEC channel is identified as a TRU channel
26+
/// \ingroup EMCALbase
27+
class FastOrStartTimeInvalidException : public std::exception
28+
{
29+
public:
30+
/// \brief Constructor
31+
/// \param l0size Size of the L0 patch
32+
FastOrStartTimeInvalidException(unsigned int time) : std::exception(), mErrorMessage(), mStartTime(time)
33+
{
34+
mErrorMessage = "FastOr starttime invalid: " + std::to_string(time);
35+
}
36+
37+
/// \brief Destructor
38+
~FastOrStartTimeInvalidException() noexcept final = default;
39+
40+
/// \brief Access to error message
41+
/// \return Error message
42+
const char* what() const noexcept final
43+
{
44+
return mErrorMessage.data();
45+
}
46+
47+
/// \brief Get the size of the L0 patch
48+
/// \return Size of the L0 patch
49+
unsigned int getStartTime() const noexcept { return mStartTime; }
50+
51+
private:
52+
std::string mErrorMessage; ///< Buffer for error message
53+
int mStartTime; ///< Size of the L0 patch
54+
};
55+
56+
} // namespace emcal
57+
58+
} // namespace o2
59+
60+
#endif // ALICEO2_EMCAL_TRUDECODINGERRORS_H

Detectors/EMCAL/reconstruction/src/FastORTimeSeries.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#include <algorithm>
1313
#include <iostream>
1414
#include "EMCALReconstruction/FastORTimeSeries.h"
15+
#include "EMCALBase/TRUDecodingErrors.h"
1516

1617
using namespace o2::emcal;
1718

1819
void FastORTimeSeries::fillReversed(const gsl::span<const uint16_t> samples, uint8_t starttime)
1920
{
20-
21+
if (starttime >= 14) {
22+
throw FastOrStartTimeInvalidException(starttime);
23+
}
2124
for (std::size_t isample = 0; isample < samples.size(); isample++) {
2225
mTimeSamples[starttime - isample] = samples[isample];
2326
}

Detectors/EMCAL/reconstruction/test/testFastORTimeSeries.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <tuple>
1717
#include <TRandom.h>
1818
#include <EMCALReconstruction/FastORTimeSeries.h>
19+
#include "EMCALBase/TRUDecodingErrors.h"
1920

2021
namespace o2
2122
{
@@ -139,6 +140,12 @@ BOOST_AUTO_TEST_CASE(FastORTimeSeries_test)
139140
BOOST_CHECK_EQUAL_COLLECTIONS(adcs.begin(), adcs.end(), reference.begin(), reference.end());
140141
BOOST_CHECK_EQUAL(testcase.calculateL1TimeSum(8), calculateTimesum(reference, 8));
141142
}
143+
144+
// test case where a normal FEC channel is identified as TRU channel. FEC channel can have lenght of 15 and would therefore cause an overflow in the FEC channel (max lenght 14)
145+
auto starttime = 14;
146+
auto bunch = generateSmallBunch(14);
147+
BOOST_CHECK_EXCEPTION(FastORTimeSeries(14, bunch, starttime), FastOrStartTimeInvalidException, [starttime](const FastOrStartTimeInvalidException& e) { return e.getStartTime() == starttime; });
148+
142149
return;
143150

144151
// test adding 2 bunches

0 commit comments

Comments
 (0)