ATLAS Offline Software
Loading...
Searching...
No Matches
SafeDeepCopy.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: SafeDeepCopy.cxx 676241 2015-06-18 06:15:44Z krasznaa $
6
7// EDM include(s):
8//#define protected public
10//#undef protected
13
14// Local include(s):
16
17namespace xAOD {
18
19 void safeDeepCopy( const SG::AuxElement& orig, SG::AuxElement& copy ) {
20
21 //
22 // Check that the target object is healthy:
23 //
24 if( ! copy.container() ) {
25 return;
26 }
27 if( ! copy.container()->hasStore() ) {
28 return;
29 }
30 if( ! copy.container()->hasNonConstStore() ) {
31 throw SG::ExcConstAuxData( "safeDeepCopy" );
32 }
33
34 //
35 // Access the original's data:
36 //
37 const SG::AuxVectorData* ocont = orig.container();
38 if( ( ! ocont ) || ( ! ocont->hasStore() ) ) {
39 // In this case let the assignment operator of SG::AuxElement take
40 // care of clearing out the target object.
41 copy = orig;
42 return;
43 }
44
45 //
46 // Do the copy:
47 //
48 const size_t iindex = orig.index();
49 const size_t oindex = copy.index();
50 SG::auxid_set_t other_ids = ocont->getAuxIDs();
52 SG::AuxVectorData& copy_container = *copy.container();
53
54 // Copy the variables that exist on the input object:
55 for( SG::auxid_t auxid : other_ids ) {
56 r.copy( auxid, copy_container, oindex, *ocont, iindex, 1 );
57 }
58 // Clear out the variables that only exist on the output object:
59 for( SG::auxid_t auxid : copy.container()->getWritableAuxIDs() ) {
60 if( !other_ids.test( auxid ) ) {
61 r.clear( auxid, copy_container, oindex, 1 );
62 }
63 }
64 }
65
66} // namespace xAOD
Base class for elements of a container that can have aux data.
Handle mappings between names and auxid_t.
Exceptions that can be thrown from AthContainers.
bool test(bit_t bit) const
Test to see if a bit is set.
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Manage lookup of vectors of auxiliary data.
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items in store associated with this object.
bool hasStore() const
Return true if this object has an associated store.
Exception — Non-const operation performed on const aux data.
A set of aux data identifiers.
Definition AuxTypes.h:47
int r
Definition globals.cxx:22
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
void safeDeepCopy(const SG::AuxElement &orig, SG::AuxElement &copy)
Function that can deep-copy "problematic" objects.