ATLAS Offline Software
SlotSpecificObj.icc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration.
3  */
4 // $Id$
5 /**
6  * @file AthenaKernel/SlotSpecificObj.icc
7  * @author scott snyder <snyder@bnl.gov>
8  * @date Jul, 2017
9  * @brief Maintain a set of objects, one per slot.
10  */
11 
12 
13 #include <cassert>
14 
15 
16 namespace SG {
17 
18 
19 /**
20  * @brief Constructor.
21  *
22  * The number of slots will be found by calling @c getNSlots().
23  */
24 template <class T>
25 inline
26 SlotSpecificObj<T>::SlotSpecificObj()
27  : SlotSpecificObj (getNSlots())
28 {
29 }
30 
31 
32 /**
33  * @brief Constructor, with number of slots specified explicitly.
34  * @param nslots The number of event slots.
35  */
36 template <class T>
37 inline
38 SlotSpecificObj<T>::SlotSpecificObj (size_t nslots)
39  : m_slots (nslots)
40 {
41 }
42 
43 
44 /**
45  * @brief Return pointer to the object for slot given by @c ctx.
46  * @param ctx Event context giving the desired slot.
47  */
48 template <class T>
49 inline
50 T* SlotSpecificObj<T>::get (const EventContext& ctx)
51 {
52  size_t slot = ctx.slot();
53  assert (slot < m_slots.size());
54  return &m_slots[slot];
55 }
56 
57 
58 /**
59  * @brief Return pointer to the object for the current slot.
60  *
61  * The slot number is found by retrieving the global current context.
62  */
63 template <class T>
64 inline
65 T* SlotSpecificObj<T>::get()
66 {
67  return get (Gaudi::Hive::currentContext());
68 }
69 
70 
71 /**
72  * @brief Return pointer to the object for slot given by @c ctx.
73  * @param ctx Event context giving the desired slot.
74  */
75 template <class T>
76 inline
77 const T* SlotSpecificObj<T>::get (const EventContext& ctx) const
78 {
79  size_t slot = ctx.slot();
80  assert (slot < m_slots.size());
81  return &m_slots[slot];
82 }
83 
84 
85 /**
86  * @brief Return pointer to the object for the current slot.
87  *
88  * The slot number is found by retrieving the global current context.
89  */
90 template <class T>
91 inline
92 const T* SlotSpecificObj<T>::get() const
93 {
94  return get (Gaudi::Hive::currentContext());
95 }
96 
97 
98 /**
99  * @brief Dereference the pointer.
100  *
101  * The slot number is found by retrieving the global current context.
102  */
103 template <class T>
104 inline
105 T& SlotSpecificObj<T>::operator* ()
106 {
107  return *get();
108 }
109 
110 
111 /**
112  * @brief Dereference the pointer.
113  *
114  * The slot number is found by retrieving the global current context.
115  */
116 template <class T>
117 inline
118 const T& SlotSpecificObj<T>::operator* () const
119 {
120  return *get();
121 }
122 
123 
124 /**
125  * @brief Dereference the pointer.
126  *
127  * The slot number is found by retrieving the global current context.
128  */
129 template <class T>
130 inline
131 T* SlotSpecificObj<T>::operator-> ()
132 {
133  return get();
134 }
135 
136 
137 /**
138  * @brief Dereference the pointer.
139  *
140  * The slot number is found by retrieving the global current context.
141  */
142 template <class T>
143 inline
144 const T* SlotSpecificObj<T>::operator-> () const
145 {
146  return get();
147 }
148 
149 
150 /**
151  * @brief Begin iterator.
152  */
153 template <class T>
154 inline
155 typename SlotSpecificObj<T>::iterator SlotSpecificObj<T>::begin()
156 {
157  return m_slots.begin();
158 }
159 
160 
161 /**
162  * @brief Const begin iterator.
163  */
164 template <class T>
165 inline
166 typename SlotSpecificObj<T>::const_iterator SlotSpecificObj<T>::begin() const
167 {
168  return m_slots.begin();
169 }
170 
171 
172 /**
173  * @brief End iterator.
174  */
175 template <class T>
176 inline
177 typename SlotSpecificObj<T>::iterator SlotSpecificObj<T>::end()
178 {
179  return m_slots.end();
180 }
181 
182 
183 /**
184  * @brief Const end iterator.
185  */
186 template <class T>
187 inline
188 typename SlotSpecificObj<T>::const_iterator SlotSpecificObj<T>::end() const
189 {
190  return m_slots.end();
191 }
192 
193 
194 } // namespace SG