diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.cxx index adce6e808adf649deb34c904e0046805e571da55..a512867b9aebf08e1ddf78796c48c1f6d4d6c4ca 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.cxx @@ -7,7 +7,6 @@ #include "MuonTrackFindingEvent/MuPatSegment.h" #include "MuonTrackFindingEvent/MuPatCandidateBase.h" #include "MuPatHitTool.h" -#include "MuPatCandidateTool.h" #include "MuonTrackMakerUtils/MuonTrackMakerStlTools.h" #include "MuonTrackMakerUtils/SortMeasurementsByPosition.h" @@ -77,7 +76,6 @@ namespace Muon { m_magFieldProperties(Trk::NoField), m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool"), m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"), - m_entryHandler("Muon::MuPatCandidateTool/MuPatCandidateTool"), m_trackToSegmentTool("Muon::MuonTrackToSegmentTool/MuonTrackToSegmentTool"), m_mdtRotCreator("Muon::MdtDriftCircleOnTrackCreator/MdtTubeHitOnTrackCreator"), m_phiHitSelector("MuonPhiHitSelector/MuonPhiHitSelector"), @@ -98,7 +96,6 @@ namespace Muon { declareProperty("HitTool",m_hitHandler); declareProperty("IdHelper",m_idHelperTool); declareProperty("MuonPrinterTool",m_printer); - declareProperty("CandidateTool",m_entryHandler); declareProperty("TrackToSegmentTool",m_trackToSegmentTool); declareProperty("MdtRotCreator",m_mdtRotCreator); declareProperty("PhiHitSelector",m_phiHitSelector); @@ -139,7 +136,6 @@ namespace Muon { ATH_CHECK( m_idHelperTool.retrieve() ); ATH_CHECK( m_edmHelperSvc.retrieve() ); ATH_CHECK( m_hitHandler.retrieve() ); - ATH_CHECK( m_entryHandler.retrieve() ); ATH_CHECK( m_printer.retrieve() ); // Configuration of the material effects diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.h b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.h index 8751968acea6e34029fbb619bec983a1533b0b77..2c527b4ba477dcb6147281dc6333e0918c7fb99e 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.h +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.h @@ -64,7 +64,6 @@ namespace Muon { class IMuonHitSelector; class MuPatCandidateBase; class MuPatTrack; - class MuPatCandidateTool; } static const InterfaceID IID_MooTrackFitter("Muon::MooTrackFitter",1,0); @@ -308,7 +307,6 @@ namespace Muon { "Muon::MuonEDMHelperSvc/MuonEDMHelperSvc", "Handle to the service providing the IMuonEDMHelperSvc interface" }; //!< multi purpose helper tool ToolHandle<MuonEDMPrinterTool> m_printer; //!< tool to print out EDM objects - ToolHandle<MuPatCandidateTool> m_entryHandler; //!< tool to manipulate MuPatSegment's and MuPatTracks ToolHandle<IMuonTrackToSegmentTool> m_trackToSegmentTool; //!< helper tool to convert tracks into segments ToolHandle<IMdtDriftCircleOnTrackCreator> m_mdtRotCreator; //!< mdt tube hit creator ToolHandle<IMuonHitSelector> m_phiHitSelector; //!< tool to clean phi hits diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.cxx index 1fb81793d4eb48e76566c459e9783d2a55ad55ed..3f9ab026fbe0c4afb2363813e87ea7da19125e6f 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.cxx @@ -37,7 +37,6 @@ #include "MuonReadoutGeometry/MuonReadoutElement.h" #include "EventPrimitives/EventPrimitivesToStringConverter.h" -#include "GaudiKernel/IIncidentSvc.h" #include <sstream> #include <string> #include <set> @@ -57,8 +56,7 @@ namespace Muon { m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"), m_hitHandler("Muon::MuPatHitTool/MuPatHitTool"), m_segmentSelector("Muon::MuonSegmentSelectionTool/MuonSegmentSelectionTool"), - m_segmentExtender("Muon::MuonSegmentInfoExtender/MuonSegmentInfoExtender"), - m_incidentSvc("IncidentSvc",n) + m_segmentExtender("Muon::MuonSegmentInfoExtender/MuonSegmentInfoExtender") { declareInterface<MuPatCandidateTool>(this); declareProperty("MdtRotCreator", m_mdtRotCreator); @@ -82,9 +80,6 @@ namespace Muon { ATH_CHECK( m_hitHandler.retrieve() ); ATH_CHECK( m_edmHelperSvc.retrieve() ); ATH_CHECK( m_printer.retrieve() ); - ATH_CHECK( m_incidentSvc.retrieve() ); - - m_incidentSvc->addListener( this, std::string("EndEvent")); ATH_CHECK( m_segmentSelector.retrieve() ); if( !m_segmentExtender.empty() && m_segmentExtender.retrieve().isFailure() ){ @@ -248,6 +243,14 @@ namespace Muon { void MuPatCandidateTool::updateHits( MuPatCandidateBase& entry, const MuPatCandidateTool::MeasVec& measurements, bool recreateMDT, bool recreateCSC, bool createComp ) const { + std::lock_guard<std::mutex> lock{m_mutex}; + const EventContext& ctx = Gaudi::Hive::currentContext(); + CacheEntry* ent{m_cache.get(ctx)}; + if (ent->m_evt != ctx.evt()) { + ent->m_evt = ctx.evt(); + ent->cleanUp(); + } + MeasVec etaHits; MeasVec phiHits; MeasVec fakePhiHits; @@ -323,7 +326,7 @@ namespace Muon { } ATH_MSG_DEBUG(" recreating MdtDriftCircleOnTrack " ); const MdtDriftCircleOnTrack* newMdt = m_mdtRotCreator->createRIO_OnTrack(*mdt->prepRawData(),mdt->globalPosition()); - m_measurementsToBeDelete.push_back(newMdt); + ent->m_measurementsToBeDeleted.push_back(newMdt); meas = newMdt; } } @@ -366,7 +369,7 @@ namespace Muon { } ATH_MSG_DEBUG(" recreating CscClusterOnTrack " ); const MuonClusterOnTrack* newCsc = m_cscRotCreator->createRIO_OnTrack(*csc->prepRawData(),csc->globalPosition()); - m_measurementsToBeDelete.push_back(newCsc); + ent->m_measurementsToBeDeleted.push_back(newCsc); meas = newCsc; } @@ -397,8 +400,8 @@ namespace Muon { } if( createComp ){ - if( m_createCompetingROTsEta && !triggerHitsEta.empty() ) createAndAddCompetingROTs(triggerHitsEta,etaHits,allHits); - if( m_createCompetingROTsPhi && !triggerHitsPhi.empty() ) createAndAddCompetingROTs(triggerHitsPhi,phiHits,allHits); + if( m_createCompetingROTsEta && !triggerHitsEta.empty() ) createAndAddCompetingROTs(triggerHitsEta, etaHits, allHits, ent->m_measurementsToBeDeleted); + if( m_createCompetingROTsPhi && !triggerHitsPhi.empty() ) createAndAddCompetingROTs(triggerHitsPhi, phiHits, allHits, ent->m_measurementsToBeDeleted); } entry.nmdtHitsMl1 = nmdtHitsMl1; @@ -435,8 +438,9 @@ namespace Muon { } void MuPatCandidateTool::createAndAddCompetingROTs( const std::vector<const MuonClusterOnTrack*>& rots, - MuPatCandidateTool::MeasVec& hits, - MuPatCandidateTool::MeasVec& allHits ) const { + MuPatCandidateTool::MeasVec& hits, + MuPatCandidateTool::MeasVec& allHits, + MuPatCandidateTool::MeasVec& measurementsToBeDeleted ) const { typedef std::map<Identifier, std::vector<const MuonClusterOnTrack*> > IdClusMap; typedef IdClusMap::iterator IdClusIt; @@ -504,7 +508,7 @@ namespace Muon { allHits.push_back(comprot); // add to garbage collection - m_measurementsToBeDelete.push_back(comprot); + measurementsToBeDeleted.push_back(comprot); } } @@ -604,8 +608,13 @@ namespace Muon { void MuPatCandidateTool::cleanUp() const { // delete segments and clear vector - std::for_each( m_measurementsToBeDelete.begin(),m_measurementsToBeDelete.end(),MuonDeleteObject<const Trk::MeasurementBase>() ); - m_measurementsToBeDelete.clear(); + std::lock_guard<std::mutex> lock{m_mutex}; + const EventContext& ctx = Gaudi::Hive::currentContext(); + CacheEntry* ent{m_cache.get(ctx)}; + if (ent->m_evt != ctx.evt()) { + ent->m_evt = ctx.evt(); + } + ent->cleanUp(); } std::string MuPatCandidateTool::print( const MuPatSegment& segment, int level ) const { @@ -665,14 +674,5 @@ namespace Muon { return "Unknown candidate type"; } - - void MuPatCandidateTool::handle(const Incident& inc) { - // Only clear cache for EndEvent incident - if (inc.type() != "EndEvent") return; - - cleanUp(); - - } - } // namespace Muon diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.h b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.h index d0a121ff2603a4eeebff4de0245b51705acc57b7..a8077dd0515c036ed93667456d77c347ba78afaa 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MuPatCandidateTool.h @@ -6,21 +6,24 @@ #define MUPATCANDIDATETOOL_H #include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" -#include "GaudiKernel/ServiceHandle.h" -#include "GaudiKernel/IIncidentListener.h" +#include "AthenaKernel/SlotSpecificObj.h" #include "MuonRecHelperTools/IMuonEDMHelperSvc.h" +#include "MuonTrackMakerUtils/MuonTrackMakerStlTools.h" #include "TrkParameters/TrackParameters.h" -#include <vector> + +#include "GaudiKernel/ToolHandle.h" +#include "GaudiKernel/ServiceHandle.h" + +#include <mutex> #include <set> +#include <vector> #include "MuPatHitTool.h" // Needed to enfornce build order for reflex dict class MsgStream; class MdtIdHelper; -class IIncidentSvc; namespace Trk { class Track; @@ -51,7 +54,7 @@ namespace Muon { static const InterfaceID IID_MuPatCandidateTool("Muon::MuPatCandidateTool",1,0); /** class to manipulate MuPatCandidateBase objects */ - class MuPatCandidateTool : public AthAlgTool, virtual public IIncidentListener { + class MuPatCandidateTool : public AthAlgTool { public: typedef std::vector<const Trk::MeasurementBase*> MeasVec; typedef MeasVec::iterator MeasIt; @@ -154,9 +157,6 @@ namespace Muon { std::string print( const std::vector<MuPatTrack*>& tracks, int level = 0 ) const; - /** incident service handle for EndEvent */ - void handle(const Incident& inc);// maybe in the future clear per event - private: /** @brief update hits for a MuPatCandidateBase */ @@ -167,7 +167,10 @@ namespace Muon { void addCluster( const Trk::MeasurementBase& meas, std::vector<const MuonClusterOnTrack*>& rots ) const; /** @brief create CompetingMuonClustersOnTracks from ROTs and add them to the MeasVec. NEVER pass mixed eta/phi hits!! */ - void createAndAddCompetingROTs( const std::vector<const MuonClusterOnTrack*>& rots, MeasVec& hits, MeasVec& allHits ) const; + void createAndAddCompetingROTs( const std::vector<const MuonClusterOnTrack*>& rots, + MeasVec& hits, + MeasVec& allHits, + MeasVec& measurementsToBeDeleted ) const; ToolHandle<IMdtDriftCircleOnTrackCreator> m_mdtRotCreator; //<! tool to calibrate MDT hits ToolHandle<IMuonClusterOnTrackCreator> m_cscRotCreator; //<! tool to calibrate CSC hits @@ -180,7 +183,6 @@ namespace Muon { ToolHandle<MuPatHitTool> m_hitHandler; //<! tool to manipulate hit lists ToolHandle<Muon::IMuonSegmentSelectionTool> m_segmentSelector; //<! tool to resolve track ambiguities ToolHandle<Muon::IMuonSegmentInfoExtender> m_segmentExtender; //<! tool to extend the segment information - ServiceHandle< IIncidentSvc > m_incidentSvc; //const MdtIdHelper* m_mdtIdHelper; @@ -189,7 +191,20 @@ namespace Muon { bool m_doMdtRecreation; bool m_doCscRecreation; - mutable MeasVec m_measurementsToBeDelete; //<! vector to store measurements owned by the track maker + // Mutex to protect the contents. + mutable std::mutex m_mutex{}; + struct CacheEntry { + EventContext::ContextEvt_t m_evt{EventContext::INVALID_CONTEXT_EVT}; + MeasVec m_measurementsToBeDeleted{}; //<! vector to store measurements owned by the track maker + void cleanUp() { // Delete measurements to be deleted now + std::for_each( m_measurementsToBeDeleted.begin(), m_measurementsToBeDeleted.end(), MuonDeleteObject<const Trk::MeasurementBase>() ); + m_measurementsToBeDeleted.clear(); + }; + ~CacheEntry() { // Destructor deletes measurements to be deleted during finalization + cleanUp(); + } + }; + mutable SG::SlotSpecificObj<CacheEntry> m_cache ATLAS_THREAD_SAFE; // Guarded by m_mutex }; diff --git a/Reconstruction/MuonIdentification/MuGirlGlobalFit/MuGirlGlobalFit/GlobalFitTool.h b/Reconstruction/MuonIdentification/MuGirlGlobalFit/MuGirlGlobalFit/GlobalFitTool.h index dceac4b6195c3bc27a9dd4b31eed986d1754d0dd..b91b037ce6c98e6f08ffe10988d325f48f9313cf 100644 --- a/Reconstruction/MuonIdentification/MuGirlGlobalFit/MuGirlGlobalFit/GlobalFitTool.h +++ b/Reconstruction/MuonIdentification/MuGirlGlobalFit/MuGirlGlobalFit/GlobalFitTool.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 */ /////////////////////////////////////////////////////////////////// @@ -40,7 +40,6 @@ namespace Muon class MuonSegment; class IMuonCompetingClustersOnTrackCreator; class CompetingMuonClustersOnTrack; - class IMuonTrackFinder; } namespace Rec { diff --git a/Reconstruction/MuonIdentification/MuGirlGlobalFit/src/GlobalFitTool.cxx b/Reconstruction/MuonIdentification/MuGirlGlobalFit/src/GlobalFitTool.cxx index 0c4c28f767d996fd5e540f3447acecc92c31309b..ec2f484979f75e96b7faf031608c24e276287049 100644 --- a/Reconstruction/MuonIdentification/MuGirlGlobalFit/src/GlobalFitTool.cxx +++ b/Reconstruction/MuonIdentification/MuGirlGlobalFit/src/GlobalFitTool.cxx @@ -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 */ /////////////////////////////////////////////////////////////////// @@ -28,7 +28,6 @@ #include "TrkExUtils/TrackSurfaceIntersection.h" //#include "TrkParameters/AtaCylinder.h" //#include "TrkParameters/AtaDisc.h" -#include "MuonRecToolInterfaces/IMuonTrackFinder.h" #include "MuonRecToolInterfaces/IMuonSegmentMaker.h" #include "TrkTrack/TrackCollection.h"