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>
14std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxContainer>> shallowCopy(
15 const T& cont, const EventContext& ctx) {
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));
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);
30 // Connect it to the interface container.
31 newCont->setStore(aux.get());
33 // Return the new objects:
34 return {std::move(newCont), std::move(aux)};
37template <SG::IsAuxDataVector T>
38std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxContainer>> shallowCopy(
41 return shallowCopy(cont, Gaudi::Hive::currentContext());
44template <SG::IsConstAuxElement T>
45std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxInfo>> shallowCopy(
46 const T& obj, const EventContext& ctx) {
48 // Create the new interface object.
49 auto newObj = prepareElementForShallowCopy(&obj);
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);
57 // Connect it to the interface container.
58 newObj->setStore(aux.get());
60 // Return the new objects:
61 return {std::move(newObj), std::move(aux)};
64template <SG::IsConstAuxElement T>
65std::pair<std::unique_ptr<T>, std::unique_ptr<ShallowAuxInfo>> shallowCopy(
68 return shallowCopy(obj, Gaudi::Hive::currentContext());
73#endif // XAODCORE_SHALLOWCOPY_ICC