ATLAS Offline Software
Loading...
Searching...
No Matches
TransformMap.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef GEOMODELUTILITIES_TRANSFORMMAP_H
6#define GEOMODELUTILITIES_TRANSFORMMAP_H
7
10
11#include <memory>
12#include <unordered_map>
13#include <shared_mutex>
14
21template <typename T, typename X> class TransformMap {
22public:
24 TransformMap() =default;
25 /*** @brief: Copy constructor from an existing map*/
26 TransformMap(const TransformMap& other) = default;
28 TransformMap& operator=(const TransformMap& other) = default;
29
30 ~TransformMap() = default;
38 bool setTransform(const T *obj, const X &xf) const;
39 bool setTransform(const T* obj, const X& xf);
45 bool setTransform(const T *obj, std::shared_ptr<const X> xf) const;
46 bool setTransform(const T* obj, std::shared_ptr<const X> xf);
47
52 const X *getTransform(const T *obj) const;
53
58 bool append(const TransformMap &other);
60 void clear();
63 void lock();
65 std::vector<const T*> getStoredKeys() const;
66
67private:
69 using ConCurrentMap_ptr = std::unique_ptr<ConCurrentMap_t>;
70 using CanonicalMap_t = std::unordered_map<const T*, std::shared_ptr<const X>>;
71 using CanonicalMap_ptr = std::unique_ptr<CanonicalMap_t>;
72
73
74 mutable CanonicalMap_t m_container ATLAS_THREAD_SAFE{};
75 mutable bool m_locked ATLAS_THREAD_SAFE{false};
76 mutable std::shared_mutex m_mutex ATLAS_THREAD_SAFE{};
77 mutable ConCurrentMap_ptr m_mutableCont ATLAS_THREAD_SAFE{
78 std::make_unique<ConCurrentMap_t>(typename ConCurrentMap_t::Updater_t())};
79
80
81};
83#endif
Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads.
Simple (non-deleting) Updater implementation.
Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads.
typename Impl_t::Updater_t Updater_t
Updater object.
Simple (non-deleting) Updater implementation.
bool setTransform(const T *obj, std::shared_ptr< const X > xf)
CxxUtils::ConcurrentToValMap< const GeoAlignableTransform *, std::shared_ptr< const GeoTrf::Transform3D >, CxxUtils::SimpleUpdater > ConCurrentMap_t
TransformMap & operator=(const TransformMap &other)=default
: Copy assignment operator
const X * getTransform(const T *obj) const
: Returns the transform that's associated with input object.
bool setTransform(const T *obj, std::shared_ptr< const X > xf) const
: Adds a transform object to the map.
bool setTransform(const T *obj, const X &xf)
std::vector< const T * > getStoredKeys() const
: Returns a vector of all objects that have been parsed to the map
~TransformMap()=default
TransformMap(const TransformMap &other)=default
bool append(const TransformMap &other)
: Copies all key value pairs from the external map and appends it to this map instance.
std::unique_ptr< ConCurrentMap_t > ConCurrentMap_ptr
TransformMap()=default
: Default constructor
void lock()
: Lock the map which switches off the mutex protection mechanism.
bool setTransform(const T *obj, const X &xf) const
: Adds a transform object to the map.
std::unordered_map< const GeoAlignableTransform *, std::shared_ptr< const GeoTrf::Transform3D > > CanonicalMap_t
void clear()
: Clear the transform cache map