diff --git a/Reconstruction/iPat/iPatTrackFollower/src/TrackBuilder.cxx b/Reconstruction/iPat/iPatTrackFollower/src/TrackBuilder.cxx index 0d53cb783edbac700edf6369201a36c8478c0381..a2408c2b06cac881053da147882155dcb14baf44 100755 --- a/Reconstruction/iPat/iPatTrackFollower/src/TrackBuilder.cxx +++ b/Reconstruction/iPat/iPatTrackFollower/src/TrackBuilder.cxx @@ -15,6 +15,14 @@ #include "iPatTrack/Track.h" #include "iPatTrackFollower/TrackBuilder.h" +namespace{ + template <class ContainerPtr> + void deleteContainedPointers(ContainerPtr * c){ + for (auto & p:*c) delete p; + return; + } +} + //<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> TrackBuilder::TrackBuilder(const std::string& type, @@ -85,8 +93,8 @@ TrackBuilder::trackFromHits (TrackStatus status, hits->begin(), hits->end())) { - for (std::list<HitOnTrack*>::const_iterator h = hits->begin(); h != hits->end(); ++h) - delete *h; + deleteContainedPointers(hits); + delete hits; delete hitQuality; ATH_MSG_DEBUG( "trackFromHits: FAIL with insufficient hits" ); @@ -172,19 +180,16 @@ TrackBuilder::trackFromHits (TrackStatus status, else { delete hitQuality; - for (std::list<HitOnTrack*>::const_iterator h = hits->begin(); h != hits->end(); ++h) - delete *h; + deleteContainedPointers(hits); + hits->clear(); delete hits; delete fitQuality; delete perigeeParameters; if (scattererParameters) { - for (parameter_iterator s = scattererParameters->begin(); - s != scattererParameters->end(); - ++s) - delete *s; - delete scattererParameters; + deleteContainedPointers(scattererParameters); + delete scattererParameters; } ATH_MSG_DEBUG( "trackFromHitsFAIL with bad fit quality" ); return 0; @@ -223,7 +228,7 @@ TrackBuilder::trackRefit (const Track& track) const hits->begin(), hits->end()); - if (m_trackQuality->goodTrack(track.status(),*fitQuality,*hitQuality)) + if (scattererParameters and m_trackQuality->goodTrack(track.status(),*fitQuality,*hitQuality)) { builtTrack = new Track(track.status(), hits, @@ -239,18 +244,14 @@ TrackBuilder::trackRefit (const Track& track) const { // TODO: the plan is to build last-layers SCT + trt secondary tracks here delete hitQuality; - for (std::list<HitOnTrack*>::const_iterator h = hits->begin(); h != hits->end(); ++h) - delete *h; + deleteContainedPointers(hits); hits->clear(); delete hits; delete fitQuality; delete perigeeParameters; if (scattererParameters) { - for (parameter_iterator s = scattererParameters->begin(); - s != scattererParameters->end(); - ++s) - delete *s; + deleteContainedPointers(scattererParameters); delete scattererParameters; } ATH_MSG_DEBUG( "trackRefit: FAIL with bad fit quality" ); diff --git a/Reconstruction/iPat/iPatTrackFollower/src/TrackFollower.cxx b/Reconstruction/iPat/iPatTrackFollower/src/TrackFollower.cxx index 9e9c28069070bcba4dbd43dfcc0e6f5c82a4bed0..4b6e8d29a0b91df27fe7c2ede0bf7331c8760cbf 100755 --- a/Reconstruction/iPat/iPatTrackFollower/src/TrackFollower.cxx +++ b/Reconstruction/iPat/iPatTrackFollower/src/TrackFollower.cxx @@ -30,6 +30,7 @@ #include "iPatTrackFollower/LayerPredictor.h" #include "iPatTrackFollower/SiliconClusterMap.h" #include "iPatTrackFollower/TrackFollower.h" +#include <memory> //<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> @@ -343,78 +344,65 @@ TrackFollower::extrapolate_inwards (const Track& track) // associate and build track for hits in one extrapolated layer at a time (expensive!) std::vector<SiliconLayer*>::iterator end = begin; - Track* extrapolatedTrack = 0; - Track* newTrack = 0; + std::unique_ptr<Track> extrapolatedTrack{}; + std::unique_ptr<Track> newTrack{}; TrackStatus status = track.status(); hit_citerator hitBegin = track.hit_list_begin(); hit_citerator hitEnd = track.hit_list_end(); - do - { - // move begin backwards to the preceding active layer. - // Include any leading material by going back again until - // an active layer is found and then go forwards one - while (begin != layers->begin() && (**(--begin)).isInactive()) ; - while (begin != layers->begin() && (**(--begin)).isInactive()) ; - if (begin != layers->begin()) ++begin; - - if (begin == layers->begin()) - { - switch (status) - { - case truncated: - status = truncated; - break; - case segment: - case long_segment: - case pendingTRT: - status = pendingTRT; - break; - case secondary: - case primary: - status = primary; - break; - default: - ATH_MSG_WARNING( " unexpected Track::extrapolate_inwards " ); - delete layers; - return 0; - }; - } - - hit_list* hits = associateSilicon(begin,end,false,track); - end = begin; - for (hit_citerator h = hitBegin; h != hitEnd; ++h) - hits->push_back(new HitOnTrack(**h)); - - newTrack = m_trackBuilder->trackFromHits(status,hits,track); - if (newTrack) - { - // keep newTrack provided it adds cluster(s) - bool haveCluster = false; - for (hit_citerator h = newTrack->hit_list_begin(); - h != newTrack->hit_list_end(); - ++h) - { - if ((**h).isCluster()) haveCluster = true; - if ((**h).status() != scatterer) continue; - if (haveCluster) - { - delete extrapolatedTrack; - extrapolatedTrack = newTrack; - hitBegin = newTrack->hit_list_begin(); - hitEnd = newTrack->hit_list_end(); - } - else - { - delete newTrack; - newTrack = 0; - } - break; - } - } + do{ + // move begin backwards to the preceding active layer. + // Include any leading material by going back again until + // an active layer is found and then go forwards one + while (begin != layers->begin() && (**(--begin)).isInactive()) ; + while (begin != layers->begin() && (**(--begin)).isInactive()) ; + if (begin != layers->begin()) ++begin; + + if (begin == layers->begin()){ + switch (status){ + case truncated: + status = truncated; + break; + case segment: + case long_segment: + case pendingTRT: + status = pendingTRT; + break; + case secondary: + case primary: + status = primary; + break; + default: + ATH_MSG_WARNING( " unexpected Track::extrapolate_inwards " ); + delete layers; + return 0; + }; + } + + hit_list* hits = associateSilicon(begin,end,false,track); + end = begin; + for (hit_citerator h = hitBegin; h != hitEnd; ++h) hits->push_back(new HitOnTrack(**h)); + // + newTrack.reset(m_trackBuilder->trackFromHits(status,hits,track)); + if (newTrack) { + // keep newTrack provided it adds cluster(s) + bool haveCluster = false; + for (hit_citerator h = newTrack->hit_list_begin();h != newTrack->hit_list_end();++h){ + if ((**h).isCluster()) haveCluster = true; + if ((**h).status() != scatterer) continue; + if (haveCluster){ + extrapolatedTrack = std::move(newTrack); + hitBegin = newTrack->hit_list_begin(); + hitEnd = newTrack->hit_list_end(); + }else{ + newTrack.reset(); + } + break; + } + } } while (newTrack && begin != layers->begin()); - + // delete layers; - return extrapolatedTrack; + return extrapolatedTrack.release(); } Track*