diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h index bd15e26dcf5243cce98eb774d393bf1eb3d1b105..57f7a54db9809c42f3e1db0a9b0a5c8b171f335d 100644 --- a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/TrkAmbiguitySolver/TrkAmbiguitySolver.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ @@ -12,16 +12,18 @@ TrkAmbiguitySolver Algorithm #define TRKAMBIGUITYSOLVER_H #include "AthenaBaseComps/AthAlgorithm.h" -#include "GaudiKernel/ToolHandle.h" -#include "TrkTrack/TrackCollection.h" -#include "AthContainers/DataVector.h" + #include "AthContainers/ConstDataVector.h" +#include "AthContainers/DataVector.h" +#include "TrkToolInterfaces/ITrackAmbiguityProcessorTool.h" +#include "TrkTrack/TrackCollection.h" + +#include "GaudiKernel/ToolHandle.h" + #include <string> namespace Trk { - class ITrackAmbiguityProcessorTool; - /**Algorithm does ambiguity processing This algorithm uses the TrkAmbiguityProcessorTool AlgTool to resolve ambiguities in the passed tracks. @@ -33,46 +35,42 @@ namespace Trk public: TrkAmbiguitySolver(const std::string& name, ISvcLocator* pSvcLocator); - ~TrkAmbiguitySolver(void); + virtual ~TrkAmbiguitySolver(void) = default; - StatusCode initialize(void) override; - StatusCode execute(void) override; - StatusCode finalize(void) override; + virtual StatusCode initialize(void) override; + virtual StatusCode execute(void) override; + virtual StatusCode finalize(void) override; private: //!<where to find tracks (set in jobOptions and can be multiple collections) SG::ReadHandleKeyArray<TrackCollection> m_tracksLocation; - SG::WriteHandleKey<TrackCollection> m_resolvedTracksLocation;//!<where to save the resolved tracks + SG::WriteHandleKey<TrackCollection> m_resolvedTracksLocation{this, "TrackOutput", "Tracks", "where to save the resolved tracks"}; /** decides whether ambi processing actually occurs (if not, the tracks are just resaved). Default=false.*/ - bool m_resolveTracks; + BooleanProperty m_resolveTracks{this, "ResolveTracks", true}; /**Number of tracks input. Useful for debugging*/ - long int m_trackInCount; + long int m_trackInCount{0}; /**Number of tracks passing Ambi solving. Useful for debugging*/ - long int m_trackOutCount; - + long int m_trackOutCount{0}; + /** responsible for actual amiguity processing*/ - ToolHandle<ITrackAmbiguityProcessorTool> m_ambiTool; + ToolHandle<ITrackAmbiguityProcessorTool> m_ambiTool{this, "AmbiguityProcessor", "Trk::SimpleAmbiguityProcessorTool/TrkAmbiguityProcessor"}; /** get tracks */ - StatusCode getTracks(ConstDataVector<TrackCollection> &oldTracks); + StatusCode getTracks(ConstDataVector<TrackCollection>& oldTracks); /** Save the processed tracks. If ambiguity process has not been called then they will still be the original converted tracks */ /** Eventually this will use the TrkAmbiguityProcessorTool to resolve the track ambiguities. At the moment it just saves a new vector of converted tracks. */ - void resolveTracks(std::unique_ptr<TrackCollection>&, ConstDataVector<TrackCollection>&); + void resolveTracks(std::unique_ptr<TrackCollection>& tracks, ConstDataVector<TrackCollection>& oldTracks); }; } -#endif - - - - +#endif diff --git a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx index 940e1c066a99ac8f4c37a9b676284a7266792198..010c3da25f8489d7c348d528e26a007f843b6106 100644 --- a/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx +++ b/Tracking/TrkAlgorithms/TrkAmbiguitySolver/src/TrkAmbiguitySolver.cxx @@ -1,46 +1,32 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "TrkAmbiguitySolver/TrkAmbiguitySolver.h" -#include "TrkToolInterfaces/ITrackAmbiguityProcessorTool.h" -#include "StoreGate/StoreGateSvc.h" Trk::TrkAmbiguitySolver::TrkAmbiguitySolver(const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm (name, pSvcLocator), - m_tracksLocation{""}, - m_resolvedTracksLocation("Tracks"), - m_resolveTracks(true), - m_trackInCount(0), - m_trackOutCount(0), - m_ambiTool("Trk::SimpleAmbiguityProcessorTool/TrkAmbiguityProcessor", this) + AthAlgorithm(name, pSvcLocator) { - declareProperty("TrackInput" , m_tracksLocation); - declareProperty("TrackOutput" , m_resolvedTracksLocation); - declareProperty("AmbiguityProcessor", m_ambiTool); - declareProperty("ResolveTracks" , m_resolveTracks); + declareProperty("TrackInput", m_tracksLocation={""}); } -//-------------------------------------------------------------------------- -Trk::TrkAmbiguitySolver::~TrkAmbiguitySolver(void) -{} - //----------------------------------------------------------------------- StatusCode Trk::TrkAmbiguitySolver::initialize() { - ATH_MSG_INFO( "TrkAmbiguitySolver::initialize(). " ); + ATH_MSG_INFO("TrkAmbiguitySolver::initialize(). "); - if (!m_resolveTracks) { - ATH_MSG_INFO( "ATTENTION: Resolving tracks turned off! " ); + if (not m_resolveTracks) { + ATH_MSG_INFO("ATTENTION: Resolving tracks turned off! "); m_ambiTool.disable(); } else { // Get Tools sevices if (m_ambiTool.retrieve().isFailure()) { - msg(MSG::FATAL) << "Failed to retrieve tool " << m_ambiTool << endmsg; + ATH_MSG_FATAL("Failed to retrieve tool " << m_ambiTool); return StatusCode::FAILURE; - } else - ATH_MSG_INFO( "Retrieved tool " << m_ambiTool ); + } else { + ATH_MSG_INFO("Retrieved tool " << m_ambiTool); + } } ATH_CHECK(m_resolvedTracksLocation.initialize()); @@ -53,15 +39,14 @@ Trk::TrkAmbiguitySolver::initialize() StatusCode Trk::TrkAmbiguitySolver::execute() { - ATH_MSG_VERBOSE ("TrkAmbiguitySolver::execute()"); + ATH_MSG_VERBOSE("TrkAmbiguitySolver::execute()"); ConstDataVector<TrackCollection> oldTracks(SG::VIEW_ELEMENTS); StatusCode loadedTracks = getTracks(oldTracks); - if ( loadedTracks.isFailure() ) - { - msg(MSG::ERROR) << "TrkAmbiguitySolver could not find any tracks. Aborting." << endmsg; - return StatusCode::SUCCESS; - } + if (loadedTracks.isFailure()) { + ATH_MSG_ERROR("TrkAmbiguitySolver could not find any tracks. Aborting."); + return StatusCode::SUCCESS; + } // Now pass tracks to AmbiTool std::unique_ptr<TrackCollection> tracks; @@ -69,8 +54,8 @@ Trk::TrkAmbiguitySolver::execute() SG::WriteHandle<TrackCollection> writeh(m_resolvedTracksLocation); ATH_CHECK(writeh.record(std::move(tracks))); - ATH_MSG_VERBOSE ("Saved "<<writeh->size()<<" tracks"); - + ATH_MSG_VERBOSE("Saved "<<writeh->size()<<" tracks"); + return StatusCode::SUCCESS; } @@ -81,59 +66,52 @@ Trk::TrkAmbiguitySolver::finalize() { m_ambiTool->statistics(); - ATH_MSG_INFO( "Finalizing with "<< m_trackInCount << " tracks input, and "<< m_trackOutCount<< " output"); + ATH_MSG_INFO("Finalizing with "<< m_trackInCount << " tracks input, and "<< m_trackOutCount<< " output"); return StatusCode::SUCCESS; } //------------------------------------------------------------------------------- - -StatusCode Trk::TrkAmbiguitySolver::getTracks(ConstDataVector<TrackCollection> &oldTracks){ - +StatusCode Trk::TrkAmbiguitySolver::getTracks(ConstDataVector<TrackCollection>& oldTracks) +{ auto handles = m_tracksLocation.makeHandles(); size_t totalsize = 0; for (SG::ReadHandle<TrackCollection>& tmpTracks : handles) { - if (!tmpTracks.isValid()) - msg(MSG::WARNING) << "Could not retrieve tracks from "<< tmpTracks.key() << endmsg; - totalsize += tmpTracks->size(); + if (not tmpTracks.isValid()) { + ATH_MSG_WARNING("Could not retrieve tracks from "<< tmpTracks.key()); + } + totalsize += tmpTracks->size(); } oldTracks.reserve(totalsize); for (SG::ReadHandle<TrackCollection>& tmpTracks : handles) { - ATH_MSG_VERBOSE ("Successfully retrieved "<<tmpTracks->size() - <<" tracks from "<< tmpTracks.key()); - copy(tmpTracks->begin(),tmpTracks->end(), std::back_inserter(oldTracks)); - + ATH_MSG_VERBOSE("Successfully retrieved "<<tmpTracks->size() + <<" tracks from "<< tmpTracks.key()); + copy(tmpTracks->begin(), tmpTracks->end(), std::back_inserter(oldTracks)); } - return StatusCode::SUCCESS; } -//------------------------------------------------------------------------------- +//------------------------------------------------------------------------------- -void Trk::TrkAmbiguitySolver::resolveTracks(std::unique_ptr<TrackCollection> &tracks, ConstDataVector<TrackCollection> &oldTracks) +void Trk::TrkAmbiguitySolver::resolveTracks(std::unique_ptr<TrackCollection>& tracks, ConstDataVector<TrackCollection>& oldTracks) { - if (m_resolveTracks) - { - // okay, and let's call the ambiguity processor, just for a laugh. - ATH_MSG_VERBOSE ("TrkAmbiguitySolver::resolveTracks() resolving " - << oldTracks.size()<<" tracks" ); - m_trackInCount += oldTracks.size(); - tracks = std::unique_ptr<TrackCollection>(m_ambiTool->process( oldTracks.asDataVector() )); - m_trackOutCount += tracks->size(); - } - else - { - // copy tracks. NOT a shallow copy as it was before, since - // this causes mem leaks when reading back in again - // see bug#9886 for details - tracks = std::make_unique<TrackCollection>(); - tracks->reserve(oldTracks.size()); - TrackCollection::const_iterator it = oldTracks.begin(); - TrackCollection::const_iterator itEnd = oldTracks.end(); - for (;it!=itEnd;it++) tracks->push_back( new Track(**it) ); - + if (m_resolveTracks) { + // okay, and let's call the ambiguity processor, just for a laugh. + ATH_MSG_VERBOSE("TrkAmbiguitySolver::resolveTracks() resolving " + << oldTracks.size()<<" tracks"); + m_trackInCount += oldTracks.size(); + tracks = std::unique_ptr<TrackCollection>(m_ambiTool->process(oldTracks.asDataVector())); + m_trackOutCount += tracks->size(); + } else { + // copy tracks. NOT a shallow copy as it was before, since + // this causes mem leaks when reading back in again + // see bug#9886 for details + tracks = std::make_unique<TrackCollection>(); + tracks->reserve(oldTracks.size()); + for (const Track* oldTrack : oldTracks) { + tracks->push_back(new Track(*oldTrack)); } + } return; } -