1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
3 Copyright (C) 2002-2025 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>
69 template <IsConstAuxElement ELT>
72 AtomicDecorator<T, ALLOC>::operator() (const ELT& e) const
75 return reinterpret_cast<reference_type> (Base::operator() (e));
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.
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.
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.
92 template <class T, class ALLOC>
95 AtomicDecorator<T, ALLOC>::operator() (const AuxVectorData& container,
99 return reinterpret_cast<reference_type> (Base::operator() (container, index));
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.
108 template <class T, class ALLOC>
110 void AtomicDecorator<T, ALLOC>::set (const AuxElement& e, const element_type& x) const
117 * @brief Get a pointer to the start of the auxiliary data array.
118 * @param container The container from which to fetch the variable.
120 template <class T, class ALLOC>
123 AtomicDecorator<T, ALLOC>::getDataArray (const AuxVectorData& container) const
124 -> const_container_pointer_type
126 return reinterpret_cast<const_container_pointer_type>
127 (container.getDataArray (Base::auxid()));
132 * @brief Get a pointer to the start of the auxiliary data array.
133 * @param container The container from which to fetch the variable.
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.
139 template <class T, class ALLOC>
142 AtomicDecorator<T, ALLOC>::getDecorationArray (const AuxVectorData& container) const
143 -> container_pointer_type
145 return reinterpret_cast<container_pointer_type>
146 (container.getDecorationArray (Base::auxid()));