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