ATLAS Offline Software
Loading...
Searching...
No Matches
JetCopier.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 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
95 std::pair<std::unique_ptr<xAOD::JetContainer>,
96 std::unique_ptr<xAOD::ShallowAuxContainer> > shallowcopy =
97 xAOD::shallowCopyContainer(*inputJetsHandle, Gaudi::Hive::currentContext());
98
99 shallowcopy.second->setShallowIO(m_shallowIO);
100
101 // Connect the copied jets to their originals
102 xAOD::setOriginalObjectLink(*inputJetsHandle, *shallowcopy.first);
103
104 return shallowcopy;
105}
106
107std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::DeepCopyJets() const {
108
109 // retrieve input
111
112 if(inputJetsHandle.isValid()) {
113 ATH_MSG_DEBUG("Retrieval of JetContainer was OK");
114 } else {
115 ATH_MSG_ERROR("Retrieval of JetContainer failed");
116 return std::make_pair(std::unique_ptr<xAOD::JetContainer>(nullptr),std::unique_ptr<SG::IAuxStore>(nullptr));
117 }
118
119 ATH_MSG_DEBUG("Deep-copying jets");
120
121 std::unique_ptr<xAOD::JetContainer> goodJets = std::make_unique<xAOD::JetContainer>();
122 std::unique_ptr<xAOD::JetAuxContainer> goodJetsAux = std::make_unique<xAOD::JetAuxContainer>();
123
124 goodJets->setStore (goodJetsAux.get());
125
126 for(const xAOD::Jet* jet : *inputJetsHandle){
127 xAOD::Jet* goodJet = new xAOD::Jet();
128 goodJets->push_back (goodJet);
129 *goodJet = *jet;
130 }
131
132 return std::make_pair(std::move(goodJets),std::move(goodJetsAux));
133}
#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".
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant 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".