ATLAS Offline Software
Loading...
Searching...
No Matches
ShallowCopy.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef XAODCORE_SHALLOWCOPY_ICC
6#define XAODCORE_SHALLOWCOPY_ICC
7
8// System include(s).
9#include <cassert>
10
11namespace xAOD {
12
13template <SG::IsAuxDataVector T>
14ShallowCopyResult_t<T> shallowCopy(const T& cont, const EventContext& ctx) {
15
16 // Create the new interface container.
17 auto newCont = std::make_unique<T>();
18 newCont->reserve(cont.size());
19 for (const auto& elem : cont) {
20 newCont->push_back(prepareElementForShallowCopy(elem));
21 }
22
23 // Create a new shallow auxiliary container.
24 assert(cont.getConstStore() != nullptr);
25 DataLink<SG::IConstAuxStore> link(cont.getConstStore(), ctx);
26 assert(link.cptr() != nullptr);
27 auto aux = std::make_unique<ShallowAuxContainer>(link);
28
29 // Connect it to the interface container.
30 newCont->setStore(aux.get());
31
32 // Return the new objects:
33 return {std::move(newCont), std::move(aux)};
34}
35
36template <SG::IsAuxDataVector T>
37ShallowCopyResult_t<T> shallowCopy(const T& cont) {
38
39 return shallowCopy(cont, Gaudi::Hive::currentContext());
40}
41
42template <SG::IsConstAuxElement T>
43ShallowCopyResult_t<T> shallowCopy(const T& obj, const EventContext& ctx) {
44
45 // Create the new interface object.
46 auto newObj = prepareElementForShallowCopy(&obj);
47
48 // Create a new shallow auxiliary container.
49 assert(obj.getConstStore() != nullptr);
50 DataLink<SG::IConstAuxStore> link(obj.getConstStore(), ctx);
51 assert(link.cptr() != nullptr);
52 auto aux = std::make_unique<ShallowAuxInfo>(link);
53
54 // Connect it to the interface container.
55 newObj->setStore(aux.get());
56
57 // Return the new objects:
58 return {std::move(newObj), std::move(aux)};
59}
60
61template <SG::IsConstAuxElement T>
62ShallowCopyResult_t<T> shallowCopy(const T& obj) {
63
64 return shallowCopy(obj, Gaudi::Hive::currentContext());
65}
66
67} // namespace xAOD
68
69#endif // XAODCORE_SHALLOWCOPY_ICC