ATLAS Offline Software
Loading...
Searching...
No Matches
TransformStore.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ACTSGEOMETRYINTERFACES_TrackingAlignStore_H
5#define ACTSGEOMETRYINTERFACES_TrackingAlignStore_H
6
9
12
13#include <array>
14#include <variant>
15#include <cassert>
16#include <iostream>
17
18namespace ActsTrk::detail{
28 public:
30 enum class Mode: std::uint8_t {
34 };
35
36 static std::string toString(const Mode m);
37 inline friend std::ostream& operator<<(std::ostream&ostr, const Mode m){
38 return ostr<<toString(m);
39 }
40
41 inline friend std::ostream& operator<<(std::ostream&ostr, const TransformStore& store){
42 return store.print(ostr);
43 }
44
48 TransformStore(const DetectorType detType, const Mode m);
50 TransformStore(TransformStore&& other) noexcept = default;
52 TransformStore& operator=(TransformStore&& other) noexcept = default;
54 TransformStore(const TransformStore& other) noexcept;
56 TransformStore& operator=(const TransformStore& other) noexcept;
61 const Amg::Transform3D* getTransform(const unsigned ticketNo) const;
67 const Amg::Transform3D& setTransform(const unsigned int ticketNo, Amg::Transform3D && trf) const;
72 const Amg::Transform3D& setTransform(const unsigned int ticketNo, Amg::Transform3D && trf);
74 Mode mode() const;
78 std::size_t size() const;
80 std::size_t filled() const;
81 private:
83 using LazyStorage_t = std::vector<CxxUtils::CachedUniquePtr<Amg::Transform3D>>;
85 using TrfVec_t = std::vector<Amg::Transform3D>;
87 using CheckVec_t = std::vector<char>;
89 using BlockStorage_t = std::pair<TrfVec_t, CheckVec_t>;
91 using Storage_t = std::variant<LazyStorage_t, BlockStorage_t>;
99 static Storage_t initStorage(const DetectorType dType,
100 const Mode mode) noexcept;
101
102 std::ostream& print(std::ostream& ostr) const;
103
104 };
105
114 public:
117 static unsigned int drawTicket(const DetectorType detType);
119 static unsigned int distributedTickets(const DetectorType detType);
124 static void giveBackTicket(const DetectorType detType, unsigned int ticketNo);
125
126
127 static constexpr unsigned s_techs{static_cast<unsigned>(DetectorType::UnDefined)};
128 using TicketCounterArr = std::array<std::atomic<unsigned>, s_techs>;
129 using ReturnedTicketArr = std::array<std::vector<char>, s_techs>;
130 using ReturnedHintArr = std::array<int, s_techs>;
131
132 private:
133 static TicketCounterArr s_clientCounter ATLAS_THREAD_SAFE;
134 static ReturnedTicketArr s_returnedTickets ATLAS_THREAD_SAFE;
135 static ReturnedHintArr s_returnedHints ATLAS_THREAD_SAFE;
136 };
137
138
139 inline const Amg::Transform3D* TransformStore::getTransform(const unsigned ticketNo) const {
140 return std::visit([&](auto& store) -> const Amg::Transform3D* {
141 using Store_t = std::decay_t<decltype(store)>;
142 if constexpr(std::is_same_v<Store_t, LazyStorage_t>) {
143 assert(ticketNo < store.size());
144 return store[ticketNo].get();
145 } else if constexpr(std::is_same_v<Store_t, BlockStorage_t>) {
146 assert(ticketNo < store.first.size());
147 return store.second[ticketNo] ? &store.first[ticketNo] : nullptr;
148 } else {
149 return nullptr;
150 }
151 }, m_storage);
152 }
153}
154
155#ifndef SIMULATIONBASE
157#endif
158#endif
Cached unique_ptr with atomic update.
ACTS_OSTREAM_FORMATTER(MuonR4::CalibratedSpacePoint::State)
Define macros for attributes used to control the static checker.
TransformStore(TransformStore &&other) noexcept=default
Define the move constructor.
const Amg::Transform3D & setTransform(const unsigned int ticketNo, Amg::Transform3D &&trf) const
Stores a transform at the index of the passed ticket number.
std::variant< LazyStorage_t, BlockStorage_t > Storage_t
Use the std::variant to dynamically switch between the two types.
Mode
Enum describing the operation mode of the cache.
@ Block
Transforms can be set later during the event processing.
const Amg::Transform3D * getTransform(const unsigned ticketNo) const
Returns the pointer to the transfomation cached in the store (Might be a nullptr if LazyFill is used)...
std::ostream & print(std::ostream &ostr) const
std::size_t filled() const
Returns the number of filled transforms.
static std::string toString(const Mode m)
Define the to string operator.
static Storage_t initStorage(const DetectorType dType, const Mode mode) noexcept
Helper method to instantiate the storage for a given detector type.
std::vector< CxxUtils::CachedUniquePtr< Amg::Transform3D > > LazyStorage_t
Abrivation of the backend in the lazy filling mode.
friend std::ostream & operator<<(std::ostream &ostr, const Mode m)
std::pair< TrfVec_t, CheckVec_t > BlockStorage_t
Abrivation of the continous vector storage.
TransformStore(const DetectorType detType, const Mode m)
Constructor.
std::vector< char > CheckVec_t
Abrivate the char vector.
friend std::ostream & operator<<(std::ostream &ostr, const TransformStore &store)
Define the to string ostream operator.
std::vector< Amg::Transform3D > TrfVec_t
Abrivate the transform vector.
DetectorType m_detType
The associated detector type.
Mode mode() const
Returns the mode with which the store has been instantiated.
std::size_t size() const
Return the size (maximum capacity) of the current store.
TransformStore & operator=(TransformStore &&other) noexcept=default
Define the move assignment operator.
const Amg::Transform3D & setTransform(const unsigned int ticketNo, Amg::Transform3D &&trf)
Stores a transform at the index of the passed ticket number.
DetectorType detectorType() const
Returns the detector type.
In order that the TransformStore is able to provide enough memory to store the transform centrally,...
static unsigned int distributedTickets(const DetectorType detType)
Returns the number of all distributed tickets.
std::array< int, s_techs > ReturnedHintArr
static unsigned int drawTicket(const DetectorType detType)
Returns a unique ID to the client under which the client can store its transfomrm inside the containe...
static TicketCounterArr s_clientCounter ATLAS_THREAD_SAFE
std::array< std::atomic< unsigned >, s_techs > TicketCounterArr
static void giveBackTicket(const DetectorType detType, unsigned int ticketNo)
Return back a ticket for the specified detector type such that its slot can be used by another instan...
std::array< std::vector< char >, s_techs > ReturnedTicketArr
StoreGateSvc * Store_t
Athena definition of the Eigen plugin.
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
@ UnDefined
Small Thing Gap chambers (NSW).
Eigen::Affine3d Transform3D