ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
12namespace Trk {
13 PreselCaloExtensionBuilderAlg::PreselCaloExtensionBuilderAlg(const std::string& name, ISvcLocator* pSvcLocator) :
14 AthReentrantAlgorithm(name, pSvcLocator) {}
15
17
20 ATH_CHECK(m_inputTracksKey.initialize());
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode execute(const EventContext &ctx) const override
ToolHandle< Trk::IParticleCaloExtensionTool > m_particleCaloExtensionTool
PreselCaloExtensionBuilderAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKey< CaloExtensionCollection > m_outputCacheKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTracksKey
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Ensure that the ATLAS eigen extensions are properly loaded.
TrackParticle_v1 TrackParticle
Reference the current persistent version: