ATLAS Offline Software
TrkAmbiguitySolver.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 Trk::TrkAmbiguitySolver::TrkAmbiguitySolver(const std::string& name, ISvcLocator* pSvcLocator) :
10  AthReentrantAlgorithm (name, pSvcLocator),
11  m_scoredTracksKey(""),
12  m_resolvedTracksKey("Tracks"),
13  m_ambiTool("Trk::SimpleAmbiguityProcessorTool/TrkAmbiguityProcessor", this),
14  m_trackInCount(0),
15  m_trackOutCount(0)
16 {
17  declareProperty("TrackInput" , m_scoredTracksKey);
18  declareProperty("TrackOutput" , m_resolvedTracksKey);
19  declareProperty("AmbiguityProcessor", m_ambiTool);
20 }
21 
22 //--------------------------------------------------------------------------
24 = default;
25 
26 //-----------------------------------------------------------------------
29 {
30  ATH_CHECK(m_ambiTool.retrieve());
31 
32  ATH_CHECK(m_scoredTracksKey.initialize());
33  ATH_CHECK(m_resolvedTracksKey.initialize());
34  m_trackInCount=0;
35  m_trackOutCount=0;
36  return StatusCode::SUCCESS;
37 }
38 
39 //-------------------------------------------------------------------------
41 Trk::TrkAmbiguitySolver::execute(const EventContext& ctx) const
42 {
43  ATH_MSG_VERBOSE ("TrkAmbiguitySolver::execute()");
44  SG::ReadHandle<TracksScores> scoredTracksHandle(m_scoredTracksKey, ctx);
45  if ( !scoredTracksHandle.isValid() ) ATH_MSG_ERROR("Could not read scoredTracks.");
46  const int nInput = scoredTracksHandle->size();
47  m_trackInCount += nInput;
48 
49  std::unique_ptr<const TrackCollection> resolvedTracks;
50  resolvedTracks.reset(m_ambiTool->process(scoredTracksHandle.cptr())); //note: take ownership and delete
51  m_trackOutCount += resolvedTracks->size();
52 
53  SG::WriteHandle<TrackCollection> resolvedTracksHandle(m_resolvedTracksKey, ctx);
54  ATH_MSG_DEBUG ("Saving "<<resolvedTracks->size()<<" tracks of " << nInput);
55  if (!resolvedTracksHandle.put(std::move(resolvedTracks))) {
56  ATH_MSG_ERROR ("Can't record tracks as " << m_resolvedTracksKey.key());
57  return StatusCode::FAILURE;
58  }
59  return StatusCode::SUCCESS;
60 }
61 
62 //---------------------------------------------------------------------------
63 
66  if (m_ambiTool.isEnabled()) {
67  m_ambiTool->statistics();
68  }
69  ATH_MSG_DEBUG( "Finalizing with "<< m_trackInCount << " tracks input, and "<< m_trackOutCount<< " output");
70  return StatusCode::SUCCESS;
71 }
Trk::TrkAmbiguitySolver::~TrkAmbiguitySolver
~TrkAmbiguitySolver(void)
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::TrkAmbiguitySolver::initialize
StatusCode initialize(void) override
Definition: TrkAmbiguitySolver.cxx:28
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ITrackAmbiguityProcessorTool.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Trk::TrkAmbiguitySolver::m_resolvedTracksKey
SG::WriteHandleKey< TrackCollection > m_resolvedTracksKey
where to save the resolved tracks
Definition: TrkAmbiguitySolver.h:49
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::TrkAmbiguitySolver::execute
StatusCode execute(const EventContext &ctx) const override
Definition: TrkAmbiguitySolver.cxx:41
Trk::TrkAmbiguitySolver::TrkAmbiguitySolver
TrkAmbiguitySolver(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrkAmbiguitySolver.cxx:9
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Trk::TrkAmbiguitySolver::m_scoredTracksKey
SG::ReadHandleKey< TracksScores > m_scoredTracksKey
<where to find tracks (set in jobOptions and can be multiple collections
Definition: TrkAmbiguitySolver.h:48
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Trk::TrkAmbiguitySolver::m_ambiTool
ToolHandle< ITrackAmbiguityProcessorTool > m_ambiTool
Definition: TrkAmbiguitySolver.h:50
TrkAmbiguitySolver.h
Trk::TrkAmbiguitySolver::finalize
StatusCode finalize(void) override
Definition: TrkAmbiguitySolver.cxx:65
SG::WriteHandle::put
const_pointer_type put(std::unique_ptr< T > data, bool returnExisting=false) const
Record an object to the store.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ITrackAmbiguityScoreProcessorTool.h