ATLAS Offline Software
Loading...
Searching...
No Matches
MuonContainerMergingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
19
20namespace CP {
21 MuonContainerMergingAlg::MuonContainerMergingAlg( const std::string& name, ISvcLocator* svcLoc )
22 : EL::AnaReentrantAlgorithm( name, svcLoc ){
23 //nothing to do here
24 }
25
27
28 // initialize list of muon containters
29 ATH_MSG_DEBUG("Initializing MuonContainerMergingAlg");
30 ATH_CHECK( m_inputMuonContainers.initialize() );
31
32 // Default m_outMuonLocationCopy key to the OutputMuonLocation key
34
35 // initialize output muon containters
38
39 // Return gracefully:
40 return StatusCode::SUCCESS;
41 }
42
43 StatusCode MuonContainerMergingAlg::execute(const EventContext &ctx) const {
44
45 // Setup containers for output, to avoid const conversions setup two different kind of containers
46 std::unique_ptr<ConstDataVector<xAOD::MuonContainer>> outputViewCol;
47 std::unique_ptr<xAOD::MuonContainer> outputCol;
48 std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
50 outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(SG::VIEW_ELEMENTS);
51 } else {
52 outputCol = std::make_unique<xAOD::MuonContainer>();
53 outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
54 outputCol->setStore(outputAuxCol.get());
55 }
56
57 // retrieve muons from StoreGate
58 std::vector<const xAOD::MuonContainer*> muonCollections;
59 muonCollections.reserve(m_inputMuonContainers.size());
60 size_t muonCountSum = 0;
61 for (const auto& mcname : m_inputMuonContainers){
62 // Retrieve tracks from StoreGate
63 SG::ReadHandle<xAOD::MuonContainer> muCol (mcname, ctx);
64 ATH_CHECK(muCol.isValid());
65 muonCollections.push_back(muCol.cptr());
66 muonCountSum += muCol->size();
67 }
69 outputViewCol->reserve(muonCountSum);
70 } else {
71 outputCol->reserve(muonCountSum);
72 }
73
75 for (auto& mciter : muonCollections) {
76 if (mciter and !mciter->empty()) {
77 ATH_MSG_DEBUG("Size of muon collection " << mciter->size());
79 for (const auto* const muon : *mciter) {
82 outputViewCol->push_back(muon);
83 } else {
84 auto newMuon = std::make_unique<xAOD::Muon>(*muon);
85 setOriginalObjectLink(*muon, *newMuon);
86 outputCol->push_back(std::move(newMuon));
87 }
88 }
89 }
90 }
91
92 // write output to SG
95 ATH_CHECK(h_write.record(std::move(outputViewCol)));
96 }
97 else {
99 ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
100 }
101
102 return StatusCode::SUCCESS;
103
104 }
105
106}
#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.
StatusCode execute(const EventContext &ctx) const 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
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...