ATLAS Offline Software
SurfaceHolderImpl.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRKEVENTPRIMITIVES_SURFACEHOLDER_H
6 #define TRKEVENTPRIMITIVES_SURFACEHOLDER_H
7 
9 
48 namespace Trk {
49 
50 /*
51  * Implementation based on plain ptr and
52  * isFree semantics
53  */
54 template<typename S>
56 {
57 public:
59  SurfacePtrHolderImpl() = default;
61  explicit SurfacePtrHolderImpl(const S& s)
63  {}
65  explicit SurfacePtrHolderImpl(const S* s)
67  {}
71  {}
75  {
76  // tranfer ownership and leave other nullptr
77  m_associatedSurface = other.m_associatedSurface;
78  other.m_associatedSurface = nullptr;
79  }
83  {
84  if (this != &other) {
85  destroySurface(); // clean up ourselves
86  m_associatedSurface = cloneHelper(other.m_associatedSurface);
87  }
88  return *this;
89  }
90 
94  {
95  // destroy current surface
97  // steal payload of other and leave it to nullptr
98  this->m_associatedSurface = other.m_associatedSurface;
99  other.m_associatedSurface = nullptr;
100  return *this;
101  }
105  void destroySurface() noexcept
106  {
107  if (m_associatedSurface && m_associatedSurface->isFree()) {
108  delete m_associatedSurface;
109  }
110  //
111  m_associatedSurface = nullptr;
112  }
114  const S* surfacePtr() { return m_associatedSurface; }
116  const S* release() noexcept
117  {
118  const S* tmp = m_associatedSurface;
119  m_associatedSurface = nullptr;
120  return tmp;
121  }
124  static const S* cloneHelper(const S* input)
125  {
126  return (input && input->isFree() ? input->clone() : input);
127  }
128 
129 protected:
130  const S* m_associatedSurface = nullptr;
131  // protected we can not create instances of this object
132  // is to be used as helper
134 };
135 
136 /*
137  * Implementation based on plain ptr and
138  * has detector Element Semantics
139  */
140 template<typename S>
142 {
143 
144 public:
148  explicit SurfacePtrHolderImplDetEl(const S& s)
150  {}
152  explicit SurfacePtrHolderImplDetEl(const S* s)
154  {}
158  {}
162  {
163  // tranfer ownership and leave other nullptr
164  m_associatedSurface = other.m_associatedSurface;
165  other.m_associatedSurface = nullptr;
166  }
170  {
171  if (this != &other) {
172  destroySurface(); // clean up ourselves
173  m_associatedSurface = cloneHelper(other.m_associatedSurface);
174  }
175  return *this;
176  }
180  SurfacePtrHolderImplDetEl&& other) noexcept
181  {
182  // destroy current surface
183  destroySurface();
184  // steal payload of other and leave it to nullptr
185  this->m_associatedSurface = other.m_associatedSurface;
186  other.m_associatedSurface = nullptr;
187  return *this;
188  }
190  const S* surfacePtr() { return m_associatedSurface; }
192  const S* release() noexcept
193  {
194  const S* tmp = m_associatedSurface;
195  m_associatedSurface = nullptr;
196  return tmp;
197  }
201  void destroySurface() noexcept
202  {
203  if (m_associatedSurface &&
204  m_associatedSurface->associatedDetectorElement() == nullptr) {
205  delete m_associatedSurface;
206  }
207  //
208  m_associatedSurface = nullptr;
209  }
210 
213  static const S* cloneHelper(const S* input)
214  {
215  return (input && input->associatedDetectorElement() == nullptr
216  ? input->clone()
217  : input);
218  }
219 
220 protected:
221  const S* m_associatedSurface = nullptr;
222  // protected we can not create instances of this object
223  // is to be used as helper
225 };
226 
227 /*
228  * Implementation based on SurfaceUniquePtr
229  */
230 template<typename S>
232 {
233 public:
236 
239 
240  explicit SurfaceUniqHolderImpl(const S& s)
241  : m_associatedSurface(s.isFree() ? s.clone() : &s)
242  {}
243 
245  explicit SurfaceUniqHolderImpl(const S* s)
247  {}
248 
253  other.m_associatedSurface->isFree()
256  {}
257 
260 
264  {
265  if (this != &other) {
266  m_associatedSurface.reset(
267  (other.m_associatedSurface && other.m_associatedSurface->isFree())
268  ? other.m_associatedSurface->clone()
269  : other.m_associatedSurface.get());
270  }
271  return *this;
272  }
273 
276 
278  const S* surfacePtr() { return m_associatedSurface.get(); }
279 
282  void destroySurface() noexcept { m_associatedSurface.reset(); }
283 
285  const S* release() noexcept { return m_associatedSurface.release(); }
286 
287 protected:
289  // protected we can not create instances of this object
290  // is to be used as helper
292 };
293 }
294 
295 #endif
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(const SurfacePtrHolderImplDetEl &other)
copy ctor
Definition: SurfaceHolderImpl.h:156
Trk::SurfacePtrHolderImplDetEl::operator=
SurfacePtrHolderImplDetEl & operator=(const SurfacePtrHolderImplDetEl &other)
copy assingmemnt if surface is free we clone/copy.
Definition: SurfaceHolderImpl.h:169
Trk::SurfacePtrHolderImpl::cloneHelper
static const S * cloneHelper(const S *input)
Helper for cloning or not when we need depending on if the surface isFree.
Definition: SurfaceHolderImpl.h:124
SurfaceUniquePtrT.h
Handle conditional ownership of surfaces.
Trk::SurfacePtrHolderImpl::surfacePtr
const S * surfacePtr()
return the ptr we hold useful for tests
Definition: SurfaceHolderImpl.h:114
Trk::SurfacePtrHolderImplDetEl::operator=
SurfacePtrHolderImplDetEl & operator=(SurfacePtrHolderImplDetEl &&other) noexcept
Move assignement we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:179
Trk::SurfacePtrHolderImplDetEl::release
const S * release() noexcept
release ala unique_ptr release
Definition: SurfaceHolderImpl.h:192
Trk::SurfacePtrHolderImpl::destroySurface
void destroySurface() noexcept
destroySurface deletes the ptr if not null and the surface isFree Usefull also for testing
Definition: SurfaceHolderImpl.h:105
Trk::SurfacePtrHolderImpl
Definition: SurfaceHolderImpl.h:56
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
Trk::SurfacePtrHolderImpl::release
const S * release() noexcept
release ala unique_ptr release
Definition: SurfaceHolderImpl.h:116
Trk::SurfacePtrHolderImplDetEl::m_associatedSurface
const S * m_associatedSurface
Definition: SurfaceHolderImpl.h:221
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(const S *s)
ctor from const Surface ptr. Takes ownership
Definition: SurfaceHolderImpl.h:245
python.Utilities.clone
clone
Definition: Utilities.py:134
Trk::SurfacePtrHolderImplDetEl::destroySurface
void destroySurface() noexcept
destroySurface deletes the ptr if not null and the surface has not a associatedDetectorElement Useful...
Definition: SurfaceHolderImpl.h:201
Trk::SurfaceUniqHolderImpl::~SurfaceUniqHolderImpl
~SurfaceUniqHolderImpl()=default
Trk::SurfacePtrHolderImplDetEl::~SurfacePtrHolderImplDetEl
~SurfacePtrHolderImplDetEl()
Definition: SurfaceHolderImpl.h:224
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(const SurfaceUniqHolderImpl &other)
copy ctor, if surface is free we clone/copy.
Definition: SurfaceHolderImpl.h:251
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(SurfaceUniqHolderImpl &&) noexcept=default
default move ctor
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(SurfacePtrHolderImpl &&other) noexcept
Move constructor we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:74
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(const S &s)
ctor from const Surface ref.
Definition: SurfaceHolderImpl.h:148
Trk::SurfacePtrHolderImpl::operator=
SurfacePtrHolderImpl & operator=(SurfacePtrHolderImpl &&other) noexcept
Move assignement we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:93
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(const S &s)
ctor from const Surface ref.
Definition: SurfaceHolderImpl.h:240
Trk::SurfacePtrHolderImpl::m_associatedSurface
const S * m_associatedSurface
Definition: SurfaceHolderImpl.h:130
Trk::SurfaceUniqHolderImpl::operator=
SurfaceUniqHolderImpl & operator=(SurfaceUniqHolderImpl &&) noexcept=default
default move assignement
Trk::SurfacePtrHolderImplDetEl::surfacePtr
const S * surfacePtr()
return the ptr we hold useful for tests
Definition: SurfaceHolderImpl.h:190
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(SurfacePtrHolderImplDetEl &&other) noexcept
Move constructor we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:161
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(const S *s)
ctor from const Surface ptr. Takes ownership
Definition: SurfaceHolderImpl.h:65
Trk::SurfacePtrHolderImplDetEl::cloneHelper
static const S * cloneHelper(const S *input)
Helper for cloning or not when we need depending on if we have an associatedDetectorElement.
Definition: SurfaceHolderImpl.h:213
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::SurfaceUniqHolderImpl::surfacePtr
const S * surfacePtr()
return the ptr we hold
Definition: SurfaceHolderImpl.h:278
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(const S *s)
ctor from const Surface ptr. Takes ownership
Definition: SurfaceHolderImpl.h:152
Trk::SurfaceUniquePtrT
std::unique_ptr< S, SurfaceDeleter< S > > SurfaceUniquePtrT
Definition: SurfaceUniquePtrT.h:32
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl()=default
default ctor
python.CaloAddPedShiftConfig.default
default
Definition: CaloAddPedShiftConfig.py:43
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Trk::SurfacePtrHolderImpl::~SurfacePtrHolderImpl
~SurfacePtrHolderImpl()
Definition: SurfaceHolderImpl.h:133
Trk::SurfaceUniqHolderImpl
Definition: SurfaceHolderImpl.h:232
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl()=default
default ctor
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(const SurfacePtrHolderImpl &other)
copy ctor
Definition: SurfaceHolderImpl.h:69
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
Trk::SurfacePtrHolderImplDetEl
Definition: SurfaceHolderImpl.h:142
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
Trk::SurfaceUniqHolderImpl::m_associatedSurface
SurfaceUniquePtrT< const S > m_associatedSurface
Definition: SurfaceHolderImpl.h:288
Trk::SurfacePtrHolderImpl::operator=
SurfacePtrHolderImpl & operator=(const SurfacePtrHolderImpl &other)
copy assingmemnt if surface is free we clone/copy.
Definition: SurfaceHolderImpl.h:82
Trk::SurfaceUniqHolderImpl::release
const S * release() noexcept
release , release the unique_ptr we hold
Definition: SurfaceHolderImpl.h:285
Trk::SurfaceUniqHolderImpl::destroySurface
void destroySurface() noexcept
destroySurface deletes the ptr if not null and is free usefull also for testing
Definition: SurfaceHolderImpl.h:282
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(const S &s)
ctor from const Surface ref.
Definition: SurfaceHolderImpl.h:61
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl()=default
default ctor