ATLAS Offline Software
Loading...
Searching...
No Matches
TrackParticleMergerAlg.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s):
7
10
11namespace CP {
12
14
15 ATH_MSG_DEBUG("Initializing TrackParticleMergerAlg");
17
20
22
23 return StatusCode::SUCCESS;
24 }
25
26 StatusCode TrackParticleMergerAlg::execute(const EventContext& ctx) const {
27
28 auto readHandles = m_inputTrackParticleLocations.makeHandles(ctx);
29 std::size_t nTracks = 0;
30 for (auto& readHandle : readHandles) {
31 nTracks += readHandle->size();
32 }
33
35 // View collection pointing to the input tracks
36 auto outputViewCol = std::make_unique<ConstDataVector<xAOD::TrackParticleContainer>>(SG::VIEW_ELEMENTS);
37 outputViewCol->reserve(nTracks);
38 for (auto& readHandle : readHandles) {
39 for (const xAOD::TrackParticle* tp : *readHandle) {
40 outputViewCol->push_back(tp);
41 }
42 }
43
45 ATH_CHECK( outputTrackParticlesView.record(std::move(outputViewCol)) );
46 } else {
47 // Deep copy of the input tracks
48 auto outputCol = std::make_unique<xAOD::TrackParticleContainer>();
49 auto outputAuxCol = std::make_unique<xAOD::TrackParticleAuxContainer>();
50 outputCol->setStore(outputAuxCol.get());
51 outputCol->reserve(nTracks);
52 for (auto& readHandle : readHandles) {
53 for (const xAOD::TrackParticle* tp : *readHandle) {
54 xAOD::TrackParticle* newTp = outputCol->push_back(std::make_unique<xAOD::TrackParticle>());
55 *newTp = *tp;
56 }
57 }
58
60 ATH_CHECK( outputTrackParticlesCopy.record(std::move(outputCol), std::move(outputAuxCol)) );
61 }
62
63 return StatusCode::SUCCESS;
64 }
65
66} // namespace CP
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
virtual StatusCode execute(const EventContext &ctx) const override final
Function executing the algorithm.
SG::ReadDecorHandleKeyArray< xAOD::TrackParticleContainer > m_requiredDecorations
Extra guard for deep-copy mode.
SG::WriteHandleKey< ConstDataVector< xAOD::TrackParticleContainer > > m_outputTrackParticleLocationView
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_outputTrackParticleLocationCopy
Output collection name.
virtual StatusCode initialize() override final
Function initialising the algorithm.
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_inputTrackParticleLocations
Input track collections to be merged.
Gaudi::Property< bool > m_createViewCollection
Option to create a view collection and not deep-copy tracks.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Select isolated Photons, Electrons and Muons.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
TrackParticle_v1 TrackParticle
Reference the current persistent version: