ATLAS Offline Software
Loading...
Searching...
No Matches
AtomicConstAccessor.icc
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4*/
5/**
6 * @file AthContainers/tools/AtomicConstAccessor.icc
7 * @author scott snyder <snyder@bnl.gov>
8 * @date Apr, 2018
9 * @brief Access an auxiliary variable atomically.
10 */
11
12
13namespace SG {
14
15
16/**
17 * @brief Constructor.
18 * @param name Name of this aux variable.
19 *
20 * The name -> auxid lookup is done here.
21 */
22template <class T, class ALLOC>
23inline
24AtomicConstAccessor<T, ALLOC>::AtomicConstAccessor (const std::string& name)
25 : Base (name, "", SG::AuxVarFlags::Atomic)
26{
27}
28
29
30/**
31 * @brief Constructor.
32 * @param name Name of this aux variable.
33 * @param clsname The name of its associated class. May be blank.
34 *
35 * The name -> auxid lookup is done here.
36 */
37template <class T, class ALLOC>
38inline
39AtomicConstAccessor<T, ALLOC>::AtomicConstAccessor (const std::string& name,
40 const std::string& clsname)
41 : Base (name, clsname, SG::AuxVarFlags::Atomic)
42{
43}
44
45
46/**
47 * @brief Constructor taking an auxid directly.
48 * @param auxid ID for this auxiliary variable.
49 *
50 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
51 */
52template <class T, class ALLOC>
53inline
54AtomicConstAccessor<T, ALLOC>::AtomicConstAccessor (const SG::auxid_t auxid)
55 : Base (auxid, SG::AuxVarFlags::Atomic)
56{
57}
58
59
60/**
61 * @brief Fetch the variable for one element, as a const reference.
62 * @param e The element for which to fetch the variable.
63 *
64 * As this class can be used only read-only for basic types, return
65 * the result by value. That makes it easier to call from python.
66 */
67template <class T, class ALLOC>
68template <IsConstAuxElement ELT>
69inline
70T AtomicConstAccessor<T, ALLOC>::operator() (const ELT& e) const
71{
72 return reinterpret_cast<const_reference_type> (Base::operator() (e));
73}
74
75
76/**
77 * @brief Fetch the variable for one element, as a const reference.
78 * @param container The container from which to fetch the variable.
79 * @param index The index of the desired element.
80 *
81 * This allows retrieving aux data by container / index.
82 * Looping over the index via this method will be faster then
83 * looping over the elements of the container.
84 *
85 * As this class can be used only read-only for basic types, return
86 * the result by value. That makes it easier to call from python.
87 */
88template <class T, class ALLOC>
89inline
90T AtomicConstAccessor<T, ALLOC>::operator() (const AuxVectorData& container,
91 size_t index) const
92{
93 return reinterpret_cast<const_reference_type> (Base::operator() (container, index));
94}
95
96
97/**
98 * @brief Get a pointer to the start of the auxiliary data array.
99 * @param container The container from which to fetch the variable.
100 */
101template <class T, class ALLOC>
102inline
103auto
104AtomicConstAccessor<T, ALLOC>::getDataArray (const AuxVectorData& container) const
105 -> const_container_pointer_type
106{
107 return reinterpret_cast<const_container_pointer_type>
108 (container.getDataArray (Base::auxid()));
109}
110
111
112} // namespace SG