ATLAS Offline Software
AtomicDecorator.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/AtomicDecorator.icc
7  * @author scott snyder <snyder@bnl.gov>
8  * @date Mar, 2018
9  * @brief Access an auxiliary variable atomically.
10  */
11 
12 
13 namespace 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  */
22 template <class T, class ALLOC>
23 inline
24 AtomicDecorator<T, ALLOC>::AtomicDecorator (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  */
37 template <class T, class ALLOC>
38 inline
39 AtomicDecorator<T, ALLOC>::AtomicDecorator (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  */
52 template <class T, class ALLOC>
53 inline
54 AtomicDecorator<T, ALLOC>::AtomicDecorator (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 non-const reference.
62  * @param e The element for which to fetch the variable.
63  *
64  * If the container is locked, this will allow fetching only variables
65  * that do not yet exist (in which case they will be marked as decorations)
66  * or variables already marked as decorations.
67  */
68 template <class T, class ALLOC>
69 template <IsConstAuxElement ELT>
70 inline
71 auto
72 AtomicDecorator<T, ALLOC>::operator() (const ELT& e) const
73  -> reference_type
74 {
75  return reinterpret_cast<reference_type> (Base::operator() (e));
76 }
77 
78 
79 /**
80  * @brief Fetch the variable for one element, as a non-const reference.
81  * @param container The container from which to fetch the variable.
82  * @param index The index of the desired element.
83  *
84  * This allows retrieving aux data by container / index.
85  * Looping over the index via this method will be faster then
86  * looping over the elements of the container.
87  *
88  * If the container is locked, this will allow fetching only variables
89  * that do not yet exist (in which case they will be marked as decorations)
90  * or variables already marked as decorations.
91  */
92 template <class T, class ALLOC>
93 inline
94 auto
95 AtomicDecorator<T, ALLOC>::operator() (const AuxVectorData& container,
96  size_t index) const
97  -> reference_type
98 {
99  return reinterpret_cast<reference_type> (Base::operator() (container, index));
100 }
101 
102 
103 /**
104  * @brief Set the variable for one element.
105  * @param e The element for which to fetch the variable.
106  * @param x The variable value to set.
107  */
108 template <class T, class ALLOC>
109 inline
110 void AtomicDecorator<T, ALLOC>::set (const AuxElement& e, const element_type& x) const
111 {
112  (*this)(e) = x;
113 }
114 
115 
116 /**
117  * @brief Get a pointer to the start of the auxiliary data array.
118  * @param container The container from which to fetch the variable.
119  */
120 template <class T, class ALLOC>
121 inline
122 auto
123 AtomicDecorator<T, ALLOC>::getDataArray (const AuxVectorData& container) const
124  -> const_container_pointer_type
125 {
126  return reinterpret_cast<const_container_pointer_type>
127  (container.getDataArray (Base::auxid()));
128 }
129 
130 
131 /**
132  * @brief Get a pointer to the start of the auxiliary data array.
133  * @param container The container from which to fetch the variable.
134  *
135  * If the container is locked, this will allow fetching only variables
136  * that do not yet exist (in which case they will be marked as decorations)
137  * or variables already marked as decorations.
138  */
139 template <class T, class ALLOC>
140 inline
141 auto
142 AtomicDecorator<T, ALLOC>::getDecorationArray (const AuxVectorData& container) const
143  -> container_pointer_type
144 {
145  return reinterpret_cast<container_pointer_type>
146  (container.getDecorationArray (Base::auxid()));
147 }
148 
149 
150 } // namespace SG