Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
14 #include "xAODMuon/MuonContainer.h"
18 
19 namespace 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 }
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
CP::MuonContainerMergingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonContainerMergingAlg.cxx:42
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
CP::MuonContainerMergingAlg::m_outMuonLocationView
SG::WriteHandleKey< ConstDataVector< xAOD::MuonContainer > > m_outMuonLocationView
Output xAOD::MuonContainer for the case of a view container.
Definition: MuonContainerMergingAlg.h:53
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CP::MuonContainerMergingAlg::initialize
virtual StatusCode initialize() override
Definition: MuonContainerMergingAlg.cxx:25
CP::MuonContainerMergingAlg::m_inputMuonContainers
SG::ReadHandleKeyArray< xAOD::MuonContainer > m_inputMuonContainers
Private data:
Definition: MuonContainerMergingAlg.h:44
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MuonAuxContainer.h
CP::MuonContainerMergingAlg::m_createViewCollection
Gaudi::Property< bool > m_createViewCollection
flag to create a view collection rather than building deep-copies (true by default)
Definition: MuonContainerMergingAlg.h:58
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CP::MuonContainerMergingAlg::m_outMuonLocationCopy
SG::WriteHandleKey< xAOD::MuonContainer > m_outMuonLocationCopy
Output xAOD::MuonContainer object.
Definition: MuonContainerMergingAlg.h:49
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
MuonContainerMergingAlg.h
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonContainer.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CP::MuonContainerMergingAlg::MuonContainerMergingAlg
MuonContainerMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: MuonContainerMergingAlg.cxx:20
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.