1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
3 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
6 * @file AthContainers/tools/AtomicDecorator.icc
7 * @author scott snyder <snyder@bnl.gov>
9 * @brief Access an auxiliary variable atomically.
18 * @param name Name of this aux variable.
20 * The name -> auxid lookup is done here.
22 template <class T, class ALLOC>
24 AtomicDecorator<T, ALLOC>::AtomicDecorator (const std::string& name)
25 : Base (name, "", SG::AuxVarFlags::Atomic)
32 * @param name Name of this aux variable.
33 * @param clsname The name of its associated class. May be blank.
35 * The name -> auxid lookup is done here.
37 template <class T, class ALLOC>
39 AtomicDecorator<T, ALLOC>::AtomicDecorator (const std::string& name,
40 const std::string& clsname)
41 : Base (name, clsname, SG::AuxVarFlags::Atomic)
47 * @brief Constructor taking an auxid directly.
48 * @param auxid ID for this auxiliary variable.
50 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
52 template <class T, class ALLOC>
54 AtomicDecorator<T, ALLOC>::AtomicDecorator (const SG::auxid_t auxid)
55 : Base (auxid, SG::AuxVarFlags::Atomic)
61 * @brief Fetch the variable for one element, as a non-const reference.
62 * @param e The element for which to fetch the variable.
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.
68 template <class T, class ALLOC>
70 ATH_REQUIRES( IsConstAuxElement<ELT> )
73 AtomicDecorator<T, ALLOC>::operator() (const ELT& e) const
76 return reinterpret_cast<reference_type> (Base::operator() (e));
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.
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.
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.
93 template <class T, class ALLOC>
96 AtomicDecorator<T, ALLOC>::operator() (const AuxVectorData& container,
100 return reinterpret_cast<reference_type> (Base::operator() (container, index));
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.
109 template <class T, class ALLOC>
111 void AtomicDecorator<T, ALLOC>::set (const AuxElement& e, const element_type& x) const
118 * @brief Get a pointer to the start of the auxiliary data array.
119 * @param container The container from which to fetch the variable.
121 template <class T, class ALLOC>
124 AtomicDecorator<T, ALLOC>::getDataArray (const AuxVectorData& container) const
125 -> const_container_pointer_type
127 return reinterpret_cast<const_container_pointer_type>
128 (container.getDataArray (Base::auxid()));
133 * @brief Get a pointer to the start of the auxiliary data array.
134 * @param container The container from which to fetch the variable.
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.
140 template <class T, class ALLOC>
143 AtomicDecorator<T, ALLOC>::getDecorationArray (const AuxVectorData& container) const
144 -> container_pointer_type
146 return reinterpret_cast<container_pointer_type>
147 (container.getDecorationArray (Base::auxid()));