Skip to content

Commit 9ff2f3b

Browse files
mfasDasawenzel
authored andcommitted
[EMCAL-603] Treatment of access to uninitialized geometry
GetInstance raising GeometryNotInitializedException in case the geometry is not initialized. In additino add catch blocks around geometry access in different classes accessing geometry via GetInstance()
1 parent 2463f1e commit 9ff2f3b

File tree

8 files changed

+46
-38
lines changed

8 files changed

+46
-38
lines changed

Detectors/EMCAL/base/include/EMCALBase/ClusterFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class ClusterFactory
188188

189189
///
190190
/// Dummy constructor
191-
ClusterFactory();
191+
ClusterFactory() = default;
192192

193193
///
194194
/// \brief Constructor initializing the ClusterFactory

Detectors/EMCAL/base/include/EMCALBase/Geometry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Geometry
7070

7171
/// \brief Get geometry instance. It should have been set before.
7272
/// \return the pointer of the unique instance of the geometry
73+
/// \throw GeometryNotInitializedException in case the geometry is not initialized
7374
static Geometry* GetInstance();
7475

7576
/// \brief Get instance of the EMCAL geometry

Detectors/EMCAL/base/include/EMCALBase/GeometryBase.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ enum AcceptanceType_t { EMCAL_ACCEPTANCE = 1,
3333

3434
const std::string DEFAULT_GEOMETRY = "EMCAL_COMPLETE12SMV1_DCAL_8SM";
3535

36+
/// \class GeometryNotInitializedException
37+
/// \brief Error handling access to non-initialized geometry
38+
/// \ingroup EMCALbase
39+
class GeometryNotInitializedException final : public std::exception
40+
{
41+
public:
42+
/// \brief Constructor
43+
GeometryNotInitializedException() = default;
44+
45+
/// \brief Destructor
46+
~GeometryNotInitializedException() noexcept final = default;
47+
48+
/// \brief Access to error message
49+
/// \return Error message
50+
const char* what() const noexcept { return "Geometry not initialized"; }
51+
};
52+
3653
/// \class InvalidModuleException
3754
/// \brief Error Handling when an invalid module ID (outside the limits) is called
3855
/// \ingroup EMCALbase

Detectors/EMCAL/base/src/ClusterFactory.cxx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@
2525

2626
using namespace o2::emcal;
2727

28-
template <typename InputType>
29-
ClusterFactory<InputType>::ClusterFactory()
30-
{
31-
mGeomPtr = o2::emcal::Geometry::GetInstance();
32-
}
33-
3428
template <class InputType>
3529
ClusterFactory<InputType>::ClusterFactory(gsl::span<const o2::emcal::Cluster> clustersContainer, gsl::span<const InputType> inputsContainer, gsl::span<const int> cellsIndices)
3630
{
37-
mGeomPtr = o2::emcal::Geometry::GetInstance();
38-
3931
setContainer(clustersContainer, inputsContainer, cellsIndices);
4032
}
4133

Detectors/EMCAL/base/src/Geometry.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ Geometry::~Geometry()
190190
Geometry* Geometry::GetInstance()
191191
{
192192
Geometry* rv = static_cast<Geometry*>(sGeom);
193+
if (!rv) {
194+
throw GeometryNotInitializedException();
195+
}
193196
return rv;
194197
}
195198

Detectors/EMCAL/calib/src/BadChannelMap.cxx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,24 @@ TH2* BadChannelMap::getHistogramRepresentation() const
7272
MAXCOLS = 96;
7373
auto hist = new TH2S("badchannelmap", "Bad Channel Map", MAXCOLS, -0.5, double(MAXCOLS) - 0.5, MAXROWS, -0.5, double(MAXROWS) - 0.5);
7474
hist->SetDirectory(nullptr);
75-
auto geo = Geometry::GetInstance();
76-
if (!geo) {
77-
LOG(error) << "Geometry needs to be initialized";
78-
return hist;
79-
}
80-
81-
for (size_t cellID = 0; cellID < mBadCells.size(); cellID++) {
82-
int value(0);
83-
if (mBadCells.test(cellID)) {
84-
value = 1;
85-
} else if (mDeadCells.test(cellID)) {
86-
value = 2;
87-
} else if (mWarmCells.test(cellID)) {
88-
value = 3;
89-
}
90-
if (value) {
91-
auto position = geo->GlobalRowColFromIndex(cellID);
92-
hist->Fill(std::get<1>(position), std::get<0>(position), value);
75+
try {
76+
auto geo = Geometry::GetInstance();
77+
for (size_t cellID = 0; cellID < mBadCells.size(); cellID++) {
78+
int value(0);
79+
if (mBadCells.test(cellID)) {
80+
value = 1;
81+
} else if (mDeadCells.test(cellID)) {
82+
value = 2;
83+
} else if (mWarmCells.test(cellID)) {
84+
value = 3;
85+
}
86+
if (value) {
87+
auto position = geo->GlobalRowColFromIndex(cellID);
88+
hist->Fill(std::get<1>(position), std::get<0>(position), value);
89+
}
9390
}
91+
} catch (o2::emcal::GeometryNotInitializedException& e) {
92+
LOG(error) << "Geometry needs to be initialized";
9493
}
9594
return hist;
9695
}

Detectors/EMCAL/calibration/include/EMCALCalibration/EMCALCalibExtractor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class EMCALCalibExtractor
6363
EMCALCalibExtractor()
6464
{
6565
LOG(info) << "initialized EMCALCalibExtractor";
66-
if (!mGeometry) {
66+
try {
67+
// Try to access geometry initialized ountside
6768
mGeometry = o2::emcal::Geometry::GetInstance();
68-
if (!mGeometry) {
69-
mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(300000); // fallback option
70-
}
69+
} catch (o2::emcal::GeometryNotInitializedException& e) {
70+
mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(300000); // fallback option
7171
}
7272
// mNcells = mGeometry->GetNCells();
7373
};

Detectors/EMCAL/calibration/src/EMCALCalibExtractor.cxx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ boostHisto EMCALCalibExtractor::buildHitAndEnergyMeanScaled(double emin, double
3030
{
3131
// create the output histogram
3232
boostHisto eSumHistoScaled = boost::histogram::make_histogram(boost::histogram::axis::regular<>(100, 0, 100, "t-texp"), boost::histogram::axis::integer<>(0, mNcells, "CELL ID"));
33-
3433
// create a slice for each cell with energies ranging from emin to emax
3534
auto hEnergyCol = boost::histogram::make_histogram(boost::histogram::axis::regular<>(100, 0, 100., "t-texp"));
3635
auto hEnergyRow = boost::histogram::make_histogram(boost::histogram::axis::regular<>(250, 0, 250., "t-texp"));
@@ -47,9 +46,8 @@ boostHisto EMCALCalibExtractor::buildHitAndEnergyMeanScaled(double emin, double
4746

4847
for (int cellID = 0; cellID < mNcells; cellID++) {
4948
auto tempSlice = boost::histogram::algorithm::reduce(cellAmplitude, boost::histogram::algorithm::shrink(cellID, cellID), boost::histogram::algorithm::shrink(emin, emax));
50-
auto geo = Geometry::GetInstance();
5149
// (0 - row, 1 - column)
52-
auto position = geo->GlobalRowColFromIndex(cellID);
50+
auto position = mGeometry->GlobalRowColFromIndex(cellID);
5351
int row = std::get<0>(position);
5452
int col = std::get<1>(position);
5553

@@ -101,9 +99,8 @@ boostHisto EMCALCalibExtractor::buildHitAndEnergyMeanScaled(double emin, double
10199

102100
// Scale each cell by the deviation of the mean of the column and the global mean
103101
for (int iCell = 0; iCell < mNcells; iCell++) {
104-
auto geo = Geometry::GetInstance();
105102
// (0 - row, 1 - column)
106-
auto position = geo->GlobalRowColFromIndex(iCell);
103+
auto position = mGeometry->GlobalRowColFromIndex(iCell);
107104
int col = std::get<1>(position);
108105
if (hEnergyCol.at(col) > 0.) {
109106
// will need to change the 100 depending on the number of energy bins we end up having
@@ -115,9 +112,8 @@ boostHisto EMCALCalibExtractor::buildHitAndEnergyMeanScaled(double emin, double
115112

116113
// Scale each cell by the deviation of the mean of the row and the global mean
117114
for (int iCell = 0; iCell < mNcells; iCell++) {
118-
auto geo = Geometry::GetInstance();
119115
// (0 - row, 1 - column)
120-
auto position = geo->GlobalRowColFromIndex(iCell);
116+
auto position = mGeometry->GlobalRowColFromIndex(iCell);
121117
int row = std::get<0>(position);
122118
if (hEnergyRow.at(row) > 0.) {
123119
// will need to change the 100 depending on the number of energy bins we end up having

0 commit comments

Comments
 (0)