2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 #ifndef GEOMODELUTILITIES_TRANSFORMMAP_ICC
6 #define GEOMODELUTILITIES_TRANSFORMMAP_ICC
8 #include "GeoModelHelpers/throwExcept.h"
9 #include "CxxUtils/inline_hints.h"
12 template <typename T, typename X> bool TransformMap<T, X>::setTransform(const T* obj, std::shared_ptr<const X> xf) const {
14 THROW_EXCEPTION("The transform map is already locked ");
16 std::unique_lock guard{m_mutex};
17 typename ConCurrentMap_t::iterator itr = m_mutableCont->find(obj);
18 if (itr !=m_mutableCont->end()) {
19 itr->second = std::move(xf);
22 return m_mutableCont->emplace(obj, xf).second;
24 template <typename T, typename X>
25 bool TransformMap<T, X>::setTransform(const T* obj, std::shared_ptr<const X> xf) {
26 std::unique_lock guardThis{m_mutex};
28 std::shared_ptr<const X>& newObj = m_container[obj];
30 newObj = std::move(xf);
33 typename ConCurrentMap_t::iterator itr = m_mutableCont->find(obj);
34 if (itr !=m_mutableCont->end()) {
35 itr->second = std::move(xf);
38 return m_mutableCont->emplace(obj, xf).second;
41 template <typename T, typename X> bool TransformMap<T, X>::setTransform(const T *obj, const X &xf) const {
42 return setTransform(obj, std::make_shared<const X>(xf));
44 template <typename T, typename X> bool TransformMap<T, X>::setTransform(const T *obj, const X &xf) {
45 return setTransform(obj, std::make_shared<const X>(xf));
49 template <typename T, typename X>
51 const X *TransformMap<T, X>::getTransform(const T *obj) const {
53 auto itr = m_container.find(obj);
54 return itr != m_container.end() ? itr->second.get() : nullptr;
56 auto itr = m_mutableCont->find(obj);
57 return itr != m_mutableCont->end() ? itr->second.get() : nullptr;
60 template <typename T, typename X> bool TransformMap<T, X>::append(const TransformMap &other) {
62 std::shared_lock guardOther{other.m_mutex};
63 std::unique_lock guardThis{m_mutex};
64 if (other.m_mutableCont) {
65 for (const auto&[key, value]: *other.m_mutableCont){
66 allGood &= setTransform(key, value);
69 for (const auto &[key, value] : other.m_container) {
70 allGood &= setTransform(key, value);
76 template <typename T, typename X> void TransformMap<T, X>::clear() {
77 std::unique_lock guardThis{m_mutex};
79 m_mutableCont = std::make_unique<ConCurrentMap_t>(typename ConCurrentMap_t::Updater_t());
83 template <typename T, typename X> void TransformMap<T, X>::lock() {
84 std::unique_lock guardThis{m_mutex};
86 for (auto& [key, value] : *m_mutableCont) {
87 m_container.insert(std::make_pair(key, value));
90 m_mutableCont.reset();
92 template <typename T, typename X>
93 std::vector<const T*> TransformMap<T, X>::getStoredKeys() const {
94 std::vector<const T*> keys{};
96 keys.reserve(m_mutableCont->size());
97 for (const auto& key_value: *m_mutableCont) {
98 keys.push_back(key_value.first);
101 keys.reserve(m_container.size());
102 for (const auto& key_value: m_container) {
103 keys.push_back(key_value.first);