ATLAS Offline Software
MuonID/MuonSelectorTools/src/MuonSelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MuonSelectionAlg.h"
6 
9 namespace CP {
10 
11  MuonSelectionAlg::MuonSelectionAlg(const std::string& name, ISvcLocator* svcloc) :
12  AthAlgorithm(name, svcloc), m_tool("CP::MuonSelectionTool") /*public tool*/ {
13  declareProperty("Input", m_inputMuons = "");
14  declareProperty("Output", m_outputMuons = "");
15  declareProperty("Tool", m_tool);
16  }
17 
19  if (m_inputMuons.empty()) {
20  ATH_MSG_ERROR("You must specify an INPUT muon collection");
21  return StatusCode::FAILURE;
22  }
23  if (m_outputMuons.empty()) {
24  ATH_MSG_ERROR("You must specify an OUTPUT muon collection");
25  return StatusCode::FAILURE;
26  }
27  CHECK(m_tool.retrieve());
28 
29  return StatusCode::SUCCESS;
30  }
31 
33  // fetch input collection
34  const xAOD::MuonContainer* muons = nullptr;
35  CHECK(evtStore()->retrieve(muons, m_inputMuons));
36 
37  // create a view container for the selected muons
38  // basically acts like pointers to the selected muons in the muon container
40 
41  for (const xAOD::Muon* iMuon : *muons) {
42  if (m_tool->accept(*iMuon)) out->push_back(iMuon);
43  }
44  ATH_MSG_DEBUG("Selected " << out->size() << " muons");
45 
46  CHECK(evtStore()->record(out, m_outputMuons));
47  // if(evtStore()->proxy(muons)->isConst()) CHECK( evtStore()->setConst(out) ); - may allow in the future
48  CHECK(evtStore()->setConst(out)); // for now we just always lock everything we put into storegate
49 
50  return StatusCode::SUCCESS;
51  }
52 
53 } // namespace CP
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
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.
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::MuonSelectionAlg::initialize
virtual StatusCode initialize()
Definition: MuonID/MuonSelectorTools/src/MuonSelectionAlg.cxx:18
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::MuonSelectionAlg::m_tool
ToolHandle< CP::IMuonSelectionTool > m_tool
Definition: MuonID/MuonSelectorTools/src/MuonSelectionAlg.h:27
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CP::MuonSelectionAlg::execute
virtual StatusCode execute()
Definition: MuonID/MuonSelectorTools/src/MuonSelectionAlg.cxx:32
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::MuonSelectionAlg::m_inputMuons
std::string m_inputMuons
Definition: MuonID/MuonSelectorTools/src/MuonSelectionAlg.h:25
CP::MuonSelectionAlg::MuonSelectionAlg
MuonSelectionAlg(const std::string &name, ISvcLocator *svcloc)
Definition: MuonID/MuonSelectorTools/src/MuonSelectionAlg.cxx:11
MuonContainer.h
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
CP::MuonSelectionAlg::m_outputMuons
std::string m_outputMuons
Definition: MuonID/MuonSelectorTools/src/MuonSelectionAlg.h:26
MuonSelectionAlg.h