2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5#ifndef XAODCORE_SHALLOWCOPY_ICC
6#define XAODCORE_SHALLOWCOPY_ICC
13template <SG::IsAuxDataVector T>
14ShallowCopyResult_t<T> shallowCopy(const T& cont, const EventContext& ctx) {
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));
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);
29 // Connect it to the interface container.
30 newCont->setStore(aux.get());
32 // Return the new objects:
33 return {std::move(newCont), std::move(aux)};
36template <SG::IsAuxDataVector T>
37ShallowCopyResult_t<T> shallowCopy(const T& cont) {
39 return shallowCopy(cont, Gaudi::Hive::currentContext());
42template <SG::IsConstAuxElement T>
43ShallowCopyResult_t<T> shallowCopy(const T& obj, const EventContext& ctx) {
45 // Create the new interface object.
46 auto newObj = prepareElementForShallowCopy(&obj);
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);
54 // Connect it to the interface container.
55 newObj->setStore(aux.get());
57 // Return the new objects:
58 return {std::move(newObj), std::move(aux)};
61template <SG::IsConstAuxElement T>
62ShallowCopyResult_t<T> shallowCopy(const T& obj) {
64 return shallowCopy(obj, Gaudi::Hive::currentContext());
69#endif // XAODCORE_SHALLOWCOPY_ICC