Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating DigitizerUtility::Amplitude to prevent memory leak #17193

Merged
merged 1 commit into from Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions SimTracker/SiPhase2Digitizer/plugins/DigitizerUtility.h
@@ -1,4 +1,3 @@

#ifndef __SimTracker_SiPhase2Digitizer_DigitizerUtility_h
#define __SimTracker_SiPhase2Digitizer_DigitizerUtility_h

Expand All @@ -18,21 +17,21 @@ namespace DigitizerUtility {
Amplitude( float amp, const PSimHit* hitp, float frac=0, size_t hitIndex=0, unsigned int tofBin=0) :
_amp(amp) {
if (frac > 0) {
if (hitp != nullptr) _simInfoList.push_back({frac,new SimHitInfoForLinks(hitp,hitIndex,tofBin)});
else _simInfoList.push_back({frac,0});
if (hitp != nullptr) _simInfoList.push_back({frac, std::make_unique<SimHitInfoForLinks>(hitp,hitIndex,tofBin)});
else _simInfoList.push_back({frac, nullptr});
}
}

// can be used as a float by convers.
operator float() const {return _amp;}
float ampl() const {return _amp;}
const std::vector<std::pair<float,SimHitInfoForLinks*> >& simInfoList() const {return _simInfoList;}
const std::vector<std::pair<float, std::unique_ptr<SimHitInfoForLinks> > >& simInfoList() const {return _simInfoList;}

void operator+= (const Amplitude& other) {
_amp += other._amp;
// in case of digi from the noise, the MC information need not be there
for (auto const & ic : other.simInfoList()) {
if (ic.first > -0.5) _simInfoList.push_back({ic.first, ic.second});
for (auto const& ic : other.simInfoList()) {
if (ic.first > -0.5) _simInfoList.push_back({ic.first, std::make_unique<SimHitInfoForLinks>(*ic.second)});
}
}
void operator+= (const float& amp) {
Expand All @@ -47,7 +46,7 @@ namespace DigitizerUtility {

private:
float _amp;
std::vector<std::pair<float,SimHitInfoForLinks*> > _simInfoList;
std::vector<std::pair<float, std::unique_ptr<SimHitInfoForLinks> > > _simInfoList;
};

//*********************************************************
Expand Down
Expand Up @@ -947,7 +947,8 @@ void Phase2TrackerDigitizerAlgorithm::digitize(const Phase2TrackerGeomDetUnit* p

// Digitize if the signal is greater than threshold
for (auto const & s : theSignal) {
DigitizerUtility::Amplitude sig_data = s.second;
// DigitizerUtility::Amplitude sig_data = s.second;
const DigitizerUtility::Amplitude& sig_data = s.second;
float signalInElectrons = sig_data.ampl();
int adc;
if (signalInElectrons >= theThresholdInE) { // check threshold
Expand All @@ -957,11 +958,9 @@ void Phase2TrackerDigitizerAlgorithm::digitize(const Phase2TrackerGeomDetUnit* p
info.sig_tot = adc;
info.ot_bit = ( signalInElectrons > theHIPThresholdInE ? true : false);
if (makeDigiSimLinks_ ) {
int j = 0;
for (auto l : sig_data.simInfoList()) {
j++;
for (auto const & l : sig_data.simInfoList()) {
float charge_frac = l.first/signalInElectrons;
if (l.first > -5.0) info.simInfoList.push_back({charge_frac,l.second});
if (l.first > -5.0) info.simInfoList.push_back({charge_frac, l.second.get()});
}
}
digi_map.insert({s.first, info});
Expand Down