ATLAS Offline Software
MuonSegmentCnvAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MuonSegmentCnvAlg.h"
6 
10 #include "TrkSegment/Segment.h"
12 #include "AthLinks/ElementLink.h"
13 
14 namespace xAODMaker {
15 
16  MuonSegmentCnvAlg::MuonSegmentCnvAlg(const std::string& name, ISvcLocator* svcLoc) :
17  AthReentrantAlgorithm(name, svcLoc) {
18  }
19 
21 
22  ATH_MSG_DEBUG( "SegmentContainerName = " << m_muonSegmentLocation.key() << " xAODContainerName = " << m_xaodContainerName.key() );
24  ATH_CHECK(m_muonSegmentLocation.initialize());
25  ATH_CHECK(m_xaodContainerName.initialize());
26 
27  // Return gracefully:
28  return StatusCode::SUCCESS;
29  }
30 
31  StatusCode MuonSegmentCnvAlg::execute(const EventContext& ctx ) const {
32 
33  // Retrieve the AOD particles:
34  const Trk::SegmentCollection* segments = nullptr;
36  if(h_segments.isValid()) {
37  segments = h_segments.cptr();
38  }
39  else{
40  ATH_MSG_FATAL( "Unable to retrieve " << m_muonSegmentLocation.key() );
41  return StatusCode::FAILURE;
42  }
43 
44  // If there's no input, we're done already:
45  if( ! segments ) return StatusCode::SUCCESS;
46 
47  // Create the xAOD container and its auxiliary store:
49  ATH_CHECK(xaod.record(std::make_unique<xAOD::MuonSegmentContainer>(),
50  std::make_unique<xAOD::MuonSegmentAuxContainer>()));
51 
52  unsigned int index = 0;
53  for( auto it = segments->begin();it!=segments->end();++it,++index ){
54  const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(&(**it));
55  if( !muonSegment ) continue;
57  m_muonSegmentConverterTool->convert(link,xaod.ptr());
58  }
59  ATH_MSG_DEBUG( "Recorded MuonSegments with key: " << m_xaodContainerName.key() << " size " << xaod->size()
60  << " from input: "<< m_muonSegmentLocation.key() << " size " <<segments->size());
61 
62  return StatusCode::SUCCESS;
63  }
64 } // namespace xAODMaker
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAODMaker::MuonSegmentCnvAlg::m_muonSegmentLocation
SG::ReadHandleKey< Trk::SegmentCollection > m_muonSegmentLocation
Definition: MuonSegmentCnvAlg.h:39
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
xAODMaker::MuonSegmentCnvAlg::MuonSegmentCnvAlg
MuonSegmentCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: MuonSegmentCnvAlg.cxx:16
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
xAODMaker::MuonSegmentCnvAlg::initialize
virtual StatusCode initialize() override
Function initialising the algorithm.
Definition: MuonSegmentCnvAlg.cxx:20
MuonSegmentAuxContainer.h
xAODMaker::MuonSegmentCnvAlg::m_muonSegmentConverterTool
ToolHandle< xAODMaker::IMuonSegmentConverterTool > m_muonSegmentConverterTool
Definition: MuonSegmentCnvAlg.h:42
skel.it
it
Definition: skel.GENtoEVGEN.py:396
xAODMaker
Definition: StoreGateSvc.h:72
MuonSegmentContainer.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonSegmentCnvAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODMaker::MuonSegmentCnvAlg::m_xaodContainerName
SG::WriteHandleKey< xAOD::MuonSegmentContainer > m_xaodContainerName
Definition: MuonSegmentCnvAlg.h:40
DataVector< Trk::Segment >
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAODMaker::MuonSegmentCnvAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
Definition: MuonSegmentCnvAlg.cxx:31
MuonSegment.h
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SegmentCollection.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Segment.h