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
12
14
16
17 ATH_MSG_DEBUG("Initializing...");
18
19 if(m_inputJets.empty()){
20 ATH_MSG_ERROR("Jet finding requested with no inputs");
21
22 return StatusCode::FAILURE;
23 }
24 else{
26 ATH_MSG_ERROR("ShallowIO set to True while ShallowCopy is False");
27
28 return StatusCode::FAILURE;
29 }
30 else{
31 ATH_CHECK(m_inputJets.initialize());
32 }
33 }
34
35 return StatusCode::SUCCESS;
36}
37
38
39#ifndef XAOD_STANDALONE
40// Setup helper to propagate decorations from original to copy
42 return m_decorDeps.initialize(m_inputJets, outputJets) ;
43}
44#endif
45
46
48 std::unique_ptr<xAOD::JetContainer> jets(nullptr);
49 std::unique_ptr<SG::IAuxStore> auxCont(nullptr);
50 std::tie(jets, auxCont) = getJets();
51
52 if(jets.get() == nullptr || auxCont.get() == nullptr) {return StatusCode::FAILURE;}
53
54 if(m_shallowCopy){
55 std::unique_ptr<xAOD::ShallowAuxContainer> auxCont_derived(static_cast<xAOD::ShallowAuxContainer*>(auxCont.release()));
56 ATH_CHECK( jetHandle.record(std::move(jets), std::move(auxCont_derived)) );
57#ifndef XAOD_STANDALONE
58 ATH_CHECK( m_decorDeps.linkDecors (m_inputJets) );
59#endif
60 }
61 else{
62 std::unique_ptr<xAOD::JetAuxContainer> auxCont_derived(static_cast<xAOD::JetAuxContainer*>(auxCont.release()));
63 ATH_CHECK( jetHandle.record(std::move(jets), std::move(auxCont_derived)) );
64#ifndef XAOD_STANDALONE
65 ATH_CHECK( m_decorDeps.linkDecors (m_inputJets) );
66#endif
67 }
68 return StatusCode::SUCCESS;
69}
70
71std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::getJets() const {
72 if(m_shallowCopy){
73 return ShallowCopyJets();
74 }
75 else{
76 return DeepCopyJets();
77 }
78}
79
80std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::ShallowCopyJets() const {
81
82 // retrieve input
84
85 if(inputJetsHandle.isValid()) {
86 ATH_MSG_DEBUG("Retrieval of JetContainer was OK");
87 } else {
88 ATH_MSG_ERROR("Retrieval of JetContainer failed");
89 return std::make_pair(std::unique_ptr<xAOD::JetContainer>(nullptr),std::unique_ptr<SG::IAuxStore>(nullptr));
90 }
91
92 ATH_MSG_DEBUG("Shallow-copying jets");
93
94 std::pair<xAOD::JetContainer*,xAOD::ShallowAuxContainer*> shallowcopy = xAOD::shallowCopyContainer(*inputJetsHandle);
95
96 shallowcopy.second->setShallowIO(m_shallowIO);
97
98 // Make sure that memory is managed safely
99 std::unique_ptr<xAOD::JetContainer> outjets(shallowcopy.first);
100 std::unique_ptr<xAOD::ShallowAuxContainer> shallowaux(shallowcopy.second);
101
102 // Connect the copied jets to their originals
103 xAOD::setOriginalObjectLink(*inputJetsHandle, *outjets);
104
105 return std::make_pair(std::move(outjets),std::move(shallowaux));
106}
107
108std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetCopier::DeepCopyJets() const {
109
110 // retrieve input
112
113 if(inputJetsHandle.isValid()) {
114 ATH_MSG_DEBUG("Retrieval of JetContainer was OK");
115 } else {
116 ATH_MSG_ERROR("Retrieval of JetContainer failed");
117 return std::make_pair(std::unique_ptr<xAOD::JetContainer>(nullptr),std::unique_ptr<SG::IAuxStore>(nullptr));
118 }
119
120 ATH_MSG_DEBUG("Deep-copying jets");
121
122 std::unique_ptr<xAOD::JetContainer> goodJets = std::make_unique<xAOD::JetContainer>();
123 std::unique_ptr<xAOD::JetAuxContainer> goodJetsAux = std::make_unique<xAOD::JetAuxContainer>();
124
125 goodJets->setStore (goodJetsAux.get());
126
127 for(const xAOD::Jet* jet : *inputJetsHandle){
128 xAOD::Jet* goodJet = new xAOD::Jet();
129 goodJets->push_back (goodJet);
130 *goodJet = *jet;
131 }
132
133 return std::make_pair(std::move(goodJets),std::move(goodJetsAux));
134}
#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:80
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:47
SG::ShallowCopyDecorDeps< xAOD::JetContainer > m_decorDeps
Definition JetCopier.h:68
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition JetCopier.cxx:15
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:71
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:41
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".