ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
xAOD
xAODBase
Root
IParticleHelpers.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
// System include(s):
6
#include <iostream>
7
8
// EDM include(s):
9
#include "AthLinks/ElementLink.h"
10
11
// Local include(s):
12
#include "
xAODBase/IParticleHelpers.h
"
13
14
namespace
xAOD
{
15
17
static
const
SG::AuxElement::Accessor< ElementLink< IParticleContainer > >
18
acc
(
"originalObjectLink"
);
19
30
bool
setOriginalObjectLink
(
const
IParticle
& original,
31
IParticle
& copy ) {
32
33
// We mustn't check for the availability of the decoration on the copied
34
// object here. Since if the copy is already part of a container, the
35
// decoration may well exist on it already. But it will not be set to
36
// anything meaningful yet.
37
38
// Check if the original is part of a container. If not, we can't set
39
// up a link.
40
const
IParticleContainer
* container =
41
dynamic_cast<
const
IParticleContainer
*
>
( original.container() );
42
if
( ! container ) {
43
std::cerr <<
"xAOD::setOriginalObjectLink ERROR Original object is "
44
<<
"not part of a container"
<< std::endl;
45
return
false
;
46
}
47
48
// Construct the ElementLink that points back to the original.
49
// We have to be tricky here. The original itself may already be a
50
// copy. In which case the new object should point back to the same
51
// original that "our original" is pointing to.
52
const
ElementLink< IParticleContainer >
link =
53
(
acc
.isAvailable( original ) ?
54
acc
( original ) :
55
ElementLink< IParticleContainer >
( *container, original.index() ) );
56
57
// Now set this link on the copy:
58
acc
( copy ) = link;
59
60
// We were successful:
61
return
true
;
62
}
63
81
bool
setOriginalObjectLink
(
const
IParticleContainer
& original,
82
IParticleContainer
& copy ) {
83
84
// Check that the containers are of the same size:
85
if
( original.
size
() != copy.size() ) {
86
std::cerr <<
"xAOD::setOriginalObjectLink ERROR Size of original "
87
<<
"and copy containers differs"
<< std::endl;
88
return
false
;
89
}
90
91
// Make sure that the original is not a view container. As the function
92
// doesn't work correctly for those.
93
if
( original.
ownPolicy
() !=
SG::OWN_ELEMENTS
) {
94
std::cerr <<
"xAOD::setOriginalObjectLink ERROR Received a view "
95
<<
"container"
<< std::endl;
96
return
false
;
97
}
98
99
// If the containers are empty, we're done:
100
if
( copy.empty() ) {
101
return
true
;
102
}
103
104
// Create an ElementLink to the first element in the original container.
105
// To be able to re-use the hashed key of this object in the loop.
106
const
ElementLink< IParticleContainer >
refLink( original, 0 );
107
108
// Loop over the copied container:
109
IParticleContainer::const_iterator
orig_itr = original.
begin
();
110
IParticleContainer::const_iterator
orig_end = original.
end
();
111
IParticleContainer::iterator
copy_itr = copy.begin();
112
// To speed up the loop over large containers a bit, make the decision
113
// about how to create the links, just once:
114
if
(
acc
.isAvailable( **orig_itr ) ) {
115
for
( ; orig_itr != orig_end; ++orig_itr, ++copy_itr ) {
116
// Copy the variable from the original object:
117
acc
( **copy_itr ) =
acc
( **orig_itr );
118
}
119
}
else
{
120
for
( ; orig_itr != orig_end; ++orig_itr, ++copy_itr ) {
121
// Construct the link from scratch:
122
acc
( **copy_itr ) =
123
ElementLink< IParticleContainer >
( refLink.
key
(),
124
( *orig_itr )->index() );
125
}
126
}
127
128
// We were successful:
129
return
true
;
130
}
131
140
const
IParticle
*
getOriginalObject
(
const
IParticle
& copy ) {
141
142
// Check if the decoration is available on the object:
143
if
( !
acc
.isAvailable( copy ) ) {
144
return
nullptr
;
145
}
146
147
// Get the link:
148
const
ElementLink< IParticleContainer >
& link =
acc
( copy );
149
150
// Check if the link is valid:
151
if
( ! link.isValid() ) {
152
return
nullptr
;
153
}
154
155
// Apparently all is fine:
156
return
*link;
157
}
158
167
const
ElementLink< IParticleContainer >
&
168
getOriginalObjectLink
(
const
IParticle
& copy ) {
169
170
// Blindly retrieve the link. Rely on the auxiliary store code throwing an
171
// appropriate exception if this cannot be done. ;-)
172
return
acc
( copy );
173
}
174
175
}
// namespace xAOD
IParticleHelpers.h
DataVector< IParticle >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
DataVector< IParticle >::iterator
DataModel_detail::iterator< DataVector > iterator
Definition
DataVector.h:842
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
DataVector::ownPolicy
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ElementLink< IParticleContainer >
ElementLink::key
sgkey_t key() const
Get the key that we reference, as a hash.
Definition
A/AthLinks/ElementLink.h:169
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition
OwnershipPolicy.h:17
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition
ICaloAffectedTool.h:24
xAOD::getOriginalObject
const IParticle * getOriginalObject(const IParticle ©)
This function can be used to conveniently get a pointer back to the original object from which a copy...
Definition
IParticleHelpers.cxx:140
xAOD::setOriginalObjectLink
bool setOriginalObjectLink(const IParticle &original, IParticle ©)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Definition
IParticleHelpers.cxx:30
xAOD::acc
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
xAOD::getOriginalObjectLink
const ElementLink< IParticleContainer > & getOriginalObjectLink(const IParticle ©)
This function should be used instead of xAOD::getOriginalObject when we want to use the "original obj...
Definition
IParticleHelpers.cxx:168
xAOD::IParticleContainer
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
Definition
xAOD/xAODBase/xAODBase/IParticleContainer.h:32
Generated on
for ATLAS Offline Software by
1.17.0