ATLAS Offline Software
PreselCaloExtensionBuilderAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include <memory>
8 
9 #include "StoreGate/ReadHandle.h"
10 #include "StoreGate/WriteHandle.h"
11 
12 namespace Trk {
13  PreselCaloExtensionBuilderAlg::PreselCaloExtensionBuilderAlg(const std::string& name, ISvcLocator* pSvcLocator) :
14  AthReentrantAlgorithm(name, pSvcLocator) {}
15 
17 
21  ATH_CHECK(m_outputCacheKey.initialize());
22  return StatusCode::SUCCESS;
23  }
24 
25  StatusCode PreselCaloExtensionBuilderAlg::execute(const EventContext& ctx) const {
26  auto tracks = SG::makeHandle(m_inputTracksKey, ctx);
27  if (!tracks.isValid()) {
28  ATH_MSG_ERROR("Failed to retrieve " << m_inputTracksKey);
29  return StatusCode::FAILURE;
30  }
31  auto cache = std::make_unique<CaloExtensionCollection>();
32  if (!tracks->empty())
33  // Use the index of the last track as a good guess of the largest index
34  // present in the container. This will be the right value if the view
35  // has not been sorted differently from the original container
36  cache->resize(tracks->back()->index() + 1);
37  for (const xAOD::TrackParticle* itrk : *tracks) {
38  if (itrk->index() >= cache->size())
39  // Handle the case where the above assumption does not hold
40  cache->resize(itrk->index() + 1);
41  cache->at(itrk->index()) = m_particleCaloExtensionTool->caloExtension(ctx, *itrk);
42  }
43  auto outputHandle = SG::makeHandle(m_outputCacheKey, ctx);
44  ATH_CHECK(outputHandle.record(std::move(cache)));
45  return StatusCode::SUCCESS;
46  }
47 } // namespace Trk
Trk::PreselCaloExtensionBuilderAlg::m_particleCaloExtensionTool
ToolHandle< Trk::IParticleCaloExtensionTool > m_particleCaloExtensionTool
Definition: PreselCaloExtensionBuilderAlg.h:40
Trk::PreselCaloExtensionBuilderAlg::PreselCaloExtensionBuilderAlg
PreselCaloExtensionBuilderAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PreselCaloExtensionBuilderAlg.cxx:13
Trk::PreselCaloExtensionBuilderAlg::initialize
virtual StatusCode initialize() override
Definition: PreselCaloExtensionBuilderAlg.cxx:18
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Trk::PreselCaloExtensionBuilderAlg::~PreselCaloExtensionBuilderAlg
~PreselCaloExtensionBuilderAlg()
Trk::PreselCaloExtensionBuilderAlg::m_inputTracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTracksKey
Definition: PreselCaloExtensionBuilderAlg.h:42
Trk::PreselCaloExtensionBuilderAlg::m_outputCacheKey
SG::WriteHandleKey< CaloExtensionCollection > m_outputCacheKey
Definition: PreselCaloExtensionBuilderAlg.h:43
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::PreselCaloExtensionBuilderAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PreselCaloExtensionBuilderAlg.cxx:25
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ReadHandle.h
Handle class for reading from StoreGate.
PreselCaloExtensionBuilderAlg.h