ATLAS Offline Software
Loading...
Searching...
No Matches
MuonContainerMergingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// MuonContainerMergingAlg
7// author Maria Mironova, Simone Pagan Griso, Kehang Bai
9
11// Generic algorithm for merging a list of muon containers
18
19namespace CP {
20 MuonContainerMergingAlg::MuonContainerMergingAlg( const std::string& name, ISvcLocator* svcLoc )
21 : EL::AnaReentrantAlgorithm( name, svcLoc ){
22 //nothing to do here
23 }
24
26
27 // initialize list of muon containters
28 ATH_MSG_DEBUG("Initializing MuonContainerMergingAlg");
29 ATH_CHECK( m_inputMuonContainers.initialize() );
30
31 // Override m_outMuonLocationCopy key
33
34 // initialize output muon containters
37
38 // Return gracefully:
39 return StatusCode::SUCCESS;
40 }
41
42 StatusCode MuonContainerMergingAlg::execute(const EventContext &ctx) const {
43
44 // Setup containers for output, to avoid const conversions setup two different kind of containers
45 auto outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(SG::VIEW_ELEMENTS);
46 auto outputCol = std::make_unique<xAOD::MuonContainer>();
47
48 std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
50 outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
51 outputCol->setStore(outputAuxCol.get());
52 }
53
54 // retrieve muons from StoreGate
55 std::vector<const xAOD::MuonContainer*> muonCollections;
56 muonCollections.reserve(m_inputMuonContainers.size());
57 size_t muonCountSum = 0;
58 for (const auto& mcname : m_inputMuonContainers){
59 // Retrieve tracks from StoreGate
60 SG::ReadHandle<xAOD::MuonContainer> muCol (mcname, ctx);
61 muonCollections.push_back(muCol.cptr());
62 muonCountSum += muCol->size();
63 }
65 outputViewCol->reserve(muonCountSum);
66 } else {
67 outputCol->reserve(muonCountSum);
68 }
69
71 for (auto& mciter : muonCollections) {
72 if (mciter and !mciter->empty()) {
73 ATH_MSG_DEBUG("Size of muon collection " << mciter->size());
75 for (const auto* const muon : *mciter) {
78 outputViewCol->push_back(muon);
79 } else {
80 xAOD::Muon* newMuon = new xAOD::Muon(*muon);
81 outputCol->push_back(newMuon);
82 }
83 }
84 }
85 }
86
87 // write output to SG
90 ATH_CHECK(h_write.record(std::move(outputViewCol)));
91 }
92 else {
94 ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
95 }
96
97 return StatusCode::SUCCESS;
98
99 }
100
101}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Handle class for recording to StoreGate.
DataVector adapter that acts like it holds const pointers.
SG::WriteHandleKey< ConstDataVector< xAOD::MuonContainer > > m_outMuonLocationView
Output xAOD::MuonContainer for the case of a view container.
SG::ReadHandleKeyArray< xAOD::MuonContainer > m_inputMuonContainers
Private data:
SG::WriteHandleKey< xAOD::MuonContainer > m_outMuonLocationCopy
Output xAOD::MuonContainer object.
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
Gaudi::Property< bool > m_createViewCollection
flag to create a view collection rather than building deep-copies (true by default)
MuonContainerMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
AnaReentrantAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Select isolated Photons, Electrons and Muons.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Muon_v1 Muon
Reference the current persistent version: