Commit ab00baed authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'AliveStraws_master_fix_memory_leak' into 'master'

Fix memory leak in TRT AliveStraws.

See merge request !30515
parents 545cf167 e391bb43
/* /*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef ALIVESTRAWS_H #ifndef ALIVESTRAWS_H
#define ALIVESTRAWS_H #define ALIVESTRAWS_H
#include "AthenaKernel/CLASS_DEF.h" #include "AthenaKernel/CLASS_DEF.h"
#include "AthenaKernel/CondCont.h" #include "AthenaKernel/CondCont.h"
#include <cassert>
#include <array>
namespace TRTCond{ namespace TRTCond{
class AliveStraws{ class AliveStraws{
public: public:
AliveStraws() { static constexpr unsigned int NTOTAL = 7;
// Create arrays for alive straws static constexpr unsigned int NLOCAL = 6;
// These are moved to CondStore which takes care of their deletion static constexpr unsigned int NWHEEL = 34;
m_stw_total = new int[7](); static constexpr unsigned int NLOCALPHI = 32;
m_stw_local = new int*[6]; AliveStraws() {}
m_stw_wheel = new int*[34];
for (int i=0; i<6 ; ++i) m_stw_local[i] = new int[32]();
for (int i=0; i<34; ++i) m_stw_wheel[i] = new int[32]();
}
virtual ~AliveStraws() {} virtual ~AliveStraws() {}
int *getStwTotal() const {return m_stw_total; } const std::array<int,NTOTAL> &getStwTotal() const {return m_stw_total; }
int **getStwLocal() const {return m_stw_local; } const std::array<std::array<int,NLOCALPHI>,NLOCAL> &getStwLocal() const {return m_stw_local; }
int **getStwWheel() const {return m_stw_wheel; } const std::array<std::array<int,NLOCALPHI>,NWHEEL> &getStwWheel() const {return m_stw_wheel; }
void update(const int& i, const int& j, const int& phi) { void update(const unsigned int i, const unsigned int j, const unsigned int phi) {
assert(i>0 && i<m_stw_total.size() && i-1<m_stw_local.size() && j<m_stw_wheel.size() && phi<NLOCALPHI);
m_stw_total[0] +=1; m_stw_total[0] +=1;
m_stw_total[i] +=1; m_stw_total[i] +=1;
m_stw_local[i-1][phi] +=1; m_stw_local[i-1][phi] +=1;
...@@ -32,10 +32,11 @@ namespace TRTCond{ ...@@ -32,10 +32,11 @@ namespace TRTCond{
} }
private: private:
int *m_stw_total; std::array<int,NTOTAL> m_stw_total {};
int **m_stw_local; std::array<std::array<int,NLOCALPHI>,NLOCAL> m_stw_local {};
int **m_stw_wheel; std::array<std::array<int,NLOCALPHI>,NWHEEL> m_stw_wheel {};
}; };
} }
CLASS_DEF(TRTCond::AliveStraws,234870469,1) CLASS_DEF(TRTCond::AliveStraws,234870469,1)
CONDCONT_DEF(TRTCond::AliveStraws,110897079); CONDCONT_DEF(TRTCond::AliveStraws,110897079);
......
/* /*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/ */
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
...@@ -78,15 +78,17 @@ namespace InDet ...@@ -78,15 +78,17 @@ namespace InDet
static const int NTOTAL = 7; static const int NTOTAL = 7;
//(barrel, ECA, ECB)side C, (barrel, ECA, ECB)side A [6][32] //(barrel, ECA, ECB)side C, (barrel, ECA, ECB)side A [6][32]
static const int NLOCAL = 6; static const int NLOCAL = 6;
static const int NWHEEL = 34;
static const int NLOCALPHI = 32; static const int NLOCALPHI = 32;
struct OccupancyData { struct OccupancyData {
OccupancyData(const std::array<std::array<int,NLOCALPHI>,NLOCAL> &local)
: m_stw_local(local)
{}
int m_occ_total[NTOTAL] = {0}; int m_occ_total[NTOTAL] = {0};
int m_hit_total[NTOTAL] = {0}; int m_hit_total[NTOTAL] = {0};
int m_occ_local[NLOCAL][NLOCALPHI] = {{0}}; int m_occ_local[NLOCAL][NLOCALPHI] = {{0}};
int m_hit_local[NLOCAL][NLOCALPHI] = {{0}}; int m_hit_local[NLOCAL][NLOCALPHI] = {{0}};
int* m_stw_total = nullptr; const std::array<std::array<int,NLOCALPHI>,NLOCAL> &m_stw_local;
int** m_stw_local = nullptr;
int** m_stw_wheel = nullptr;
float m_stws_ratio[2][NLOCALPHI] = {{0}}; float m_stws_ratio[2][NLOCALPHI] = {{0}};
}; };
......
/* /*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/ */
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
...@@ -163,6 +163,7 @@ float TRT_LocalOccupancy::LocalOccupancy(const Trk::Track& track ) const { ...@@ -163,6 +163,7 @@ float TRT_LocalOccupancy::LocalOccupancy(const Trk::Track& track ) const {
float averageocc = 0; float averageocc = 0;
int nhits = 0; int nhits = 0;
const std::array<std::array<int,NLOCALPHI>,NLOCAL> &stw_local = data->m_stw_local;
for (int i=0; i<6; ++i){ for (int i=0; i<6; ++i){
for (int j = 0; j < 32; j++){ for (int j = 0; j < 32; j++){
...@@ -171,8 +172,8 @@ float TRT_LocalOccupancy::LocalOccupancy(const Trk::Track& track ) const { ...@@ -171,8 +172,8 @@ float TRT_LocalOccupancy::LocalOccupancy(const Trk::Track& track ) const {
if (hits_array<1) continue; if (hits_array<1) continue;
float occ=0; float occ=0;
occ = (data->m_occ_local [i][j])*1.e-2 ; occ = (data->m_occ_local [i][j])*1.e-2 ;
if (data->m_stw_local[i][j] != 0){ if (stw_local[i][j] != 0){
if(occ == 0 && float(hits_array)/data->m_stw_local[i][j] > 0.01){ if(occ == 0 && float(hits_array)/stw_local[i][j] > 0.01){
ATH_MSG_DEBUG("Occupancy is 0 for : " << i << " " << j << " BUT THERE ARE HITS!!!: " << hits_array); ATH_MSG_DEBUG("Occupancy is 0 for : " << i << " " << j << " BUT THERE ARE HITS!!!: " << hits_array);
continue; continue;
} }
...@@ -247,15 +248,13 @@ std::map<int, double> TRT_LocalOccupancy::getDetectorOccupancy( const TRT_RDO_C ...@@ -247,15 +248,13 @@ std::map<int, double> TRT_LocalOccupancy::getDetectorOccupancy( const TRT_RDO_C
SG::ReadCondHandle<TRTCond::AliveStraws> strawHandle{m_strawReadKey}; SG::ReadCondHandle<TRTCond::AliveStraws> strawHandle{m_strawReadKey};
const TRTCond::AliveStraws* strawCounts{*strawHandle}; const TRTCond::AliveStraws* strawCounts{*strawHandle};
const std::array<int,TRTCond::AliveStraws::NTOTAL> &straws = strawCounts->getStwTotal();
int* straws = strawCounts->getStwTotal();
occResults[-1] = (double)hitCounter[-1]/(double)straws[1]; occResults[-1] = (double)hitCounter[-1]/(double)straws[1];
occResults[-2] = (double)hitCounter[-2]/(double)(straws[2] + straws[3]); occResults[-2] = (double)hitCounter[-2]/(double)(straws[2] + straws[3]);
occResults[1] = (double)hitCounter[1] /(double)straws[4]; occResults[1] = (double)hitCounter[1] /(double)straws[4];
occResults[2] = (double)hitCounter[2] /(double)(straws[5] + straws[6]); occResults[2] = (double)hitCounter[2] /(double)(straws[5] + straws[6]);
return occResults; return occResults;
} }
...@@ -488,10 +487,14 @@ const TRT_LocalOccupancy::OccupancyData* TRT_LocalOccupancy::getData() const ...@@ -488,10 +487,14 @@ const TRT_LocalOccupancy::OccupancyData* TRT_LocalOccupancy::getData() const
std::unique_ptr<TRT_LocalOccupancy::OccupancyData> std::unique_ptr<TRT_LocalOccupancy::OccupancyData>
TRT_LocalOccupancy::makeData() const TRT_LocalOccupancy::makeData() const
{ {
auto data = std::make_unique<OccupancyData>();
SG::ReadHandle<TRT_DriftCircleContainer> driftCircleContainer( m_trt_driftcircles ); SG::ReadHandle<TRT_DriftCircleContainer> driftCircleContainer( m_trt_driftcircles );
// count live straws
SG::ReadCondHandle<TRTCond::AliveStraws> strawHandle{m_strawReadKey};
const TRTCond::AliveStraws* strawCounts{*strawHandle};
auto data = std::make_unique<OccupancyData>(strawCounts->getStwLocal());
// put # hits in vectors // put # hits in vectors
if ( driftCircleContainer.isValid() ) { if ( driftCircleContainer.isValid() ) {
ATH_MSG_DEBUG("Found Drift Circles in StoreGate"); ATH_MSG_DEBUG("Found Drift Circles in StoreGate");
...@@ -519,19 +522,14 @@ TRT_LocalOccupancy::makeData() const ...@@ -519,19 +522,14 @@ TRT_LocalOccupancy::makeData() const
ATH_MSG_WARNING("No TRT Drift Circles in StoreGate"); ATH_MSG_WARNING("No TRT Drift Circles in StoreGate");
} }
const std::array<int,NTOTAL> &stw_total = strawCounts->getStwTotal();
const std::array<std::array<int,NLOCALPHI>,NLOCAL> &stw_local = strawCounts->getStwLocal();
// count live straws
SG::ReadCondHandle<TRTCond::AliveStraws> strawHandle{m_strawReadKey};
const TRTCond::AliveStraws* strawCounts{*strawHandle};
data->m_stw_total = strawCounts->getStwTotal();
data->m_stw_local = strawCounts->getStwLocal();
// Calculate Occs: // Calculate Occs:
for (int i=0; i<NTOTAL; ++i) { for (int i=0; i<NTOTAL; ++i) {
float occ = 0; float occ = 0;
int hits = data->m_hit_total[i]; int hits = data->m_hit_total[i];
int stws = data->m_stw_total[i]; int stws = stw_total[i];
if (stws>0) occ = float(hits*100)/stws; if (stws>0) occ = float(hits*100)/stws;
data->m_occ_total[i] = int(occ); data->m_occ_total[i] = int(occ);
} }
...@@ -539,13 +537,13 @@ TRT_LocalOccupancy::makeData() const ...@@ -539,13 +537,13 @@ TRT_LocalOccupancy::makeData() const
for (int j=0; j<NLOCALPHI; ++j) { for (int j=0; j<NLOCALPHI; ++j) {
float occ = 0; float occ = 0;
int hits = data->m_hit_local[i][j]; int hits = data->m_hit_local[i][j];
int stws = data->m_stw_local[i][j]; int stws = stw_local[i][j];
if (stws>0) occ = float(hits*100)/stws; if (stws>0) occ = float(hits*100)/stws;
data->m_occ_local[i][j] = int(occ); data->m_occ_local[i][j] = int(occ);
} }
} }
ATH_MSG_DEBUG("Active straws: " << data->m_stw_total[0] << "\t total number of hits: " << data->m_hit_total[0] << "\t occ: " << data->m_occ_total[0] ); ATH_MSG_DEBUG("Active straws: " << stw_total[0] << "\t total number of hits: " << data->m_hit_total[0] << "\t occ: " << data->m_occ_total[0] );
return data; return data;
} }
...@@ -553,17 +551,17 @@ TRT_LocalOccupancy::makeData() const ...@@ -553,17 +551,17 @@ TRT_LocalOccupancy::makeData() const
std::unique_ptr<TRT_LocalOccupancy::OccupancyData> std::unique_ptr<TRT_LocalOccupancy::OccupancyData>
TRT_LocalOccupancy::makeDataTrigger() const TRT_LocalOccupancy::makeDataTrigger() const
{ {
auto data = std::make_unique<OccupancyData>();
SG::ReadCondHandle<TRTCond::AliveStraws> strawHandle{m_strawReadKey}; SG::ReadCondHandle<TRTCond::AliveStraws> strawHandle{m_strawReadKey};
const TRTCond::AliveStraws* strawCounts{*strawHandle}; const TRTCond::AliveStraws* strawCounts{*strawHandle};
data->m_stw_local = strawCounts->getStwLocal(); auto data = std::make_unique<OccupancyData>(strawCounts->getStwLocal());
data->m_stw_wheel = strawCounts->getStwWheel(); const std::array<std::array<int,NLOCALPHI>,NLOCAL> &stw_local = strawCounts->getStwLocal();;
const std::array<std::array<int,NLOCALPHI>,NWHEEL> &stw_wheel = strawCounts->getStwWheel();
for (int i=0; i<5; ++i){ for (int i=0; i<5; ++i){
for (int j=0; j<NLOCALPHI; ++j){ for (int j=0; j<NLOCALPHI; ++j){
data->m_stws_ratio[0][j]+=float(data->m_stw_wheel[i+3 ][j])/data->m_stw_local[1][j]; data->m_stws_ratio[0][j]+=float(stw_wheel[i+3 ][j])/stw_local[1][j];
data->m_stws_ratio[1][j]+=float(data->m_stw_wheel[i+20][j])/data->m_stw_local[4][j]; data->m_stws_ratio[1][j]+=float(stw_wheel[i+20][j])/stw_local[4][j];
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment