Skip to content

Commit d1fa18a

Browse files
authored
[EMCAL-1154] Adjust CellLabels for cross talk emulation (#14385)
- The CellLabel class used gsl::span as its members to store the mcLabels and amplitude fractions. However, when we want to use the cross talk emulation, we want to add new cells which happens inside the cross talk emulation function. Outside of this function the newley added CellLabels would point to dangling memory. That's why the members needed to be changed to std::vectors. Also a move constructor was added.
1 parent 0bbb3da commit d1fa18a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cstddef>
1616
#include <cstdint>
1717
#include <gsl/span>
18+
#include <vector>
1819

1920
namespace o2
2021
{
@@ -34,10 +35,15 @@ class CellLabel
3435
public:
3536
// CellLabel() = default;
3637

37-
/// \brief Constructor
38+
/// \brief Constructor using std::vector by moving NOT copying
3839
/// \param labels list of mc labels
3940
/// \param amplitudeFractions list of amplitude fractions
40-
CellLabel(const gsl::span<const int> labels, const gsl::span<const float> amplitudeFractions);
41+
CellLabel(std::vector<int> labels, std::vector<float> amplitudeFractions);
42+
43+
/// \brief Constructor using gsl::span
44+
/// \param labels list of mc labels
45+
/// \param amplitudeFractions list of amplitude fractions
46+
CellLabel(gsl::span<const int> labels, gsl::span<const float> amplitudeFractions);
4147

4248
// ~CellLabel() = default;
4349
// CellLabel(const CellLabel& clus) = default;
@@ -52,21 +58,21 @@ class CellLabel
5258
int32_t GetLabel(size_t index) const { return mLabels[index]; }
5359

5460
/// \brief Getter for labels
55-
gsl::span<const int32_t> GetLabels() const { return mLabels; }
61+
std::vector<int32_t> GetLabels() const { return mLabels; }
5662

5763
/// \brief Getter for amplitude fraction
5864
/// \param index index which amplitude fraction to get
5965
float GetAmplitudeFraction(size_t index) const { return mAmplitudeFraction[index]; }
6066

6167
/// \brief Getter for amplitude fractions
62-
gsl::span<const float> GetAmplitudeFractions() const { return mAmplitudeFraction; }
68+
std::vector<float> GetAmplitudeFractions() const { return mAmplitudeFraction; }
6369

6470
/// \brief Getter for label with leading amplitude fraction
6571
int32_t GetLeadingMCLabel() const;
6672

6773
protected:
68-
gsl::span<const int32_t> mLabels; ///< List of MC particles that generated the cluster, ordered in deposited energy.
69-
gsl::span<const float> mAmplitudeFraction; ///< List of the fraction of the cell energy coming from a MC particle. Index aligns with mLabels!
74+
std::vector<int32_t> mLabels; ///< List of MC particles that generated the cluster, ordered in deposited energy.
75+
std::vector<float> mAmplitudeFraction; ///< List of the fraction of the cell energy coming from a MC particle. Index aligns with mLabels!
7076
};
7177

7278
} // namespace emcal

DataFormats/Detectors/EMCAL/src/CellLabel.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
#include <cstddef>
1717
#include <cstdint>
1818
#include <gsl/span>
19+
#include <vector>
20+
#include <utility>
1921

2022
using namespace o2::emcal;
2123

22-
CellLabel::CellLabel(const gsl::span<const int> labels, const gsl::span<const float> amplitudeFractions) : mLabels(labels), mAmplitudeFraction(amplitudeFractions)
24+
CellLabel::CellLabel(std::vector<int> labels, std::vector<float> amplitudeFractions) : mLabels(std::move(labels)), mAmplitudeFraction(std::move(amplitudeFractions))
25+
{
26+
if (labels.size() != amplitudeFractions.size()) {
27+
LOG(error) << "Size of labels " << labels.size() << " does not match size of amplitude fraction " << amplitudeFractions.size() << " !";
28+
}
29+
}
30+
31+
CellLabel::CellLabel(gsl::span<const int> labels, gsl::span<const float> amplitudeFractions) : mLabels(labels.begin(), labels.end()), mAmplitudeFraction(amplitudeFractions.begin(), amplitudeFractions.end())
2332
{
2433
if (labels.size() != amplitudeFractions.size()) {
2534
LOG(error) << "Size of labels " << labels.size() << " does not match size of amplitude fraction " << amplitudeFractions.size() << " !";

0 commit comments

Comments
 (0)