Skip to content

Commit de61d45

Browse files
mfasDashahor02
authored andcommitted
[EMCAL-915] Error handling for STU decoding
- STU error base class with main error codes - Integration of STU decoding errors into ErrorTypeFEE
1 parent 007ac6f commit de61d45

4 files changed

Lines changed: 155 additions & 9 deletions

File tree

DataFormats/Detectors/EMCAL/include/DataFormatsEMCAL/ErrorTypeFEE.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class ErrorTypeFEE
5757
FIT_ERROR, ///< Raw fit failed
5858
GEOMETRY_ERROR, ///< Decoded position outside EMCAL
5959
GAIN_ERROR, ///< Error due to gain type
60+
STU_ERROR, ///< Error from STU data
6061
UNDEFINED ///< Error source undefined
6162
};
6263
/// \brief Constructor
@@ -97,6 +98,10 @@ class ErrorTypeFEE
9798
/// \param gainError Error code of the gain type error
9899
void setGainErrorType(int gainError) { setError(ErrorSource_t::GAIN_ERROR, gainError); }
99100

101+
/// \brief Set the error as STU decoder error and store the error code
102+
/// \param gainError Error code of the STU decoder error
103+
void setSTUDecoderErrorType(int gainError) { setError(ErrorSource_t::STU_ERROR, gainError); }
104+
100105
/// \brief Set the error type of the object
101106
/// \param errorsource Error type of the object
102107
void setErrorType(ErrorSource_t errorsource) { mErrorSource = errorsource; }
@@ -157,6 +162,10 @@ class ErrorTypeFEE
157162
/// \return Error code (-1 in case the object is not a gain type error)
158163
int getGainTypeErrorType() const { return getRawErrorForType(ErrorSource_t::GAIN_ERROR); }
159164

165+
/// \brief Get the error code of the obect in case the object is a STU decoder error
166+
/// \return Error code (-1 in case the object is not a STU decoder error)
167+
int getSTUDecoderErrorType() const { return getRawErrorForType(ErrorSource_t::STU_ERROR); }
168+
160169
/// \brief Get subspecification of the error
161170
/// \return Subspecification of the error
162171
int getSubspecification() const { return mSubspecification; }

DataFormats/Detectors/EMCAL/src/ErrorTypeFEE.cxx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ void ErrorTypeFEE::PrintStream(std::ostream& stream) const
3434
case ErrorSource_t::GEOMETRY_ERROR:
3535
typestring = "geometry error";
3636
break;
37-
case ErrorTypeFEE::GAIN_ERROR:
37+
case ErrorSource_t::GAIN_ERROR:
3838
typestring = "gain type error";
3939
break;
40+
case ErrorSource_t::STU_ERROR:
41+
typestring = "STU decoder error";
42+
break;
4043
case ErrorSource_t::UNDEFINED:
4144
typestring = "unknown error";
4245
break;
@@ -66,8 +69,10 @@ const char* ErrorTypeFEE::getErrorTypeName(unsigned int errorTypeID)
6669
return "Fit";
6770
case ErrorSource_t::GEOMETRY_ERROR:
6871
return "Geometry";
69-
case ErrorTypeFEE::GAIN_ERROR:
72+
case ErrorSource_t::GAIN_ERROR:
7073
return "GainType";
74+
case ErrorSource_t::STU_ERROR:
75+
return "STUDecoding";
7176
case ErrorSource_t::UNDEFINED:
7277
return "Undefined";
7378
default:
@@ -88,8 +93,10 @@ const char* ErrorTypeFEE::getErrorTypeTitle(unsigned int errorTypeID)
8893
return "Fit";
8994
case ErrorSource_t::GEOMETRY_ERROR:
9095
return "Geometry";
91-
case ErrorTypeFEE::GAIN_ERROR:
96+
case ErrorSource_t::GAIN_ERROR:
9297
return "Gain";
98+
case ErrorSource_t::STU_ERROR:
99+
return "STUDecoding";
93100
case ErrorSource_t::UNDEFINED:
94101
return "Unknown";
95102
default:

Detectors/EMCAL/reconstruction/include/EMCALReconstruction/STUDecoderError.h

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,82 @@
1818
namespace o2::emcal
1919
{
2020

21+
/// \class STUDecoderError
22+
/// \brief Handling of STU reconstruction errors
23+
/// \ingroup EMCALreconstruction
24+
/// \since April 25, 2023
25+
///
26+
/// In order to distinguish different error types the STUDecoder error
27+
/// carries an error code which can be uniquely identified with a
28+
/// condition raising the excpetion. Source is always the DDL of the
29+
/// STU raising the exception.
2130
class STUDecoderError : public std::exception
2231
{
2332
public:
33+
/// \enum ErrorCode_t
34+
/// \brief Error codes of STU decoding
2435
enum class ErrorCode_t {
25-
PAGE_ERROR,
26-
WORD_UNEXPECTED,
27-
INDEX_UNEXPECTED,
28-
ADC_OVERFLOW
36+
PAGE_ERROR, ///< Page decoding failed (missing header)
37+
WORD_UNEXPECTED, ///< Word unexpected
38+
INDEX_UNEXPECTED, ///< Patch index unexpected
39+
ADC_OVERFLOW, ///< ADC overflow
40+
UNKNOWN ///< Unknown error code (needed for conversion to int)
2941
};
30-
STUDecoderError() = default;
42+
43+
/// \brief Get integer representation of error code
44+
/// \param errorcode Error code
45+
/// \return Integer representation
46+
static int errorCodeToInt(ErrorCode_t errorcode);
47+
48+
/// \brief Convert integer to error code
49+
/// \param errorcode Error code as integer
50+
/// \return Error code (symbolic) - UNKNOWN for invalid integer error codes
51+
static ErrorCode_t intToErrorCode(int errorcode);
52+
53+
/// \brief Get the name of the error code
54+
/// \param errorcode Error code
55+
/// \return Name of the error code
56+
static std::string getErrorCodeName(ErrorCode_t errorcode);
57+
58+
/// \brief Get the name of the error code
59+
/// \param errorcode Error code (integer representation)
60+
/// \return Name of the error code
61+
static std::string getErrorCodeName(int errorcode) { return getErrorCodeName(intToErrorCode(errorcode)); }
62+
63+
/// \brief Get the title of the error code
64+
/// \param errorcode Error code
65+
/// \return Title of the error code
66+
static std::string getErrorCodeTitle(ErrorCode_t errorcode);
67+
68+
/// \brief Get the title of the error code
69+
/// \param errorcode Error code (integer representation)
70+
/// \return Title of the error code
71+
static std::string getErrorCodeTitle(int errorcode) { return getErrorCodeTitle(intToErrorCode(errorcode)); }
72+
73+
/// \brief Constructor
74+
/// \param ddlID ID of the DDL for which the exception is raised
75+
/// \param errcode Error code of the exception
76+
STUDecoderError(int ddlID, ErrorCode_t errcode);
77+
78+
/// \brief Destructor
3179
~STUDecoderError() noexcept final = default;
3280

81+
/// \brief Access to error message
82+
/// \return Error message
3383
const char* what() const noexcept final { return mMessage.data(); }
3484

85+
/// \brief Get the ID of the DDL in which the exception is raised
86+
/// \return ID of the DDL
3587
int getDDLID() const noexcept { return mDDLId; }
3688

89+
/// \brief Get error code of the exception
90+
/// \return Error code
91+
ErrorCode_t getErrorCode() const noexcept { return mErrorCode; }
92+
93+
/// \brief Print details of the error on the stream
94+
/// \param stream Stream to print on
95+
///
96+
/// Helper function for streaming operator
3797
void printStream(std::ostream& stream) const;
3898

3999
private:
@@ -42,6 +102,10 @@ class STUDecoderError : public std::exception
42102
std::string mMessage; ///< Message buffer
43103
};
44104

105+
/// \brief Streaming operator of STU decoding errors
106+
/// \param stream Stream to print the error on
107+
/// \param error Error to be streamed
108+
/// \return Stream after printing
45109
std::ostream& operator<<(std::ostream& stream, const STUDecoderError& error);
46110

47111
} // namespace o2::emcal

Detectors/EMCAL/reconstruction/src/STUDecoderError.cxx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,79 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
11+
#include <array>
12+
#include <iostream>
1213
#include "EMCALReconstruction/STUDecoderError.h"
1314

1415
using namespace o2::emcal;
1516

17+
STUDecoderError::STUDecoderError(int ddlID, ErrorCode_t errcode) : mDDLId(ddlID),
18+
mErrorCode(errcode)
19+
{
20+
mMessage = "STU decoding error of type" + getErrorCodeTitle(mErrorCode) + " in DDL " + std::to_string(mDDLId);
21+
}
22+
23+
void STUDecoderError::printStream(std::ostream& stream) const
24+
{
25+
}
26+
1627
std::ostream& o2::emcal::operator<<(std::ostream& stream, const STUDecoderError& error)
1728
{
1829
error.printStream(stream);
1930
return stream;
31+
}
32+
33+
int STUDecoderError::errorCodeToInt(ErrorCode_t errorcode)
34+
{
35+
switch (errorcode) {
36+
case ErrorCode_t::PAGE_ERROR:
37+
return 0;
38+
case ErrorCode_t::WORD_UNEXPECTED:
39+
return 1;
40+
case ErrorCode_t::INDEX_UNEXPECTED:
41+
return 2;
42+
case ErrorCode_t::ADC_OVERFLOW:
43+
return 3;
44+
default:
45+
return -1;
46+
}
47+
}
48+
STUDecoderError::ErrorCode_t STUDecoderError::intToErrorCode(int errorcode)
49+
{
50+
static constexpr std::size_t NUMERRORCODES = 4;
51+
static constexpr std::array<ErrorCode_t, NUMERRORCODES> errorcodes = {{ErrorCode_t::PAGE_ERROR, ErrorCode_t::WORD_UNEXPECTED, ErrorCode_t::INDEX_UNEXPECTED, ErrorCode_t::ADC_OVERFLOW}};
52+
if (errorcode < 0 || errorcode >= NUMERRORCODES) {
53+
return ErrorCode_t::UNKNOWN;
54+
}
55+
return errorcodes[errorcode];
56+
}
57+
std::string STUDecoderError::getErrorCodeName(ErrorCode_t errorcode)
58+
{
59+
switch (errorcode) {
60+
case ErrorCode_t::PAGE_ERROR:
61+
return "PageDecoding";
62+
case ErrorCode_t::WORD_UNEXPECTED:
63+
return "WordUnexpected";
64+
case ErrorCode_t::INDEX_UNEXPECTED:
65+
return "IndexUnexpected";
66+
case ErrorCode_t::ADC_OVERFLOW:
67+
return "ADCOverflow";
68+
default:
69+
return "Unknown";
70+
}
71+
}
72+
std::string STUDecoderError::getErrorCodeTitle(ErrorCode_t errorcode)
73+
{
74+
switch (errorcode) {
75+
case ErrorCode_t::PAGE_ERROR:
76+
return "page decoding";
77+
case ErrorCode_t::WORD_UNEXPECTED:
78+
return "unexpected word";
79+
case ErrorCode_t::INDEX_UNEXPECTED:
80+
return "invalid index";
81+
case ErrorCode_t::ADC_OVERFLOW:
82+
return "ADC overflow";
83+
default:
84+
return "Unknown";
85+
}
2086
}

0 commit comments

Comments
 (0)