ATLAS Offline Software
L1JetCopyAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
5 #include "xAODCore/ShallowCopy.h"
7 
8 //**********************************************************************
9 
10 template<typename T>
11 L1JetCopyAlgorithm<T>::L1JetCopyAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ) : AthReentrantAlgorithm(name,pSvcLocator){
12  declareProperty("JetInContainerName" ,m_jetInContainerKey="");
13  declareProperty("JetOutContainerName" ,m_jetOutContainerKey="");
14 }
15 
16 template<typename T>
18 
19  ATH_MSG_INFO(" Initializing " << name());
20  ATH_CHECK( m_jetInContainerKey.initialize() );
21  ATH_CHECK( m_jetOutContainerKey.initialize() );
22 
23  return StatusCode::SUCCESS;
24 }
25 
26 template<typename T>
28  ATH_MSG_INFO ("Finalizing " << name());
29  return StatusCode::SUCCESS;
30 }
31 
32 //**********************************************************************
33 
34 template<typename T>
35 StatusCode L1JetCopyAlgorithm<T>::execute(const EventContext& ctx) const {
36  SG::ReadHandle<JetContainer> inputJetsHandle(m_jetInContainerKey, ctx); // read handle
37  if (!inputJetsHandle.isValid() ) {
38  ATH_MSG_ERROR("evtStore() does not contain jet Collection with name "<< m_jetInContainerKey);
39  return StatusCode::FAILURE;
40  }
41 
42  ATH_MSG_DEBUG("Shallow-copying "<<m_jetInContainerKey);
43  SG::WriteHandle<JetContainer> jetsOut(m_jetOutContainerKey,ctx);
44 
45  auto shallowcopy = xAOD::shallowCopyContainer(*inputJetsHandle);
46  std::unique_ptr<JetContainer> copiedjets(shallowcopy.first);
47  std::unique_ptr<xAOD::ShallowAuxContainer> shallowaux(shallowcopy.second);
48 
49  if(copiedjets.get() == nullptr || shallowaux.get() == nullptr) {
50  ATH_MSG_ERROR("Failed to make shallow copy of "<<m_jetInContainerKey<<".");
51  return StatusCode::FAILURE;
52  }
53  ATH_CHECK( jetsOut.record(std::move(copiedjets), std::move(shallowaux)) );
54 
55  return StatusCode::SUCCESS;
56 }
57 
ShallowCopy.h
L1JetCopyAlgorithm
Definition: L1JetCopyAlgorithm.h:15
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
L1JetCopyAlgorithm::initialize
StatusCode initialize() override
Definition: L1JetCopyAlgorithm.cxx:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AuxContainerBase.h
L1JetCopyAlgorithm::finalize
StatusCode finalize() override
Definition: L1JetCopyAlgorithm.cxx:27
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
L1JetCopyAlgorithm::L1JetCopyAlgorithm
L1JetCopyAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: L1JetCopyAlgorithm.cxx:11
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
L1JetCopyAlgorithm::m_jetInContainerKey
SG::ReadHandleKey< JetContainer > m_jetInContainerKey
Definition: L1JetCopyAlgorithm.h:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
L1JetCopyAlgorithm::execute
StatusCode execute(const EventContext &ctx) const override
Definition: L1JetCopyAlgorithm.cxx:35
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.
L1JetCopyAlgorithm::m_jetOutContainerKey
SG::WriteHandleKey< JetContainer > m_jetOutContainerKey
Definition: L1JetCopyAlgorithm.h:30
L1JetCopyAlgorithm.h