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>
14std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxContainer>> shallowCopy(
15 const T& cont, const EventContext& ctx) {
16
17 // Create the new interface container.
18 auto newCont = std::make_unique<T>();
19 newCont->reserve(cont.size());
20 for (const auto& elem : cont) {
21 newCont->push_back(prepareElementForShallowCopy(elem));
22 }
23
24 // Create a new shallow auxiliary container.
25 assert(cont.getConstStore() != nullptr);
26 DataLink<SG::IConstAuxStore> link(cont.getConstStore(), ctx);
27 assert(link.cptr() != nullptr);
28 auto aux = std::make_unique<ShallowAuxContainer>(link);
29
30 // Connect it to the interface container.
31 newCont->setStore(aux.get());
32
33 // Return the new objects:
34 return {std::move(newCont), std::move(aux)};
35}
36
37template <SG::IsAuxDataVector T>
38std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxContainer>> shallowCopy(
39 const T& cont) {
40
41 return shallowCopy(cont, Gaudi::Hive::currentContext());
42}
43
44template <SG::IsConstAuxElement T>
45std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxInfo>> shallowCopy(
46 const T& obj, const EventContext& ctx) {
47
48 // Create the new interface object.
49 auto newObj = prepareElementForShallowCopy(&obj);
50
51 // Create a new shallow auxiliary container.
52 assert(obj.getConstStore() != nullptr);
53 DataLink<SG::IConstAuxStore> link(obj.getConstStore(), ctx);
54 assert(link.cptr() != nullptr);
55 auto aux = std::make_unique<ShallowAuxInfo>(link);
56
57 // Connect it to the interface container.
58 newObj->setStore(aux.get());
59
60 // Return the new objects:
61 return {std::move(newObj), std::move(aux)};
62}
63
64template <SG::IsConstAuxElement T>
65std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxInfo>> shallowCopy(
66 const T& obj) {
67
68 return shallowCopy(obj, Gaudi::Hive::currentContext());
69}
70
71} // namespace xAOD
72
73#endif // XAODCORE_SHALLOWCOPY_ICC