ATLAS Offline Software
Loading...
Searching...
No Matches
JetCopier.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "JetRec/JetCopier.h"
6
13
15
17
18 ATH_MSG_DEBUG("Initializing...");
19
20 if(m_inputJets.empty()){
21 ATH_MSG_ERROR("Jet finding requested with no inputs");
22
23 return StatusCode::FAILURE;
24 }
25 else{
27 ATH_MSG_ERROR("ShallowIO set to True while ShallowCopy is False");
28
29 return StatusCode::FAILURE;
30 }
31 else{
32 ATH_CHECK(m_inputJets.initialize());
33 }
34 }
35
36 return StatusCode::SUCCESS;
37}
38
39
40#ifndef XAOD_STANDALONE
41// Setup helper to propagate decorations from original to copy
43 return m_decorDeps.initialize(m_inputJets, outputJets) ;
44}
45#endif
46
47
49 std::unique_ptr<xAOD::JetContainer> jets(nullptr);
50 std::unique_ptr<SG::IAuxStore> auxCont(nullptr);
51 std::tie(jets, auxCont) = getJets();
52
53 if(jets.get() == nullptr || auxCont.get() == nullptr) {return StatusCode::FAILURE;}
54
55 if(m_shallowCopy){
56 std::unique_ptr<xAOD::ShallowAuxContainer> auxCont_derived(static_cast<xAOD::ShallowAuxContainer*>(auxCont.release()));
57 ATH_CHECK( jetHandle.record(std::move(jets), std::move(auxCont_derived)) );
58#ifndef XAOD_STANDALONE
59 ATH_CHECK( m_decorDeps.linkDecors (m_inputJets) );
60#endif
61 }
62 else{
63 std::unique_ptr<xAOD::JetAuxContainer> auxCont_derived(static_cast<xAOD::JetAuxContainer*>(auxCont.release()));
64 ATH_CHECK( jetHandle.record(std::move(jets), std::move(auxCont_derived)) );
65#ifndef XAOD_STANDALONE
66 ATH_CHECK( m_decorDeps.linkDecors (m_inputJets) );
67#endif
68 }
69 return StatusCode::SUCCESS;
70}
71
72std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::getJets() const {
73 if(m_shallowCopy){
74 return ShallowCopyJets();
75 }
76 else{
77 return DeepCopyJets();
78 }
79}
80
81std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::ShallowCopyJets() const {
82
83 // retrieve input
85
86 if(inputJetsHandle.isValid()) {
87 ATH_MSG_DEBUG("Retrieval of JetContainer was OK");
88 } else {
89 ATH_MSG_ERROR("Retrieval of JetContainer failed");
90 return std::make_pair(std::unique_ptr<xAOD::JetContainer>(nullptr),std::unique_ptr<SG::IAuxStore>(nullptr));
91 }
92
93 ATH_MSG_DEBUG("Shallow-copying jets");
94
96 xAOD::shallowCopy(*inputJetsHandle);
97
98 shallowcopy.second->setShallowIO(m_shallowIO);
99
100 // Connect the copied jets to their originals
101 xAOD::setOriginalObjectLink(*inputJetsHandle, *shallowcopy.first);
102
103 return shallowcopy;
104}
105
106std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::DeepCopyJets() const {
107
108 // retrieve input
110
111 if(inputJetsHandle.isValid()) {
112 ATH_MSG_DEBUG("Retrieval of JetContainer was OK");
113 } else {
114 ATH_MSG_ERROR("Retrieval of JetContainer failed");
115 return std::make_pair(std::unique_ptr<xAOD::JetContainer>(nullptr),std::unique_ptr<SG::IAuxStore>(nullptr));
116 }
117
118 ATH_MSG_DEBUG("Deep-copying jets");
119
120 std::unique_ptr<xAOD::JetContainer> goodJets = std::make_unique<xAOD::JetContainer>();
121 std::unique_ptr<xAOD::JetAuxContainer> goodJetsAux = std::make_unique<xAOD::JetAuxContainer>();
122
123 goodJets->setStore (goodJetsAux.get());
124
125 for(const xAOD::Jet* jet : *inputJetsHandle){
126 xAOD::Jet* goodJet = new xAOD::Jet();
127 goodJets->push_back (goodJet);
128 *goodJet = *jet;
129 }
130
131 return std::make_pair(std::move(goodJets),std::move(goodJetsAux));
132}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
virtual std::pair< std::unique_ptr< xAOD::JetContainer >, std::unique_ptr< SG::IAuxStore > > ShallowCopyJets() const
Definition JetCopier.cxx:81
virtual std::pair< std::unique_ptr< xAOD::JetContainer >, std::unique_ptr< SG::IAuxStore > > DeepCopyJets() const
Gaudi::Property< bool > m_shallowCopy
Definition JetCopier.h:64
virtual StatusCode getAndRecordJets(SG::WriteHandle< xAOD::JetContainer > &jetHandle) const override
Method to allow the client to pass in a WriteHandle for the container and aux container to be recorde...
Definition JetCopier.cxx:48
SG::ShallowCopyDecorDeps< xAOD::JetContainer > m_decorDeps
Definition JetCopier.h:68
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition JetCopier.cxx:16
SG::ReadHandleKey< xAOD::JetContainer > m_inputJets
Definition JetCopier.h:62
virtual std::pair< std::unique_ptr< xAOD::JetContainer >, std::unique_ptr< SG::IAuxStore > > getJets() const override
Method to build the collection and return it to the caller.
Definition JetCopier.cxx:72
Gaudi::Property< bool > m_shallowIO
Definition JetCopier.h:65
virtual StatusCode initWithOutput(const SG::WriteHandleKey< xAOD::JetContainer > &outputJets) override
Method to allow the client to pass in a WriteHandle during initialisation, in case this is needed for...
Definition JetCopier.cxx:42
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Class creating a shallow copy of an existing auxiliary container.
Jet_v1 Jet
Definition of the current "jet version".
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition ShallowCopy.h:68
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
JetAuxContainer_v1 JetAuxContainer
Definition of the current jet auxiliary container.
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
JetContainer_v1 JetContainer
Definition of the current "jet container version".