ATLAS Offline Software
Loading...
Searching...
No Matches
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
14namespace 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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
This is the common class for 3D segments used in the muon spectrometer.
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.
pointer_type ptr()
Dereference the pointer.
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
ToolHandle< xAODMaker::IMuonSegmentConverterTool > m_muonSegmentConverterTool
virtual StatusCode initialize() override
Function initialising the algorithm.
MuonSegmentCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
SG::WriteHandleKey< xAOD::MuonSegmentContainer > m_xaodContainerName
SG::ReadHandleKey< Trk::SegmentCollection > m_muonSegmentLocation
DataVector< Trk::Segment > SegmentCollection
Definition index.py:1