Skip to content

Commit 7b078a9

Browse files
committed
[EMCAL] Modernize EMCal code
- Moderinze EMCal code: EMCALBase/Geometry and ClusterFactory Classes and DataFormatsEMCAL classes, removing c-style arrays - Fixing clang-tidy warnings and errors that would appear when using the O2Physics clang-tidy settings - Switching from gsl::span to std::span to use official stl container [EMCAL] update
1 parent f2a59e7 commit 7b078a9

15 files changed

Lines changed: 467 additions & 568 deletions

File tree

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

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
#ifndef ALICEO2_EMCAL_ANALYSISCLUSTER_H_
1313
#define ALICEO2_EMCAL_ANALYSISCLUSTER_H_
1414

15+
#include "MathUtils/Cartesian.h" // IWYU pragma: keep
16+
17+
#include <Rtypes.h>
18+
#include <TLorentzVector.h>
19+
1520
#include <fairlogger/Logger.h>
1621
#include <gsl/span>
17-
#include <array>
18-
#include "Rtypes.h"
19-
#include "MathUtils/Cartesian.h"
20-
#include "TLorentzVector.h"
2122

22-
namespace o2
23-
{
23+
#include <array>
2424

25-
namespace emcal
25+
namespace o2::emcal
2626
{
2727

2828
/// \class AnalysisCluster
@@ -45,8 +45,7 @@ class AnalysisCluster
4545
public:
4646
/// \brief Constructor, setting cell wrong cell index raising the exception
4747
/// \param cellIndex Cell index raising the exception
48-
CellOutOfRangeException(Int_t cellIndex) : std::exception(),
49-
mCellIndex(cellIndex),
48+
CellOutOfRangeException(Int_t cellIndex) : mCellIndex(cellIndex),
5049
mMessage("Cell index " + std::to_string(mCellIndex) + " out of range.")
5150
{
5251
}
@@ -56,11 +55,11 @@ class AnalysisCluster
5655

5756
/// \brief Access to cell ID raising the exception
5857
/// \return Cell ID
59-
Int_t getCellIndex() const noexcept { return mCellIndex; }
58+
[[nodiscard]] Int_t getCellIndex() const noexcept { return mCellIndex; }
6059

6160
/// \brief Access to error message of the exception
6261
/// \return Error message
63-
const char* what() const noexcept final { return mMessage.data(); }
62+
[[nodiscard]] const char* what() const noexcept final { return mMessage.data(); }
6463

6564
private:
6665
Int_t mCellIndex; ///< Cell index raising the exception
@@ -76,55 +75,55 @@ class AnalysisCluster
7675
// Common EMCAL/PHOS/FMD/PMD
7776

7877
void setID(int id) { mID = id; }
79-
int getID() const { return mID; }
78+
[[nodiscard]] int getID() const { return mID; }
8079

8180
void setE(float ene) { mEnergy = ene; }
82-
float E() const { return mEnergy; }
81+
[[nodiscard]] float E() const { return mEnergy; }
8382

8483
void setChi2(float chi2) { mChi2 = chi2; }
85-
float Chi2() const { return mChi2; }
84+
[[nodiscard]] float Chi2() const { return mChi2; }
8685

8786
///
8887
/// Set the cluster global position.
89-
void setGlobalPosition(math_utils::Point3D<float> x);
90-
math_utils::Point3D<float> getGlobalPosition() const
88+
void setGlobalPosition(const math_utils::Point3D<float>& x);
89+
[[nodiscard]] math_utils::Point3D<float> getGlobalPosition() const
9190
{
9291
return mGlobalPos;
9392
}
9493

95-
void setLocalPosition(math_utils::Point3D<float> x);
96-
math_utils::Point3D<float> getLocalPosition() const
94+
void setLocalPosition(const math_utils::Point3D<float>& x);
95+
[[nodiscard]] math_utils::Point3D<float> getLocalPosition() const
9796
{
9897
return mLocalPos;
9998
}
10099

101100
void setDispersion(float disp) { mDispersion = disp; }
102-
float getDispersion() const { return mDispersion; }
101+
[[nodiscard]] float getDispersion() const { return mDispersion; }
103102

104103
void setM20(float m20) { mM20 = m20; }
105-
float getM20() const { return mM20; }
104+
[[nodiscard]] float getM20() const { return mM20; }
106105

107106
void setM02(float m02) { mM02 = m02; }
108-
float getM02() const { return mM02; }
107+
[[nodiscard]] float getM02() const { return mM02; }
109108

110109
void setNExMax(unsigned char nExMax) { mNExMax = nExMax; }
111-
unsigned char getNExMax() const { return mNExMax; }
110+
[[nodiscard]] unsigned char getNExMax() const { return mNExMax; }
112111

113112
void setEmcCpvDistance(float dEmcCpv) { mEmcCpvDistance = dEmcCpv; }
114-
float getEmcCpvDistance() const { return mEmcCpvDistance; }
113+
[[nodiscard]] float getEmcCpvDistance() const { return mEmcCpvDistance; }
115114
void setTrackDistance(float dx, float dz)
116115
{
117116
mTrackDx = dx;
118117
mTrackDz = dz;
119118
}
120-
float getTrackDx() const { return mTrackDx; }
121-
float getTrackDz() const { return mTrackDz; }
119+
[[nodiscard]] float getTrackDx() const { return mTrackDx; }
120+
[[nodiscard]] float getTrackDz() const { return mTrackDz; }
122121

123122
void setDistanceToBadChannel(float dist) { mDistToBadChannel = dist; }
124-
float getDistanceToBadChannel() const { return mDistToBadChannel; }
123+
[[nodiscard]] float getDistanceToBadChannel() const { return mDistToBadChannel; }
125124

126125
void setNCells(int n) { mNCells = n; }
127-
int getNCells() const { return mNCells; }
126+
[[nodiscard]] int getNCells() const { return mNCells; }
128127

129128
///
130129
/// Set the array of cell indices.
@@ -133,7 +132,7 @@ class AnalysisCluster
133132
mCellsIndices = array;
134133
}
135134

136-
const std::vector<unsigned short>& getCellsIndices() const { return mCellsIndices; }
135+
[[nodiscard]] const std::vector<unsigned short>& getCellsIndices() const { return mCellsIndices; }
137136

138137
///
139138
/// Set the array of cell amplitude fractions.
@@ -143,53 +142,51 @@ class AnalysisCluster
143142
{
144143
mCellsAmpFraction = array;
145144
}
146-
const std::vector<float>& getCellsAmplitudeFraction() const { return mCellsAmpFraction; }
145+
[[nodiscard]] const std::vector<float>& getCellsAmplitudeFraction() const { return mCellsAmpFraction; }
147146

148-
int getCellIndex(int i) const
147+
[[nodiscard]] int getCellIndex(int i) const
149148
{
150149
if (i >= 0 && i < mNCells) {
151150
return mCellsIndices[i];
152-
} else {
153-
throw CellOutOfRangeException(i);
154151
}
152+
throw CellOutOfRangeException(i);
155153
}
156154

157-
float getCellAmplitudeFraction(int i) const
155+
[[nodiscard]] float getCellAmplitudeFraction(int i) const
158156
{
159157
if (i >= 0 && i < mNCells) {
160158
return mCellsAmpFraction[i];
161-
} else {
162-
throw CellOutOfRangeException(i);
163159
}
160+
throw CellOutOfRangeException(i);
164161
}
165162

166-
bool getIsExotic() const { return mIsExotic; }
163+
[[nodiscard]] bool getIsExotic() const { return mIsExotic; }
167164
void setIsExotic(bool b) { mIsExotic = b; }
168165

169166
void setClusterTime(float time)
170167
{
171168
mTime = time;
172169
}
173170

174-
float getClusterTime() const
171+
[[nodiscard]] float getClusterTime() const
175172
{
176173
return mTime;
177174
}
178175

179-
int getIndMaxInput() const { return mInputIndMax; }
176+
[[nodiscard]] int getIndMaxInput() const { return mInputIndMax; }
180177
void setIndMaxInput(const int ind) { mInputIndMax = ind; }
181178

182-
float getCoreEnergy() const { return mCoreEnergy; }
179+
[[nodiscard]] float getCoreEnergy() const { return mCoreEnergy; }
183180
void setCoreEnergy(float energy) { mCoreEnergy = energy; }
184181

185-
float getFCross() const { return mFCross; }
182+
[[nodiscard]] float getFCross() const { return mFCross; }
186183
void setFCross(float fCross) { mFCross = fCross; }
187184

188185
///
189186
/// Returns TLorentzVector with momentum of the cluster. Only valid for clusters
190187
/// identified as photons or pi0 (overlapped gamma) produced on the vertex
191188
/// Vertex can be recovered with esd pointer doing:
192-
TLorentzVector getMomentum(std::array<const float, 3> vertexPosition) const;
189+
[[nodiscard]] TLorentzVector getMomentum(std::array<const float, 3> vertexPosition) const;
193190

194191
protected:
195192
/// TODO to replace later by o2::MCLabel when implementing the MC handling
@@ -230,9 +227,8 @@ class AnalysisCluster
230227

231228
int mInputIndMax = -1; ///< index of digit/cell with max energy
232229

233-
ClassDefNV(AnalysisCluster, 2);
230+
ClassDefNV(AnalysisCluster, 3);
234231
};
235232

236-
} // namespace emcal
237-
} // namespace o2
233+
} // namespace o2::emcal
238234
#endif // ANALYSISCLUSTER_H

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
#ifndef ALICEO2_EMCAL_CELL_H_
1313
#define ALICEO2_EMCAL_CELL_H_
1414

15-
#include <bitset>
15+
#include "DataFormatsEMCAL/Constants.h"
16+
1617
#include <cfloat>
1718
#include <climits>
18-
#include "DataFormatsEMCAL/Constants.h"
1919

20-
namespace o2
21-
{
22-
namespace emcal
20+
namespace o2::emcal
2321
{
2422

2523
/// \class Cell
@@ -90,72 +88,72 @@ class Cell
9088

9189
/// \brief Get the tower ID
9290
/// \return Tower ID
93-
short getTower() const { return mTowerID; }
91+
[[nodiscard]] short getTower() const { return mTowerID; }
9492

9593
/// \brief Set the time stamp
9694
/// \param timestamp Time in ns
9795
void setTimeStamp(float timestamp) { mTimestamp = timestamp; }
9896

9997
/// \brief Get the time stamp
10098
/// \return Time in ns
101-
float getTimeStamp() const { return mTimestamp; }
99+
[[nodiscard]] float getTimeStamp() const { return mTimestamp; }
102100

103101
/// \brief Set the energy of the cell
104102
/// \brief Energy of the cell in GeV
105103
void setEnergy(float energy) { mEnergy = energy; }
106104

107105
/// \brief Get the energy of the cell
108106
/// \return Energy of the cell
109-
float getEnergy() const { return mEnergy; }
107+
[[nodiscard]] float getEnergy() const { return mEnergy; }
110108

111109
/// \brief Set the amplitude of the cell
112110
/// \param amplitude Cell amplitude
113111
void setAmplitude(float amplitude) { setEnergy(amplitude); }
114112

115113
/// \brief Get cell amplitude
116114
/// \return Cell amplitude in GeV
117-
float getAmplitude() const { return getEnergy(); }
115+
[[nodiscard]] float getAmplitude() const { return getEnergy(); }
118116

119117
/// \brief Set the type of the cell
120118
/// \param ctype Type of the cell (HIGH_GAIN, LOW_GAIN, LEDMON, TRU)
121119
void setType(ChannelType_t ctype) { mChannelType = ctype; }
122120

123121
/// \brief Get the type of the cell
124122
/// \return Type of the cell (HIGH_GAIN, LOW_GAIN, LEDMON, TRU)
125-
ChannelType_t getType() const { return mChannelType; }
123+
[[nodiscard]] ChannelType_t getType() const { return mChannelType; }
126124

127125
/// \brief Check whether the cell is of a given type
128126
/// \param ctype Type of the cell (HIGH_GAIN, LOW_GAIN, LEDMON, TRU)
129127
/// \return True if the type of the cell matches the requested type, false otherwise
130-
bool isChannelType(ChannelType_t ctype) const { return mChannelType == ctype; }
128+
[[nodiscard]] bool isChannelType(ChannelType_t ctype) const { return mChannelType == ctype; }
131129

132130
/// \brief Mark cell as low gain cell
133131
void setLowGain() { setType(ChannelType_t::LOW_GAIN); }
134132

135133
/// \brief Check whether the cell is a low gain cell
136134
/// \return True if the cell type is low gain, false otherwise
137-
Bool_t getLowGain() const { return isChannelType(ChannelType_t::LOW_GAIN); }
135+
[[nodiscard]] Bool_t getLowGain() const { return isChannelType(ChannelType_t::LOW_GAIN); }
138136

139137
/// \brief Mark cell as high gain cell
140138
void setHighGain() { setType(ChannelType_t::HIGH_GAIN); }
141139

142140
/// \brief Check whether the cell is a high gain cell
143141
/// \return True if the cell type is high gain, false otherwise
144-
Bool_t getHighGain() const { return isChannelType(ChannelType_t::HIGH_GAIN); };
142+
[[nodiscard]] Bool_t getHighGain() const { return isChannelType(ChannelType_t::HIGH_GAIN); };
145143

146144
/// \brief Mark cell as LED monitor cell
147145
void setLEDMon() { setType(ChannelType_t::LEDMON); }
148146

149147
/// \brief Check whether the cell is a LED monitor cell
150148
/// \return True if the cell type is LED monitor, false otherwise
151-
Bool_t getLEDMon() const { return isChannelType(ChannelType_t::LEDMON); }
149+
[[nodiscard]] Bool_t getLEDMon() const { return isChannelType(ChannelType_t::LEDMON); }
152150

153151
/// \brief Mark cell as TRU cell
154152
void setTRU() { setType(ChannelType_t::TRU); }
155153

156154
/// \brief Check whether the cell is a TRU cell
157155
/// \return True if the cell type is TRU, false otherwise
158-
Bool_t getTRU() const { return isChannelType(ChannelType_t::TRU); }
156+
[[nodiscard]] Bool_t getTRU() const { return isChannelType(ChannelType_t::TRU); }
159157

160158
/// \brief Apply compression as done during writing to / reading from CTF
161159
/// \param version Encoder version
@@ -181,7 +179,7 @@ class Cell
181179
/// \return Encoded bit representation
182180
///
183181
/// Same as getTower - no compression applied for tower ID
184-
uint16_t getTowerIDEncoded() const;
182+
[[nodiscard]] uint16_t getTowerIDEncoded() const;
185183

186184
/// \brief Get encoded bit representation of timestamp (for CTF)
187185
/// \return Encoded bit representation
@@ -191,7 +189,7 @@ class Cell
191189
/// be stored is from -1023 to 1023 ns. In case the
192190
/// range is exceeded the time is set to the limit
193191
/// of the range.
194-
uint16_t getTimeStampEncoded() const;
192+
[[nodiscard]] uint16_t getTimeStampEncoded() const;
195193

196194
/// \brief Get encoded bit representation of energy (for CTF)
197195
/// \param version Encoding verions
@@ -203,11 +201,11 @@ class Cell
203201
/// the limits is provided the energy is
204202
/// set to the limits (0 in case of negative
205203
/// energy, 250. in case of energies > 250 GeV)
206-
uint16_t getEnergyEncoded(EncoderVersion version = EncoderVersion::EncodingV2) const;
204+
[[nodiscard]] uint16_t getEnergyEncoded(EncoderVersion version = EncoderVersion::EncodingV2) const;
207205

208206
/// \brief Get encoded bit representation of cell type (for CTF)
209207
/// \return Encoded bit representation
210-
uint16_t getCellTypeEncoded() const;
208+
[[nodiscard]] uint16_t getCellTypeEncoded() const;
211209

212210
void initializeFromPackedBitfieldV0(const char* bitfield);
213211

@@ -231,8 +229,8 @@ class Cell
231229
private:
232230
/// \brief Set cell energy from encoded bit representation (from CTF)
233231
/// \param energyBits Bit representation of energy
234-
/// \param cellTypeBits Bit representation of cell type
235-
void setEnergyEncoded(uint16_t energyBits, uint16_t cellTypeBits, EncoderVersion version = EncoderVersion::EncodingV1);
232+
/// \param channelTypeBits Bit representation of cell type
233+
void setEnergyEncoded(uint16_t energyBits, uint16_t channelTypeBits, EncoderVersion version = EncoderVersion::EncodingV1);
236234

237235
/// \brief Set cell time from encoded bit representation (from CTF)
238236
/// \param timestampBits Bit representation of timestamp
@@ -259,7 +257,6 @@ class Cell
259257
/// \param cell Cell to be printed
260258
/// \return Stream after printing
261259
std::ostream& operator<<(std::ostream& stream, const Cell& cell);
262-
} // namespace emcal
263-
} // namespace o2
260+
} // namespace o2::emcal
264261

265262
#endif

0 commit comments

Comments
 (0)