ATLAS Offline Software
Loading...
Searching...
No Matches
ActsTrk::detail::TrfStoreTicketCounter Class Reference

In order that the TransformStore is able to provide enough memory to store the transform centrally, it needs to know how many clients are instantiated for a certain detector type. More...

#include <TransformStore.h>

Collaboration diagram for ActsTrk::detail::TrfStoreTicketCounter:

Public Types

using TicketCounterArr = std::array<std::atomic<unsigned>, s_techs>
using ReturnedTicketArr = std::array<std::vector<char>, s_techs>
using ReturnedHintArr = std::array<int, s_techs>

Static Public Member Functions

static unsigned int drawTicket (const DetectorType detType)
 Returns a unique ID to the client under which the client can store its transfomrm inside the container.
static unsigned int distributedTickets (const DetectorType detType)
 Returns the number of all distributed tickets.
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 instance.

Static Public Attributes

static constexpr unsigned s_techs {static_cast<unsigned>(DetectorType::UnDefined)}

Static Private Attributes

static TicketCounterArr s_clientCounter ATLAS_THREAD_SAFE
static ReturnedTicketArr s_returnedTickets ATLAS_THREAD_SAFE
static ReturnedHintArr s_returnedHints ATLAS_THREAD_SAFE

Detailed Description

In order that the TransformStore is able to provide enough memory to store the transform centrally, it needs to know how many clients are instantiated for a certain detector type.

Each client which wants to use the TansformStore to outsource its transform caching needs to draw a ticket when it is instantiated. As the life time of certain instances may actually be short, the client is supposed to return its ticket to the counter when destructed. In this way, the cache size matches exactly the memory needs.

Definition at line 113 of file TransformStore.h.

Member Typedef Documentation

◆ ReturnedHintArr

Definition at line 130 of file TransformStore.h.

◆ ReturnedTicketArr

Definition at line 129 of file TransformStore.h.

◆ TicketCounterArr

using ActsTrk::detail::TrfStoreTicketCounter::TicketCounterArr = std::array<std::atomic<unsigned>, s_techs>

Definition at line 128 of file TransformStore.h.

Member Function Documentation

◆ distributedTickets()

unsigned ActsTrk::detail::TrfStoreTicketCounter::distributedTickets ( const DetectorType detType)
static

Returns the number of all distributed tickets.

Definition at line 186 of file TransformStore.cxx.

186 {
187 std::unique_lock guard{s_ticketMutex};
188 return s_clientCounter[static_cast<unsigned>(type)];
189 }

◆ drawTicket()

unsigned ActsTrk::detail::TrfStoreTicketCounter::drawTicket ( const DetectorType detType)
static

Returns a unique ID to the client under which the client can store its transfomrm inside the container.

Definition at line 155 of file TransformStore.cxx.

155 {
156 std::unique_lock guard{s_ticketMutex};
157 const unsigned idx = static_cast<unsigned>(type);
158 std::vector<char>& returnedPool = s_returnedTickets[idx];
159 int& returnedHint = s_returnedHints[idx];
160 if (returnedPool.size() && returnedHint >= 0) {
161 for (size_t i = returnedHint; i < returnedPool.size(); ++i) {
162 if (returnedPool[i]) {
163 returnedPool[i] = false;
164
165 returnedHint = i+1;
166 if (static_cast<size_t>(returnedHint) >= returnedPool.size()) {
167 returnedHint = 0;
168 }
169 return i;
170 }
171 }
172
173 for (size_t i = 0; i < static_cast<size_t>(returnedHint); ++i) {
174 if (returnedPool[i]) {
175 returnedPool[i] = false;
176 returnedHint = i+1;
177 return i;
178 }
179 }
180 returnedHint = -1;
181 } else {
182 returnedHint = -1;
183 }
184 return s_clientCounter[idx]++;
185 }

◆ giveBackTicket()

void ActsTrk::detail::TrfStoreTicketCounter::giveBackTicket ( const DetectorType detType,
unsigned int ticketNo )
static

Return back a ticket for the specified detector type such that its slot can be used by another instance.

Parameters
detTypeThe ATLAS sub detector type for which the ticket is returned
ticketNoThe number of the drawn ticket to return

The ticket which was handed out at the very latest is returned. Remove all returned tickets from before

Remove all trailing ticket numbers

Definition at line 190 of file TransformStore.cxx.

191 {
192 std::unique_lock guard{s_ticketMutex};
193 const unsigned idx = static_cast<unsigned>(type);
194 std::vector<char>& returnedPool = s_returnedTickets[idx];
195 int& returnedHint = s_returnedHints[idx];
197 const unsigned distributed = s_clientCounter[idx];
198 if (ticketNo == distributed -1) {
199
200 if (ticketNo > 0 && ticketNo-1 < returnedPool.size()) {
201 for (; ticketNo > 0 && returnedPool[ticketNo-1]; --ticketNo){}
202 returnedPool.resize (ticketNo);
203 }
205 s_clientCounter[idx] = ticketNo;
206 if (returnedHint >= static_cast<int>(ticketNo)) {
207 returnedHint = 0;
208 }
209 } else {
210 if (returnedPool.size() <= ticketNo) {
211 returnedPool.resize (ticketNo+1);
212 }
213 returnedPool[ticketNo] = true;
214 if (returnedHint < 0 || static_cast<int>(ticketNo) < returnedHint) {
215 returnedHint = ticketNo;
216 }
217 }
218 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/3]

ReturnedHintArr s_returnedHints ActsTrk::detail::TrfStoreTicketCounter::ATLAS_THREAD_SAFE
staticprivate

Definition at line 135 of file TransformStore.h.

◆ ATLAS_THREAD_SAFE [2/3]

ReturnedTicketArr s_returnedTickets ActsTrk::detail::TrfStoreTicketCounter::ATLAS_THREAD_SAFE
staticprivate

Definition at line 134 of file TransformStore.h.

◆ ATLAS_THREAD_SAFE [3/3]

TicketCounterArr s_clientCounter ActsTrk::detail::TrfStoreTicketCounter::ATLAS_THREAD_SAFE
staticprivate

Definition at line 133 of file TransformStore.h.

◆ s_techs

unsigned ActsTrk::detail::TrfStoreTicketCounter::s_techs {static_cast<unsigned>(DetectorType::UnDefined)}
staticconstexpr

Definition at line 127 of file TransformStore.h.

127{static_cast<unsigned>(DetectorType::UnDefined)};
@ UnDefined
Small Thing Gap chambers (NSW).

The documentation for this class was generated from the following files: