ATLAS Offline Software
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-2024 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 
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 AtomicConstAccessor<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  */
37 template <class T, class ALLOC>
38 inline
39 AtomicConstAccessor<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  */
52 template <class T, class ALLOC>
53 inline
54 AtomicConstAccessor<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  */
67 template <class T, class ALLOC>
68 template <class ELT>
69 ATH_REQUIRES( IsConstAuxElement<ELT> )
70 inline
71 T AtomicConstAccessor<T, ALLOC>::operator() (const ELT& e) const
72 {
73  return reinterpret_cast<const_reference_type> (Base::operator() (e));
74 }
75 
76 
77 /**
78  * @brief Fetch the variable for one element, as a const reference.
79  * @param container The container from which to fetch the variable.
80  * @param index The index of the desired element.
81  *
82  * This allows retrieving aux data by container / index.
83  * Looping over the index via this method will be faster then
84  * looping over the elements of the container.
85  *
86  * As this class can be used only read-only for basic types, return
87  * the result by value. That makes it easier to call from python.
88  */
89 template <class T, class ALLOC>
90 inline
91 T AtomicConstAccessor<T, ALLOC>::operator() (const AuxVectorData& container,
92  size_t index) const
93 {
94  return reinterpret_cast<const_reference_type> (Base::operator() (container, index));
95 }
96 
97 
98 /**
99  * @brief Get a pointer to the start of the auxiliary data array.
100  * @param container The container from which to fetch the variable.
101  */
102 template <class T, class ALLOC>
103 inline
104 auto
105 AtomicConstAccessor<T, ALLOC>::getDataArray (const AuxVectorData& container) const
106  -> const_container_pointer_type
107 {
108  return reinterpret_cast<const_container_pointer_type>
109  (container.getDataArray (Base::auxid()));
110 }
111 
112 
113 } // namespace SG